Make idle selectable
[oswald.git] / ui / oswald_screens.c
index b6158d8..7790b70 100644 (file)
@@ -5,24 +5,58 @@
 
 #include "oswald_screens.h"
 
+typedef struct {
+       void (*screendraw_func)(boolean shoq_seconds);
+       boolean show_seconds;
+       boolean analogue;
+} idle_data_t;
+static idle_data_t idle_screen = {
+       DrawLcdDigitalClock,
+       FALSE,
+       FALSE,
+};
 void idle_handle_user_buttons(watch_button button)
 {
+       switch (button) {
+               case BUTTON_D:
+                       if (idle_screen.show_seconds)
+                               idle_screen.show_seconds = FALSE;
+                       else
+                               idle_screen.show_seconds = TRUE;
+                       break;
+               case BUTTON_E:
+                       if (idle_screen.analogue == TRUE) {
+                               idle_screen.analogue = FALSE;
+                               idle_screen.screendraw_func = DrawLcdDigitalClock;
+                       } else {
+                               idle_screen.analogue = TRUE;
+                               idle_screen.screendraw_func = DrawLcdAnaClock;
+                       };
+                       break;
+               default:
+                       break;
+       };
+       idle_screen.screendraw_func(idle_screen.show_seconds);
 }
+
 void idle_handle_events(u16t event, void *data)
 {
        switch (event) {
                case EVENT_ONE_SEC_TIMER:
                case EVENT_SCREEN_VISIBLE:
-                       DrawLcdDigitalClock();
+                       idle_screen.screendraw_func(idle_screen.show_seconds);
                        break;
                case EVENT_USER_BUTTONS:
                        dbg_out("button event %d\n", *(int *)data);
+                       idle_handle_user_buttons(*(watch_button *)data);
                        break;
                default:
                        break;
        };
 }
 
+
 void draw_accel_screen(void)
 {
        lcd_clear_display();
@@ -34,6 +68,7 @@ void draw_accel_screen(void)
        WriteLcdString(2, 34, "Y:");
        WriteLcdString(20, 34, "123");
 }
+
 void accel_handle_events(u16t event, void *data)
 {
        switch (event) {
@@ -48,6 +83,7 @@ void accel_handle_events(u16t event, void *data)
        };
 }
 
+
 void draw_datetime_setup_screen(void)
 {
        lcd_clear_display();
@@ -57,6 +93,7 @@ void draw_datetime_setup_screen(void)
        WriteLcdString(2, 34, "22:39");
        WriteLcdString(2, 50, "07.08.2012");
 }
+
 void datetime_setup_events(u16t event, void *data)
 {
        switch (event) {
@@ -71,7 +108,11 @@ void datetime_setup_events(u16t event, void *data)
        };
 }
 
-static u8t test_menu_pos = 0;
+
+typedef struct {
+       u8t menu_pos;
+} test_menu_t;
+static test_menu_t test_menu = { 0 };
 
 void draw_menu_test_screen(void)
 {
@@ -85,19 +126,19 @@ void draw_menu_test_screen(void)
        WriteLcdString(2, 47, "Item 4");
        WriteLcdString(2, 56, "Item 5");
 
-       WriteLcdString(50, 20+(9*test_menu_pos), "*");
+       WriteLcdString(50, 20+(9*test_menu.menu_pos), "*");
 }
 
 static void handle_menu_user_buttons(watch_button button)
 {
        switch (button) {
                case BUTTON_A:
-                       test_menu_pos--;
-                       test_menu_pos%=5;
+                       test_menu.menu_pos--;
+                       test_menu.menu_pos%=5;
                        break;
                case BUTTON_B:
-                       test_menu_pos++;
-                       test_menu_pos%=5;
+                       test_menu.menu_pos++;
+                       test_menu.menu_pos%=5;
                        break;
                default:
                        break;
@@ -113,7 +154,7 @@ void test_menu_handle_events(u16t event, void *data)
                        handle_menu_user_buttons(*(watch_button *)data);
                        break;
                case EVENT_SCREEN_VISIBLE:
-                       test_menu_pos = 0;
+                       test_menu.menu_pos = 0;
                        draw_menu_test_screen();
                        break;
                default: