Browse code

Use strutils instead of snprintf (to save some bytes), set default year to 2014, partial revamp of the stopwatch

Dario Rodriguez authored on 14/01/2014 22:59:59
Showing 1 changed files
... ...
@@ -4,6 +4,8 @@
4 4
 #include "oswald_hal.h"
5 5
 
6 6
 #include "embedvm.h"
7
+#include "mymem.h"
8
+#include "strutils.h"
7 9
 
8 10
 #include "oswald_main.h"
9 11
 
... ...
@@ -174,27 +176,46 @@ void oswald_handle_comm_input(uint16_t mlen, const void *mdat)
174 176
 
175 177
 	if (icmd[0] == '$') {
176 178
 		if (strncmp(icmd, "$GRT", 4) == 0) { // get current RTC
177
-			char rtime[16];
178
-			snprintf(rtime, 16, "#RTC%02d%02d%02d\n", OswaldClk.hour, OswaldClk.minute, OswaldClk.second);
179
+			char rtime[12];
180
+			mymemcpy(rtime,"#RTC",4);
181
+			num2str(OswaldClk.hour,rtime+4,2,2);
182
+			num2str(OswaldClk.minute,rtime+6,2,2);
183
+			num2str(OswaldClk.second,rtime+8,2,2);
184
+			rtime[10]='\n';
185
+			rtime[11]='\0';
179 186
 			hal_bluetooth_send_data(rtime, strlen(rtime));
180 187
 		} else if (strncmp(icmd, "$SRT", 4) == 0) { // set current RTC
181 188
 			char rtime[16];
182
-			snprintf(rtime, 16, "#USP\n");
189
+			mymemcpy(rtime,"#USP\n",6);
183 190
 			hal_bluetooth_send_data(rtime, strlen(rtime));
184 191
 		} else if (strncmp(icmd, "$MSG", 4) == 0) { // message on main screen
185 192
 			char *msg = (icmd+4);
186 193
 			mlen -= 4;
187
-			memset(MainMessage, 0, 148);
188
-			strncpy(MainMessage, msg, (mlen > 147) ? 147 : mlen);
194
+			mymemset(MainMessage, 0, 148);
195
+			if(mlen>147) 
196
+				mlen=147;
197
+			mymemcpy(MainMessage,msg,mlen);
198
+			MainMessage[mlen]='\0';
189 199
 		} else if (strncmp(icmd, "$MCL", 4) == 0) { // clear message
190
-			memset(MainMessage, 0, 148);
200
+			mymemset(MainMessage, 0, 148);
191 201
 		} else if (strncmp(icmd, "$BAT", 4) == 0) { // clear message
192 202
 			char rtime[16];
193
-			snprintf(rtime, 16, "#BAT%d,%d\n", OswaldPowerState.charge_state, OswaldPowerState.percent);
203
+			int off;
204
+			mymemcpy(rtime,"#BAT",4);
205
+			off=4;
206
+			off+=num2str(OswaldPowerState.charge_state,rtime+off,1,sizeof(rtime)-3-off);
207
+			rtime[off++]=',';
208
+			off+=num2str(OswaldPowerState.percent,rtime+off,1,sizeof(rtime)-2-off);
209
+			rtime[off++]='\n';
210
+			rtime[off++]='\0';
194 211
 			hal_bluetooth_send_data(rtime, strlen(rtime));
195 212
 		} else if (strncmp(icmd, "$GAL", 4) == 0) { // get ambient light value
196
-			char rtime[16];
197
-			snprintf(rtime, 16, "#GAL%d\n", hal_amblight_get_val());
213
+			char rtime[16],off;
214
+			mymemcpy(rtime,"#GAL",4);
215
+			off=4;
216
+			off+=num2str(hal_amblight_get_val(),rtime+off,1,sizeof(rtime)-2-off);
217
+			rtime[off++]='\n';
218
+			rtime[off++]='\0';
198 219
 			hal_bluetooth_send_data(rtime, strlen(rtime));
199 220
 		}
200 221
 	}
Browse code

Enable 4 alarms, fix alarm UI, implement a rough version of the main menu

Dario Rodriguez authored on 08/01/2014 22:59:59
Showing 1 changed files
... ...
@@ -13,7 +13,7 @@
13 13
  * through function calls thus saving stack space
14 14
  */
15 15
 clock_state OswaldClk;
16
-alarm_clk OswaldAlarm;
16
+alarm_clk OswaldAlarm[MAX_ALARM];
17 17
 watch_state OswaldState;
18 18
 watch_screen OswaldScreens[SCREENS_END];
19 19
 power_state OswaldPowerState;
... ...
@@ -54,13 +54,17 @@ static void update_clock_state (void)
54 54
 
55 55
 	/* check for pending alarm once per minute */
