Make idle selectable
[oswald.git] / ui / oswald_screens.c
1 #include "oswald.h"
2 #include "oswald_watch_faces.h"
3 #include "Fonts.h"
4 #include "LcdDisplay.h"
5
6 #include "oswald_screens.h"
7
8 typedef struct {
9         void (*screendraw_func)(boolean shoq_seconds);
10         boolean show_seconds;
11         boolean analogue;
12 } idle_data_t;
13 static idle_data_t idle_screen = {
14         DrawLcdDigitalClock,
15         FALSE,
16         FALSE,
17 };
18  
19 void idle_handle_user_buttons(watch_button button)
20 {
21         switch (button) {
22                 case BUTTON_D:
23                         if (idle_screen.show_seconds)
24                                 idle_screen.show_seconds = FALSE;
25                         else
26                                 idle_screen.show_seconds = TRUE;
27                         break;
28                 case BUTTON_E:
29                         if (idle_screen.analogue == TRUE) {
30                                 idle_screen.analogue = FALSE;
31                                 idle_screen.screendraw_func = DrawLcdDigitalClock;
32                         } else {
33                                 idle_screen.analogue = TRUE;
34                                 idle_screen.screendraw_func = DrawLcdAnaClock;
35                         };
36                         break;
37                 default:
38                         break;
39         };
40         idle_screen.screendraw_func(idle_screen.show_seconds);
41 }
42
43 void idle_handle_events(u16t event, void *data)
44 {
45         switch (event) {
46                 case EVENT_ONE_SEC_TIMER:
47                 case EVENT_SCREEN_VISIBLE:
48                         idle_screen.screendraw_func(idle_screen.show_seconds);
49                         break;
50                 case EVENT_USER_BUTTONS:
51                         dbg_out("button event %d\n", *(int *)data);
52                         idle_handle_user_buttons(*(watch_button *)data);
53                         break;
54                 default:
55                         break;
56         };
57 }
58
59
60 void draw_accel_screen(void)
61 {
62         lcd_clear_display();
63         SetFont(MetaWatch16);
64         WriteLcdString(2, 2, "X:");
65         WriteLcdString(20, 2, "123");
66         WriteLcdString(2, 18, "Z:");
67         WriteLcdString(20, 18, "123");
68         WriteLcdString(2, 34, "Y:");
69         WriteLcdString(20, 34, "123");
70 }
71
72 void accel_handle_events(u16t event, void *data)
73 {
74         switch (event) {
75                 case EVENT_SCREEN_VISIBLE:
76                         draw_accel_screen();
77                         break;
78                 case EVENT_USER_BUTTONS:
79                         dbg_out("button event %d\n", *(int *)data);
80                         break;
81                 default:
82                         break;
83         };
84 }
85
86
87 void draw_datetime_setup_screen(void)
88 {
89         lcd_clear_display();
90         SetFont(MetaWatch16);
91         WriteLcdString(2, 2, "Date / Time");
92         WriteLcdString(2, 18, "Setting");
93         WriteLcdString(2, 34, "22:39");
94         WriteLcdString(2, 50, "07.08.2012");
95 }
96
97 void datetime_setup_events(u16t event, void *data)
98 {
99         switch (event) {
100                 case EVENT_SCREEN_VISIBLE:
101                         draw_datetime_setup_screen();
102                         break;
103                 case EVENT_USER_BUTTONS:
104                         dbg_out("button event %d\n", *(int *)data);
105                         break;
106                 default:
107                         break;
108         };
109 }
110
111
112 typedef struct {
113         u8t menu_pos;
114 } test_menu_t;
115 static test_menu_t test_menu = { 0 };
116
117 void draw_menu_test_screen(void)
118 {
119         lcd_clear_display();
120         SetFont(MetaWatch16);
121         WriteLcdString(2, 2, "Menu");
122         SetFont(MetaWatch7);
123         WriteLcdString(2, 20, "Item 1");
124         WriteLcdString(2, 29, "Item 2");
125         WriteLcdString(2, 38, "Item 3");
126         WriteLcdString(2, 47, "Item 4");
127         WriteLcdString(2, 56, "Item 5");
128
129         WriteLcdString(50, 20+(9*test_menu.menu_pos), "*");
130 }
131
132 static void handle_menu_user_buttons(watch_button button)
133 {
134         switch (button) {
135                 case BUTTON_A:
136                         test_menu.menu_pos--;
137                         test_menu.menu_pos%=5;
138                         break;
139                 case BUTTON_B:
140                         test_menu.menu_pos++;
141                         test_menu.menu_pos%=5;
142                         break;
143                 default:
144                         break;
145         }
146         draw_menu_test_screen();
147 }
148
149 void test_menu_handle_events(u16t event, void *data)
150 {
151         switch (event) {
152                 case EVENT_USER_BUTTONS:
153                         dbg_out("button event %d\n", *(int *)data);
154                         handle_menu_user_buttons(*(watch_button *)data);
155                         break;
156                 case EVENT_SCREEN_VISIBLE:
157                         test_menu.menu_pos = 0;
158                         draw_menu_test_screen();
159                         break;
160                 default:
161                         break;
162         };
163 }
164