diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 580c4653..78817d4d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ list(APPEND SOURCE_FILES DisplayApp/Screens/Screen.cpp DisplayApp/Screens/Clock.cpp DisplayApp/Screens/Message.cpp + DisplayApp/Screens/Rainbow.cpp main.cpp drivers/St7789.cpp drivers/SpiMaster.cpp @@ -60,6 +61,7 @@ set(INCLUDE_FILES DisplayApp/Screens/Screen.h DisplayApp/Screens/Clock.h DisplayApp/Screens/Message.h + DisplayApp/Screens/Rainbow.h drivers/St7789.h drivers/SpiMaster.h Components/Gfx/Gfx.h diff --git a/src/Components/Gfx/Gfx.cpp b/src/Components/Gfx/Gfx.cpp index bcab9617..81ae316d 100644 --- a/src/Components/Gfx/Gfx.cpp +++ b/src/Components/Gfx/Gfx.cpp @@ -30,7 +30,7 @@ void Gfx::ClearScreen() { void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t color) { SetBackgroundColor(color); - state.remainingIterations = 240 + 1; + state.remainingIterations = h; state.currentIteration = 0; state.busy = true; state.action = Action::FillRectangle; diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index f12b5948..0ae09270 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -26,9 +26,10 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController}, - clockScreen{gfx} { + clockScreen{gfx}, + rainbowScreen{gfx} { msgQueue = xQueueCreate(queueSize, itemSize); - currentScreen = &clockScreen; + currentScreen = &rainbowScreen; } void DisplayApp::Start() { @@ -68,7 +69,7 @@ void DisplayApp::Refresh() { break; case States::Running: RunningState(); - queueTimeout = 1; + queueTimeout = 50; break; } @@ -139,7 +140,12 @@ void DisplayApp::OnTouchEvent() { auto info = touchPanel.GetTouchInfo(); if(info.isTouch) { - gfx.FillRectangle(info.x-10, info.y-10, 20,20, pointColor); - pointColor+=10; + if(currentScreen == &clockScreen) + currentScreen = &rainbowScreen; + else { + gfx.SetScrollStartLine(0); + currentScreen = &clockScreen; + } + currentScreen->Refresh(true); } } diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 5a5d3ee6..d0d15ddf 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -14,6 +14,7 @@ #include #include #include +#include extern const FONT_INFO lCD_70ptFontInfo; @@ -58,6 +59,7 @@ namespace Pinetime { void OnTouchEvent(); Screens::Clock clockScreen; + Screens::Rainbow rainbowScreen; Screens::Screen* currentScreen = nullptr; static constexpr uint8_t pinLcdBacklight1 = 14; static constexpr uint8_t pinLcdBacklight2 = 22; diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp index ae6904aa..fb50d0a1 100644 --- a/src/DisplayApp/Screens/Clock.cpp +++ b/src/DisplayApp/Screens/Clock.cpp @@ -5,7 +5,6 @@ #include "Clock.h" using namespace Pinetime::Applications::Screens; -uint16_t line = 0; void Clock::Refresh(bool fullRefresh) { if(fullRefresh) { gfx.FillRectangle(0,0,240,240,0x0000); @@ -14,14 +13,9 @@ void Clock::Refresh(bool fullRefresh) { currentChar[2] = 3; currentChar[3] = 4; auto dummy = currentDateTime.Get(); - - gfx.SetScrollArea(74, 78, 320-(78+74)); - line = 74; } - gfx.SetScrollStartLine(line); - line++; - if(line == 78+74) line = 74; + if (fullRefresh || batteryPercentRemaining.IsUpdated()) { char batteryChar[11]; auto newBatteryValue = batteryPercentRemaining.Get(); diff --git a/src/DisplayApp/Screens/Rainbow.cpp b/src/DisplayApp/Screens/Rainbow.cpp new file mode 100644 index 00000000..50212ad4 --- /dev/null +++ b/src/DisplayApp/Screens/Rainbow.cpp @@ -0,0 +1,58 @@ +#include "Rainbow.h" + +using namespace Pinetime::Applications::Screens; + +void Rainbow::Refresh(bool fullRefresh) { + if(fullRefresh) { + gfx.FillRectangle(0, 0, 240, 240, 0x0000); + + gfx.SetScrollArea(0, 240, 320 - 240); + scrollLine = 0; + b = 31; + r = 0; + g = 0; + step = 0; + } + + gfx.SetScrollStartLine(scrollLine); + + switch(step) { + case 0: + if(r == 31) step = 1; + else r++; + break; + case 1: + if(b == 0) step = 2; + else b--; + break; + case 2: + if(g == 31) step = 3; + else g++; + break; + case 3: + if(r == 0) step = 4; + else r--; + break; + case 4: + if(b == 31) step = 5; + else b++; + break; + case 5: + if(g == 0) step = 0; + else g--; + break; + } + + uint16_t color = (g & 0x1f) | ((r & 0x1f) << 6) | ((b & 0x1f) << 11); + + // Invert the 2 byte from color to adapt to the lcd controller + uint8_t l = color & 0x00ffu; + uint8_t h = (color >> 8u) & 0x00ffu; + + uint16_t c = h + (l << 8); + + gfx.FillRectangle(0, scrollLine,240,1, c); + scrollLine+=1; + + if(scrollLine == 240) scrollLine = 0; +} diff --git a/src/DisplayApp/Screens/Rainbow.h b/src/DisplayApp/Screens/Rainbow.h new file mode 100644 index 00000000..6a6d1b3c --- /dev/null +++ b/src/DisplayApp/Screens/Rainbow.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Screen.h" + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Rainbow : public Screen{ + public: + explicit Rainbow(Components::Gfx& gfx) : Screen(gfx) {} + + void Refresh(bool fullRefresh) override; + + private: + uint16_t scrollLine = 0; + uint8_t r = 0; + uint8_t g = 0; + uint8_t b = 0; + + uint8_t step = 0; + }; + } + } +} \ No newline at end of file