From 03ff18d1784e09a558f7e7c3c1f6399f0647a1d8 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Wed, 1 May 2024 01:26:21 -0500 Subject: [PATCH] More progress, implement testing application, polish color gradient calculation code as well --- src/CMakeLists.txt | 1 + src/displayapp/UserApps.h | 1 + src/displayapp/WeatherHelper.cpp | 38 +++++++++-------- src/displayapp/WeatherHelper.h | 6 ++- src/displayapp/apps/Apps.h.in | 1 + src/displayapp/apps/CMakeLists.txt | 1 + src/displayapp/screens/WeatherColorTester.cpp | 34 +++++++++++++++ src/displayapp/screens/WeatherColorTester.h | 41 +++++++++++++++++++ 8 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 src/displayapp/screens/WeatherColorTester.cpp create mode 100644 src/displayapp/screens/WeatherColorTester.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a49fe863..83ddfa27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -381,6 +381,7 @@ list(APPEND SOURCE_FILES displayapp/screens/Metronome.cpp displayapp/screens/Motion.cpp displayapp/screens/Weather.cpp + displayapp/screens/WeatherColorTester.cpp displayapp/screens/FirmwareValidation.cpp displayapp/screens/ApplicationList.cpp displayapp/screens/Notifications.cpp diff --git a/src/displayapp/UserApps.h b/src/displayapp/UserApps.h index 531a447d..bbd01141 100644 --- a/src/displayapp/UserApps.h +++ b/src/displayapp/UserApps.h @@ -15,6 +15,7 @@ #include "displayapp/screens/WatchFacePineTimeStyle.h" #include "displayapp/screens/WatchFaceTerminal.h" #include "displayapp/screens/Weather.h" +#include "displayapp/screens/WeatherColorTester.h" namespace Pinetime { namespace Applications { diff --git a/src/displayapp/WeatherHelper.cpp b/src/displayapp/WeatherHelper.cpp index b2d5babb..7a6e78a6 100644 --- a/src/displayapp/WeatherHelper.cpp +++ b/src/displayapp/WeatherHelper.cpp @@ -20,8 +20,11 @@ #include #include #include +#include +#include #include #include +#include #include using namespace Pinetime::Applications; @@ -68,6 +71,13 @@ using namespace Pinetime::Applications; int outputRed = (redA + (redB - redA) * normalValue); int outputGreen = (greenA + (greenB - greenA) * normalValue); int outputBlue = (blueA + (blueB - blueA) * normalValue); + + //increase brightness + float incAmount = 1.2; + outputRed = std::min(255, static_cast(outputRed*incAmount)); + outputGreen = std::min(255, static_cast(outputGreen*incAmount)); + outputBlue = std::min(255, static_cast(outputBlue*incAmount)); + auto lerpOutput = LV_COLOR_MAKE(outputRed, outputGreen, outputBlue); NRF_LOG_INFO("pointA: %i, %i, %i", redA, greenA, blueA); NRF_LOG_INFO("pointB: %i, %i, %i", redB, greenB, blueB); @@ -75,32 +85,26 @@ using namespace Pinetime::Applications; return lerpOutput; } - const lv_color_t WeatherHelper::TemperatureColor(int16_t temperature) { - const std::vector colors = {0x5555ff, 0x00c9ff, 0x00ff3e, 0xff9b00, 0xff0000}; - std::vector stops; + constexpr std::array getColors() { + const std::array colors = {0x5555ff, 0x00c9ff, 0xff9b00, 0xff0000}; + std::array stops; + int8_t i = 0; for (auto colorVal: colors) { - stops.emplace_back(hexToFloat(colorVal)); + stops[i++] = (hexToFloat(colorVal)); } + return stops; + } + + const lv_color_t WeatherHelper::TemperatureColor(int16_t temperature) { + std::array stops = getColors(); int tempRounded = RoundTemperature(temperature); if (tempRounded < 0) { tempRounded = 1; } // convert temperature to range between newMin and newMax - float oldMax = 40; - float oldMin = 0; - float newMax = 1; - float newMin = 0; float oldRange = (oldMax - oldMin); float newRange = (newMax - newMin); float newValue = (((tempRounded - oldMin) * newRange) / oldRange) + newMin; newValue = normalize(newValue); - if (newValue <= .25f) { - return lerp(stops[0], stops[1], newValue); - } else if (newValue <= .50f) { - return lerp(stops[1], stops[2], newValue); - } else if (newValue <= .75f) { - return lerp(stops[2], stops[3], newValue); - } else { - return lerp(stops[3], stops[4], newValue); - } + return lerp(stops[0], stops[3], newValue); } diff --git a/src/displayapp/WeatherHelper.h b/src/displayapp/WeatherHelper.h index 035bc943..bb3aba81 100644 --- a/src/displayapp/WeatherHelper.h +++ b/src/displayapp/WeatherHelper.h @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#pragma once #include #include @@ -26,6 +26,10 @@ namespace Pinetime { static int16_t RoundTemperature(int16_t temp); static const lv_color_t TemperatureColor(int16_t temperature); static const char* floatToRgbHex(lv_color_t rgb); + constexpr static float oldMax = 50; + constexpr static float oldMin = 0; + constexpr static float newMax = 1; + constexpr static float newMin = 0; }; } } diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in index 2104a267..12e3a726 100644 --- a/src/displayapp/apps/Apps.h.in +++ b/src/displayapp/apps/Apps.h.in @@ -29,6 +29,7 @@ namespace Pinetime { Steps, Dice, Weather, + WeatherColorTester, PassKey, QuickSettings, Settings, diff --git a/src/displayapp/apps/CMakeLists.txt b/src/displayapp/apps/CMakeLists.txt index d7858760..718f1488 100644 --- a/src/displayapp/apps/CMakeLists.txt +++ b/src/displayapp/apps/CMakeLists.txt @@ -14,6 +14,7 @@ else () set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather") + set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::WeatherColorTester") #set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion") set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware") endif () diff --git a/src/displayapp/screens/WeatherColorTester.cpp b/src/displayapp/screens/WeatherColorTester.cpp new file mode 100644 index 00000000..bf63a6c6 --- /dev/null +++ b/src/displayapp/screens/WeatherColorTester.cpp @@ -0,0 +1,34 @@ +#include "displayapp/screens/WeatherColorTester.h" +#include "displayapp/WeatherHelper.h" +#include "displayapp/LittleVgl.h" +#include +#include // std::fill +using namespace Pinetime::Applications::Screens; + +WeatherColorTester::WeatherColorTester(Pinetime::Components::LittleVgl& lvgl) : lvgl {lvgl} { + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); + Refresh(); +} + +void WeatherColorTester::Refresh() { //WeatherHelper::oldMax + for (size_t i = 0; i < WeatherHelper::oldMax; ++i) { + // get current color + currentColor = WeatherHelper::TemperatureColor(i * 100); + // create area we want to color + lv_area_t area; + area.y1 = x + i; + area.x1 = 0; + area.y2 = (x + i) + 1; + area.x2 = y; + NRF_LOG_INFO("area coords: %i, %i, %i, %i", area.x1, area.y1, area.x2, area.y2); + // write the buffer to the display + lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::None); + std::fill(buffer, buffer + bufferSize, currentColor); + lvgl.FlushDisplay(&area, buffer); + } +} + +WeatherColorTester::~WeatherColorTester() { + lv_task_del(taskRefresh); + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/WeatherColorTester.h b/src/displayapp/screens/WeatherColorTester.h new file mode 100644 index 00000000..5c9b4286 --- /dev/null +++ b/src/displayapp/screens/WeatherColorTester.h @@ -0,0 +1,41 @@ +#pragma once + +#include "displayapp/apps/Apps.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/Controllers.h" +#include +#include "Symbols.h" + +namespace Pinetime { + namespace Applications { + namespace Screens { + class WeatherColorTester : public Screen { + public: + explicit WeatherColorTester(Pinetime::Components::LittleVgl& lvgl); + WeatherColorTester() = delete; + ~WeatherColorTester() override; + void Refresh() override; + private: + Pinetime::Components::LittleVgl& lvgl; + lv_task_t* taskRefresh; + static constexpr int x = 0; + static constexpr int y = 240; + static constexpr int bufferSize = (480); + lv_color_t buffer[bufferSize]; + + lv_color_t currentColor; + //static lv_disp_draw_buf_t disp_buf; + }; + } + + + template <> + struct AppTraits { + static constexpr Apps app = Apps::WeatherColorTester; + static constexpr const char* icon = Screens::Symbols::bolt; + static Screens::Screen* Create(AppControllers& controllers) { + return new Screens::WeatherColorTester(controllers.lvgl); + } + }; + } +}