Skip to content

Commit

Permalink
Merge pull request #25 from AllanOricil/feat/require-pin-on-awake
Browse files Browse the repository at this point in the history
feat: display PIN screen immediately upon screen wake-up
  • Loading branch information
AllanOricil authored Dec 7, 2024
2 parents d04b80d + e548745 commit 5926305
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,36 @@
#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()
{
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.");
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ 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
numberOfWrongUnlockAttempts = maxNumberOfWrongUnlockAttempts;
_maxNumberOfWrongUnlockAttempts = maxNumberOfWrongUnlockAttempts;
if (displayPinScreen)
{
ui_pin_screen_screen_init();
lv_disp_load_scr(ui_pin_screen);
}
else
Expand Down

0 comments on commit 5926305

Please sign in to comment.