#include #include "alarm_target.h" #include "departures_window.h" #include "disruption_window.h" #include "line_window.h" #include "model.h" #include "station_window.h" #include "msg.h" #include "glance.h" #include "row_paint.h" #include "touch.h" static void on_update(uint8_t mask) { if (mask & (MSG_UPDATE_BOARD | MSG_UPDATE_CONFIG)) { departures_window_refresh(); station_window_refresh(); } if (mask & (MSG_UPDATE_LINE | MSG_UPDATE_CONFIG)) { line_window_refresh(); } if (mask & MSG_UPDATE_CONFIG) { disruption_window_refresh(); } } static void on_connection(bool connected) { if (connected) { model_set_state(STATE_LOADING); msg_request_refresh(departures_window_open_page()); } else { model_set_state(STATE_NO_PHONE); } on_update(MSG_UPDATE_BOARD | MSG_UPDATE_LINE | MSG_UPDATE_CONFIG); } static void on_tick(struct tm *tick_time, TimeUnits changed) { Page open_page = departures_window_open_page(); if (model_check_staleness(open_page, time(NULL)) == STALENESS_NUDGE) { msg_request_refresh(open_page); } departures_window_refresh(); line_window_refresh(); station_window_refresh(); disruption_window_refresh(); } static void on_wakeup(WakeupId id, int32_t cookie) { vibes_double_pulse(); alarm_target_clear(); on_update(MSG_UPDATE_BOARD | MSG_UPDATE_LINE | MSG_UPDATE_CONFIG); } int main(void) { model_init(); alarm_target_boot(); msg_init(on_update); touch_init(); wakeup_service_subscribe(on_wakeup); char wake_stop[ID_LEN] = ""; char wake_line[LINE_LEN] = ""; AlarmWakeKind wake_kind = ALARM_WAKE_LINE; if (launch_reason() == APP_LAUNCH_WAKEUP) { vibes_double_pulse(); strncpy(wake_stop, model_wakeup_stop_id(), ID_LEN - 1); wake_stop[ID_LEN - 1] = '\0'; strncpy(wake_line, model_wakeup_line(), LINE_LEN - 1); wake_line[LINE_LEN - 1] = '\0'; wake_kind = alarm_target_wake_kind(); alarm_target_clear(); } departures_window_push(); if (wake_stop[0] && wake_kind == ALARM_WAKE_STATION) { station_window_push_id(PAGE_TRAINS, wake_stop); } else if (wake_stop[0] && wake_line[0] && wake_kind == ALARM_WAKE_LINE) { line_window_push_label(wake_stop, wake_line, ""); } connection_service_subscribe((ConnectionHandlers){ .pebble_app_connection_handler = on_connection }); tick_timer_service_subscribe(MINUTE_UNIT, on_tick); app_event_loop(); touch_deinit(); glance_publish(); row_paint_deinit(); model_deinit(); }