X-Git-Url: https://git.karo-electronics.de/?p=oswald.git;a=blobdiff_plain;f=ui%2Foswald_main.c;h=90be0d0a5fd6d831564d9fcb2b0696a961fa926b;hp=dc8cfa1c34401f5ad4553937f2c05dc4f4ea7331;hb=019424a494c8312fd8bac9eb89839aea943f4d88;hpb=013b763c4c6740bb48dfcb28c2dd8547ff7e7697 diff --git a/ui/oswald_main.c b/ui/oswald_main.c index dc8cfa1..90be0d0 100644 --- a/ui/oswald_main.c +++ b/ui/oswald_main.c @@ -1,8 +1,10 @@ #include "oswald.h" #include "oswald_watch_faces.h" +#include "oswald_screens.h" +#if 0 #include "Fonts.h" #include "LcdDisplay.h" - +#endif #include "oswald_main.h" /* @@ -12,19 +14,17 @@ */ clock_state OswaldClk; watch_state OswaldState; +watch_screen OswaldScreens[LAST_SCREEN]; -void update_screen(void) -{ - if (OswaldState.user_screendraw_func != NULL) - OswaldState.user_screendraw_func(); -} -void oswald_change_to_screen(screen_number screen) +void oswald_change_to_screen(screen_number screen_id) { // we spare the update if no change happened - if (OswaldState.screen != screen) { - OswaldState.screen = screen; - update_screen(); + if (OswaldState.screen_id != screen_id) { + OswaldState.screen_id = screen_id; + if ((OswaldState.screen->event_func != NULL) && + (OswaldState.screen->event_mask & EVENT_SCREEN_VISIBLE)) + OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL); } } @@ -57,24 +57,14 @@ static void update_clock_state (void) void oswald_one_second_tick(void) { + /* update our 'RTC' */ update_clock_state(); - update_screen(); -} -void draw_accel_screen(void) -{ - lcd_clear_display(); - SetFont(MetaWatch16); - WriteLcdString(2, 2, "X:"); - WriteLcdString(20, 2, "123"); - WriteLcdString(2, 18, "Z:"); - WriteLcdString(20, 18, "123"); - WriteLcdString(2, 34, "Y:"); - WriteLcdString(20, 34, "123"); -} - -void idle_handle_user_buttons(watch_button button) -{ + /* wake-up screen if interested in the one-second-event */ + if (OswaldState.screen->event_func != NULL && + (OswaldState.screen->event_mask & EVENT_ONE_SEC_TIMER)) + OswaldState.screen->event_func(EVENT_ONE_SEC_TIMER, NULL); + // oswald_update_screen(); } void oswald_handle_button_press(watch_button button) @@ -84,27 +74,19 @@ void oswald_handle_button_press(watch_button button) case BUTTON_B: case BUTTON_D: case BUTTON_E: - if (OswaldState.user_button_func != NULL) - OswaldState.user_button_func(button); + if (OswaldState.screen->event_func != NULL && + (OswaldState.screen->event_mask & EVENT_USER_BUTTONS)) + OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button); break; case BUTTON_C: // next screen - OswaldState.screen++; - if (OswaldState.screen >= LAST_SCREEN) { - OswaldState.screen = IDLE_SCREEN; - OswaldState.user_button_func = idle_handle_user_buttons; - OswaldState.user_screendraw_func = DrawLcdDigitalClock; - } else { - switch (OswaldState.screen) { - case SETTING_DATETIME_SCREEN: - OswaldState.user_button_func = idle_handle_user_buttons; - OswaldState.user_screendraw_func = draw_accel_screen; - break; - default: - break; - }; + OswaldState.screen_id++; + if (OswaldState.screen_id >= LAST_SCREEN) { + OswaldState.screen_id = IDLE_SCREEN; }; - update_screen(); + OswaldState.screen = &OswaldScreens[OswaldState.screen_id]; + //oswald_update_screen(); + OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL); break; case BUTTON_F: // backlight on/off @@ -117,9 +99,24 @@ void oswald_handle_button_press(watch_button button) void oswald_init(void) { - OswaldState.screen = IDLE_SCREEN; + OswaldScreens[IDLE_SCREEN].event_mask = EVENT_ONE_SEC_TIMER; + OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events; + + OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS; + OswaldScreens[ACCEL_DISPLAY_SCREEN].event_func = accel_handle_events; + + + OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER; + OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events; + + OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS; + OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events; + + OswaldState.screen_id = IDLE_SCREEN; + OswaldState.screen = &OswaldScreens[OswaldState.screen_id]; OswaldState.idle_show_seconds = FALSE; - OswaldState.user_screendraw_func = DrawLcdDigitalClock; - OswaldState.user_button_func = idle_handle_user_buttons; + + if (OswaldState.screen->event_func != NULL) + OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL); }