diff options
Diffstat (limited to 'watch-library/simulator')
-rw-r--r-- | watch-library/simulator/shell.html | 6 | ||||
-rw-r--r-- | watch-library/simulator/watch/watch_buzzer.c | 1 | ||||
-rw-r--r-- | watch-library/simulator/watch/watch_extint.c | 68 | ||||
-rw-r--r-- | watch-library/simulator/watch/watch_rtc.c | 4 |
4 files changed, 53 insertions, 26 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 @@ </div> </div> - <div style="display: flex; flex-direction: column; width: 100%"> + <form onSubmit="sendText(); return false" style="display: flex; flex-direction: column; width: 100%"> <textarea id="output" rows="8" style="width: 100%"></textarea> <div style="display: flex"> <input id="input" placeholder="Filesystem command (see filesystem.c)" style="flex-grow: 1"></input> - <button id="submit" onclick="sendText()">Send</button> + <button type="submit">Send</button> </div> - </div> + </form> <p> <a href="https://github.com/alexisphilip/Casio-F-91W">Original F-91W SVG</a> is © 2020 Alexis Philip, used here diff --git a/watch-library/simulator/watch/watch_buzzer.c b/watch-library/simulator/watch/watch_buzzer.c index 211235df..7ccb8545 100644 --- a/watch-library/simulator/watch/watch_buzzer.c +++ b/watch-library/simulator/watch/watch_buzzer.c @@ -23,6 +23,7 @@ */ #include "watch_buzzer.h" +#include "watch_private_buzzer.h" #include "watch_main_loop.h" #include <emscripten.h> diff --git a/watch-library/simulator/watch/watch_extint.c b/watch-library/simulator/watch/watch_extint.c index cbba4c3d..b5894b95 100644 --- a/watch-library/simulator/watch/watch_extint.c +++ b/watch-library/simulator/watch/watch_extint.c @@ -22,13 +22,15 @@ * SOFTWARE. */ +#include <string.h> + #include "watch_extint.h" #include "watch_main_loop.h" #include <emscripten.h> #include <emscripten/html5.h> -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,27 +47,47 @@ 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; - - const char *key = keyEvent->key; - if (key[1] != 0) return EM_FALSE; + if (debug_console_focused || keyEvent->repeat) 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; @@ -86,7 +108,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 +120,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'; diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c index f6279eed..2bb6074c 100644 --- a/watch-library/simulator/watch/watch_rtc.c +++ b/watch-library/simulator/watch/watch_rtc.c @@ -92,7 +92,7 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen if (__builtin_popcount(frequency) != 1) return; // this left-justifies the period in a 32-bit integer. - uint32_t tmp = frequency << 24; + uint32_t tmp = (frequency & 0xFF) << 24; // now we can count the leading zeroes to get the value we need. // 0x01 (1 Hz) will have 7 leading zeros for PER7. 0xF0 (128 Hz) will have no leading zeroes for PER0. uint8_t per_n = __builtin_clz(tmp); @@ -105,7 +105,7 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen void watch_rtc_disable_periodic_callback(uint8_t frequency) { if (__builtin_popcount(frequency) != 1) return; - uint8_t per_n = __builtin_clz(frequency << 24); + uint8_t per_n = __builtin_clz((frequency & 0xFF) << 24); if (tick_callbacks[per_n] != -1) { emscripten_clear_interval(tick_callbacks[per_n]); tick_callbacks[per_n] = -1; |