From 3dfc27e93ee75c935ab200d1d346aacf1c815a79 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 1 Jun 2025 17:52:09 +0200 Subject: [PATCH] Fixes for colours and margins in GPIO app and more (#284) - Fixes for colours and margins in GPIO app - Removed unused imports --- Tactility/Include/Tactility/lvgl/Color.h | 9 ++++++ Tactility/Include/Tactility/lvgl/LabelUtils.h | 2 +- Tactility/Include/Tactility/lvgl/Lvgl.h | 5 +++ Tactility/Include/Tactility/lvgl/Spinner.h | 2 +- Tactility/Include/Tactility/lvgl/Style.h | 2 +- Tactility/Include/Tactility/lvgl/Toolbar.h | 2 +- .../Tactility/app/i2cscanner/I2cScanner.h | 8 ----- Tactility/Source/app/gpio/Gpio.cpp | 32 +++++++++---------- Tactility/Source/lvgl/Color.cpp | 13 ++++++++ 9 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 Tactility/Include/Tactility/lvgl/Color.h create mode 100644 Tactility/Include/Tactility/lvgl/Lvgl.h create mode 100644 Tactility/Source/lvgl/Color.cpp diff --git a/Tactility/Include/Tactility/lvgl/Color.h b/Tactility/Include/Tactility/lvgl/Color.h new file mode 100644 index 00000000..67a58e98 --- /dev/null +++ b/Tactility/Include/Tactility/lvgl/Color.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +lv_color_t lv_color_foreground(); + +lv_color_t lv_color_background(); + +lv_color_t lv_color_background_darkest(); diff --git a/Tactility/Include/Tactility/lvgl/LabelUtils.h b/Tactility/Include/Tactility/lvgl/LabelUtils.h index 04cc892f..2e508e42 100644 --- a/Tactility/Include/Tactility/lvgl/LabelUtils.h +++ b/Tactility/Include/Tactility/lvgl/LabelUtils.h @@ -1,6 +1,6 @@ #pragma once -#include "lvgl.h" +#include namespace tt::lvgl { diff --git a/Tactility/Include/Tactility/lvgl/Lvgl.h b/Tactility/Include/Tactility/lvgl/Lvgl.h new file mode 100644 index 00000000..53117f26 --- /dev/null +++ b/Tactility/Include/Tactility/lvgl/Lvgl.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +#include "./Colors.h" diff --git a/Tactility/Include/Tactility/lvgl/Spinner.h b/Tactility/Include/Tactility/lvgl/Spinner.h index 71bd173c..39b20008 100644 --- a/Tactility/Include/Tactility/lvgl/Spinner.h +++ b/Tactility/Include/Tactility/lvgl/Spinner.h @@ -1,4 +1,4 @@ -#include "lvgl.h" +#include namespace tt::lvgl { diff --git a/Tactility/Include/Tactility/lvgl/Style.h b/Tactility/Include/Tactility/lvgl/Style.h index dd89dd07..cb97c811 100644 --- a/Tactility/Include/Tactility/lvgl/Style.h +++ b/Tactility/Include/Tactility/lvgl/Style.h @@ -1,6 +1,6 @@ #pragma once -#include "lvgl.h" +#include namespace tt::lvgl { diff --git a/Tactility/Include/Tactility/lvgl/Toolbar.h b/Tactility/Include/Tactility/lvgl/Toolbar.h index eac3d747..733f1474 100644 --- a/Tactility/Include/Tactility/lvgl/Toolbar.h +++ b/Tactility/Include/Tactility/lvgl/Toolbar.h @@ -1,7 +1,7 @@ #pragma once -#include "lvgl.h" #include "../app/AppContext.h" +#include namespace tt::lvgl { diff --git a/Tactility/Private/Tactility/app/i2cscanner/I2cScanner.h b/Tactility/Private/Tactility/app/i2cscanner/I2cScanner.h index e83fbd13..0baa9eb3 100644 --- a/Tactility/Private/Tactility/app/i2cscanner/I2cScanner.h +++ b/Tactility/Private/Tactility/app/i2cscanner/I2cScanner.h @@ -1,13 +1,5 @@ #pragma once -#include -#include -#include -#include "lvgl.h" -#include -#include "Timer.h" -#include - namespace tt::app::i2cscanner { void start(); diff --git a/Tactility/Source/app/gpio/Gpio.cpp b/Tactility/Source/app/gpio/Gpio.cpp index 892704ef..9524642f 100644 --- a/Tactility/Source/app/gpio/Gpio.cpp +++ b/Tactility/Source/app/gpio/Gpio.cpp @@ -1,10 +1,10 @@ #include "Tactility/service/loader/Loader.h" -#include "Tactility/lvgl/Toolbar.h" #include #include +#include "Tactility/lvgl/Toolbar.h" #include +#include #include -#include #include namespace tt::app::gpio { @@ -13,10 +13,8 @@ extern const AppManifest manifest; class GpioApp : public App { -private: - - lv_obj_t* lvPins[GPIO_NUM_MAX] = {0 }; - uint8_t pinStates[GPIO_NUM_MAX] = {0 }; + lv_obj_t* lvPins[GPIO_NUM_MAX] = { nullptr }; + uint8_t pinStates[GPIO_NUM_MAX] = { 0 }; std::unique_ptr timer; Mutex mutex; @@ -40,7 +38,7 @@ void GpioApp::updatePinStates() { // Update pin states for (int i = 0; i < GPIO_NUM_MAX; ++i) { #ifdef ESP_PLATFORM - pinStates[i] = gpio_get_level((gpio_num_t)i); + pinStates[i] = gpio_get_level(static_cast(i)); #else pinStates[i] = gpio_get_level(i); #endif @@ -60,9 +58,9 @@ void GpioApp::updatePinWidgets() { if (reinterpret_cast(level) != label_user_data) { lv_obj_set_user_data(label, reinterpret_cast(level)); if (level == 0) { - lv_obj_set_style_text_color(label, lv_color_black(), 0); + lv_obj_set_style_text_color(label, lv_color_background_darkest(), LV_STATE_DEFAULT); } else { - lv_obj_set_style_text_color(label, lv_color_make(0, 200, 0), 0); + lv_obj_set_style_text_color(label, lv_color_make(0, 200, 0), LV_STATE_DEFAULT); } } } @@ -71,8 +69,8 @@ void GpioApp::updatePinWidgets() { lv_obj_t* GpioApp::createGpioRowWrapper(lv_obj_t* parent) { lv_obj_t* wrapper = lv_obj_create(parent); - lv_obj_set_style_pad_all(wrapper, 0, 0); - lv_obj_set_style_border_width(wrapper, 0, 0); + lv_obj_set_style_pad_all(wrapper, 0, LV_STATE_DEFAULT); + lv_obj_set_style_border_width(wrapper, 0, LV_STATE_DEFAULT); lv_obj_set_size(wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT); return wrapper; } @@ -87,7 +85,7 @@ void GpioApp::onTimer() { void GpioApp::startTask() { mutex.lock(); assert(timer == nullptr); - timer = std::make_unique(Timer::Type::Periodic, [this]() { + timer = std::make_unique(Timer::Type::Periodic, [this] { onTimer(); }); timer->start(100 / portTICK_PERIOD_MS); @@ -113,7 +111,7 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) { auto* wrapper = lv_obj_create(parent); lv_obj_set_width(wrapper, LV_PCT(100)); lv_obj_set_flex_grow(wrapper, 1); - lv_obj_set_style_border_width(wrapper, 0, 0); + lv_obj_set_style_border_width(wrapper, 0, LV_STATE_DEFAULT); auto* display = lv_obj_get_display(parent); auto horizontal_px = lv_display_get_horizontal_resolution(display); @@ -122,7 +120,8 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) { int32_t x_spacing = 20; uint8_t column = 0; - uint8_t column_limit = is_landscape_display ? 10 : 5; + const uint8_t offset_from_left_label = 4; + const uint8_t column_limit = is_landscape_display ? 10 : 5; auto* row_wrapper = createGpioRowWrapper(wrapper); lv_obj_align(row_wrapper, LV_ALIGN_TOP_MID, 0, 0); @@ -138,8 +137,9 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) { // Add a new GPIO status indicator auto* status_label = lv_label_create(row_wrapper); - lv_obj_set_pos(status_label, (int32_t)((column+1) * x_spacing), 0); + lv_obj_set_pos(status_label, (int32_t)((column+1) * x_spacing + offset_from_left_label), 0); lv_label_set_text_fmt(status_label, "%s", LV_SYMBOL_STOP); + lv_obj_set_style_text_color(status_label, lv_color_background_darkest(), LV_STATE_DEFAULT); lvPins[i] = status_label; column++; @@ -148,7 +148,7 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) { // Add the GPIO number after the last item on a row auto* postfix = lv_label_create(row_wrapper); lv_label_set_text_fmt(postfix, "%02d", i); - lv_obj_set_pos(postfix, (int32_t)((column+1) * x_spacing), 0); + lv_obj_set_pos(postfix, (int32_t)((column+1) * x_spacing + offset_from_left_label), 0); // Add a new row wrapper underneath the last one auto* new_row_wrapper = createGpioRowWrapper(wrapper); diff --git a/Tactility/Source/lvgl/Color.cpp b/Tactility/Source/lvgl/Color.cpp new file mode 100644 index 00000000..a0fdfb35 --- /dev/null +++ b/Tactility/Source/lvgl/Color.cpp @@ -0,0 +1,13 @@ +#include "Tactility/lvgl/Color.h" + +lv_color_t lv_color_foreground() { + return lv_color_make(0xFF, 0xFF, 0xFF); +} + +lv_color_t lv_color_background() { + return lv_color_make(0x28, 0x2B, 0x30); +} + +lv_color_t lv_color_background_darkest() { + return lv_color_make(0x00, 0x00, 0x00); +}