56 56
 	if (OswaldClk.second == 0) {
57
-		if (OswaldClk.hour == OswaldAlarm.hour &&
58
-			OswaldClk.minute == OswaldAlarm.minute &&
59
-			((1 << OswaldClk.wday) & OswaldAlarm.wday)) {
60
-			OswaldState.screen->event_func(EVENT_SCREEN_DESTROY, NULL);
61
-			OswaldState.screen_id = ALARM_SCREEN;
62
-			OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
63
-			OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
57
+		int i;
58
+		for(i=0;i<MAX_ALARM;i++) {
59
+			if (OswaldClk.hour == OswaldAlarm[i].hour &&
60
+				OswaldClk.minute == OswaldAlarm[i].minute &&
61
+				((1 << OswaldClk.wday) & OswaldAlarm[i].wday)) {
62
+				OswaldState.screen->event_func(EVENT_SCREEN_DESTROY, NULL);
63
+				OswaldState.screen_id = ALARM_SCREEN;
64
+				OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
65
+				OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
66
+				break;
67
+			}
64 68
 		}
65 69
 	}
66 70
 }
... ...
@@ -198,6 +202,7 @@ void oswald_handle_comm_input(uint16_t mlen, const void *mdat)
198 202
 
199 203
 void oswald_init(void)
200 204
 {
205
+	int i;
201 206
 	OswaldScreens[IDLE_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
202 207
 	OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events;
203 208
 
... ...
@@ -241,10 +246,10 @@ void oswald_init(void)
241 246
 
242 247
 	if (OswaldState.screen->event_func != NULL)
243 248
 		OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
244
-
245
-	OswaldAlarm.hour = 12;
246
-	OswaldAlarm.minute = 0;
247
-	OswaldAlarm.wday = 0x00;
248
-
249
+	for(i=0;i<MAX_ALARM;i++) {
250
+		OswaldAlarm[i].hour = 12;
251
+		OswaldAlarm[i].minute = 0;
252
+		OswaldAlarm[i].wday = 0x00;
253
+	}
249 254
 }
250 255
 
Browse code

Replace font handling, add new watch face, add calendar. More watchfaces, make calendar interactive and start rearranging button functions

Dario Rodriguez authored on 17/12/2013 22:59:59
Showing 1 changed files
... ...
@@ -102,14 +102,14 @@ void oswald_handle_button_press(watch_button button)
102 102
 	switch (button) {
103 103
 		case BUTTON_A:
104 104
 		case BUTTON_B:
105
-		case BUTTON_E:
105
+		case BUTTON_C:
106 106
 		case BUTTON_F:
107 107
 			if (OswaldState.screen->event_func != NULL &&
108 108
 			    (OswaldState.screen->event_mask & EVENT_USER_BUTTONS)) {
109 109
 			    	OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button);
110 110
 			}
111 111
 			break;
112
-		case BUTTON_C:
112
+		case BUTTON_E:
113 113
 			if (OswaldState.screen->event_func != NULL &&
114 114
 			    (OswaldState.screen->event_mask & EVENT_USER_BUTTONS)) {
115 115
 			    	if (OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button) == EVENT_RET_HANDLED)
... ...
@@ -227,6 +227,8 @@ void oswald_init(void)
227 227
 
228 228
 	OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
229 229
 	OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events;
230
+	OswaldScreens[CALENDAR_OVERVIEW_SCREEN].event_mask = EVENT_USER_BUTTONS|EVENT_ONE_SEC_TIMER;
231
+	OswaldScreens[CALENDAR_OVERVIEW_SCREEN].event_func = calendar_overview_handle_events;
230 232
 
231 233
 	OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS;
232 234
 	OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events;
Browse code

Power saving changes, add new fonts, bitmaps and screens

Nils Faerber authored on 19/05/2013 00:07:04
Showing 1 changed files
... ...
@@ -116,11 +116,15 @@ void oswald_handle_button_press(watch_button button)
116 116
 			    		break;
117 117
 			}
118 118
 			OswaldState.screen->event_func(EVENT_SCREEN_DESTROY, NULL);
119
+#if 0
119 120
 			// next screen
120 121
 			OswaldState.screen_id++;
121 122
 			if (OswaldState.screen_id >= LAST_SCREEN) {
122 123
 				OswaldState.screen_id = IDLE_SCREEN;
123 124
 			};
125
+#else
126
+			OswaldState.screen_id = IDLE_SCREEN;
127
+#endif
124 128
 			OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
125 129
 			OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
126 130
 			break;
... ...
@@ -170,6 +174,9 @@ void oswald_handle_comm_input(uint16_t mlen, const void *mdat)
170 174
 			snprintf(rtime, 16, "#RTC%02d%02d%02d\n", OswaldClk.hour, OswaldClk.minute, OswaldClk.second);
171 175
 			hal_bluetooth_send_data(rtime, strlen(rtime));
