2 #include "oswald_watch_faces.h"
3 #include "oswald_screens.h"
6 #include "LcdDisplay.h"
8 #include "oswald_main.h"
11 * some variable defining our curent state
12 * these are globals in order to avoid having to pass pointers
13 * through function calls thus saving stack space
15 clock_state OswaldClk;
16 watch_state OswaldState;
17 watch_screen OswaldScreens[LAST_SCREEN];
20 void oswald_change_to_screen(screen_number screen_id)
22 // we spare the update if no change happened
23 if (OswaldState.screen_id != screen_id) {
24 OswaldState.screen_id = screen_id;
25 if ((OswaldState.screen->event_func != NULL) &&
26 (OswaldState.screen->event_mask & EVENT_SCREEN_VISIBLE))
27 OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
31 void oswald_set_time(u8t hour, u8t minute, u8t second)
33 OswaldClk.hour = hour;
34 OswaldClk.minute = minute;
35 OswaldClk.second = second;
38 static void update_clock_state (void)
40 OswaldClk.second += 1;
41 if (OswaldClk.second > 59) {
43 OswaldClk.minute += 1;
46 if (OswaldClk.minute > 59) {
51 if (OswaldClk.hour > 23) {
58 void oswald_one_second_tick(void)
60 /* update our 'RTC' */
63 /* wake-up screen if interested in the one-second-event */
64 if (OswaldState.screen->event_func != NULL &&
65 (OswaldState.screen->event_mask & EVENT_ONE_SEC_TIMER))
66 OswaldState.screen->event_func(EVENT_ONE_SEC_TIMER, NULL);
67 // oswald_update_screen();
70 void oswald_handle_button_press(watch_button button)
77 if (OswaldState.screen->event_func != NULL &&
78 (OswaldState.screen->event_mask & EVENT_USER_BUTTONS))
79 OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button);
83 OswaldState.screen_id++;
84 if (OswaldState.screen_id >= LAST_SCREEN) {
85 OswaldState.screen_id = IDLE_SCREEN;
87 OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
88 //oswald_update_screen();
89 OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
95 // should never get here
100 void oswald_init(void)
102 OswaldScreens[IDLE_SCREEN].event_mask = EVENT_ONE_SEC_TIMER;
103 OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events;
105 OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS;
106 OswaldScreens[ACCEL_DISPLAY_SCREEN].event_func = accel_handle_events;
109 OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
110 OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events;
112 OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS;
113 OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events;
115 OswaldState.screen_id = IDLE_SCREEN;
116 OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
117 OswaldState.idle_show_seconds = FALSE;
119 if (OswaldState.screen->event_func != NULL)
120 OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);