timer: Replace screen timeout with SysTick

This provides an incredibly accurate screen timeout and removes the
superfluous screen timeout counter
This commit is contained in:
Saleem Rashid 2016-11-17 19:10:57 +00:00 committed by Pavol Rusnak
parent 25b9bfd97b
commit 0ec32a6146
4 changed files with 13 additions and 8 deletions

View File

@ -28,6 +28,7 @@
#include "string.h" #include "string.h"
#include "util.h" #include "util.h"
#include "qr_encode.h" #include "qr_encode.h"
#include "timer.h"
void *layoutLast = layoutHome; void *layoutLast = layoutHome;
@ -81,6 +82,9 @@ void layoutHome(void)
} }
} }
oledRefresh(); oledRefresh();
// Reset lock screen timeout
system_millis_lock = system_millis + SCREEN_TIMEOUT_MILLIS;
} }
const char *str_amount(uint64_t amnt, const char *abbr, char *buf, int len) const char *str_amount(uint64_t amnt, const char *abbr, char *buf, int len)

View File

@ -38,15 +38,12 @@ void __attribute__((noreturn)) __stack_chk_fail(void)
for (;;) {} // loop forever for (;;) {} // loop forever
} }
static uint32_t saver_counter = 0;
void check_lock_screen(void) void check_lock_screen(void)
{ {
buttonUpdate(); buttonUpdate();
// wake from screensaver on any button // wake from screensaver on any button
if (layoutLast == layoutScreensaver && (button.NoUp || button.YesUp)) { if (layoutLast == layoutScreensaver && (button.NoUp || button.YesUp)) {
saver_counter = 0;
layoutHome(); layoutHome();
return; return;
} }
@ -82,15 +79,11 @@ void check_lock_screen(void)
// if homescreen is shown for longer than 10 minutes, lock too // if homescreen is shown for longer than 10 minutes, lock too
if (layoutLast == layoutHome) { if (layoutLast == layoutHome) {
saver_counter++; if (system_millis >= system_millis_lock) {
if (saver_counter > 285000 * 60 * 10) {
// lock the screen // lock the screen
session_clear(true); session_clear(true);
layoutScreensaver(); layoutScreensaver();
saver_counter = 0;
} }
} else {
saver_counter = 0;
} }
} }

View File

@ -26,6 +26,9 @@
/* 1 tick = 1 ms */ /* 1 tick = 1 ms */
volatile uint32_t system_millis; volatile uint32_t system_millis;
/* Screen timeout */
uint32_t system_millis_lock;
/* /*
* Initialise the Cortex-M3 SysTick timer * Initialise the Cortex-M3 SysTick timer
*/ */

View File

@ -23,6 +23,11 @@
/* 1 tick = 1 ms */ /* 1 tick = 1 ms */
extern volatile uint32_t system_millis; extern volatile uint32_t system_millis;
/* Screen timeout */
extern uint32_t system_millis_lock;
#define SCREEN_TIMEOUT_MILLIS (1000 * 60 * 10) /* 10 minutes */
void timer_init(void); void timer_init(void);
void sys_tick_handler(void); void sys_tick_handler(void);