commit 284f95b414feb1dcebc50add2362036c32ef1f1f
parent 291a4a929eaa4f8c4898c8c1dd9f7d38081aa8d0
Author: Lukas F. Hartmann <lukas@mntre.com>
Date: Thu, 1 Sep 2022 20:49:43 +0200
keyboard-fw: mechanism for menu page auto-refresh; auto-refresh battery status every 2 seconds
Diffstat:
5 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/reform2-keyboard-fw/hid_report.c b/reform2-keyboard-fw/hid_report.c
@@ -27,7 +27,7 @@
void hid_report_cmd(uint8_t* data) {
const uint32_t command = *(uint32_t *)data;
-
+
if (command == CMD_TEXT_FRAME) {
gfx_on();
for (int y=0; y<4; y++) {
@@ -49,6 +49,7 @@ void hid_report_cmd(uint8_t* data) {
kbd_brightness_set(brite);
}
else if (command == CMD_POWER_OFF) {
+ reset_menu();
anim_goodbye();
remote_turn_off_som();
keyboard_power_off();
diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c
@@ -95,6 +95,7 @@ void reset_keyboard_state(void) {
matrix_state[i] = 0;
}
last_meta_key = 0;
+ reset_menu();
}
inline bool is_media_key(uint8_t keycode) {
@@ -299,6 +300,9 @@ int main(void)
remote_check_for_low_battery();
counter = 0;
}
+ if (counter%2048 == 0) {
+ refresh_menu_page();
+ }
if (counter%750 == 0) {
remote_process_alerts();
}
diff --git a/reform2-keyboard-fw/menu.c b/reform2-keyboard-fw/menu.c
@@ -15,6 +15,7 @@
int current_menu_y = 0;
int current_scroll_y = 0;
+int current_menu_page = 0;
#ifdef KBD_VARIANT_STANDALONE
#define MENU_NUM_ITEMS 5
@@ -43,11 +44,16 @@ const MenuItem menu_items[] = {
// main system power.
{ "KBD Power-Off p", KEY_P },
};
-#endif
+#endif
-void reset_and_render_menu() {
+void reset_menu() {
current_scroll_y = 0;
current_menu_y = 0;
+ current_menu_page = MENU_PAGE_NONE;
+}
+
+void reset_and_render_menu() {
+ reset_menu();
render_menu(current_scroll_y);
}
@@ -61,8 +67,18 @@ void render_menu(int y) {
gfx_flush();
}
+// automatically refresh the current menu page if needed
+void refresh_menu_page() {
+ if (current_menu_page == MENU_PAGE_BATTERY_STATUS) {
+ remote_get_voltages();
+ }
+}
+
int execute_menu_function(int y) {
+ current_menu_page = MENU_PAGE_NONE;
+
if (y>=0 && y<MENU_NUM_ITEMS) {
+ current_menu_page = MENU_PAGE_OTHER;
return execute_meta_function(menu_items[y].keycode);
}
return execute_meta_function(KEY_ESCAPE);
@@ -102,6 +118,7 @@ int execute_meta_function(int keycode) {
remote_turn_off_aux();
}*/
else if (keycode == KEY_B) {
+ current_menu_page = MENU_PAGE_BATTERY_STATUS;
remote_get_voltages();
return 0;
}
diff --git a/reform2-keyboard-fw/menu.h b/reform2-keyboard-fw/menu.h
@@ -12,8 +12,14 @@ typedef struct MenuItem {
int keycode;
} MenuItem;
+#define MENU_PAGE_NONE 0
+#define MENU_PAGE_OTHER 1
+#define MENU_PAGE_BATTERY_STATUS 2
+
void reset_and_render_menu(void);
+void reset_menu(void);
void render_menu(int y);
+void refresh_menu_page(void);
int execute_menu_function(int y);
int execute_meta_function(int keycode);
void anim_hello(void);
diff --git a/reform2-keyboard-fw/remote.c b/reform2-keyboard-fw/remote.c
@@ -255,6 +255,7 @@ int remote_check_for_low_battery(void) {
for (int i=0; i<8; i++) {
// TODO: only accept digits
+ // FIXME: duplication from remote_get_voltages()
voltages[i] = ((float)((response[i*3]-'0')*10 + (response[i*3+1]-'0')))/10.0;
if (voltages[i]<0) voltages[i]=0;
if (voltages[i]>=10) voltages[i]=9.9;