Skip to content

Commit d9f6de5

Browse files
committed
rewrite modm::ui::color
1 parent c47e7b7 commit d9f6de5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2503
-1731
lines changed

examples/arduino_nano/color/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Sensorthread : public modm::pt::Protothread
6565
if (PT_CALL(sensor.readColor()))
6666
{
6767
const auto rgb = data.getColor();
68-
MODM_LOG_INFO << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv(rgb) << modm::endl;
68+
MODM_LOG_INFO << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv888(rgb) << modm::endl;
6969
}
7070
}
7171

examples/avr/display/dogm128/image/main.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,9 @@ drawNumber(modm::glcd::Point cursor, uint8_t number)
203203
int
204204
main()
205205
{
206-
led::R::set();
207-
led::G::set();
208-
led::B::reset();
209-
210-
led::R::setOutput();
211-
led::G::setOutput();
212-
led::B::setOutput();
206+
led::R::setOutput(true);
207+
led::G::setOutput(true);
208+
led::B::setOutput(false);
213209

214210
lcd::SPI::connect<lcd::Sck::BitBang, lcd::Mosi::BitBang>();
215211
lcd::SPI::initialize<SystemClock, 2_MHz>();

examples/nucleo_f446re/color/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ThreadOne : public modm::pt::Protothread
6464
if (PT_CALL(sensor.readColor()))
6565
{
6666
const auto rgb = data.getColor();
67-
MODM_LOG_INFO << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv(rgb) << modm::endl;
67+
MODM_LOG_INFO << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv888(rgb) << modm::endl;
6868
}
6969
timeout.restart(500ms);
7070
PT_WAIT_UNTIL(timeout.isExpired());

examples/stm32f469_discovery/game_of_life/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ uint16_t * displayBuffer;
7272
#define TRAIL_LENGTH ((1 << TRAIL_POWER) + 1)
7373
constexpr uint8_t alive = (1 << TRAIL_POWER);
7474

75-
#define COLOR_SHADE(red, green, blue, fraction) modm::color::Rgb(\
75+
#define COLOR_SHADE(red, green, blue, fraction) modm::color::Rgb888(\
7676
uint8_t(uint32_t(red) * (fraction) / TRAIL_LENGTH), \
7777
uint8_t(uint32_t(green) * (fraction) / TRAIL_LENGTH), \
7878
uint8_t(uint32_t(blue) * (fraction) / TRAIL_LENGTH) )
@@ -137,7 +137,7 @@ static inline void touch(framebuffer_t buffer)
137137

