... | ... |
@@ -1,9 +1,5 @@ |
1 |
-#include <time.h> |
|
2 |
-#include <stdio.h> |
|
3 |
-#include <string.h> |
|
4 |
-#include <math.h> |
|
5 |
- |
|
6 | 1 |
#include "oswald-ui.h" |
2 |
+#include "oswald_strings.h" |
|
7 | 3 |
#include "Fonts.h" |
8 | 4 |
|
9 | 5 |
#include "LcdDisplay.h" |
... | ... |
@@ -142,13 +138,14 @@ u8t WriteLcdCharacter(u8t x, u8t y, u8t Character) |
142 | 138 |
|
143 | 139 |
void WriteLcdString(u8t x, u8t y, u8t *str) |
144 | 140 |
{ |
145 |
- register lx, i; |
|
141 |
+ register lx, i, strl; |
|
146 | 142 |
|
147 |
- if (str == NULL || strlen(str)==0) |
|
143 |
+ strl = oswald_strlen(str); |
|
144 |
+ if (strl == 0) |
|
148 | 145 |
return; |
149 | 146 |
|
150 | 147 |
lx = x; |
151 |
- for (i=0; i<strlen(str); i++) { |
|
148 |
+ for (i=0; i<strl; i++) { |
|
152 | 149 |
lx += WriteLcdCharacter(lx, y, str[i]); |
153 | 150 |
} |
154 | 151 |
} |
... | ... |
@@ -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 |
|
5 |
+oswald_gui_SOURCES = oswald-ui.c LcdDisplay.c Fonts.c oswald_main.c oswald_watch_faces.c oswald_strings.c |
|
6 | 6 |
oswald_gui_CFLAGS = -g $(GTK_CFLAGS) |
7 | 7 |
oswald_gui_LDADD = $(GTK_LIBS) |
8 | 8 |
|
... | ... |
@@ -13,6 +13,7 @@ |
13 | 13 |
#include <gtk/gtk.h> |
14 | 14 |
|
15 | 15 |
#include "Fonts.h" // the MetaWatch fonts |
16 |
+#include "oswald.h" |
|
16 | 17 |
#include "oswald_main.h" |
17 | 18 |
|
18 | 19 |
#include "oswald-ui.h" |
... | ... |
@@ -86,52 +87,77 @@ expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) |
86 | 87 |
return FALSE; |
87 | 88 |
} |
88 | 89 |
|
89 |
-void button_A_pressed (GtkButton *button, gpointer user_data) |
|
90 |
+void button_A_clicked (GtkButton *button, gpointer user_data) |
|
90 | 91 |
{ |
91 | 92 |
oswald_ui *ui = (oswald_ui *)user_data; |
92 | 93 |
|
93 |
- g_print("Button-A pressed\n"); |
|
94 |
+ g_print("Button-A clicked\n"); |
|
94 | 95 |
oswald_handle_button_press(BUTTON_A); |
95 | 96 |
} |
96 | 97 |
|
97 |
-void button_B_pressed (GtkButton *button, gpointer user_data) |
|
98 |
+void button_B_clicked (GtkButton *button, gpointer user_data) |
|
98 | 99 |
{ |
99 | 100 |
oswald_ui *ui = (oswald_ui *)user_data; |
100 | 101 |
|
101 |
- g_print("Button-B pressed\n"); |
|
102 |
+ g_print("Button-B clicked\n"); |
|
103 |
+ oswald_handle_button_press(BUTTON_B); |
|
102 | 104 |
} |
103 | 105 |
|
104 |
-void button_C_pressed (GtkButton *button, gpointer user_data) |
|
106 |
+void button_C_clicked (GtkButton *button, gpointer user_data) |
|
105 | 107 |
{ |
106 | 108 |
oswald_ui *ui = (oswald_ui *)user_data; |
107 | 109 |
|
108 |
- g_print("Button-C pressed\n"); |
|
110 |
+ g_print("Button-C clicked\n"); |
|
111 |
+ oswald_handle_button_press(BUTTON_C); |
|
109 | 112 |
} |
110 | 113 |
|
111 |
-void button_D_pressed (GtkButton *button, gpointer user_data) |
|
114 |
+void button_D_clicked (GtkButton *button, gpointer user_data) |
|
112 | 115 |
{ |
113 | 116 |
oswald_ui *ui = (oswald_ui *)user_data; |
114 | 117 |
|
115 |
- g_print("Button-D pressed\n"); |
|
118 |
+ g_print("Button-D clicked\n"); |
|
119 |
+ oswald_handle_button_press(BUTTON_D); |
|
116 | 120 |
} |
117 | 121 |
|
118 |
-void button_E_pressed (GtkButton *button, gpointer user_data) |
|
122 |
+void button_E_clicked (GtkButton *button, gpointer user_data) |
|
119 | 123 |
{ |
120 | 124 |
oswald_ui *ui = (oswald_ui *)user_data; |
121 | 125 |
|
122 |
- g_print("Button-E pressed\n"); |
|
126 |
+ g_print("Button-E clicked\n"); |
|
127 |
+ oswald_handle_button_press(BUTTON_E); |
|
123 | 128 |
} |
124 | 129 |
|
125 |
-void button_F_pressed (GtkButton *button, gpointer user_data) |
|
130 |
+void button_F_clicked (GtkButton *button, gpointer user_data) |
|
126 | 131 |
{ |
127 | 132 |
oswald_ui *ui = (oswald_ui *)user_data; |
128 | 133 |
|
129 |
- g_print("Button-F pressed\n"); |
|
134 |
+ g_print("Button-F clicked\n"); |
|
135 |
+ oswald_handle_button_press(BUTTON_F); |
|
136 |
+} |
|
137 |
+ |
|
138 |
+gboolean button_F_pr (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
|
139 |
+{ |
|
140 |
+ oswald_ui *ui = (oswald_ui *)user_data; |
|
141 |
+ static gint32 press_time; |
|
142 |
+ |
|
143 |
+ GdkEventButton *bev = (GdkEventButton *)event; |
|
144 |
+ if (bev->type == GDK_BUTTON_PRESS) { |
|
145 |
+ press_time = bev->time; |
|
146 |
+ return FALSE; |
|
147 |
+ }; |
|
148 |
+ if (bev->type == GDK_BUTTON_RELEASE) { |
|
149 |
+ if (bev->time > (press_time+1000)) { |
|
150 |
+ g_print("Button-F long press\n"); |
|
151 |
+ return TRUE; |
|
152 |
+ }; |
|
153 |
+ }; |
|
154 |
+ |
|
155 |
+ return FALSE; |
|
130 | 156 |
} |
131 | 157 |
|
132 | 158 |
static void create_mainwin(oswald_ui *ui) |
133 | 159 |
{ |
134 |
- GtkWidget *hb, *vb, *btn; |
|
160 |
+ GtkWidget *mvb, *hb, *vb, *btn, *sc, *l; |
|
135 | 161 |
|
136 | 162 |
ui->pixmap = NULL; |
137 | 163 |
|
... | ... |
@@ -139,24 +165,28 @@ static void create_mainwin(oswald_ui *ui) |
139 | 165 |
// gtk_window_set_default_size (GTK_WINDOW (ui->mainwin), 440, 240); |
140 | 166 |
g_signal_connect(G_OBJECT(ui->mainwin), "destroy", gtk_main_quit, NULL); |
141 | 167 |
|
168 |
+ mvb = gtk_vbox_new(FALSE, 5); |
|
169 |
+ gtk_container_add(GTK_CONTAINER(ui->mainwin), mvb); |
|
170 |
+ |
|
142 | 171 |
hb = gtk_hbox_new(FALSE, 5); |
143 |
- gtk_container_add(GTK_CONTAINER(ui->mainwin), hb); |
|
172 |
+ gtk_box_pack_start (GTK_BOX(mvb), hb, FALSE, FALSE, 5); |
|
144 | 173 |
|
145 | 174 |
vb = gtk_vbox_new(FALSE, 5); |
146 | 175 |
gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5); |
147 | 176 |
|
148 | 177 |
btn = gtk_button_new_with_label(" D "); |
149 | 178 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
150 |
- g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_pressed), ui); |
|
179 |
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui); |
|
151 | 180 |
|
152 | 181 |
btn = gtk_button_new_with_label(" E "); |
153 | 182 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
154 |
- g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_pressed), ui); |
|
183 |
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui); |
|
155 | 184 |
|
156 | 185 |
btn = gtk_button_new_with_label(" F "); |
157 | 186 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
158 |
- g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_pressed), ui); |
|
159 |
- |
|
187 |
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_clicked), ui); |
|
188 |
+ g_signal_connect(G_OBJECT(btn), "button-press-event", G_CALLBACK(button_F_pr), ui); |
|
189 |
+ g_signal_connect(G_OBJECT(btn), "button-release-event", G_CALLBACK(button_F_pr), ui); |
|
160 | 190 |
|
161 | 191 |
ui->darea = gtk_drawing_area_new (); |
162 | 192 |
gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5); |
... | ... |
@@ -178,15 +208,36 @@ static void create_mainwin(oswald_ui *ui) |
178 | 208 |
|
179 | 209 |
btn = gtk_button_new_with_label(" A "); |
180 | 210 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
181 |
- g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_A_pressed), ui); |
|
211 |
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_A_clicked), ui); |
|
182 | 212 |
|
183 | 213 |
btn = gtk_button_new_with_label(" B "); |
184 | 214 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
185 |
- g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_B_pressed), ui); |
|
215 |
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_B_clicked), ui); |
|
186 | 216 |
|
187 | 217 |
btn = gtk_button_new_with_label(" C "); |
188 | 218 |
gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); |
189 |
- g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_C_pressed), ui); |
|
219 |
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_C_clicked), ui); |
|
220 |
+ |
|
221 |
+ sc = gtk_vscale_new_with_range (0, 255, 1); |
|
222 |
+ gtk_box_pack_start (GTK_BOX(hb), sc, FALSE, FALSE, 5); |
|
223 |
+ |
|
224 |
+ hb = gtk_hbox_new(FALSE, 0); |
|
225 |
+ gtk_box_pack_start (GTK_BOX(mvb), hb, FALSE, FALSE, 5); |
|
226 |
+ |
|
227 |
+ l = gtk_label_new("X:"); |
|
228 |
+ gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5); |
|
229 |
+ sc = gtk_hscale_new_with_range (0, 255, 1); |
|
230 |
+ gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5); |
|
231 |
+ |
|
232 |
+ l = gtk_label_new("Y:"); |
|
233 |
+ gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5); |
|
234 |
+ sc = gtk_hscale_new_with_range (0, 255, 1); |
|
235 |
+ gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5); |
|
236 |
+ |
|
237 |
+ l = gtk_label_new("Z:"); |
|
238 |
+ gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5); |
|
239 |
+ sc = gtk_hscale_new_with_range (0, 255, 1); |
|
240 |
+ gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5); |
|
190 | 241 |
|
191 | 242 |
gtk_widget_show_all(ui->mainwin); |
192 | 243 |
} |
... | ... |
@@ -3,6 +3,8 @@ |
3 | 3 |
|
4 | 4 |
typedef signed char s8t; |
5 | 5 |
typedef unsigned char u8t; |
6 |
+typedef signed short s16t; |
|
7 |
+typedef unsigned short u16t; |
|
6 | 8 |
typedef u8t boolean; |
7 | 9 |
#ifdef TRUE |
8 | 10 |
#undef TRUE |
... | ... |
@@ -27,7 +29,11 @@ typedef struct { |
27 | 29 |
|
28 | 30 |
typedef enum { |
29 | 31 |
IDLE_SCREEN = 0, |
30 |
- APPLICATION_SCREEN, |
|
32 |
+ SETTING_DATETIME_SCREEN, |
|
33 |
+// SCREEN2_SCREEN, |
|
34 |
+// SCREEN3_SCREEN, |
|
35 |
+// APPLICATION_SCREEN, |
|
36 |
+ LAST_SCREEN, // a marker for the last (not valid) screen) |
|
31 | 37 |
} screen_number; |
32 | 38 |
|
33 | 39 |
typedef enum { |
... | ... |
@@ -39,12 +45,17 @@ typedef enum { |
39 | 45 |
BUTTON_F, |
40 | 46 |
} watch_button; |
41 | 47 |
|
48 |
+typedef struct { |
|
49 |
+ void (*button_func)(watch_button button); |
|
50 |
+} watch_screen; |
|
51 |
+ |
|
42 | 52 |
typedef struct { |
43 | 53 |
screen_number screen; |
44 |
- void (*idle_draw_func)(boolean show_seconds); |
|
54 |
+ // void (*draw_watchface_func)(boolean show_seconds); |
|
45 | 55 |
boolean idle_show_seconds; |
56 |
+ void (*user_button_func)(watch_button button); |
|
57 |
+ void (*user_screendraw_func)(void); |
|
46 | 58 |
} watch_state; |
47 | 59 |
|
48 |
- |
|
49 | 60 |
#endif |
50 | 61 |
|
... | ... |
@@ -1,5 +1,7 @@ |
1 | 1 |
#include "oswald.h" |
2 | 2 |
#include "oswald_watch_faces.h" |
3 |
+#include "Fonts.h" |
|
4 |
+#include "LcdDisplay.h" |
|
3 | 5 |
|
4 | 6 |
#include "oswald_main.h" |
5 | 7 |
|
... | ... |
@@ -13,21 +15,13 @@ watch_state OswaldState; |
13 | 15 |
|
14 | 16 |
void update_screen(void) |
15 | 17 |
{ |
16 |
- switch (OswaldState.screen) { |
|
17 |
- case IDLE_SCREEN: |
|
18 |
- if (OswaldState.idle_draw_func != NULL) |
|
19 |
- OswaldState.idle_draw_func(OswaldState.idle_show_seconds); |
|
20 |
- break; |
|
21 |
- case APPLICATION_SCREEN: |
|
22 |
- break; |
|
23 |
- deafault: |
|
24 |
- break; |
|
25 |
- }; |
|
18 |
+ if (OswaldState.user_screendraw_func != NULL) |
|
19 |
+ OswaldState.user_screendraw_func(); |
|
26 | 20 |
} |
27 | 21 |
|
28 | 22 |
void oswald_change_to_screen(screen_number screen) |
29 | 23 |
{ |
30 |
- // we spare the update if no change |
|
24 |
+ // we spare the update if no change happened |
|
31 | 25 |
if (OswaldState.screen != screen) { |
32 | 26 |
OswaldState.screen = screen; |
33 | 27 |
update_screen(); |
... | ... |
@@ -67,14 +61,65 @@ void oswald_one_second_tick(void) |
67 | 61 |
update_screen(); |
68 | 62 |
} |
69 | 63 |
|
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 |
+{ |
|
78 |
+} |
|
79 |
+ |
|
70 | 80 |
void oswald_handle_button_press(watch_button button) |
71 | 81 |
{ |
82 |
+ switch (button) { |
|
83 |
+ case BUTTON_A: |
|
84 |
+ case BUTTON_B: |
|
85 |
+ case BUTTON_D: |
|
86 |
+ case BUTTON_E: |
|
87 |
+ if (OswaldState.user_button_func != NULL) |
|
88 |
+ OswaldState.user_button_func(button); |
|
89 |
+ break; |
|
90 |
+ case BUTTON_C: |
|
91 |
+ // 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 |
+ }; |
|
106 |
+ }; |
|
107 |
+ update_screen(); |
|
108 |
+ break; |
|
109 |
+ case BUTTON_F: |
|
110 |
+ // backlight on/off |
|
111 |
+ break; |
|
112 |
+ default: |
|
113 |
+ // should never get here |
|
114 |
+ break; |
|
115 |
+ }; |
|
72 | 116 |
} |
73 | 117 |
|
74 | 118 |
void oswald_init(void) |
75 | 119 |
{ |
76 | 120 |
OswaldState.screen = IDLE_SCREEN; |
77 |
- OswaldState.idle_draw_func = DrawLcdDigitalClock; |
|
78 | 121 |
OswaldState.idle_show_seconds = FALSE; |
122 |
+ OswaldState.user_screendraw_func = DrawLcdDigitalClock; |
|
123 |
+ OswaldState.user_button_func = idle_handle_user_buttons; |
|
79 | 124 |
} |
80 | 125 |
|
... | ... |
@@ -8,7 +8,7 @@ |
8 | 8 |
|
9 | 9 |
#include "oswald_watch_faces.h" |
10 | 10 |
|
11 |
-void DrawLcdAnaClock(boolean show_seconds) |
|
11 |
+void DrawLcdAnaClock(void) |
|
12 | 12 |
{ |
13 | 13 |
unsigned char *bbuf; |
14 | 14 |
char daystr[5]; |
... | ... |
@@ -52,7 +52,7 @@ void DrawLcdAnaClock(boolean show_seconds) |
52 | 52 |
tmp = 48 + (40. * sin(((2. * M_PI) / 60.) * (double)minute)); |
53 | 53 |
y = tmp; |
54 | 54 |
DrawLcdLineBresenhamWW(48, 48, x, y, 2); |
55 |
- if (show_seconds) { |
|
55 |
+ if (OswaldState.idle_show_seconds) { |
|
56 | 56 |
// Seconds |
57 | 57 |
tmp = 48. + (40. * cos(((2. * M_PI) / 60.) * (double)seconds)); |
58 | 58 |
x = tmp; |
... | ... |
@@ -65,7 +65,7 @@ void DrawLcdAnaClock(boolean show_seconds) |
65 | 65 |
// mw_buf_print(mwbuf, 74, 45, daystr, 0, MW_WHITE, MW_BLACK); |
66 | 66 |
} |
67 | 67 |
|
68 |
-void DrawLcdDigitalClock(boolean show_seconds) |
|
68 |
+void DrawLcdDigitalClock(void) |
|
69 | 69 |
{ |
70 | 70 |
gint gRow = 3; |
71 | 71 |
gint gColumn = 4; |
... | ... |
@@ -79,7 +79,7 @@ void DrawLcdDigitalClock(boolean show_seconds) |
79 | 79 |
gRow += WriteLcdCharacter(gRow, gColumn, TIME_CHARACTER_COLON_INDEX); |
80 | 80 |
gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute / 10)); |
81 | 81 |
gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute % 10)); |
82 |
- if (show_seconds) { |
|
82 |
+ if (OswaldState.idle_show_seconds) { |
|
83 | 83 |
gRow += WriteLcdCharacter(gRow, gColumn, TIME_CHARACTER_COLON_INDEX); |
84 | 84 |
gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.second / 10)); |
85 | 85 |
gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.second % 10)); |