... | ... |
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4 |
2 | 2 |
|
3 | 3 |
bin_PROGRAMS = oswald-gui |
4 | 4 |
|
5 |
-oswald_gui_SOURCES = oswald-ui.c LcdDisplay.c Fonts.c oswald_main.c oswald_watch_faces.c oswald_strings.c |
|
5 |
+oswald_gui_SOURCES = oswald-ui.c LcdDisplay.c Fonts.c oswald_main.c oswald_watch_faces.c oswald_strings.c oswald_screens.c |
|
6 | 6 |
oswald_gui_CFLAGS = -g $(GTK_CFLAGS) |
7 | 7 |
oswald_gui_LDADD = $(GTK_LIBS) |
8 | 8 |
|
... | ... |
@@ -91,7 +91,7 @@ void button_A_clicked (GtkButton *button, gpointer user_data) |
91 | 91 |
{ |
92 | 92 |
oswald_ui *ui = (oswald_ui *)user_data; |
93 | 93 |
|
94 |
- g_print("Button-A clicked\n"); |
|
94 |
+ // g_print("Button-A clicked\n"); |
|
95 | 95 |
oswald_handle_button_press(BUTTON_A); |
96 | 96 |
} |
97 | 97 |
|
... | ... |
@@ -99,7 +99,7 @@ void button_B_clicked (GtkButton *button, gpointer user_data) |
99 | 99 |
{ |
100 | 100 |
oswald_ui *ui = (oswald_ui *)user_data; |
101 | 101 |
|
102 |
- g_print("Button-B clicked\n"); |
|
102 |
+ // g_print("Button-B clicked\n"); |
|
103 | 103 |
oswald_handle_button_press(BUTTON_B); |
104 | 104 |
} |
105 | 105 |
|
... | ... |
@@ -107,7 +107,7 @@ void button_C_clicked (GtkButton *button, gpointer user_data) |
107 | 107 |
{ |
108 | 108 |
oswald_ui *ui = (oswald_ui *)user_data; |
109 | 109 |
|
110 |
- g_print("Button-C clicked\n"); |
|
110 |
+ // g_print("Button-C clicked\n"); |
|
111 | 111 |
oswald_handle_button_press(BUTTON_C); |
112 | 112 |
} |
113 | 113 |
|
... | ... |
@@ -115,7 +115,7 @@ void button_D_clicked (GtkButton *button, gpointer user_data) |
115 | 115 |
{ |
116 | 116 |
oswald_ui *ui = (oswald_ui *)user_data; |
117 | 117 |
|
118 |
- g_print("Button-D clicked\n"); |
|
118 |
+ // g_print("Button-D clicked\n"); |
|
119 | 119 |
oswald_handle_button_press(BUTTON_D); |
120 | 120 |
} |
121 | 121 |
|
... | ... |
@@ -123,7 +123,7 @@ void button_E_clicked (GtkButton *button, gpointer user_data) |
123 | 123 |
{ |
124 | 124 |
oswald_ui *ui = (oswald_ui *)user_data; |
125 | 125 |
|
126 |
- g_print("Button-E clicked\n"); |
|
126 |
+ // g_print("Button-E clicked\n"); |
|
127 | 127 |
oswald_handle_button_press(BUTTON_E); |
128 | 128 |
} |
129 | 129 |
|
... | ... |
@@ -131,7 +131,7 @@ void button_F_clicked (GtkButton *button, gpointer user_data) |
131 | 131 |
{ |
132 | 132 |
oswald_ui *ui = (oswald_ui *)user_data; |
133 | 133 |
|
134 |
- g_print("Button-F clicked\n"); |
|
134 |
+ // g_print("Button-F clicked\n"); |
|
135 | 135 |
oswald_handle_button_press(BUTTON_F); |
136 | 136 |
} |
137 | 137 |
|
... | ... |
@@ -180,7 +180,7 @@ static void create_mainwin(oswald_ui *ui) |
180 | 180 |
|
181 | 181 |
btn = gtk_button_new_with_label(" E "); |
182 | 182 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
183 |
- g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui); |
|
183 |
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_E_clicked), ui); |
|
184 | 184 |
|
185 | 185 |
btn = gtk_button_new_with_label(" F "); |
186 | 186 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
... | ... |
@@ -271,9 +271,10 @@ int main(int argc , char ** argv) |
271 | 271 |
gtk_init (&argc, &argv); |
272 | 272 |
|
273 | 273 |
create_mainwin(&ui); |
274 |
+ gtk_widget_realize(ui.mainwin); |
|
274 | 275 |
|
275 |
- oswald_init(); |
|
276 | 276 |
oswald_set_time(mtime.tm_hour, mtime.tm_min, mtime.tm_sec); |
277 |
+ oswald_init(); |
|
277 | 278 |
|
278 | 279 |
g_timeout_add_seconds(1, one_second_tmo_handler, &ui); |
279 | 280 |
// g_idle_add(app_idle_handler, &ui); |
... | ... |
@@ -1,6 +1,13 @@ |
1 | 1 |
#ifndef _OSWALD_H |
2 | 2 |
#define _OSWALD_H |
3 | 3 |
|
4 |
+#define DEBUG 1 |
|
5 |
+#ifdef DEBUG |
|
6 |
+#define dbg_out( args... ) fprintf(stderr, args) |
|
7 |
+#else |
|
8 |
+#define dbg_out( args... ) do {} while (0) |
|
9 |
+#endif |
|
10 |
+ |
|
4 | 11 |
typedef signed char s8t; |
5 | 12 |
typedef unsigned char u8t; |
6 | 13 |
typedef signed short s16t; |
... | ... |
@@ -29,7 +36,9 @@ typedef struct { |
29 | 36 |
|
30 | 37 |
typedef enum { |
31 | 38 |
IDLE_SCREEN = 0, |
32 |
- SETTING_DATETIME_SCREEN, |
|
39 |
+ ACCEL_DISPLAY_SCREEN, |
|
40 |
+ DATETIME_SETTING_SCREEN, |
|
41 |
+ MENU_TEST_SCREEN, |
|
33 | 42 |
// SCREEN2_SCREEN, |
34 | 43 |
// SCREEN3_SCREEN, |
35 | 44 |
// APPLICATION_SCREEN, |
... | ... |
@@ -45,16 +54,31 @@ typedef enum { |
45 | 54 |
BUTTON_F, |
46 | 55 |
} watch_button; |
47 | 56 |
|
57 |
+#define EVENT_SCREEN_VISIBLE (1<<0) // screen just became visible |
|
58 |
+#define EVENT_SCREEN_DESTROY (1<<1) // screen is destroyed |
|
59 |
+#define EVENT_ONE_SEC_TIMER (1<<2) |
|
60 |
+#define EVENT_MS_TIMER (1<<3) |
|
61 |
+#define EVENT_USER_BUTTONS (1<<4) |
|
62 |
+#define EVENT_ACCEL_UPDATE (1<<5) |
|
63 |
+#define EVENT_AMBIENTLIGHT_UPDATE (1<<6) |
|
64 |
+#define EVENT_POWER_CHANGE (1<<7) |
|
65 |
+#define EVENT_COMMS (1<<8) |
|
66 |
+ |
|
48 | 67 |
typedef struct { |
49 |
- void (*button_func)(watch_button button); |
|
68 |
+ u16t event_mask; // the event the screen wants to receive |
|
69 |
+ void (*event_func)(u16t event, void *data); // callback for events |
|
70 |
+// void (*button_func)(watch_button button); // handles button presses |
|
71 |
+// void (*screendraw_func)(void); // callback for screen update |
|
72 |
+// void *user_data; |
|
50 | 73 |
} watch_screen; |
51 | 74 |
|
52 | 75 |
typedef struct { |
53 |
- screen_number screen; |
|
76 |
+ screen_number screen_id; |
|
54 | 77 |
// void (*draw_watchface_func)(boolean show_seconds); |
55 | 78 |
boolean idle_show_seconds; |
56 |
- void (*user_button_func)(watch_button button); |
|
57 |
- void (*user_screendraw_func)(void); |
|
79 |
+ watch_screen *screen; // the current screen |
|
80 |
+ // void (*user_button_func)(watch_button button); |
|
81 |
+ // void (*user_screendraw_func)(void); |
|
58 | 82 |
} watch_state; |
59 | 83 |
|
60 | 84 |
#endif |
... | ... |
@@ -1,8 +1,10 @@ |
1 | 1 |
#include "oswald.h" |
2 | 2 |
#include "oswald_watch_faces.h" |
3 |
+#include "oswald_screens.h" |
|
4 |
+#if 0 |
|
3 | 5 |
#include "Fonts.h" |
4 | 6 |
#include "LcdDisplay.h" |
5 |
- |
|
7 |
+#endif |
|
6 | 8 |
#include "oswald_main.h" |
7 | 9 |
|
8 | 10 |
/* |
... | ... |
@@ -12,19 +14,17 @@ |
12 | 14 |
*/ |
13 | 15 |
clock_state OswaldClk; |
14 | 16 |
watch_state OswaldState; |
17 |
+watch_screen OswaldScreens[LAST_SCREEN]; |
|
15 | 18 |
|
16 |
-void update_screen(void) |
|
17 |
-{ |
|
18 |
- if (OswaldState.user_screendraw_func != NULL) |
|
19 |
- OswaldState.user_screendraw_func(); |
|
20 |
-} |
|
21 | 19 |
|
22 |
-void oswald_change_to_screen(screen_number screen) |
|
20 |
+void oswald_change_to_screen(screen_number screen_id) |
|
23 | 21 |
{ |
24 | 22 |
// we spare the update if no change happened |
25 |
- if (OswaldState.screen != screen) { |
|
26 |
- OswaldState.screen = screen; |
|
27 |
- update_screen(); |
|
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); |
|
28 | 28 |
} |
29 | 29 |
} |
30 | 30 |
|
... | ... |
@@ -57,24 +57,14 @@ static void update_clock_state (void) |
57 | 57 |
|
58 | 58 |
void oswald_one_second_tick(void) |
59 | 59 |
{ |
60 |
+ /* update our 'RTC' */ |
|
60 | 61 |
update_clock_state(); |
61 |
- update_screen(); |
|
62 |
-} |
|
63 | 62 |
|
64 |
-void draw_accel_screen(void) |
|
65 |
-{ |
|
66 |
- lcd_clear_display(); |
|
67 |
- SetFont(MetaWatch16); |
|
68 |
- WriteLcdString(2, 2, "X:"); |
|
69 |
- WriteLcdString(20, 2, "123"); |
|
70 |
- WriteLcdString(2, 18, "Z:"); |
|
71 |
- WriteLcdString(20, 18, "123"); |
|
72 |
- WriteLcdString(2, 34, "Y:"); |
|
73 |
- WriteLcdString(20, 34, "123"); |
|
74 |
-} |
|
75 |
- |
|
76 |
-void idle_handle_user_buttons(watch_button button) |
|
77 |
-{ |
|
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(); |
|
78 | 68 |
} |
79 | 69 |
|
80 | 70 |
void oswald_handle_button_press(watch_button button) |
... | ... |
@@ -84,27 +74,19 @@ void oswald_handle_button_press(watch_button button) |
84 | 74 |
case BUTTON_B: |
85 | 75 |
case BUTTON_D: |
86 | 76 |
case BUTTON_E: |
87 |
- if (OswaldState.user_button_func != NULL) |
|
88 |
- OswaldState.user_button_func(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); |
|
89 | 80 |
break; |
90 | 81 |
case BUTTON_C: |
91 | 82 |
// next screen |
92 |
- OswaldState.screen++; |
|
93 |
- if (OswaldState.screen >= LAST_SCREEN) { |
|
94 |
- OswaldState.screen = IDLE_SCREEN; |
|
95 |
- OswaldState.user_button_func = idle_handle_user_buttons; |
|
96 |
- OswaldState.user_screendraw_func = DrawLcdDigitalClock; |
|
97 |
- } else { |
|
98 |
- switch (OswaldState.screen) { |
|
99 |
- case SETTING_DATETIME_SCREEN: |
|
100 |
- OswaldState.user_button_func = idle_handle_user_buttons; |
|
101 |
- OswaldState.user_screendraw_func = draw_accel_screen; |
|
102 |
- break; |
|
103 |
- default: |
|
104 |
- break; |
|
105 |
- }; |
|
83 |
+ OswaldState.screen_id++; |
|
84 |
+ if (OswaldState.screen_id >= LAST_SCREEN) { |
|
85 |
+ OswaldState.screen_id = IDLE_SCREEN; |
|
106 | 86 |
}; |
107 |
- update_screen(); |
|
87 |
+ OswaldState.screen = &OswaldScreens[OswaldState.screen_id]; |
|
88 |
+ //oswald_update_screen(); |
|
89 |
+ OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL); |
|
108 | 90 |
break; |
109 | 91 |
case BUTTON_F: |
110 | 92 |
// backlight on/off |
... | ... |
@@ -117,9 +99,24 @@ void oswald_handle_button_press(watch_button button) |
117 | 99 |
|
118 | 100 |
void oswald_init(void) |
119 | 101 |
{ |
120 |
- OswaldState.screen = IDLE_SCREEN; |
|
102 |
+ OswaldScreens[IDLE_SCREEN].event_mask = EVENT_ONE_SEC_TIMER; |
|
103 |
+ OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events; |
|
104 |
+ |
|
105 |
+ OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS; |
|
106 |
+ OswaldScreens[ACCEL_DISPLAY_SCREEN].event_func = accel_handle_events; |
|
107 |
+ |
|
108 |
+ |
|
109 |
+ OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER; |
|
110 |
+ OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events; |
|
111 |
+ |
|
112 |
+ OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS; |
|
113 |
+ OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events; |
|
114 |
+ |
|
115 |
+ OswaldState.screen_id = IDLE_SCREEN; |
|
116 |
+ OswaldState.screen = &OswaldScreens[OswaldState.screen_id]; |
|
121 | 117 |
OswaldState.idle_show_seconds = FALSE; |
122 |
- OswaldState.user_screendraw_func = DrawLcdDigitalClock; |
|
123 |
- OswaldState.user_button_func = idle_handle_user_buttons; |
|
118 |
+ |
|
119 |
+ if (OswaldState.screen->event_func != NULL) |
|
120 |
+ OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL); |
|
124 | 121 |
} |
125 | 122 |
|
11 | 12 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,123 @@ |
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 |
+void idle_handle_user_buttons(watch_button button) |
|
9 |
+{ |
|
10 |
+} |
|
11 |
+void idle_handle_events(u16t event, void *data) |
|
12 |
+{ |
|
13 |
+ switch (event) { |
|
14 |
+ case EVENT_ONE_SEC_TIMER: |
|
15 |
+ case EVENT_SCREEN_VISIBLE: |
|
16 |
+ DrawLcdDigitalClock(); |
|
17 |
+ break; |
|
18 |
+ case EVENT_USER_BUTTONS: |
|
19 |
+ dbg_out("button event %d\n", *(int *)data); |
|
20 |
+ break; |
|
21 |
+ default: |
|
22 |
+ break; |
|
23 |
+ }; |
|
24 |
+} |
|
25 |
+ |
|
26 |
+void draw_accel_screen(void) |
|
27 |
+{ |
|
28 |
+ lcd_clear_display(); |
|
29 |
+ SetFont(MetaWatch16); |
|
30 |
+ WriteLcdString(2, 2, "X:"); |
|
31 |
+ WriteLcdString(20, 2, "123"); |
|
32 |
+ WriteLcdString(2, 18, "Z:"); |
|
33 |
+ WriteLcdString(20, 18, "123"); |
|
34 |
+ WriteLcdString(2, 34, "Y:"); |
|
35 |
+ WriteLcdString(20, 34, "123"); |
|
36 |
+} |
|
37 |
+void accel_handle_events(u16t event, void *data) |
|
38 |
+{ |
|
39 |
+ switch (event) { |
|
40 |
+ case EVENT_SCREEN_VISIBLE: |
|
41 |
+ draw_accel_screen(); |
|
42 |
+ break; |
|
43 |
+ case EVENT_USER_BUTTONS: |
|
44 |
+ dbg_out("button event %d\n", *(int *)data); |
|
45 |
+ break; |
|
46 |
+ default: |
|
47 |
+ break; |
|
48 |
+ }; |
|
49 |
+} |
|
50 |
+ |
|
51 |
+void draw_datetime_setup_screen(void) |
|
52 |
+{ |
|
53 |
+ lcd_clear_display(); |
|
54 |
+ SetFont(MetaWatch16); |
|
55 |
+ WriteLcdString(2, 2, "Date / Time"); |
|
56 |
+ WriteLcdString(2, 18, "Setting"); |
|
57 |
+ WriteLcdString(2, 34, "22:39"); |
|
58 |
+ WriteLcdString(2, 50, "07.08.2012"); |
|
59 |
+} |
|
60 |
+void datetime_setup_events(u16t event, void *data) |
|
61 |
+{ |
|
62 |
+ switch (event) { |
|
63 |
+ case EVENT_SCREEN_VISIBLE: |
|
64 |
+ draw_datetime_setup_screen(); |
|
65 |
+ break; |
|
66 |
+ case EVENT_USER_BUTTONS: |
|
67 |
+ dbg_out("button event %d\n", *(int *)data); |
|
68 |
+ break; |
|
69 |
+ default: |
|
70 |
+ break; |
|
71 |
+ }; |
|
72 |
+} |
|
73 |
+ |
|
74 |
+static u8t test_menu_pos = 0; |
|
75 |
+ |
|
76 |
+void draw_menu_test_screen(void) |
|
77 |
+{ |
|
78 |
+ lcd_clear_display(); |
|
79 |
+ SetFont(MetaWatch16); |
|
80 |
+ WriteLcdString(2, 2, "Menu"); |
|
81 |
+ SetFont(MetaWatch7); |
|
82 |
+ WriteLcdString(2, 20, "Item 1"); |
|
83 |
+ WriteLcdString(2, 29, "Item 2"); |
|
84 |
+ WriteLcdString(2, 38, "Item 3"); |
|
85 |
+ WriteLcdString(2, 47, "Item 4"); |
|
86 |
+ WriteLcdString(2, 56, "Item 5"); |
|
87 |
+ |
|
88 |
+ WriteLcdString(50, 20+(9*test_menu_pos), "*"); |
|
89 |
+} |
|
90 |
+ |
|
91 |
+static void handle_menu_user_buttons(watch_button button) |
|
92 |
+{ |
|
93 |
+ switch (button) { |
|
94 |
+ case BUTTON_A: |
|
95 |
+ test_menu_pos--; |
|
96 |
+ test_menu_pos%=5; |
|
97 |
+ break; |
|
98 |
+ case BUTTON_B: |
|
99 |
+ test_menu_pos++; |
|
100 |
+ test_menu_pos%=5; |
|
101 |
+ break; |
|
102 |
+ default: |
|
103 |
+ break; |
|
104 |
+ } |
|
105 |
+ draw_menu_test_screen(); |
|
106 |
+} |
|
107 |
+ |
|
108 |
+void test_menu_handle_events(u16t event, void *data) |
|
109 |
+{ |
|
110 |
+ switch (event) { |
|
111 |
+ case EVENT_USER_BUTTONS: |
|
112 |
+ dbg_out("button event %d\n", *(int *)data); |
|
113 |
+ handle_menu_user_buttons(*(watch_button *)data); |
|
114 |
+ break; |
|
115 |
+ case EVENT_SCREEN_VISIBLE: |
|
116 |
+ test_menu_pos = 0; |
|
117 |
+ draw_menu_test_screen(); |
|
118 |
+ break; |
|
119 |
+ default: |
|
120 |
+ break; |
|
121 |
+ }; |
|
122 |
+} |
|
123 |
+ |
0 | 124 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,17 @@ |
1 |
+#ifndef _OSWALD_SCREENS_H |
|
2 |
+#define _OSWALD_SCREENS_H |
|
3 |
+ |
|
4 |
+void idle_handle_user_buttons(watch_button button); |
|
5 |
+void idle_handle_events(u16t event, void *data); |
|
6 |
+ |
|
7 |
+void draw_accel_screen(void); |
|
8 |
+void accel_handle_events(u16t event, void *data); |
|
9 |
+ |
|
10 |
+void draw_datetime_setup_screen(void); |
|
11 |
+void datetime_setup_events(u16t event, void *data); |
|
12 |
+ |
|
13 |
+void draw_menu_test_screen(void); |
|
14 |
+void test_menu_handle_events(u16t event, void *data); |
|
15 |
+ |
|
16 |
+#endif |
|
17 |
+ |