138138
static inline void setPixel(int x, int y, uint8_t color)
139139
{
140-
#define DRAW(x, y) displayBuffer[(y) * 800 + (x)] = GET_TRAIL_COLOR(color).color;
140+
#define DRAW(x, y) displayBuffer[(y) * 800 + (x)] = GET_TRAIL_COLOR(color).value();
141141
#if SCALE >= 8
142142
// >:v x:y
143143
// 0 | |
@@ -148,7 +148,7 @@ static inline void setPixel(int x, int y, uint8_t color)
148148
// 5 | x x |
149149
// 6 | xxxx |
150150
// 7 | |
151-
GET_TRAIL_COLOR(color).color;
151+
GET_TRAIL_COLOR(color).value();
152152
// 1
153153
DRAW(x+2, y+1);
154154
DRAW(x+3, y+1);

examples/stm32f4_discovery/colour_tcs3414/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ThreadOne : public modm::pt::Protothread
9999
{
100100
if (PT_CALL(sensor.readColor())) {
101101
const auto rgb = data.getColor();
102-
stream << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv(rgb) << modm::endl;
102+
stream << "RGB: " << rgb << "\tHSV: " << modm::color::Hsv888(rgb) << modm::endl;
103103
}
104104
timeout.restart(500ms);
105105
PT_WAIT_UNTIL(timeout.isExpired());

src/modm/board/disco_f469ni/board_display.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DsiDisplay : public modm::ColorGraphicDisplay
4949
void
5050
clear() final
5151
{
52-
std::fill(buffer, buffer + this->getBufferWidth()*this->getBufferHeight(), this->backgroundColor.color);
52+
std::fill(buffer, buffer + this->getBufferWidth()*this->getBufferHeight(), this->backgroundColor.value());
5353
}
5454

5555
void
@@ -62,21 +62,21 @@ class DsiDisplay : public modm::ColorGraphicDisplay
6262
setPixel(int16_t x, int16_t y) final
6363
{
6464
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return;
65-
buffer[y * 800 + x] = this->foregroundColor.color;
65+
buffer[y * 800 + x] = this->foregroundColor.value();
6666
}
6767

6868
void
6969
clearPixel(int16_t x, int16_t y) final
7070
{
7171
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return;
72-
buffer[y * 800 + x] = this->backgroundColor.color;
72+
buffer[y * 800 + x] = this->backgroundColor.value();
7373
}
7474

7575
modm::color::Rgb565
7676
getPixel(int16_t x, int16_t y) const final
7777
{
78-
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return false;
79-
return buffer[y * 800 + x];
78+
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return modm::color::html::Black;
79+
return modm::color::Rgb565(buffer[y * 800 + x]);
8080
}
8181

8282
protected:

src/modm/driver/color/tcs3414.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct tcs3414
123123
};
124124

125125

126-
using Rgb = color::RgbT<uint16_t>;
126+
using Rgb = color::Rgb161616;
127127

128128
struct modm_packed
129129
Data

src/modm/driver/color/tcs3472.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct tcs3472
139139
addr(uint8_t version=5)
140140
{ return version < 5 ? 0x39 : 0x29; }
141141

142-
using Rgb = color::RgbT<uint16_t>;
142+
using Rgb = color::Rgb161616;
143143

144144
struct modm_packed
145145
Data

src/modm/driver/display/ili9341_impl.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void
202202
Ili9341<Interface, Reset, Backlight, BufferSize>::drawHorizontalLine(
203203
glcd::Point start, uint16_t length)
204204
{
205-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
205+
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.value()) };
206206
auto minLength { std::min(std::size_t(length), BufferSize) };
207207
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
208208
std::fill(buffer16, buffer16+minLength, pixelValue);
@@ -223,7 +223,7 @@ void
223223
Ili9341<Interface, Reset, Backlight, BufferSize>::drawVerticalLine(
224224
glcd::Point start, uint16_t length)
225225
{
226-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
226+
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.value()) };
227227
auto minLength { std::min(std::size_t(length), BufferSize) };
228228
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
229229
std::fill(buffer16, buffer16+minLength, pixelValue);
@@ -248,7 +248,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillRectangle(
248248
auto const y { upperLeft.getY() };
249249
std::size_t pixelCount { std::size_t(width) * std::size_t(height) };
250250

251-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
251+
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.value()) };
252252
auto minLength { std::min(std::size_t(pixelCount), BufferSize) };
253253
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
254254
std::fill(buffer16, buffer16+minLength, pixelValue);
@@ -270,8 +270,8 @@ void
270270
Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
271271
glcd::Point center, uint16_t radius)
272272
{
273-
uint8_t const setColor[] { uint8_t((foregroundColor.color >> 8) & 0xff),
274-
uint8_t(foregroundColor.color & 0xff) };
273+
uint8_t const setColor[] { uint8_t((foregroundColor.value() >> 8) & 0xff),
274+
uint8_t(foregroundColor.value() & 0xff) };
275275

276276
int16_t f = 1 - radius;
277277
int16_t ddF_x = 0;
@@ -317,10 +317,10 @@ void
317317
Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upperLeft,
318318
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t> data)
319319
{
320-
uint8_t const setColor[] { uint8_t((foregroundColor.color >> 8) & 0xff),
321-
uint8_t(foregroundColor.color & 0xff) };
322-
uint8_t const clearColor[] { uint8_t((backgroundColor.color >> 8) & 0xff),
323-
uint8_t(backgroundColor.color & 0xff) };
320+
uint8_t const setColor[] { uint8_t((foregroundColor.value() >> 8) & 0xff),
321+
uint8_t(foregroundColor.value() & 0xff) };
322+
uint8_t const clearColor[] { uint8_t((backgroundColor.value() >> 8) & 0xff),
323+
uint8_t(backgroundColor.value() & 0xff) };
324324

325325
BatchHandle h(*this);
326326

@@ -392,7 +392,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::setColoredPixel(
392392
int16_t x, int16_t y, color::Rgb565 const &color)
393393
{
394394
auto const pixelColor { color };
395-
uint8_t const setColor[] { uint8_t((pixelColor.color >> 8) & 0xff), uint8_t(pixelColor.color & 0xff) };
395+
uint8_t const setColor[] { uint8_t((pixelColor.value() >> 8) & 0xff), uint8_t(pixelColor.value() & 0xff) };
396396

397397
BatchHandle h(*this);
398398

src/modm/driver/display/parallel_tft_impl.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ modm::ParallelTft<INTERFACE>::clear()
110110
interface.writeIndex(0x0022);
111111
for (uint32_t i = 0; i < MAX_X * MAX_Y; i++)
112112
{
113-
interface.writeData(backgroundColor.color);
113+
interface.writeData(backgroundColor.value());
114114
}
115115
}
116116

@@ -123,7 +123,7 @@ modm::ParallelTft<INTERFACE>::setPixel(int16_t x, int16_t y)
123123
}
124124

125125
writeCursor(x, y);
126-
interface.writeRegister(0x0022, foregroundColor.color);
126+
interface.writeRegister(0x0022, foregroundColor.value());
127127
}
128128

129129
template <typename INTERFACE>
@@ -138,7 +138,7 @@ modm::ParallelTft<INTERFACE>::clearPixel(int16_t x, int16_t y)
138138
// }
139139
//
140140
// writeCursor(x, y);
141-
// interface.writeRegister(0x0022, color.getValue());
141+
// interface.writeRegister(0x0022, color.value());
142142
}
143143

144144
template <typename INTERFACE>
@@ -148,7 +148,7 @@ modm::ParallelTft<INTERFACE>::getPixel(int16_t x, int16_t y) const
148148
(void) x;
149149
(void) y;
150150

151-
return false;
151+
return modm::color::Rgb565();
152152
}
153153

154154
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)