Skip to content
Snippets Groups Projects
Commit 284f95b4 authored by minute's avatar minute
Browse files

keyboard-fw: mechanism for menu page auto-refresh; auto-refresh battery status every 2 seconds

parent 291a4a92
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
......@@ -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();
}
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment