Commit b8da7cee authored by Robey Pointer's avatar Robey Pointer
Browse files

if the menu is active but hasn't had interaction in 15 seconds, deactivate it and clear the screen

parent 9b85bfc2
......@@ -61,6 +61,9 @@
#define BATTERY_ALERT_ON_MSEC 500
#define BATTERY_ALERT_OFF_MSEC 4500
// how long to let the menu display before idling out
#define MENU_IDLE_MSEC 15000
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
......@@ -279,6 +282,8 @@ static void scan_keyboard_matrix(void) {
static uint8_t scan_keyboard(uint8_t keys[]) {
static bool in_circle_menu = false;
static uint8_t previous_key = 0;
static uint32_t last_key_ticks = 0;
uint32_t now = timer_get_ticks();
uint8_t count = 0;
for (int i = 0; i < MATRIX_BYTES; i++) {
......@@ -294,6 +299,7 @@ static uint8_t scan_keyboard(uint8_t keys[]) {
menu_start(circle_menu);
in_circle_menu = true;
previous_key = KEY_CIRCLE;
last_key_ticks = now;
return 0;
}
......@@ -305,6 +311,10 @@ static uint8_t scan_keyboard(uint8_t keys[]) {
if (count == 1 && keys[0] != previous_key) {
in_circle_menu = menu_key(keys[0]);
previous_key = keys[0];
last_key_ticks = now;
} else if (count == 0 && timer_diff_msec(last_key_ticks, now) >= MENU_IDLE_MSEC) {
in_circle_menu = false;
menu_stop();
}
return 0;
}
......
......@@ -45,6 +45,8 @@ void menu_start(const menu_item_t *menu) {
void menu_stop(void) {
items = NULL;
display_clear();
display_flush();
}
bool menu_is_active(void) {
......@@ -55,15 +57,13 @@ static bool menu_action(uint8_t index) {
if (!items[index].action) {
// no action = exit menu
menu_stop();
display_clear();
display_flush();
return false;
}
items[index].action();
if (items[index].terminate_menu) {
// don't clear the screen: might have been a display request
menu_stop();
items = NULL;
return false;
}
return true;
......@@ -94,8 +94,6 @@ bool menu_key(uint8_t key) {
case KEY_ESCAPE:
case KEY_CIRCLE:
menu_stop();
display_clear();
display_flush();
return false;
default:
for (int i = 0; items[i].label != NULL; i++) {
......@@ -103,8 +101,6 @@ bool menu_key(uint8_t key) {
}
// exit quietly
menu_stop();
display_clear();
display_flush();
return false;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment