Fix & simplify fatal screens

This commit is contained in:
Raphael Coeffic
2022-06-17 05:34:47 +02:00
committed by Raphael Coeffic
parent 6798b2fde9
commit ac84ac1397
4 changed files with 65 additions and 151 deletions
+62 -132
View File
@@ -137,54 +137,6 @@ class ShutdownAnimation: public FormGroup
#endif #endif
void paint(BitmapBuffer * dc) override 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 void deleteLater(bool detach = true, bool trash = true) override
@@ -205,116 +157,94 @@ class ShutdownAnimation: public FormGroup
std::string message; std::string message;
}; };
static ShutdownAnimation *shutdownAnimation = nullptr;
void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration,
const char* message) const char* message)
{ {
if (totalDuration == 0) if (totalDuration == 0) return;
return;
if(!shutdownAnimation) LcdFlags fgColor;
shutdownAnimation = new ShutdownAnimation(duration, totalDuration); LcdFlags bgColor;
else
shutdownAnimation->update(duration, totalDuration);
shutdownAnimation->invalidate();
WDG_RESET(); if (ThemePersistance::instance()->isDefaultTheme()) {
RTOS_WAIT_MS(1); fgColor = COLOR2FLAGS(WHITE);
MainWindow::instance()->run(false); bgColor = COLOR2FLAGS(BLACK);
LvglWrapper::instance()->run(); } else {
fgColor = COLOR_THEME_PRIMARY2;
bgColor = COLOR_THEME_SECONDARY1;
}
static const BitmapBuffer* shutdown = OpenTxTheme::instance()->shutdown;
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);
}
}
}
lcdRefresh();
} }
void clearShutdownAnimation()
{
if(!shutdownAnimation)
return;
shutdownAnimation->deleteLater();
shutdownAnimation = nullptr;
}
class FatalErrorScreen: public FormGroup
{
public:
FatalErrorScreen(const std::string& message):
FormGroup(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE | FORM_NO_BORDER),
message(std::move(message))
{
Layer::push(this);
bringToTop();
// setFocus(SET_FOCUS_DEFAULT);
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "FatalErrorScreen";
}
#endif
void paint(BitmapBuffer * dc) override
{
dc->clear(COLOR2FLAGS(BLACK));
dc->drawText(LCD_W/2, LCD_H/2-20, message.c_str(), FONT(XL)|CENTERED|COLOR2FLAGS(WHITE));
}
void deleteLater(bool detach = true, bool trash = true) override
{
Layer::pop(this);
Window::deleteLater(detach, trash);
}
protected:
std::string message;
};
static FatalErrorScreen *errorScreen = nullptr;
void drawFatalErrorScreen(const char * message) void drawFatalErrorScreen(const char * message)
{ {
if(!errorScreen) backlightEnable(100);
{ lcdInitDirectDrawing();
errorScreen = new FatalErrorScreen(message); lcd->clear(COLOR2FLAGS(BLACK));
} lcd->drawText(LCD_W/2, LCD_H/2-20, message, FONT(XL)|CENTERED|COLOR2FLAGS(WHITE));
RTOS_WAIT_MS(1); lcdRefresh();
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
void clearFatalErrorScreen()
{
if(!errorScreen)
return;
errorScreen->deleteLater(); // invalidate screen to enable quick return
errorScreen = nullptr; // to normal display routine
lv_obj_invalidate(lv_scr_act());
} }
void runFatalErrorScreen(const char * message) void runFatalErrorScreen(const char * message)
{ {
lcdInitDisplayDriver(); lcdInitDisplayDriver();
while (true) { while (true) {
backlightEnable(100); drawFatalErrorScreen(message);
lcd->reset();
lcdInitDirectDrawing();
lcd->clear(COLOR2FLAGS(BLACK));
lcd->drawText(LCD_W/2, LCD_H/2-20, message, FONT(XL)|CENTERED|COLOR2FLAGS(WHITE));
WDG_RESET(); WDG_RESET();
lcdRefresh();
uint8_t refresh = false; // loop as long as PWR button is pressed
while (true) { while (true) {
uint32_t pwr_check = pwrCheck(); uint32_t pwr_check = pwrCheck();
if (pwr_check == e_power_off) { if (pwr_check == e_power_off) {
boardOff(); boardOff();
return; // only happens in SIMU, required for proper shutdown return; // only happens in SIMU, required for proper shutdown
} }
else if (pwr_check == e_power_press) { else if (pwr_check == e_power_on) {
refresh = true;
}
else if (pwr_check == e_power_on && refresh) {
break; break;
} }
WDG_RESET();
} }
} }
} }
+3
View File
@@ -142,6 +142,9 @@ static void flushLcd(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_
void lcdInitDisplayDriver() void lcdInitDisplayDriver()
{ {
// we already have a display: exit
if (disp != nullptr) return;
lv_init(); lv_init();
// Clear buffers first // Clear buffers first
-12
View File
@@ -476,7 +476,6 @@ void guiMain(event_t evt)
void perMain() void perMain()
{ {
DEBUG_TIMER_START(debugTimerPerMain1); DEBUG_TIMER_START(debugTimerPerMain1);
static bool fatalError = false;
checkSpeakerVolume(); checkSpeakerVolume();
@@ -509,7 +508,6 @@ void perMain()
#if defined(RTC_BACKUP_RAM) #if defined(RTC_BACKUP_RAM)
if (globalData.unexpectedShutdown) { if (globalData.unexpectedShutdown) {
fatalError = true;
drawFatalErrorScreen(STR_EMERGENCY_MODE); drawFatalErrorScreen(STR_EMERGENCY_MODE);
return; return;
} }
@@ -527,22 +525,12 @@ void perMain()
// TODO: implement for b/w // TODO: implement for b/w
#if defined(COLORLCD) #if defined(COLORLCD)
fatalError = true;
drawFatalErrorScreen(STR_NO_SDCARD); drawFatalErrorScreen(STR_NO_SDCARD);
return; return;
#endif #endif
} }
#endif #endif
#if defined(LIBOPENUI)
if(fatalError)
{
clearFatalErrorScreen();
fatalError = false;
}
#endif
if (usbPlugged() && getSelectedUsbMode() == USB_MASS_STORAGE_MODE) { if (usbPlugged() && getSelectedUsbMode() == USB_MASS_STORAGE_MODE) {
#if defined(LIBOPENUI) #if defined(LIBOPENUI)
// draw some image showing USB // draw some image showing USB
-7
View File
@@ -2043,13 +2043,6 @@ uint32_t pwrCheck()
} }
} }
else { else {
#if defined(COLORLCD)
if (pwr_press_time != 0)
{
clearShutdownAnimation();
MainWindow::instance()->invalidate();
}
#endif
pwr_check_state = PWR_CHECK_ON; pwr_check_state = PWR_CHECK_ON;
pwr_press_time = 0; pwr_press_time = 0;
} }