#include <stddef.h>
#include "watch_extint.h"
#include "app.h"
+#include <emscripten.h>
+
static uint32_t watch_backup_data[8];
+static bool _wake_up = false;
+static watch_cb_t _callback = NULL;
+
+
+void _wake_up_simulator(void) {
+ _wake_up = true;
+}
+
+static void cb_extwake_wrapper(void) {
+ _wake_up_simulator();
+
+ if (_callback) {
+ _callback();
+ }
+}
+
void watch_register_extwake_callback(uint8_t pin, watch_cb_t callback, bool level) {
if (pin == HAL_GPIO_BTN_ALARM_pin()) {
+ _callback = callback;
watch_enable_external_interrupts();
- watch_register_interrupt_callback(pin, callback, level ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING);
+ watch_register_interrupt_callback(pin, cb_extwake_wrapper, level ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING);
}
}
void watch_disable_extwake_interrupt(uint8_t pin) {
if (pin == HAL_GPIO_BTN_ALARM_pin()) {
+ _callback = NULL;
watch_register_interrupt_callback(pin, NULL, INTERRUPT_TRIGGER_NONE);
}
}
void watch_enter_sleep_mode(void) {
// TODO: (a2) hook to UI
- // enter standby (4); we basically hang out here until an interrupt wakes us.
- // sleep(4);
+ // disable tick interrupt
+ watch_rtc_disable_all_periodic_callbacks();
+
+ // // disable all buttons but alarm
+ watch_register_interrupt_callback(HAL_GPIO_BTN_MODE_pin(), NULL, INTERRUPT_TRIGGER_NONE);
+ watch_register_interrupt_callback(HAL_GPIO_BTN_LIGHT_pin(), NULL, INTERRUPT_TRIGGER_NONE);
+
+ sleep(4);
// call app_setup so the app can re-enable everything we disabled.
app_setup();
}
-void watch_enter_deep_sleep_mode(void) {
- // identical to sleep mode except we disable the LCD first.
+void watch_enter_backup_mode(void) {
// TODO: (a2) hook to UI
- watch_enter_sleep_mode();
+ // go into backup sleep mode (5). when we exit, the reset controller will take over.
+ sleep(5);
}
-void watch_enter_backup_mode(void) {
- // TODO: (a2) hook to UI
+void sleep(const uint8_t mode) {
+ (void) mode;
- // go into backup sleep mode (5). when we exit, the reset controller will take over.
- // sleep(5);
+ // we basically hang out here until an interrupt wakes us.
+ while(!_wake_up) {
+ emscripten_sleep(100);
+ }
+
+ _wake_up = false;
}