Skip to content

Commit 7db1732

Browse files
committed
rewrite modm::ui::color
1 parent 7f30961 commit 7db1732

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

+2502
-1731
lines changed

examples/arduino_nano/color/main.cpp

+1-1
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

+3-7
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

+1-1
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

+3-3
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

+1-1
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

+5-5
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

+1-1
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

+1-1
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

+10-10
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

+4-4
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
// ----------------------------------------------------------------------------

src/modm/driver/pwm/apa102.hpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,28 @@ class Apa102
4343
}
4444

4545
bool
46-
setColorBrightness(size_t index, const color::Rgb &color, uint8_t brightness)
46+
setColorBrightness(size_t index, const color::RgbPallete<8,8,8> &color, uint8_t brightness)
4747
{
4848
if (index >= LEDs) return false;
49-
uint32_t value = (color.red << 24) | (color.green << 16) |
50-
(color.blue << 8) | (brightness | 0xe0);
49+
uint32_t value = color.value() << 8 | (brightness | 0xe0);
5150
reinterpret_cast<uint32_t*>(data)[1+index] = value;
5251
return true;
5352
}
5453

5554
bool
56-
setColor(size_t index, const color::Rgb &color)
55+
setColor(size_t index, const color::RgbPallete<8,8,8> &color)
5756
{
5857
if (index >= LEDs) return false;
5958
// read the brightness value and clear all colors
6059
uint32_t value = reinterpret_cast<const uint32_t*>(data)[1+index] & 0xfful;
6160
// set all colors
62-
value |= (color.red << 24) | (color.green << 16) | (color.blue << 8);
61+
value |= color.value() << 8;
6362
// write back entire value
6463
reinterpret_cast<uint32_t*>(data)[1+index] = value;
6564
return true;
6665
}
6766

68-
color::Rgb
67+
color::Rgb888
6968
getColor(size_t index) const
7069
{
7170
if (index >= LEDs) return {};

src/modm/driver/pwm/sk6812w.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class Sk6812w
7272
}
7373

7474
void
75-
setColorBrightness(size_t index, const color::Rgb &color, uint8_t brightness)
75+
setColorBrightness(size_t index, const color::Rgb888 &color, uint8_t brightness)
7676
{
7777
if (index >= LEDs) return;
7878

79-
const uint8_t colors[] = {color.green, color.red, color.blue, brightness};
79+
const uint8_t colors[] = {color.green(), color.red(), color.blue(), brightness};
8080
for (size_t ii = 0; ii < 4; ii++)
8181
{
8282
const uint32_t c = (spread(colors[ii]) << 12) | spread(colors[ii] >> 4);
@@ -86,11 +86,11 @@ class Sk6812w
8686
}
8787

8888
void
89-
setColor(size_t index, const color::Rgb &color)
89+
setColor(size_t index, const color::Rgb888 &color)
9090
{
9191
if (index >= LEDs) return;
9292

93-
const uint8_t colors[] = {color.green, color.red, color.blue};
93+
const uint8_t colors[] = {color.green(), color.red(), color.blue()};
9494
for (size_t ii = 0; ii < 3; ii++)
9595
{
9696
const uint32_t c = (spread(colors[ii]) << 12) | spread(colors[ii] >> 4);
@@ -99,7 +99,7 @@ class Sk6812w
9999
}
100100
}
101101

102-
color::Rgb
102+
color::Rgb888
103103
getColor(size_t index) const
104104
{
105105
if (index >= LEDs) return {};

src/modm/driver/pwm/ws2812b.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class Ws2812b
7272
}
7373

7474
void
75-
setColor(size_t index, const color::Rgb &color)
75+
setColor(size_t index, const color::Rgb888 &color)
7676
{
7777
if (index >= LEDs) return;
7878

79-
const uint8_t colors[3] = {color.green, color.red, color.blue};
79+
const uint8_t colors[3] = {color.green(), color.red(), color.blue()};
8080
for (size_t ii = 0; ii < 3; ii++)
8181
{
8282
const uint32_t c = (spread(colors[ii]) << 12) | spread(colors[ii] >> 4);
@@ -85,7 +85,7 @@ class Ws2812b
8585
}
8686
}
8787

88-
color::Rgb
88+
color::Rgb888
8989
getColor(size_t index) const
9090
{
9191
if (index >= LEDs) return {};

src/modm/math/filter/s_curve_controller_impl.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#error "Don't include this file directly, use 's_curve_controller.hpp' instead!"
2020
#endif
2121

22-
22+
#include <algorithm>
2323
#include <modm/math/utils.hpp>
2424

2525
// ----------------------------------------------------------------------------
@@ -113,9 +113,9 @@ modm::SCurveController<T>::update(T error, const T& speed)
113113
outputDecrement = std::sqrt(error * parameter.decreaseFactor * 2);
114114
}
115115

116-
output = modm::min(outputIncrement, outputDecrement);
116+
output = std::min(outputIncrement, outputDecrement);
117117
// TODO smooth breaking if the speedMaximum has changed to a lower value
118-
output = modm::min(output, parameter.speedMaximum);
118+
output = std::min(output, parameter.speedMaximum);
119119

120120
if (output < parameter.speedMinimum) {
121121
output = parameter.speedMinimum;

0 commit comments

Comments
 (0)