From 2534dc7a654b78b271495f37d2b5540c882a17f0 Mon Sep 17 00:00:00 2001 From: Hugo Chargois Date: Sat, 18 Nov 2023 02:21:23 +0100 Subject: [PATCH 1/3] Simulator: Allow typing a, l & m in console input These keys are the shortcuts to "press" the alarm, light and mode buttons. However, they prevent these letters from being input in the debug console to send filesystem commands. Strangely, there was already some code to allow typing these letters in the console output, but not in the input. --- watch-library/simulator/watch/watch_extint.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/watch-library/simulator/watch/watch_extint.c b/watch-library/simulator/watch/watch_extint.c index cbba4c3d..88e4f30a 100644 --- a/watch-library/simulator/watch/watch_extint.c +++ b/watch-library/simulator/watch/watch_extint.c @@ -28,7 +28,7 @@ #include #include -static bool output_focused = false; +static bool debug_console_focused = false; static bool external_interrupt_enabled = false; static bool button_callbacks_installed = false; static ext_irq_cb_t external_interrupt_mode_callback = NULL; @@ -45,7 +45,7 @@ static const uint8_t BTN_IDS[] = { BTN_ID_ALARM, BTN_ID_LIGHT, BTN_ID_MODE }; static EM_BOOL watch_invoke_interrupt_callback(const uint8_t button_id, watch_interrupt_trigger trigger); static EM_BOOL watch_invoke_key_callback(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData) { - if (output_focused || keyEvent->repeat) return EM_FALSE; + if (debug_console_focused || keyEvent->repeat) return EM_FALSE; const char *key = keyEvent->key; if (key[1] != 0) return EM_FALSE; @@ -86,7 +86,7 @@ static EM_BOOL watch_invoke_touch_callback(int eventType, const EmscriptenTouchE } static EM_BOOL watch_invoke_focus_callback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData) { - output_focused = eventType == EMSCRIPTEN_EVENT_FOCUS; + debug_console_focused = eventType == EMSCRIPTEN_EVENT_FOCUS; return EM_TRUE; } @@ -98,6 +98,10 @@ static void watch_install_button_callbacks(void) { emscripten_set_focus_callback(target_output, NULL, EM_FALSE, watch_invoke_focus_callback); emscripten_set_blur_callback(target_output, NULL, EM_FALSE, watch_invoke_focus_callback); + const char *target_input = "#input"; + emscripten_set_focus_callback(target_input, NULL, EM_FALSE, watch_invoke_focus_callback); + emscripten_set_blur_callback(target_input, NULL, EM_FALSE, watch_invoke_focus_callback); + for (int i = 0, count = sizeof(BTN_IDS) / sizeof(BTN_IDS[0]); i < count; i++) { char target[] = "#btn_"; target[4] = BTN_IDS[i] + '0'; From bd9d792230094ec447f9948a7a8f164d8f7535cb Mon Sep 17 00:00:00 2001 From: Hugo Chargois Date: Sat, 18 Nov 2023 02:29:44 +0100 Subject: [PATCH 2/3] Simulator: Allow sending debug command with Enter --- watch-library/simulator/shell.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/watch-library/simulator/shell.html b/watch-library/simulator/shell.html index c8da063e..29fbed03 100644 --- a/watch-library/simulator/shell.html +++ b/watch-library/simulator/shell.html @@ -907,13 +907,13 @@ -
+
- +
-
+

Original F-91W SVG is © 2020 Alexis Philip, used here From b82d7289371dd0245df2275dd9789b70b6b3d63b Mon Sep 17 00:00:00 2001 From: Hugo Chargois Date: Sat, 18 Nov 2023 02:22:03 +0100 Subject: [PATCH 3/3] Simulator: Add keyboard arrows as buttons shortcuts --- watch-library/simulator/watch/watch_extint.c | 58 ++++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/watch-library/simulator/watch/watch_extint.c b/watch-library/simulator/watch/watch_extint.c index 88e4f30a..b5894b95 100644 --- a/watch-library/simulator/watch/watch_extint.c +++ b/watch-library/simulator/watch/watch_extint.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include + #include "watch_extint.h" #include "watch_main_loop.h" @@ -47,25 +49,45 @@ static EM_BOOL watch_invoke_interrupt_callback(const uint8_t button_id, watch_in static EM_BOOL watch_invoke_key_callback(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData) { if (debug_console_focused || keyEvent->repeat) return EM_FALSE; - const char *key = keyEvent->key; - if (key[1] != 0) return EM_FALSE; - uint8_t button_id; - switch (key[0]) { - case 'A': - case 'a': - button_id = BTN_ID_ALARM; - break; - case 'L': - case 'l': - button_id = BTN_ID_LIGHT; - break; - case 'M': - case 'm': - button_id = BTN_ID_MODE; - break; - default: - return EM_FALSE; + const char *key = keyEvent->key; + if (key[1] == 0) { + // event is from a plain letter key + switch (key[0]) { + case 'A': + case 'a': + button_id = BTN_ID_ALARM; + break; + case 'L': + case 'l': + button_id = BTN_ID_LIGHT; + break; + case 'M': + case 'm': + button_id = BTN_ID_MODE; + break; + default: + return EM_FALSE; + } + } else if (strncmp(key, "Arrow", 5) == 0) { + // event is from one of the arrow keys + switch(key[5]) { + case 'U': // ArrowUp + button_id = BTN_ID_LIGHT; + break; + case 'D': // ArrowDown + case 'L': // ArrowLeft + button_id = BTN_ID_MODE; + break; + case 'R': // ArrowRight + button_id = BTN_ID_ALARM; + break; + default: + return EM_FALSE; + } + } else { + // another kind of key + return EM_FALSE; } watch_interrupt_trigger trigger = eventType == EMSCRIPTEN_EVENT_KEYDOWN ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING;