From e548745726adc1a1f8dac2cbf39fb3cd10ebe775 Mon Sep 17 00:00:00 2001 From: Allan Oricil Date: Sat, 7 Dec 2024 18:04:53 -0300 Subject: [PATCH] feat: display PIN screen immediately upon screen wake-up --- src/display.cpp | 15 +++++++++++++++ src/ui/ui.c | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/display.cpp b/src/display.cpp index e16a133..ff52d2b 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -6,11 +6,13 @@ #include "constants.h" #include "config.hpp" #include "touch.hpp" +#include "./ui/ui.h" TFT_eSPI tft = TFT_eSPI(); static lv_disp_drv_t disp_drv; unsigned long sleepTimeout = 0; unsigned long lastActivityTime = 0; +bool displayPinScreen = false; bool displayIsOn = false; void turn_off_display() @@ -18,10 +20,22 @@ void turn_off_display() ledcWrite(PWM_CHANNEL_BCKL, 0); displayIsOn = false; Serial.println("Display turned off."); + + // NOTE: The PIN screen is loaded immediately after the display turns off. This prevents users from briefly seeing the TOTP screen when the display is turned back on. + if (displayPinScreen) + { + lv_textarea_set_text(ui_pin_textarea, ""); + lv_disp_load_scr(ui_pin_screen); + } } void turn_on_display() { + // NOTE: number could be accidentally be pressed when awaking the display with a touch in the keys area. So, this will ensure the text area is reset + if (displayPinScreen) + { + lv_textarea_set_text(ui_pin_textarea, ""); + } ledcWrite(PWM_CHANNEL_BCKL, 0.5 * PWM_MAX_BCKL); displayIsOn = true; Serial.println("Display turned on."); @@ -102,6 +116,7 @@ void init_display(Configuration config) Serial.println("Initializing display."); sleepTimeout = config.display.sleepTimeout * 1000; + displayPinScreen = !config.security.pin.hash.isEmpty() && !config.security.pin.key.isEmpty(); Serial.println("Initializing backlight."); pinMode(TFT_BCKL, OUTPUT); diff --git a/src/ui/ui.c b/src/ui/ui.c index b2084c1..69c51db 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -84,7 +84,9 @@ void ui_init(bool displayPinScreen, int maxNumberOfWrongUnlockAttempts) LV_FONT_DEFAULT); LV_EVENT_SETUP_COMPLETE = lv_event_register_id(); lv_disp_set_theme(disp, theme); + // NOTE: initialize screens ui_totp_screen_screen_init(); + ui_pin_screen_screen_init(); ui____initial_actions0 = lv_obj_create(NULL); // TODO: find a better way of sharing config props to avoid dups @@ -92,7 +94,6 @@ void ui_init(bool displayPinScreen, int maxNumberOfWrongUnlockAttempts) _maxNumberOfWrongUnlockAttempts = maxNumberOfWrongUnlockAttempts; if (displayPinScreen) { - ui_pin_screen_screen_init(); lv_disp_load_scr(ui_pin_screen); } else