Skip to content

Commit

Permalink
refactored modm::ui::color
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Apr 18, 2021
1 parent 02660d0 commit a122503
Show file tree
Hide file tree
Showing 26 changed files with 501 additions and 429 deletions.
7 changes: 2 additions & 5 deletions examples/arduino_nano/color/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ class Sensorthread : public modm::pt::Protothread
PT_WAIT_UNTIL(TCS3472_INT::read() == false);
if (PT_CALL(sensor.readColor()))
{
const auto color = data.getColor();
MODM_LOG_INFO << "RGB: " << color;
modm::color::HsvT<uint16_t> hsv;
color.toHsv(&hsv);
MODM_LOG_INFO << "\tHSV: " << hsv << modm::endl;
const auto rgb = data.getColor();
MODM_LOG_INFO << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv(rgb) << modm::endl;
}
}

Expand Down
20 changes: 7 additions & 13 deletions examples/nucleo_f446re/color/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// ----------------------------------------------------------------------------

#include <modm/board.hpp>
#include <modm/processing.hpp>
#include <modm/driver/color/tcs3472.hpp>
#include <modm/processing.hpp>

class ThreadOne : public modm::pt::Protothread
{
Expand All @@ -28,9 +28,7 @@ class ThreadOne : public modm::pt::Protothread
while (true)
{
// we wait until the task started
if (PT_CALL(sensor.ping())) {
break;
}
if (PT_CALL(sensor.ping())) { break; }
// otherwise, try again in 100ms
timeout.restart(100ms);
PT_WAIT_UNTIL(timeout.isExpired());
Expand All @@ -40,9 +38,7 @@ class ThreadOne : public modm::pt::Protothread

while (true)
{
if (PT_CALL(sensor.initialize())) {
break;
}
if (PT_CALL(sensor.initialize())) { break; }
// otherwise, try again in 100ms
timeout.restart(100ms);
PT_WAIT_UNTIL(timeout.isExpired());
Expand All @@ -52,7 +48,8 @@ class ThreadOne : public modm::pt::Protothread

while (true)
{
if (PT_CALL(sensor.configure(sensor.Gain::X4, sensor.IntegrationTime::MSEC_101))) {
if (PT_CALL(sensor.configure(sensor.Gain::X4, sensor.IntegrationTime::MSEC_101)))
{
break;
}
// otherwise, try again in 100ms
Expand All @@ -66,11 +63,8 @@ class ThreadOne : public modm::pt::Protothread
{
if (PT_CALL(sensor.readColor()))
{
const auto color = data.getColor();
MODM_LOG_INFO << "RGB: " << color;
modm::color::HsvT<uint16_t> hsv;
color.toHsv(&hsv);
MODM_LOG_INFO << "\tHSV: " << hsv << modm::endl;
const auto rgb = data.getColor();
MODM_LOG_INFO << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv(rgb) << modm::endl;
}
timeout.restart(500ms);
PT_WAIT_UNTIL(timeout.isExpired());
Expand Down
4 changes: 2 additions & 2 deletions examples/stm32f469_discovery/game_of_life/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ uint16_t * displayBuffer;
#define TRAIL_LENGTH ((1 << TRAIL_POWER) + 1)
constexpr uint8_t alive = (1 << TRAIL_POWER);

#define COLOR_SHADE(red, green, blue, fraction) Color( \
#define COLOR_SHADE(red, green, blue, fraction) modm::color::Rgb565( \
uint8_t(uint32_t(red) * (fraction) / TRAIL_LENGTH), \
uint8_t(uint32_t(green) * (fraction) / TRAIL_LENGTH), \
uint8_t(uint32_t(blue) * (fraction) / TRAIL_LENGTH) )
Expand Down Expand Up @@ -137,7 +137,7 @@ static inline void touch(framebuffer_t buffer)

static inline void drawPixel(int x, int y, uint8_t color)
{
#define DRAW(x, y) displayBuffer[(y) * 800 + (x)] = GET_TRAIL_COLOR(color).getValue();
#define DRAW(x, y) displayBuffer[(y) * 800 + (x)] = GET_TRAIL_COLOR(color).color;
#if SCALE >= 8
// >:v x:y
// 0 | |
Expand Down
7 changes: 2 additions & 5 deletions examples/stm32f4_discovery/colour_tcs3414/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ class ThreadOne : public modm::pt::Protothread
while (true)
{
if (PT_CALL(sensor.readColor())) {
auto color = data.getColor();
stream << "RGB: " << color;
modm::color::HsvT<uint16_t> hsv;
color.toHsv(&hsv);
stream << "\tHSV: " << hsv << modm::endl;
const auto rgb = data.getColor();
stream << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv(rgb) << modm::endl;
}
timeout.restart(500ms);
PT_WAIT_UNTIL(timeout.isExpired());
Expand Down
8 changes: 4 additions & 4 deletions src/modm/board/disco_f469ni/board_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DsiDisplay : public modm::GraphicDisplay
{
for (int ii = 0; ii < 800*480; ii++)
{
buffer[ii] = this->backgroundColor.getValue();
buffer[ii] = this->backgroundColor.color;
}
}

Expand All @@ -51,21 +51,21 @@ class DsiDisplay : public modm::GraphicDisplay
setPixel(int16_t x, int16_t y) override
{
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return;
buffer[y * 800 + x] = this->foregroundColor.getValue();
buffer[y * 800 + x] = this->foregroundColor.color;
}

void
clearPixel(int16_t x, int16_t y) override
{
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return;
buffer[y * 800 + x] = this->backgroundColor.getValue();
buffer[y * 800 + x] = this->backgroundColor.color;
}

bool
getPixel(int16_t x, int16_t y) override
{
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return false;
return (buffer[y * 800 + x] != this->backgroundColor.getValue());
return (buffer[y * 800 + x] != this->backgroundColor.color);
}

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/modm/driver/display/ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Ili9341 : public Interface, public modm::GraphicDisplay
modm::accessor::Flash<uint8_t> data) override;

virtual void
drawRaw(glcd::Point upperLeft, uint16_t width, uint16_t height, glcd::Color* data);
drawRaw(glcd::Point upperLeft, uint16_t width, uint16_t height, color::Rgb565* data);

void
setScrollArea(uint16_t topFixedRows, uint16_t bottomFixedRows, uint16_t firstRow);
Expand Down Expand Up @@ -280,7 +280,7 @@ class Ili9341 : public Interface, public modm::GraphicDisplay

private:
void
setColoredPixel(int16_t x, int16_t y, glcd::Color const &color);
setColoredPixel(int16_t x, int16_t y, color::Rgb565 const &color);
void
setClipping(uint16_t x, uint16_t y, uint16_t width, uint16_t height);

Expand Down
18 changes: 9 additions & 9 deletions src/modm/driver/display/ili9341_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void
Ili9341<Interface, Reset, Backlight, BufferSize>::drawHorizontalLine(
glcd::Point start, uint16_t length)
{
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.getValue()) };
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
auto minLength { std::min(std::size_t(length), BufferSize) };
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
std::fill(buffer16, buffer16+minLength, pixelValue);
Expand All @@ -223,7 +223,7 @@ void
Ili9341<Interface, Reset, Backlight, BufferSize>::drawVerticalLine(
glcd::Point start, uint16_t length)
{
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.getValue()) };
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
auto minLength { std::min(std::size_t(length), BufferSize) };
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
std::fill(buffer16, buffer16+minLength, pixelValue);
Expand All @@ -248,7 +248,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillRectangle(
auto const y { upperLeft.getY() };
std::size_t pixelCount { std::size_t(width) * std::size_t(height) };

uint16_t const pixelValue { modm::toBigEndian(foregroundColor.getValue()) };
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
auto minLength { std::min(std::size_t(pixelCount), BufferSize) };
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
std::fill(buffer16, buffer16+minLength, pixelValue);
Expand All @@ -270,7 +270,7 @@ void
Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
glcd::Point center, uint16_t radius)
{
auto const fgColor { foregroundColor.getValue() };
auto const fgColor { foregroundColor.color };
uint8_t const setColor[] { uint8_t((fgColor >> 8) & 0xff),
uint8_t(fgColor & 0xff) };

Expand Down Expand Up @@ -318,8 +318,8 @@ void
Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upperLeft,
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t> data)
{
auto const fgColor { foregroundColor.getValue() };
auto const bgColor { backgroundColor.getValue() };
auto const fgColor { foregroundColor.color };
auto const bgColor { backgroundColor.color };
uint8_t const setColor[] { uint8_t((fgColor >> 8) & 0xff),
uint8_t(fgColor & 0xff) };
uint8_t const clearColor[] { uint8_t((bgColor >> 8) & 0xff),
Expand Down Expand Up @@ -350,7 +350,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
void
Ili9341<Interface, Reset, Backlight, BufferSize>::drawRaw(glcd::Point upperLeft,
uint16_t width, uint16_t height, glcd::Color* data)
uint16_t width, uint16_t height, color::Rgb565* data)
{
BatchHandle h(*this);

Expand Down Expand Up @@ -392,9 +392,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::scrollTo(uint16_t row)
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
void
Ili9341<Interface, Reset, Backlight, BufferSize>::setColoredPixel(
int16_t x, int16_t y, glcd::Color const &color)
int16_t x, int16_t y, color::Rgb565 const &color)
{
auto const pixelColor { color.getValue() };
auto const pixelColor { color.color };
uint8_t const setColor[] { uint8_t((pixelColor >> 8) & 0xff), uint8_t(pixelColor & 0xff) };

BatchHandle h(*this);
Expand Down
4 changes: 2 additions & 2 deletions src/modm/driver/display/parallel_tft_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ modm::ParallelTft<INTERFACE>::clear()
interface.writeIndex(0x0022);
for (uint32_t i = 0; i < MAX_X * MAX_Y; i++)
{
interface.writeData(backgroundColor.getValue());
interface.writeData(backgroundColor.color);
}
}

Expand All @@ -139,7 +139,7 @@ modm::ParallelTft<INTERFACE>::setPixel(int16_t x, int16_t y)
}

writeCursor(x, y);
interface.writeRegister(0x0022, foregroundColor.getValue());
interface.writeRegister(0x0022, foregroundColor.color);
}

template <typename INTERFACE>
Expand Down
53 changes: 0 additions & 53 deletions src/modm/ui/color.cpp

This file was deleted.

Loading

0 comments on commit a122503

Please sign in to comment.