From 89ff8c53f48fb5952776aae62b46ab9f14ca7757 Mon Sep 17 00:00:00 2001 From: gagarinlg Date: Thu, 10 Mar 2022 22:57:29 +0100 Subject: [PATCH] fix shutdown animation --- radio/src/gui/colorlcd/draw_functions.cpp | 164 +++++++++++++++------- radio/src/gui/colorlcd/draw_functions.h | 1 + radio/src/opentx.cpp | 3 + 3 files changed, 116 insertions(+), 52 deletions(-) diff --git a/radio/src/gui/colorlcd/draw_functions.cpp b/radio/src/gui/colorlcd/draw_functions.cpp index 639ef54ae..4fd19aa9a 100644 --- a/radio/src/gui/colorlcd/draw_functions.cpp +++ b/radio/src/gui/colorlcd/draw_functions.cpp @@ -105,64 +105,122 @@ void drawSleepBitmap() } #define SHUTDOWN_CIRCLE_DIAMETER 150 +class ShutdownAnimation: public FormGroup +{ + public: + ShutdownAnimation(uint32_t duration, uint32_t totalDuration): + FormGroup(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE | FORM_NO_BORDER), + duration(duration), + totalDuration(totalDuration) + { + Layer::push(this); + bringToTop(); + setFocus(SET_FOCUS_DEFAULT); + } + +#if defined(DEBUG_WINDOWS) + std::string getName() const override + { + return "ShutdownAnimation"; + } +#endif + void paint(BitmapBuffer * dc) override + { + LcdFlags fgColor; + LcdFlags bgColor; + + if (ThemePersistance::instance()->isDefaultTheme()) { + fgColor = COLOR2FLAGS(WHITE); + bgColor = COLOR2FLAGS(BLACK); + } else { + fgColor = COLOR_THEME_PRIMARY2; + bgColor = COLOR_THEME_SECONDARY1; + } + + static const BitmapBuffer* shutdown = OpenTxTheme::instance()->shutdown; + + dc->reset(); + dc->clear(bgColor); + + if (shutdown) { + dc->drawMask((LCD_W - shutdown->width()) / 2, + (LCD_H - shutdown->height()) / 2, shutdown, fgColor); + + int quarter = duration / (totalDuration / 5); + if (quarter >= 1) + dc->drawBitmapPattern(LCD_W / 2, (LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2, + LBM_SHUTDOWN_CIRCLE, fgColor, 0, + SHUTDOWN_CIRCLE_DIAMETER / 2); + if (quarter >= 2) + dc->drawBitmapPattern(LCD_W / 2, LCD_H / 2, LBM_SHUTDOWN_CIRCLE, fgColor, + SHUTDOWN_CIRCLE_DIAMETER / 2, + SHUTDOWN_CIRCLE_DIAMETER / 2); + if (quarter >= 3) + dc->drawBitmapPattern((LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2, LCD_H / 2, + LBM_SHUTDOWN_CIRCLE, fgColor, + SHUTDOWN_CIRCLE_DIAMETER, + SHUTDOWN_CIRCLE_DIAMETER / 2); + if (quarter >= 4) + dc->drawBitmapPattern( + (LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2, + (LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2, LBM_SHUTDOWN_CIRCLE, fgColor, + SHUTDOWN_CIRCLE_DIAMETER * 3 / 2, SHUTDOWN_CIRCLE_DIAMETER / 2); + } else { + int quarter = duration / (totalDuration / 5); + for (int i = 1; i <= 4; i++) { + if (quarter >= i) { + dc->drawSolidFilledRect(LCD_W / 2 - 70 + 24 * i, LCD_H / 2 - 10, 20, + 20, fgColor); + } + } + } + } + + void deleteLater(bool detach = true, bool trash = true) override + { + Layer::pop(this); + Window::deleteLater(detach, trash); + } + + void update(uint32_t newDuration, uint32_t newTotalDuration) + { + duration = newDuration; + totalDuration = newTotalDuration; + } + + protected: + uint32_t duration; + uint32_t totalDuration; + std::string message; +}; + +static ShutdownAnimation *shutdownAnimation = nullptr; void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char* message) { - if (totalDuration == 0) return; + if (totalDuration == 0) + return; - LcdFlags fgColor; - LcdFlags bgColor; - - if (ThemePersistance::instance()->isDefaultTheme()) { - fgColor = COLOR2FLAGS(WHITE); - bgColor = COLOR2FLAGS(BLACK); - } else { - fgColor = COLOR_THEME_PRIMARY2; - bgColor = COLOR_THEME_SECONDARY1; - } - - static const BitmapBuffer* shutdown = OpenTxTheme::instance()->shutdown; - - lcd->reset(); - lcdInitDirectDrawing(); - lcd->clear(bgColor); - - if (shutdown) { - lcd->drawMask((LCD_W - shutdown->width()) / 2, - (LCD_H - shutdown->height()) / 2, shutdown, fgColor); - - int quarter = duration / (totalDuration / 5); - if (quarter >= 1) - lcd->drawBitmapPattern(LCD_W / 2, (LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2, - LBM_SHUTDOWN_CIRCLE, fgColor, 0, - SHUTDOWN_CIRCLE_DIAMETER / 2); - if (quarter >= 2) - lcd->drawBitmapPattern(LCD_W / 2, LCD_H / 2, LBM_SHUTDOWN_CIRCLE, fgColor, - SHUTDOWN_CIRCLE_DIAMETER / 2, - SHUTDOWN_CIRCLE_DIAMETER / 2); - if (quarter >= 3) - lcd->drawBitmapPattern((LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2, LCD_H / 2, - LBM_SHUTDOWN_CIRCLE, fgColor, - SHUTDOWN_CIRCLE_DIAMETER, - SHUTDOWN_CIRCLE_DIAMETER / 2); - if (quarter >= 4) - lcd->drawBitmapPattern( - (LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2, - (LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2, LBM_SHUTDOWN_CIRCLE, fgColor, - SHUTDOWN_CIRCLE_DIAMETER * 3 / 2, SHUTDOWN_CIRCLE_DIAMETER / 2); - } else { - int quarter = duration / (totalDuration / 5); - for (int i = 1; i <= 4; i++) { - if (quarter >= i) { - lcd->drawSolidFilledRect(LCD_W / 2 - 70 + 24 * i, LCD_H / 2 - 10, 20, - 20, fgColor); - } - } - } + if(!shutdownAnimation) + shutdownAnimation = new ShutdownAnimation(duration, totalDuration); + else + shutdownAnimation->update(duration, totalDuration); + shutdownAnimation->invalidate(); WDG_RESET(); - lcdRefresh(); + RTOS_WAIT_MS(1); + MainWindow::instance()->run(false); + LvglWrapper::instance()->run(); +} + +void clearShutdownAnimation() +{ + if(!shutdownAnimation) + return; + + shutdownAnimation->deleteLater(); + shutdownAnimation = nullptr; } @@ -197,7 +255,6 @@ class FatalErrorScreen: public FormGroup protected: std::string message; - bool running = false; }; static FatalErrorScreen *errorScreen = nullptr; @@ -214,6 +271,9 @@ void drawFatalErrorScreen(const char * message) } void clearFatalErrorScreen() { + if(!errorScreen) + return; + errorScreen->deleteLater(); errorScreen = nullptr; } diff --git a/radio/src/gui/colorlcd/draw_functions.h b/radio/src/gui/colorlcd/draw_functions.h index 3980a9ba8..be10b52d1 100644 --- a/radio/src/gui/colorlcd/draw_functions.h +++ b/radio/src/gui/colorlcd/draw_functions.h @@ -93,6 +93,7 @@ inline void drawChn(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t idx, LcdFla void drawSplash(); void drawSleepBitmap(); void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char * message); +void clearShutdownAnimation(); // Main view standard widgets void drawMainPots(); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index e2e2a0d66..e9113458f 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2049,7 +2049,10 @@ uint32_t pwrCheck() else { #if defined(COLORLCD) if (pwr_press_time != 0) + { + clearShutdownAnimation(); MainWindow::instance()->invalidate(); + } #endif pwr_check_state = PWR_CHECK_ON; pwr_press_time = 0;