Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor modm:ui:color #616

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
salkinium marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
11 changes: 6 additions & 5 deletions examples/avr/display/dogm128/benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;
using namespace modm::color::html;


namespace led
Expand Down Expand Up @@ -161,7 +162,7 @@ main()
while (!timer.execute())
{
// rectangle in left side of screen
// TODO display.setColor(Color::black());
// display.setColor(Black);
display.drawRectangle(Point(0, 0), 62, 62);

// rounded rectangle around text area
Expand All @@ -176,14 +177,14 @@ main()
display.drawCircle(Point(31, 31), 31);

// clear previous spinner position
// TODO display.setColor(Color::white());
// TODO display.setColor(White);
display.fillRectangle(Point(87, 40), 16, 16);

static uint8_t loops = 0;
// TODO display.setColor(Color::black());
// TODO display.setColor(Black);
drawSpinner(Point(95, 48), loops++);

// TODO display.setColor(Color::white());
// TODO display.setColor(White);
display.setCursor(Point(25, 40));
display << ++iter;
display.update();
Expand All @@ -192,7 +193,7 @@ main()
// print number of iterations in one second
display.clear();
display.setCursor(Point(80, 10));
// TODO display.setColor(Color::white());
// display.setColor(White);
display << "FPS=" << iter;
}
}
5 changes: 3 additions & 2 deletions examples/avr/display/dogm128/draw/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using namespace modm::platform;
using namespace modm::literals;
using namespace modm::color::html;


namespace led
Expand Down Expand Up @@ -71,11 +72,11 @@ main()

display.fillRectangle(Point(10, 10), 20, 20);
display.fillCircle(Point(45, 40), 23);
// TODO display.setColor(Color::white());
// display.setColor(White);
display.fillRectangle(Point(20, 20), 20, 20);
display.fillCircle(Point(55, 50), 8);

// TODO display.setColor(Color::black());
// display.setColor(Black);
display.drawLine(Point(0, 0), Point(127, 63));

display.update();
Expand Down
3 changes: 2 additions & 1 deletion examples/blue_pill_f103/graphics/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ main()
tft.initialize();
tft.enableBacklight(true);
LedGreen::set();
tft.setColor(modm::glcd::Color::black());
tft.setColor(modm::color::html::Black);

int16_t w = tft.getWidth();
int16_t h = tft.getHeight();
tft.drawLine({0,0}, {w, h});
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
17 changes: 9 additions & 8 deletions examples/nucleo_l452re/graphics_touch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <modm/driver/touch/touch2046.hpp>

using namespace Board;
using namespace modm::color::html;

namespace tft
{
Expand Down Expand Up @@ -86,12 +87,12 @@ main()

LedGreen::set();

tftController.setColor(modm::glcd::Color::black());
tftController.setBackgroundColor(modm::glcd::Color::red());
tftController.setColor(Black);
tftController.setBackgroundColor(Red);
tftController.clear();

tftController.setFont(modm::font::ArcadeClassic);
tftController.setColor(modm::glcd::Color::white());
tftController.setColor(White);
tftController.setCursor(10,12);
tftController << "(10,10)";
tftController.setCursor(150,202);
Expand All @@ -101,7 +102,7 @@ main()
tftController.drawLine(145, 200, 155, 200);
tftController.drawLine(150, 195, 150, 205);

tftController.setColor(modm::glcd::Color::black());
tftController.setColor(Black);
tftController.setFont(modm::font::Ubuntu_36);

int16_t X = 0;
Expand All @@ -113,19 +114,19 @@ main()
LedGreen::set();

std::tie(X, Y, Z) = RF_CALL_BLOCKING(touchController.getRawValues());
tftController.setColor(modm::glcd::Color::red());
tftController.setColor(Red);
tftController.fillRectangle({30, 50}, 90, 115);
tftController.setColor(modm::glcd::Color::black());
tftController.setColor(Black);
tftController.setCursor(0, 50);
tftController << "X=" << X;
tftController.setCursor(0, 90);
tftController << "Y=" << Y;
tftController.setCursor(0, 130);
tftController << "Z=" << Z;

tftController.setColor(modm::glcd::Color::red());
tftController.setColor(Red);
tftController.fillRectangle({30, 220}, 120, 35);
tftController.setColor(modm::glcd::Color::black());
tftController.setColor(Black);
if(RF_CALL_BLOCKING(touchController.isTouched())) {
std::tie(X, Y) = RF_CALL_BLOCKING(touchController.getTouchPosition());
tftController.setCursor(5, 220);
Expand Down
2 changes: 1 addition & 1 deletion examples/nucleo_l452re/lvgl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void my_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t *
{area->x1, area->y1},
(area->x2 - area->x1 +1),
(area->y2 - area->y1 + 1),
(modm::glcd::Color*)color_p);
(modm::color::Rgb565*)color_p);
lv_disp_flush_ready(disp_drv);
}

Expand Down
36 changes: 18 additions & 18 deletions examples/stm32_f4ve/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

#include <modm/ui/gui.hpp>


#include "touchscreen_calibrator.hpp"