172 176
 		} else if (strncmp(icmd, "$SRT", 4) == 0) { // set current RTC
177
+			char rtime[16];
178
+			snprintf(rtime, 16, "#USP\n");
179
+			hal_bluetooth_send_data(rtime, strlen(rtime));
173 180
 		} else if (strncmp(icmd, "$MSG", 4) == 0) { // message on main screen
174 181
 			char *msg = (icmd+4);
175 182
 			mlen -= 4;
... ...
@@ -181,6 +188,10 @@ void oswald_handle_comm_input(uint16_t mlen, const void *mdat)
181 188
 			char rtime[16];
182 189
 			snprintf(rtime, 16, "#BAT%d,%d\n", OswaldPowerState.charge_state, OswaldPowerState.percent);
183 190
 			hal_bluetooth_send_data(rtime, strlen(rtime));
191
+		} else if (strncmp(icmd, "$GAL", 4) == 0) { // get ambient light value
192
+			char rtime[16];
193
+			snprintf(rtime, 16, "#GAL%d\n", hal_amblight_get_val());
194
+			hal_bluetooth_send_data(rtime, strlen(rtime));
184 195
 		}
185 196
 	}
186 197
 }
... ...
@@ -190,30 +201,39 @@ void oswald_init(void)
190 201
 	OswaldScreens[IDLE_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
191 202
 	OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events;
192 203
 
193
-	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ACCEL_UPDATE;
194
-	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_func = accel_handle_events;
195
-
196
-	OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
197
-	OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events;
204
+	OswaldScreens[MAIN_MENU_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
205
+	OswaldScreens[MAIN_MENU_SCREEN].event_func = main_menu_handle_events;
198 206
 
199 207
 	OswaldScreens[ALARM_SETUP_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
200 208
 	OswaldScreens[ALARM_SETUP_SCREEN].event_func = alarm_setup_events;
201 209
 
202
-	OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS;
203
-	OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events;
204
-
205 210
 	OswaldScreens[STOP_WATCH_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_CS_TIMER;
206 211
 	OswaldScreens[STOP_WATCH_SCREEN].event_func = stop_watch_handle_events;
207 212
 
208 213
 	OswaldScreens[BLUETOOTH_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
209 214
 	OswaldScreens[BLUETOOTH_SCREEN].event_func = bluetooth_screen_events;
210 215
 
211
-	OswaldScreens[ALARM_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
212
-	OswaldScreens[ALARM_SCREEN].event_func = alarm_handle_events;
216
+	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ACCEL_UPDATE;
217
+	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_func = accel_handle_events;
218
+
219
+	OswaldScreens[MESSAGES_SCREEN].event_mask = EVENT_USER_BUTTONS;
220
+	OswaldScreens[MESSAGES_SCREEN].event_func = messages_screen_handle_events;
221
+
222
+	OswaldScreens[MESSAGE_SCREEN].event_mask = EVENT_USER_BUTTONS;
223
+	OswaldScreens[MESSAGE_SCREEN].event_func = message_screen_handle_events;
213 224
 
214 225
 	OswaldScreens[INFO_SCREEN].event_mask = 0x00; // this one does not consume any events
215 226
 	OswaldScreens[INFO_SCREEN].event_func = info_screen_handle_events;
216 227
 
228
+	OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
229
+	OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events;
230
+
231
+	OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS;
232
+	OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events;
233
+
234
+	OswaldScreens[ALARM_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
235
+	OswaldScreens[ALARM_SCREEN].event_func = alarm_handle_events;
236
+
217 237
 	OswaldState.screen_id = IDLE_SCREEN;
218 238
 	OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
219 239
 
... ...
@@ -224,6 +244,5 @@ void oswald_init(void)
224 244
 	OswaldAlarm.minute = 0;
225 245
 	OswaldAlarm.wday = 0x00;
226 246
 
227
-	// strcpy(MainMessage, "So koennte dann eine Nachricht aussehen. Samt Text mit Unterlaengen. Und dies ist dann die letzte Zeile und mehr Text als paßt.");
228 247
 }
229 248
 
Browse code

Add version information and info screen, some more work on the accel screen

Nils Faerber authored on 05/05/2013 01:54:24
Showing 1 changed files
... ...
@@ -211,6 +211,9 @@ void oswald_init(void)
211 211
 	OswaldScreens[ALARM_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
212 212
 	OswaldScreens[ALARM_SCREEN].event_func = alarm_handle_events;
213 213
 
214
+	OswaldScreens[INFO_SCREEN].event_mask = 0x00; // this one does not consume any events
215
+	OswaldScreens[INFO_SCREEN].event_func = info_screen_handle_events;
216
+
214 217
 	OswaldState.screen_id = IDLE_SCREEN;
215 218
 	OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
216 219
 
Browse code

Rework font code, add new fonts, also proportional, rework watch usage - "SET" button now enters settings mode

Nils Faerber authored on 04/05/2013 19:23:25
Showing 1 changed files
... ...
@@ -17,7 +17,7 @@ alarm_clk OswaldAlarm;
17 17
 watch_state OswaldState;
18 18
 watch_screen OswaldScreens[SCREENS_END];
19 19
 power_state OswaldPowerState;
20
-u8t backlight_safety_off = 0;
20
+uint8_t backlight_safety_off = 0;
21 21
 char MainMessage[148];
22 22
 
23 23
 
... ...
@@ -32,7 +32,7 @@ void oswald_change_to_screen(screen_number screen_id)
32 32
 	}
33 33
 }
34 34
 
35
-void oswald_set_time(u8t hour, u8t minute, u8t second, boolean clk24hr)
35
+void oswald_set_time(uint8_t hour, uint8_t minute, uint8_t second, boolean clk24hr)
36 36
 {
37 37
 	OswaldClk.hour = hour;
38 38
 	OswaldClk.minute = minute;
... ...
@@ -40,7 +40,7 @@ void oswald_set_time(u8t hour, u8t minute, u8t second, boolean clk24hr)
40 40
 	OswaldClk.clk24hr = clk24hr;
41 41
 }
42 42
 
43
-void oswald_set_date(u8t day, u8t month, u16t year, boolean day_first)
43
+void oswald_set_date(uint8_t day, uint8_t month, uint16_t year, boolean day_first)
44 44
 {
45 45
 	OswaldClk.day = day;
46 46
 	OswaldClk.month = month;
... ...
@@ -100,25 +100,21 @@ void oswald_halfsecond_tick(void)
100 100
 void oswald_handle_button_press(watch_button button)
101 101
 {
102 102
 	switch (button) {
103
-		case BUTTON_D:
104
-			// backlight on/off
105
-			if (hal_lcd_get_backlight()) {
106
-				hal_lcd_set_backlight(FALSE);
107
-				backlight_safety_off = 0;
108
-			} else {
109
-				hal_lcd_set_backlight(TRUE);
110
-				backlight_safety_off = 2;
111
-			}
112
-			break;
113 103
 		case BUTTON_A:
114 104
 		case BUTTON_B:
115 105
 		case BUTTON_E:
116 106
 		case BUTTON_F:
117 107
 			if (OswaldState.screen->event_func != NULL &&
118
-			    (OswaldState.screen->event_mask & EVENT_USER_BUTTONS))
119
-				OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button);
108
+			    (OswaldState.screen->event_mask & EVENT_USER_BUTTONS)) {
109
+			    	OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button);
110
+			}
120 111
 			break;
121 112
 		case BUTTON_C:
113
+			if (OswaldState.screen->event_func != NULL &&
114
+			    (OswaldState.screen->event_mask & EVENT_USER_BUTTONS)) {
115
+			    	if (OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button) == EVENT_RET_HANDLED)
116
+			    		break;
117
+			}
122 118
 			OswaldState.screen->event_func(EVENT_SCREEN_DESTROY, NULL);
123 119
 			// next screen
124 120
 			OswaldState.screen_id++;
... ...
@@ -128,13 +124,23 @@ void oswald_handle_button_press(watch_button button)
128 124
 			OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
129 125
 			OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
130 126
 			break;
127
+		case BUTTON_D:
128
+			// backlight on/off
129
+			if (hal_lcd_get_backlight()) {
130
+				hal_lcd_set_backlight(FALSE);
131
+				backlight_safety_off = 0;
132
+			} else {
133
+				hal_lcd_set_backlight(TRUE);
134
+				backlight_safety_off = 2;
135
+			}
136
+			break;
131 137
 		default:
132 138
 			// should never get here
133 139
 			break;
134 140
 	};
135 141
 }
136 142
 
137
-void oswald_handle_accel_event(u8t x, u8t y, u8t z)
143
+void oswald_handle_accel_event(uint8_t x, uint8_t y, uint8_t z)
138 144
 {
139 145
 	accel_data_t accel_data;
140 146
 
... ...
@@ -147,7 +153,7 @@ void oswald_handle_accel_event(u8t x, u8t y, u8t z)
147 153
 		OswaldState.screen->event_func(EVENT_ACCEL_UPDATE, &accel_data);
148 154
 }
149 155
 
150
-void oswald_handle_ambientlight_event(u8t light_level)
156
+void oswald_handle_ambientlight_event(uint8_t light_level)
151 157
 {
152 158
 	if (OswaldState.screen->event_func != NULL &&
153 159
 	    (OswaldState.screen->event_mask & EVENT_AMBIENTLIGHT_UPDATE))
... ...
@@ -214,5 +220,7 @@ void oswald_init(void)
214 220
 	OswaldAlarm.hour = 12;
215 221
 	OswaldAlarm.minute = 0;
216 222
 	OswaldAlarm.wday = 0x00;
223
+
224
+	// strcpy(MainMessage, "So koennte dann eine Nachricht aussehen. Samt Text mit Unterlaengen. Und dies ist dann die letzte Zeile und mehr Text als paßt.");
217 225
 }
218 226
 
Browse code

Lot's of stuff...

Nils Faerber authored on 27/04/2013 20:19:55
Showing 1 changed files
... ...
@@ -161,8 +161,9 @@ void oswald_handle_comm_input(uint16_t mlen, const void *mdat)
161 161
 	if (icmd[0] == '$') {
162 162
 		if (strncmp(icmd, "$GRT", 4) == 0) { // get current RTC
163 163
 			char rtime[16];
164
-			snprintf(rtime, 10, "%02d%02d%02d\n", OswaldClk.hour, OswaldClk.minute, OswaldClk.second);
164
+			snprintf(rtime, 16, "#RTC%02d%02d%02d\n", OswaldClk.hour, OswaldClk.minute, OswaldClk.second);
165 165
 			hal_bluetooth_send_data(rtime, strlen(rtime));
166
+		} else if (strncmp(icmd, "$SRT", 4) == 0) { // set current RTC
166 167
 		} else if (strncmp(icmd, "$MSG", 4) == 0) { // message on main screen
167 168
 			char *msg = (icmd+4);
168 169
 			mlen -= 4;
... ...
@@ -170,6 +171,10 @@ void oswald_handle_comm_input(uint16_t mlen, const void *mdat)
170 171
 			strncpy(MainMessage, msg, (mlen > 147) ? 147 : mlen);
171 172
 		} else if (strncmp(icmd, "$MCL", 4) == 0) { // clear message
172 173
 			memset(MainMessage, 0, 148);
174
+		} else if (strncmp(icmd, "$BAT", 4) == 0) { // clear message
175
+			char rtime[16];
176
+			snprintf(rtime, 16, "#BAT%d,%d\n", OswaldPowerState.charge_state, OswaldPowerState.percent);
177
+			hal_bluetooth_send_data(rtime, strlen(rtime));
173 178
 		}
174 179
 	}
175 180
 }
Browse code

Bluetooth handling, screen reworks for icons

Nils Faerber authored on 21/04/2013 23:10:13
Showing 1 changed files
... ...
@@ -18,6 +18,8 @@ watch_state OswaldState;
18 18
 watch_screen OswaldScreens[SCREENS_END];
19 19
 power_state OswaldPowerState;
20 20
 u8t backlight_safety_off = 0;
21
+char MainMessage[148];
22
+
21 23
 
22 24
 void oswald_change_to_screen(screen_number screen_id)
23 25
 {
... ...
@@ -152,6 +154,26 @@ void oswald_handle_ambientlight_event(u8t light_level)
152 154
 		OswaldState.screen->event_func(EVENT_AMBIENTLIGHT_UPDATE, &light_level);
153 155
 }
154 156
 
157
+void oswald_handle_comm_input(uint16_t mlen, const void *mdat)
158
+{
159
+	char *icmd = (char *) mdat;
160
+
161
+	if (icmd[0] == '$') {
162
+		if (strncmp(icmd, "$GRT", 4) == 0) { // get current RTC
163
+			char rtime[16];
164
+			snprintf(rtime, 10, "%02d%02d%02d\n", OswaldClk.hour, OswaldClk.minute, OswaldClk.second);
165
+			hal_bluetooth_send_data(rtime, strlen(rtime));
166
+		} else if (strncmp(icmd, "$MSG", 4) == 0) { // message on main screen
167
+			char *msg = (icmd+4);
168
+			mlen -= 4;
169
+			memset(MainMessage, 0, 148);
170
+			strncpy(MainMessage, msg, (mlen > 147) ? 147 : mlen);
171
+		} else if (strncmp(icmd, "$MCL", 4) == 0) { // clear message
172
+			memset(MainMessage, 0, 148);
173
+		}
174
+	}
175
+}
176
+
155 177
 void oswald_init(void)
156 178
 {
157 179
 	OswaldScreens[IDLE_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
... ...
@@ -172,6 +194,9 @@ void oswald_init(void)
172 194
 	OswaldScreens[STOP_WATCH_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_CS_TIMER;
173 195
 	OswaldScreens[STOP_WATCH_SCREEN].event_func = stop_watch_handle_events;
174 196
 
197
+	OswaldScreens[BLUETOOTH_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
198
+	OswaldScreens[BLUETOOTH_SCREEN].event_func = bluetooth_screen_events;
199
+
175 200
 	OswaldScreens[ALARM_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
176 201
 	OswaldScreens[ALARM_SCREEN].event_func = alarm_handle_events;
177 202
 
Browse code

Oh boy... lots of changes, too many to describe

Nils Faerber authored on 21/04/2013 14:26:38
Showing 1 changed files
... ...
@@ -1,6 +1,7 @@
1 1
 #include "oswald.h"
2 2
 #include "oswald_watch_faces.h"
3 3
 #include "oswald_screens.h"
4
+#include "oswald_hal.h"
4 5
 
5 6
 #include "embedvm.h"
6 7
 
... ...
@@ -12,9 +13,11 @@
12 13
  * through function calls thus saving stack space
13 14
  */
14 15
 clock_state OswaldClk;
16
+alarm_clk OswaldAlarm;
15 17
 watch_state OswaldState;
16 18
 watch_screen OswaldScreens[SCREENS_END];
17
-
19
+power_state OswaldPowerState;
20
+u8t backlight_safety_off = 0;
18 21
 
19 22
 void oswald_change_to_screen(screen_number screen_id)
20 23
 {
... ...
@@ -45,29 +48,33 @@ void oswald_set_date(u8t day, u8t month, u16t year, boolean day_first)
45 48
 
46 49
 static void update_clock_state (void)
47 50
 {
48
-	OswaldClk.second += 1;
49
-	if (OswaldClk.second > 59) {
50
-		OswaldClk.second = 0;
51
-		OswaldClk.minute += 1;
52
-	} else
53
-		return;
54
-	if (OswaldClk.minute > 59) {
55
-		OswaldClk.minute = 0;
56
-		OswaldClk.hour += 1;
57
-	} else
58
-		return;
59
-	if (OswaldClk.hour > 23) {
60
-		OswaldClk.hour = 0;
61
-		// day++
62
-	} else
63
-		return;
51
+	hal_get_rtc(&OswaldClk);
52
+
53
+	/* check for pending alarm once per minute */
54
+	if (OswaldClk.second == 0) {
55
+		if (OswaldClk.hour == OswaldAlarm.hour &&
56
+			OswaldClk.minute == OswaldAlarm.minute &&
57
+			((1 << OswaldClk.wday) & OswaldAlarm.wday)) {
58
+			OswaldState.screen->event_func(EVENT_SCREEN_DESTROY, NULL);
59
+			OswaldState.screen_id = ALARM_SCREEN;
60
+			OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
61
+			OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
62
+		}
63
+	}
64 64
 }
65 65
 
66 66
 void oswald_one_second_tick(void)
67 67
 {
68
-	/* update our 'RTC' */
68
+	/* update clock - should use RTC if available */
69 69
 	update_clock_state();
70 70
 
71
+	hal_get_power_state(&OswaldPowerState);
72
+	if (backlight_safety_off) {
73
+		backlight_safety_off--;
74
+		if (!backlight_safety_off)
75
+			hal_lcd_set_backlight(FALSE);
76
+	}
77
+
71 78
 	/* wake-up screen if interested in the one-second-event */
72 79
 	if (OswaldState.screen->event_func != NULL &&
73 80
 	    (OswaldState.screen->event_mask & EVENT_ONE_SEC_TIMER))
... ...
@@ -91,10 +98,20 @@ void oswald_halfsecond_tick(void)
91 98
 void oswald_handle_button_press(watch_button button)
92 99
 {
93 100
 	switch (button) {
101
+		case BUTTON_D:
102
+			// backlight on/off
103
+			if (hal_lcd_get_backlight()) {
104
+				hal_lcd_set_backlight(FALSE);
105
+				backlight_safety_off = 0;
106
+			} else {
107
+				hal_lcd_set_backlight(TRUE);
108
+				backlight_safety_off = 2;
109
+			}
110
+			break;
94 111
 		case BUTTON_A:
95 112
 		case BUTTON_B:
96
-		case BUTTON_D:
97 113
 		case BUTTON_E:
114
+		case BUTTON_F:
98 115
 			if (OswaldState.screen->event_func != NULL &&
99 116
 			    (OswaldState.screen->event_mask & EVENT_USER_BUTTONS))
100 117
 				OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button);
... ...
@@ -109,9 +126,6 @@ void oswald_handle_button_press(watch_button button)
109 126
 			OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
110 127
 			OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
111 128
 			break;
112
-		case BUTTON_F:
113
-			// backlight on/off
114
-			break;
115 129
 		default:
116 130
 			// should never get here
117 131
 			break;
... ...
@@ -149,16 +163,26 @@ void oswald_init(void)
149 163
 	OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
150 164
 	OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events;
151 165
 
166
+	OswaldScreens[ALARM_SETUP_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
167
+	OswaldScreens[ALARM_SETUP_SCREEN].event_func = alarm_setup_events;
168
+
152 169
 	OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS;
153 170
 	OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events;
154 171
 
155 172
 	OswaldScreens[STOP_WATCH_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_CS_TIMER;
156 173
 	OswaldScreens[STOP_WATCH_SCREEN].event_func = stop_watch_handle_events;
157 174
 
175
+	OswaldScreens[ALARM_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
176
+	OswaldScreens[ALARM_SCREEN].event_func = alarm_handle_events;
177
+
158 178
 	OswaldState.screen_id = IDLE_SCREEN;
159 179
 	OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
160 180
 
161 181
 	if (OswaldState.screen->event_func != NULL)
162 182
 		OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
183
+
184
+	OswaldAlarm.hour = 12;
185
+	OswaldAlarm.minute = 0;
186
+	OswaldAlarm.wday = 0x00;
163 187
 }
164 188
 
Browse code

Add fixes for it to work properly on microcontroller

Nils Faerber authored on 19/03/2013 19:22:58
Showing 1 changed files
... ...
@@ -13,7 +13,7 @@
13 13
  */
14 14
 clock_state OswaldClk;
15 15
 watch_state OswaldState;
16
-watch_screen OswaldScreens[LAST_SCREEN];
16
+watch_screen OswaldScreens[SCREENS_END];
17 17
 
18 18
 
19 19
 void oswald_change_to_screen(screen_number screen_id)
... ...
@@ -107,7 +107,6 @@ void oswald_handle_button_press(watch_button button)
107 107
 				OswaldState.screen_id = IDLE_SCREEN;
108 108
 			};
109 109
 			OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
110
-			//oswald_update_screen();
111 110
 			OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
112 111
 			break;
113 112
 		case BUTTON_F:
... ...
@@ -153,6 +152,9 @@ void oswald_init(void)
153 152
 	OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS;
154 153
 	OswaldScreens[MENU_TEST_SCREEN].event_func = test_menu_handle_events;
155 154
 
155
+	OswaldScreens[STOP_WATCH_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_CS_TIMER;
156
+	OswaldScreens[STOP_WATCH_SCREEN].event_func = stop_watch_handle_events;
157
+
156 158
 	OswaldState.screen_id = IDLE_SCREEN;
157 159
 	OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
158 160
 
Browse code

Countless fixes and enhancements

Nils Faerber authored on 12/08/2012 21:14:19
Showing 1 changed files
... ...
@@ -27,11 +27,20 @@ void oswald_change_to_screen(screen_number screen_id)
27 27
 	}
28 28
 }
29 29
 
30
-void oswald_set_time(u8t hour, u8t minute, u8t second)
30
+void oswald_set_time(u8t hour, u8t minute, u8t second, boolean clk24hr)
31 31
 {
32 32
 	OswaldClk.hour = hour;
33 33
 	OswaldClk.minute = minute;
34 34
 	OswaldClk.second = second;
35
+	OswaldClk.clk24hr = clk24hr;
36
+}
37
+
38
+void oswald_set_date(u8t day, u8t month, u16t year, boolean day_first)
39
+{
40
+	OswaldClk.day = day;
41
+	OswaldClk.month = month;
42
+	OswaldClk.year = year;
43
+	OswaldClk.day_first = day_first;
35 44
 }
36 45
 
37 46
 static void update_clock_state (void)
... ...
@@ -63,7 +72,20 @@ void oswald_one_second_tick(void)
63 72
 	if (OswaldState.screen->event_func != NULL &&
64 73
 	    (OswaldState.screen->event_mask & EVENT_ONE_SEC_TIMER))
65 74
 		OswaldState.screen->event_func(EVENT_ONE_SEC_TIMER, NULL);
66
-	// oswald_update_screen();
75
+}
76
+
77
+void oswald_centisecond_tick(void)
78
+{
79
+	if (OswaldState.screen->event_func != NULL &&
80
+	    (OswaldState.screen->event_mask & EVENT_CS_TIMER))
81
+		OswaldState.screen->event_func(EVENT_CS_TIMER, NULL);
82
+}
83
+
84
+void oswald_halfsecond_tick(void)
85
+{
86
+	if (OswaldState.screen->event_func != NULL &&
87
+	    (OswaldState.screen->event_mask & EVENT_HALF_SEC_TIMER))
88
+		OswaldState.screen->event_func(EVENT_HALF_SEC_TIMER, NULL);
67 89
 }
68 90
 
69 91
 void oswald_handle_button_press(watch_button button)
... ...
@@ -78,6 +100,7 @@ void oswald_handle_button_press(watch_button button)
78 100
 				OswaldState.screen->event_func(EVENT_USER_BUTTONS, &button);
79 101
 			break;
80 102
 		case BUTTON_C:
103
+			OswaldState.screen->event_func(EVENT_SCREEN_DESTROY, NULL);
81 104
 			// next screen
82 105
 			OswaldState.screen_id++;
83 106
 			if (OswaldState.screen_id >= LAST_SCREEN) {
... ...
@@ -96,16 +119,35 @@ void oswald_handle_button_press(watch_button button)
96 119
 	};
97 120
 }
98 121
 
122
+void oswald_handle_accel_event(u8t x, u8t y, u8t z)
123
+{
124
+	accel_data_t accel_data;
125
+
126
+	accel_data.x = x;
127
+	accel_data.y = y;
128
+	accel_data.z = z;
129
+
130
+	if (OswaldState.screen->event_func != NULL &&
131
+	    (OswaldState.screen->event_mask & EVENT_ACCEL_UPDATE))
132
+		OswaldState.screen->event_func(EVENT_ACCEL_UPDATE, &accel_data);
133
+}
134
+
135
+void oswald_handle_ambientlight_event(u8t light_level)
136
+{
137
+	if (OswaldState.screen->event_func != NULL &&
138
+	    (OswaldState.screen->event_mask & EVENT_AMBIENTLIGHT_UPDATE))
139
+		OswaldState.screen->event_func(EVENT_AMBIENTLIGHT_UPDATE, &light_level);
140
+}
141
+
99 142
 void oswald_init(void)
100 143
 {
101 144
 	OswaldScreens[IDLE_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
102 145
 	OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events;
103 146
 
104
-	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS;
147
+	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ACCEL_UPDATE;
105 148
 	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_func = accel_handle_events;
106
-	
107 149
 
108
-	OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
150
+	OswaldScreens[DATETIME_SETTING_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_HALF_SEC_TIMER;
109 151
 	OswaldScreens[DATETIME_SETTING_SCREEN].event_func = datetime_setup_events;
110 152
 
111 153
 	OswaldScreens[MENU_TEST_SCREEN].event_mask = EVENT_USER_BUTTONS;
Browse code

Make idle selectable

Nils Faerber authored on 12/08/2012 02:11:30
Showing 1 changed files
... ...
@@ -1,10 +1,9 @@
1 1
 #include "oswald.h"
2 2
 #include "oswald_watch_faces.h"
3 3
 #include "oswald_screens.h"
4
-#if 0
5
-#include "Fonts.h"
6
-#include "LcdDisplay.h"
7
-#endif
4
+
5
+#include "embedvm.h"
6
+
8 7
 #include "oswald_main.h"
9 8
 
10 9
 /*
... ...
@@ -99,7 +98,7 @@ void oswald_handle_button_press(watch_button button)
99 98
 
100 99
 void oswald_init(void)
101 100
 {
102
-	OswaldScreens[IDLE_SCREEN].event_mask = EVENT_ONE_SEC_TIMER;
101
+	OswaldScreens[IDLE_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
103 102
 	OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events;
104 103
 
105 104
 	OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS;
... ...
@@ -114,7 +113,6 @@ void oswald_init(void)
114 113
 
115 114
 	OswaldState.screen_id = IDLE_SCREEN;
116 115
 	OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
117
-	OswaldState.idle_show_seconds = FALSE;
118 116
 
119 117
 	if (OswaldState.screen->event_func != NULL)
120 118
 		OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
Browse code

Redesign to an event based handling

Nils Faerber authored on 07/08/2012 22:09:29
Showing 1 changed files
... ...
@@ -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
 
Browse code

Add support for more screens

Nils Faerber authored on 06/08/2012 14:12:20
Showing 1 changed files
... ...
@@ -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
 
Browse code

Too much to note...

Nils Faerber authored on 05/08/2012 17:07:17
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,80 @@
1
+#include "oswald.h"
2
+#include "oswald_watch_faces.h"
3
+
4
+#include "oswald_main.h"
5
+
6
+/*
7
+ * some variable defining our curent state
8
+ * these are globals in order to avoid having to pass pointers
9
+ * through function calls thus saving stack space
10
+ */
11
+clock_state OswaldClk;
12
+watch_state OswaldState;
13
+
14
+void update_screen(void)
15
+{
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
+	};
26
+}
27
+
28
+void oswald_change_to_screen(screen_number screen)
29
+{
30
+	// we spare the update if no change
31
+	if (OswaldState.screen != screen) {
32
+		OswaldState.screen = screen;
33
+		update_screen();
34
+	}
35
+}
36
+
37
+void oswald_set_time(u8t hour, u8t minute, u8t second)
38
+{
39
+	OswaldClk.hour = hour;
40
+	OswaldClk.minute = minute;
41
+	OswaldClk.second = second;
42
+}
43
+
44
+static void update_clock_state (void)
45
+{
46
+	OswaldClk.second += 1;
47
+	if (OswaldClk.second > 59) {
48
+		OswaldClk.second = 0;
49
+		OswaldClk.minute += 1;
50
+	} else
51
+		return;
52
+	if (OswaldClk.minute > 59) {
53
+		OswaldClk.minute = 0;
54
+		OswaldClk.hour += 1;
55
+	} else
56
+		return;
57
+	if (OswaldClk.hour > 23) {
58
+		OswaldClk.hour = 0;
59
+		// day++
60
+	} else
61
+		return;
62
+}
63
+
64
+void oswald_one_second_tick(void)
65
+{
66
+	update_clock_state();
67
+	update_screen();
68
+}
69
+
70
+void oswald_handle_button_press(watch_button button)
71
+{
72
+}
73
+
74
+void oswald_init(void)
75
+{
76
+	OswaldState.screen = IDLE_SCREEN;
77
+	OswaldState.idle_draw_func = DrawLcdDigitalClock;
78
+	OswaldState.idle_show_seconds = FALSE;
79
+}
80
+