#include "images/bluetooth_12x16.hpp"

using namespace modm::color;


// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -166,13 +168,13 @@ initTouchscreen()
static void
drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center)
{
display.setColor(modm::glcd::Color::red());
display.setColor(html::Red);
display.drawLine(center.x - 15, center.y, center.x - 2, center.y);
display.drawLine(center.x + 2, center.y, center.x + 15, center.y);
display.drawLine(center.x, center.y - 15, center.x, center.y - 2);
display.drawLine(center.x, center.y + 2, center.x, center.y + 15);

display.setColor(modm::glcd::Color::white());
display.setColor(html::White);
display.drawLine(center.x - 15, center.y + 15, center.x - 7, center.y + 15);
display.drawLine(center.x - 15, center.y + 7, center.x - 15, center.y + 15);

Expand All @@ -198,7 +200,7 @@ calibrateTouchscreen(modm::ColorGraphicDisplay& display, modm::glcd::Point *fixe
{
display.clear();

display.setColor(modm::glcd::Color::yellow());
display.setColor(modm::color::html::Yellow);
display.setCursor(50, 5);
display << "Touch crosshair to calibrate";

Expand Down Expand Up @@ -385,20 +387,18 @@ test_callback(const modm::gui::InputEvent& ev, modm::gui::Widget* w, void* data)
Board::LedGreen2::toggle();
}


modm::glcd::Color colors[modm::gui::Color::PALETTE_SIZE] {
modm::glcd::Color::black(),
modm::glcd::Color::white(),
modm::glcd::Color::gray(),
modm::glcd::Color::red(),
modm::glcd::Color::green(),
modm::glcd::Color::blue(),
modm::glcd::Color::blue(), // BORDER
modm::glcd::Color::red(), // TEXT
modm::glcd::Color::black(), // BACKGROUND
modm::glcd::Color::red(), // ACTIVATED
modm::glcd::Color::blue(), // DEACTIVATED

modm::color::Rgb565 colors[modm::gui::Color::PALETTE_SIZE] {
html::Black,
html::White,
html::Gray,
html::Red,
html::Green,
html::Blue,
html::Blue, // BORDER
html::Red, // TEXT
html::Black, // BACKGROUND
html::Red, // ACTIVATED
html::Blue, // DEACTIVATED
};
modm::gui::ColorPalette colorpalette{colors};
/*
Expand Down Expand Up @@ -444,7 +444,7 @@ main()
* manipulate the color palette
*/

colorpalette.setColor(modm::gui::Color::TEXT, modm::glcd::Color::yellow());
colorpalette.setColor(modm::gui::Color::TEXT, html::Yellow);


/*
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f469_discovery/display/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ main()
} else {
display.setCursor(rand() % 750, rand() % 460);
display << "Hello World!";
display.setColor(Color(uint16_t(rand())));
display.setColor(uint16_t(rand()));
}
}

Expand Down
8 changes: 4 additions & 4 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::Rgb(\
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 All @@ -82,7 +82,7 @@ constexpr uint8_t alive = (1 << TRAIL_POWER);
COLOR_SHADE(r,g,b,8), COLOR_SHADE(r,g,b,9), COLOR_SHADE(r,g,b,10),COLOR_SHADE(r,g,b,11), \
COLOR_SHADE(r,g,b,12),COLOR_SHADE(r,g,b,13),COLOR_SHADE(r,g,b,14),COLOR_SHADE(r,g,b,15) }

static const Color shades_of_color[][16] {
static const modm::color::Rgb565 shades_of_color[][16] {
COLOR_PALETTE(0xff, 0xff, 0xff),

COLOR_PALETTE(0xff, 0, 0),
Expand Down Expand Up @@ -137,7 +137,7 @@ static inline void touch(framebuffer_t buffer)

static inline void setPixel(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 All @@ -148,7 +148,7 @@ static inline void setPixel(int x, int y, uint8_t color)
// 5 | x x |
// 6 | xxxx |
// 7 | |

GET_TRAIL_COLOR(color).color;
// 1
DRAW(x+2, y+1);
DRAW(x+3, y+1);
Expand Down
6 changes: 3 additions & 3 deletions examples/stm32f469_discovery/touchscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LineDrawer : public modm::pt::Protothread
touch(touchData),
display{Board::getDisplay()},
px{-1, -1}, py{-1, -1},
c{Color::white(), Color::white()}
c{modm::color::html::White, modm::color::html::White}
{}

bool
Expand Down Expand Up @@ -72,7 +72,7 @@ class LineDrawer : public modm::pt::Protothread
// invalidate points
px[tp.id] = -1; py[tp.id] = -1;
// generate new random color
c[tp.id] = Color(uint16_t(rand()));
c[tp.id] = modm::color::Rgb565(uint16_t(rand()));
}
}
LedRed::reset();
Expand All @@ -86,7 +86,7 @@ class LineDrawer : public modm::pt::Protothread
Touch touch;
modm::ColorGraphicDisplay& display;
int16_t px[2], py[2];
Color c[2];
modm::color::Rgb565 c[2];
};

LineDrawer drawer;
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
Loading