Browse code

Some minor improvements.

Nils Faerber authored on 06/07/2013 21:21:35
Showing 1 changed files
... ...
@@ -23,13 +23,14 @@
23 23
 
24 24
 static oswald_ui *ui_g;
25 25
 
26
-void hal_lcd_set_pixel(gint x, gint y, gboolean state)
26
+void hal_lcd_set_pixel(gint x, gint y, uint8_t state)
27 27
 {
28 28
 	gint ix, iy;
29 29
 
30 30
 	ix = x*2;
31 31
 	iy = y*2;
32 32
 
33
+	// we double all pixel to get a bigger picture
33 34
 	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy);
34 35
 	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy);
35 36
 	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy+1);
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
... ...
@@ -491,6 +491,11 @@ boolean hal_vibration_get_state(void)
491 491
 	return VibrationState;
492 492
 }
493 493
 
494
+uint16_t hal_amblight_get_val(void)
495
+{
496
+        return 42;
497
+} 
498
+
494 499
 
495 500
 int main(int argc , char ** argv)
496 501
 {
Browse code

Fix alarm not confirmable, enhance GTK simulation diplay for charge state, fix RTC time handling

Nils Faerber authored on 06/05/2013 11:12:37
Showing 1 changed files
... ...
@@ -119,7 +119,7 @@ void hal_accelerometer_enable(void)
119 119
 
120 120
 void hal_accelerometer_disable(void)
121 121
 {
122
-	g_printerr("accel enable\n");
122
+	g_printerr("accel disable\n");
123 123
 	gtk_widget_set_sensitive(ui_g->x_sc, FALSE);
124 124
 	gtk_widget_set_sensitive(ui_g->y_sc, FALSE);
125 125
 	gtk_widget_set_sensitive(ui_g->z_sc, FALSE);
... ...
@@ -445,8 +445,10 @@ void hal_get_rtc(clock_state *rtc)
445 445
 	rtc->minute = mtime.tm_min;
446 446
 	rtc->second = mtime.tm_sec;
447 447
 	rtc->day = mtime.tm_mday;
448
+	rtc->wday = mtime.tm_wday;
448 449
 	rtc->month = (mtime.tm_mon + 1);
449 450
 	rtc->year = (mtime.tm_year + 1900);
451
+	
450 452
 }
451 453
 
452 454
 void hal_set_rtc(const clock_state *rtc, boolean set_set)
... ...
@@ -455,6 +457,10 @@ void hal_set_rtc(const clock_state *rtc, boolean set_set)
455 457
 
456 458
 void hal_get_power_state(power_state *pwr)
457 459
 {
460
+	pwr->source = POWER_SOURCE_EXTERNAL;
461
+	pwr->charge_state = POWER_CHARGER_CHARGING;
462
+	pwr->percent = 50;
463
+	pwr->level = 3242; // mV
458 464
 }
459 465
 
460 466
 static boolean BacklightState = FALSE;
... ...
@@ -471,15 +477,18 @@ boolean hal_lcd_get_backlight(void)
471 477
 	return BacklightState;
472 478
 }
473 479
 
480
+static boolean VibrationState = FALSE;
474 481
 
475 482
 /* sets the vibration motor on/off, on=TRUE, off=FALSE */
476 483
 void hal_vibration_set_state(boolean state)
477 484
 {
485
+	g_print("turn vibration %s\n", state ? "on" : "off");
486
+	VibrationState = state;
478 487
 }
479 488
 
480 489
 boolean hal_vibration_get_state(void)
481 490
 {
482
-	return FALSE;
491
+	return VibrationState;
483 492
 }
484 493
 
485 494
 
Browse code

Make accelerometer work, interrup driven tilt change mode

Nils Faerber authored on 05/05/2013 21:22:33
Showing 1 changed files
... ...
@@ -109,6 +109,22 @@ const char *hal_get_radio_version_string(void)
109 109
 	return "BlueZ";
110 110
 }
111 111
 
112
+void hal_accelerometer_enable(void)
113
+{
114
+	g_printerr("accel enable\n");
115
+	gtk_widget_set_sensitive(ui_g->x_sc, TRUE);
116
+	gtk_widget_set_sensitive(ui_g->y_sc, TRUE);
117
+	gtk_widget_set_sensitive(ui_g->z_sc, TRUE);
118
+}
119
+
120
+void hal_accelerometer_disable(void)
121
+{
122
+	g_printerr("accel enable\n");
123
+	gtk_widget_set_sensitive(ui_g->x_sc, FALSE);
124
+	gtk_widget_set_sensitive(ui_g->y_sc, FALSE);
125
+	gtk_widget_set_sensitive(ui_g->z_sc, FALSE);
126
+}
127
+
112 128
 
113 129
 static gint
114 130
 configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
... ...
@@ -330,18 +346,24 @@ static void create_mainwin(oswald_ui *ui)
330 346
 	sc = gtk_hscale_new_with_range (-128, 127, 1);
331 347
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
332 348
 	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelX_value_changed), ui);
349
+	ui->x_sc = sc;
350
+	gtk_widget_set_sensitive(ui->x_sc, FALSE);
333 351
 
334 352
 	l = gtk_label_new("Y:");
335 353
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
336 354
 	sc = gtk_hscale_new_with_range (-128, 127, 1);
337 355
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
338 356
 	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelY_value_changed), ui);
357
+	ui->y_sc = sc;
358
+	gtk_widget_set_sensitive(ui->y_sc, FALSE);
339 359
 
340 360
 	l = gtk_label_new("Z:");
341 361
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
342 362
 	sc = gtk_hscale_new_with_range (-128, 127, 1);
343 363
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
344 364
 	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelZ_value_changed), ui);
365
+	ui->z_sc = sc;
366
+	gtk_widget_set_sensitive(ui->z_sc, FALSE);
345 367
 
346 368
 	gtk_widget_show_all(ui->mainwin);
347 369
 }
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
... ...
@@ -94,6 +94,22 @@ void hal_bluetooth_send_data(const void *mdat, uint16_t mlen)
94 94
 	g_printerr("write comm %d\n", mlen);
95 95
 }
96 96
 
97
+const char *hal_get_version_string(void)
98
+{
99
+	return "GTK v0.3";
100
+}
101
+
102
+const char *hal_get_buildno_string(void)
103
+{
104
+	return BUILDNO;
105
+}
106
+
107
+const char *hal_get_radio_version_string(void)
108
+{
109
+	return "BlueZ";
110
+}
111
+
112
+
97 113
 static gint
98 114
 configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
99 115
 {
... ...
@@ -311,19 +327,19 @@ static void create_mainwin(oswald_ui *ui)
311 327
 
312 328
 	l = gtk_label_new("X:");
313 329
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
314
-	sc = gtk_hscale_new_with_range (0, 255, 1);
330
+	sc = gtk_hscale_new_with_range (-128, 127, 1);
315 331
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
316 332
 	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelX_value_changed), ui);
317 333
 
318 334
 	l = gtk_label_new("Y:");
319 335
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
320
-	sc = gtk_hscale_new_with_range (0, 255, 1);
336
+	sc = gtk_hscale_new_with_range (-128, 127, 1);
321 337
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
322 338
 	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelY_value_changed), ui);
323 339
 
324 340
 	l = gtk_label_new("Z:");
325 341
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
326
-	sc = gtk_hscale_new_with_range (0, 255, 1);
342
+	sc = gtk_hscale_new_with_range (-128, 127, 1);
327 343
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
328 344
 	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelZ_value_changed), ui);
329 345
 
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
... ...
@@ -12,7 +12,7 @@
12 12
 
13 13
 #include <gtk/gtk.h>
14 14
 
15
-#include "Fonts.h" // the MetaWatch fonts
15
+//#include "Fonts.h" // the MetaWatch fonts
16 16
 #include "oswald.h"
17 17
 #include "oswald_main.h"
18 18
 
... ...
@@ -205,7 +205,7 @@ void ambientlight_value_changed (GtkRange *range, gpointer  user_data)
205 205
 	double val;
206 206
 
207 207
 	val = gtk_range_get_value(range);
208
-	oswald_handle_ambientlight_event((u8t) val);
208
+	oswald_handle_ambientlight_event((uint8_t) val);
209 209
 }
210 210
 
211 211
 void accelX_value_changed (GtkRange *range, gpointer  user_data)
... ...
@@ -214,7 +214,7 @@ void accelX_value_changed (GtkRange *range, gpointer  user_data)
214 214
 	double val;
215 215
 
216 216
 	val = gtk_range_get_value(range);
217
-	ui->accel_x = (u8t)val;
217
+	ui->accel_x = (uint8_t)val;
218 218
 	oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z);
219 219
 }
220 220
 
... ...
@@ -224,7 +224,7 @@ void accelY_value_changed (GtkRange *range, gpointer  user_data)
224 224
 	double val;
225 225
 
226 226
 	val = gtk_range_get_value(range);
227
-	ui->accel_y = (u8t)val;
227
+	ui->accel_y = (uint8_t)val;
228 228
 	oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z);
229 229
 }
230 230
 
... ...
@@ -234,7 +234,7 @@ void accelZ_value_changed (GtkRange *range, gpointer  user_data)
234 234
 	double val;
235 235
 
236 236
 	val = gtk_range_get_value(range);
237
-	ui->accel_z = (u8t)val;
237
+	ui->accel_z = (uint8_t)val;
238 238
 	oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z);
239 239
 }
240 240
 
Browse code

Bluetooth handling, screen reworks for icons

Nils Faerber authored on 21/04/2013 23:10:13
Showing 1 changed files
... ...
@@ -35,7 +35,6 @@ void hal_lcd_set_pixel(gint x, gint y, gboolean state)
35 35
 	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy+1);
36 36
 	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy+1);
37 37
 
38
-//	gtk_widget_queue_draw(ui_g->darea);
39 38
 }
40 39
 
41 40
 /* updates the actual LCD so that drawing becomes visible */
... ...
@@ -56,6 +55,45 @@ void hal_lcd_clear_display(void)
56 55
 	gtk_widget_queue_draw(ui_g->darea);
57 56
 }
58 57
 
58
+static bluetooth_state bt_state = BLUETOOTH_OFF;
59
+static boolean bt_visible = FALSE;
60
+
61
+bluetooth_state hal_bluetooth_set_state(bluetooth_state state)
62
+{
63
+	bt_state = state;
64
+	if (bt_state == BLUETOOTH_OFF)
65
+		bt_visible = FALSE;
66
+
67
+	return bt_state;
68
+}
69
+
70
+bluetooth_state hal_bluetooth_get_state(void)
71
+{
72
+	return bt_state;
73
+}
74
+
75
+uint8_t *hal_bluetooth_get_local_bdaddr(void)
76
+{
77
+	static uint8_t local_bdaddr[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
78
+
79
+	return local_bdaddr;
80
+}
81
+
82
+void hal_bluetooth_set_visible(boolean visible)
83
+{
84
+	bt_visible = visible;
85
+}
86
+
87
+boolean hal_bluetooth_get_visible(void)
88
+{
89
+	return bt_visible;
90
+}
91
+
92
+void hal_bluetooth_send_data(const void *mdat, uint16_t mlen)
93
+{
94
+	g_printerr("write comm %d\n", mlen);
95
+}
96
+
59 97
 static gint
60 98
 configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
61 99
 {
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
... ...
@@ -23,7 +23,7 @@
23 23
 
24 24
 static oswald_ui *ui_g;
25 25
 
26
-void lcd_set_pixel(gint x, gint y, gboolean state)
26
+void hal_lcd_set_pixel(gint x, gint y, gboolean state)
27 27
 {
28 28
 	gint ix, iy;
29 29
 
... ...
@@ -39,12 +39,12 @@ void lcd_set_pixel(gint x, gint y, gboolean state)
39 39
 }
40 40
 
41 41
 /* updates the actual LCD so that drawing becomes visible */
42
-void lcd_update_display(void)
42
+void hal_lcd_update_display(void)
43 43
 {
44 44
 	gtk_widget_queue_draw(ui_g->darea);
45 45
 }
46 46
 
47
-void lcd_clear_display(void)
47
+void hal_lcd_clear_display(void)
48 48
 {
49 49
 	gdk_draw_rectangle (ui_g->pixmap,
50 50
 		ui_g->darea->style->white_gc,
... ...
@@ -219,19 +219,19 @@ static void create_mainwin(oswald_ui *ui)
219 219
 	vb = gtk_vbox_new(FALSE, 5);
220 220
 	gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
221 221
 
222
-	btn = gtk_button_new_with_label(" D ");
222
+	btn = gtk_button_new_with_label(" F ");
223 223
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
224
-	g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui);
224
+	g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_clicked), ui);
225
+	g_signal_connect(G_OBJECT(btn), "button-press-event", G_CALLBACK(button_F_pr), ui);
226
+	g_signal_connect(G_OBJECT(btn), "button-release-event", G_CALLBACK(button_F_pr), ui);
225 227
 
226 228
 	btn = gtk_button_new_with_label(" E ");
227 229
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
228 230
 	g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_E_clicked), ui);
229 231
 
230
-	btn = gtk_button_new_with_label(" F ");
232
+	btn = gtk_button_new_with_label(" D ");
231 233
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
232
-	g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_clicked), ui);
233
-	g_signal_connect(G_OBJECT(btn), "button-press-event", G_CALLBACK(button_F_pr), ui);
234
-	g_signal_connect(G_OBJECT(btn), "button-release-event", G_CALLBACK(button_F_pr), ui);
234
+	g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui);
235 235
 
236 236
 	ui->darea = gtk_drawing_area_new ();
237 237
 	gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5);
... ...
@@ -323,13 +323,13 @@ static gboolean centisecond_tmo_handler (gpointer userdata)
323 323
 	return TRUE;
324 324
 }
325 325
 
326
-void enable_centisecond_timer(void)
326
+void hal_enable_centisecond_timer(void)
327 327
 {
328 328
 	ui_g->centisecond_active = TRUE;
329 329
 	g_timeout_add(10, centisecond_tmo_handler, ui_g);
330 330
 }
331 331
 
332
-void disable_centisecond_timer(void)
332
+void hal_disable_centisecond_timer(void)
333 333
 {
334 334
 	ui_g->centisecond_active = FALSE;
335 335
 }
... ...
@@ -346,17 +346,67 @@ static gboolean halfsecond_tmo_handler (gpointer userdata)
346 346
 	return TRUE;
347 347
 }
348 348
 
349
-void enable_halfsecond_timer(void)
349
+void hal_enable_halfsecond_timer(void)
350 350
 {
351 351
 	ui_g->halfsecond_active = TRUE;
352 352
 	g_timeout_add(500, halfsecond_tmo_handler, ui_g);
353 353
 }
354 354
 
355
-void disable_halfsecond_timer(void)
355
+void hal_disable_halfsecond_timer(void)
356 356
 {
357 357
 	ui_g->halfsecond_active = FALSE;
358 358
 }
359 359
 
360
+void hal_get_rtc(clock_state *rtc)
361
+{
362
+	time_t mt;
363
+	struct tm mtime;
364
+
365
+	mt = time(NULL);
366
+	localtime_r(&mt, &mtime);
367
+
368
+	rtc->hour = mtime.tm_hour;
369
+	rtc->minute = mtime.tm_min;
370
+	rtc->second = mtime.tm_sec;
371
+	rtc->day = mtime.tm_mday;
372
+	rtc->month = (mtime.tm_mon + 1);
373
+	rtc->year = (mtime.tm_year + 1900);
374
+}
375
+
376
+void hal_set_rtc(const clock_state *rtc, boolean set_set)
377
+{
378
+}
379
+
380
+void hal_get_power_state(power_state *pwr)
381
+{
382
+}
383
+
384
+static boolean BacklightState = FALSE;
385
+
386
+/* sets the backlight on/off, on=TRUE, off=FALSE */
387
+void hal_lcd_set_backlight(boolean state)
388
+{
389
+	g_print("turn LCD backlight %s\n", state ? "on" : "off");
390
+	BacklightState = state;
391
+}
392
+
393
+boolean hal_lcd_get_backlight(void)
394
+{
395
+	return BacklightState;
396
+}
397
+
398
+
399
+/* sets the vibration motor on/off, on=TRUE, off=FALSE */
400
+void hal_vibration_set_state(boolean state)
401
+{
402
+}
403
+
404
+boolean hal_vibration_get_state(void)
405
+{
406
+	return FALSE;
407
+}
408
+
409
+
360 410
 int main(int argc , char ** argv)
361 411
 {
362 412
 	oswald_ui ui;
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
... ...
@@ -35,6 +35,12 @@ void lcd_set_pixel(gint x, gint y, gboolean state)
35 35
 	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy+1);
36 36
 	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy+1);
37 37
 
38
+//	gtk_widget_queue_draw(ui_g->darea);
39
+}
40
+
41
+/* updates the actual LCD so that drawing becomes visible */
42
+void lcd_update_display(void)
43
+{
38 44
 	gtk_widget_queue_draw(ui_g->darea);
39 45
 }
40 46
 
Browse code

Countless fixes and enhancements

Nils Faerber authored on 12/08/2012 21:14:19
Showing 1 changed files
... ...
@@ -155,6 +155,45 @@ gboolean button_F_pr (GtkWidget *widget, GdkEvent *event, gpointer user_data)
155 155
 	return FALSE;
156 156
 }
157 157
 
158
+void ambientlight_value_changed (GtkRange *range, gpointer  user_data)
159
+{
160
+	oswald_ui *ui = (oswald_ui *)user_data;
161
+	double val;
162
+
163
+	val = gtk_range_get_value(range);
164
+	oswald_handle_ambientlight_event((u8t) val);
165
+}
166
+
167
+void accelX_value_changed (GtkRange *range, gpointer  user_data)
168
+{
169
+	oswald_ui *ui = (oswald_ui *)user_data;
170
+	double val;
171
+
172
+	val = gtk_range_get_value(range);
173
+	ui->accel_x = (u8t)val;
174
+	oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z);
175
+}
176
+
177
+void accelY_value_changed (GtkRange *range, gpointer  user_data)
178
+{
179
+	oswald_ui *ui = (oswald_ui *)user_data;
180
+	double val;
181
+
182
+	val = gtk_range_get_value(range);
183
+	ui->accel_y = (u8t)val;
184
+	oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z);
185
+}
186
+
187
+void accelZ_value_changed (GtkRange *range, gpointer  user_data)
188
+{
189
+	oswald_ui *ui = (oswald_ui *)user_data;
190
+	double val;
191
+
192
+	val = gtk_range_get_value(range);
193
+	ui->accel_z = (u8t)val;
194
+	oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z);
195
+}
196
+
158 197
 static void create_mainwin(oswald_ui *ui)
159 198
 {
160 199
 	GtkWidget *mvb, *hb, *vb, *btn, *sc, *l;
... ...
@@ -218,8 +257,10 @@ static void create_mainwin(oswald_ui *ui)
218 257
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
219 258
 	g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_C_clicked), ui);
220 259
 
260
+	// ambient light sensor
221 261
 	sc = gtk_vscale_new_with_range (0, 255, 1);
222 262
 	gtk_box_pack_start (GTK_BOX(hb), sc, FALSE, FALSE, 5);
263
+	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(ambientlight_value_changed), ui);
223 264
 
224 265
 	hb = gtk_hbox_new(FALSE, 0);
225 266
 	gtk_box_pack_start (GTK_BOX(mvb), hb, FALSE, FALSE, 5);
... ...
@@ -228,21 +269,24 @@ static void create_mainwin(oswald_ui *ui)
228 269
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
229 270
 	sc = gtk_hscale_new_with_range (0, 255, 1);
230 271
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
272
+	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelX_value_changed), ui);
231 273
 
232 274
 	l = gtk_label_new("Y:");
233 275
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
234 276
 	sc = gtk_hscale_new_with_range (0, 255, 1);
235 277
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
278
+	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelY_value_changed), ui);
236 279
 
237 280
 	l = gtk_label_new("Z:");
238 281
 	gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
239 282
 	sc = gtk_hscale_new_with_range (0, 255, 1);
240 283
 	gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
284
+	g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelZ_value_changed), ui);
241 285
 
242 286
 	gtk_widget_show_all(ui->mainwin);
243 287
 }
244 288
 
245
-gboolean one_second_tmo_handler (gpointer userdata)
289
+static gboolean one_second_tmo_handler (gpointer userdata)
246 290
 {
247 291
 	oswald_ui *ui = (oswald_ui *)userdata;
248 292
 
... ...
@@ -251,7 +295,7 @@ gboolean one_second_tmo_handler (gpointer userdata)
251 295
 	return TRUE;
252 296
 }
253 297
 
254
-gboolean app_idle_handler (gpointer user_data)
298
+static gboolean app_idle_handler (gpointer user_data)
255 299
 {
256 300
 	g_print("i");
257 301
 	if (OswaldState.pending_idle) {
... ...
@@ -261,6 +305,52 @@ gboolean app_idle_handler (gpointer user_data)
261 305
 	return FALSE;
262 306
 }
263 307
 
308
+static gboolean centisecond_tmo_handler (gpointer userdata)
309
+{
310
+	oswald_ui *ui = (oswald_ui *)userdata;
311
+
312
+	if (ui->centisecond_active)
313
+		oswald_centisecond_tick();
314
+	else
315
+		return FALSE;
316
+
317
+	return TRUE;
318
+}
319
+
320
+void enable_centisecond_timer(void)
321
+{
322
+	ui_g->centisecond_active = TRUE;
323
+	g_timeout_add(10, centisecond_tmo_handler, ui_g);
324
+}
325
+
326
+void disable_centisecond_timer(void)
327
+{
328
+	ui_g->centisecond_active = FALSE;
329
+}
330
+
331
+static gboolean halfsecond_tmo_handler (gpointer userdata)
332
+{
333
+	oswald_ui *ui = (oswald_ui *)userdata;
334
+
335
+	if (ui->halfsecond_active)
336
+		oswald_halfsecond_tick();
337
+	else
338
+		return FALSE;
339
+
340
+	return TRUE;
341
+}
342
+
343
+void enable_halfsecond_timer(void)
344
+{
345
+	ui_g->halfsecond_active = TRUE;
346
+	g_timeout_add(500, halfsecond_tmo_handler, ui_g);
347
+}
348
+
349
+void disable_halfsecond_timer(void)
350
+{
351
+	ui_g->halfsecond_active = FALSE;
352
+}
353
+
264 354
 int main(int argc , char ** argv)
265 355
 {
266 356
 	oswald_ui ui;
... ...
@@ -269,6 +359,12 @@ int main(int argc , char ** argv)
269 359
 
270 360
 	ui_g = &ui;
271 361
 
362
+	ui.accel_x = 0;
363
+	ui.accel_y = 0;
364
+	ui.accel_z = 0;
365
+	ui.halfsecond_active = FALSE;
366
+	ui.centisecond_active = FALSE;
367
+
272 368
 	mt = time(NULL);
273 369
 	localtime_r(&mt, &mtime);
274 370
 
... ...
@@ -277,7 +373,8 @@ int main(int argc , char ** argv)
277 373
 	create_mainwin(&ui);
278 374
 	gtk_widget_realize(ui.mainwin);
279 375
 
280
-	oswald_set_time(mtime.tm_hour, mtime.tm_min, mtime.tm_sec);
376
+	oswald_set_time(mtime.tm_hour, mtime.tm_min, mtime.tm_sec, TRUE);
377
+	oswald_set_date(mtime.tm_mday, (mtime.tm_mon + 1), (mtime.tm_year + 1900), TRUE);
281 378
 	oswald_init();
282 379
 
283 380
 	g_timeout_add_seconds(1, one_second_tmo_handler, &ui);
Browse code

Make idle selectable

Nils Faerber authored on 12/08/2012 02:11:30
Showing 1 changed files
... ...
@@ -254,7 +254,11 @@ gboolean one_second_tmo_handler (gpointer userdata)
254 254
 gboolean app_idle_handler (gpointer user_data)
255 255
 {
256 256
 	g_print("i");
257
-	return TRUE;
257
+	if (OswaldState.pending_idle) {
258
+		// call Oswald's idle function
259
+		return TRUE;
260
+	};
261
+	return FALSE;
258 262
 }
259 263
 
260 264
 int main(int argc , char ** argv)
Browse code

Redesign to an event based handling

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

Add support for more screens

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

Too much to note...

Nils Faerber authored on 05/08/2012 17:07:17
Showing 1 changed files
... ...
@@ -12,50 +12,41 @@
12 12
 
13 13
 #include <gtk/gtk.h>
14 14
 
15
-#include "oswald-ui.h"
16 15
 #include "Fonts.h" // the MetaWatch fonts
16
+#include "oswald_main.h"
17
+
18
+#include "oswald-ui.h"
17 19
 
18 20
 #define BITMAP_WIDTH	192
19 21
 #define BITMAP_HEIGHT	192
20 22
 
21
-void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
23
+static oswald_ui *ui_g;
24
+
25
+void lcd_set_pixel(gint x, gint y, gboolean state)
22 26
 {
23
-	GdkRectangle update_rect;
24 27
 	gint ix, iy;
25 28
 
26 29
 	ix = x*2;
27 30
 	iy = y*2;
28 31
 
29
-	update_rect.x = ix - 5;
30
-	update_rect.y = iy - 5;
31
-	update_rect.width = 10;
32
-	update_rect.height = 10;
33
-
34
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy);
35
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy);
36
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy+1);
37
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy+1);
32
+	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy);
33
+	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy);
34
+	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy+1);
35
+	gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy+1);
38 36
 
39
-	gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
37
+	gtk_widget_queue_draw(ui_g->darea);
40 38
 }
41 39
 
42
-void clear_display(oswald_ui *ui)
40
+void lcd_clear_display(void)
43 41
 {
44
-	GdkRectangle update_rect;
45
-
46
-	update_rect.x = 0;
47
-	update_rect.y = 0;
48
-	update_rect.width = BITMAP_WIDTH;
49
-	update_rect.height = BITMAP_HEIGHT;
50
-
51
-	gdk_draw_rectangle (ui->pixmap,
52
-		ui->darea->style->white_gc,
42
+	gdk_draw_rectangle (ui_g->pixmap,
43
+		ui_g->darea->style->white_gc,
53 44
 		TRUE,
54 45
 		0, 0,
55
-		ui->darea->allocation.width,
56
-		ui->darea->allocation.height);
46
+		ui_g->darea->allocation.width,
47
+		ui_g->darea->allocation.height);
57 48
 
58
-	gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
49
+	gtk_widget_queue_draw(ui_g->darea);
59 50
 }
60 51
 
61 52
 static gint
... ...
@@ -95,6 +86,49 @@ expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
95 86
 	return FALSE;
96 87
 }
97 88
 
89
+void button_A_pressed (GtkButton *button, gpointer user_data)
90
+{
91
+	oswald_ui *ui = (oswald_ui *)user_data;
92
+
93
+	g_print("Button-A pressed\n");
94
+	oswald_handle_button_press(BUTTON_A);
95
+}
96
+
97
+void button_B_pressed (GtkButton *button, gpointer user_data)
98
+{
99
+	oswald_ui *ui = (oswald_ui *)user_data;
100
+
101
+	g_print("Button-B pressed\n");
102
+}
103
+
104
+void button_C_pressed (GtkButton *button, gpointer user_data)
105
+{
106
+	oswald_ui *ui = (oswald_ui *)user_data;
107
+
108
+	g_print("Button-C pressed\n");
109
+}
110
+
111
+void button_D_pressed (GtkButton *button, gpointer user_data)
112
+{
113
+	oswald_ui *ui = (oswald_ui *)user_data;
114
+
115
+	g_print("Button-D pressed\n");
116
+}
117
+
118
+void button_E_pressed (GtkButton *button, gpointer user_data)
119
+{
120
+	oswald_ui *ui = (oswald_ui *)user_data;
121
+
122
+	g_print("Button-E pressed\n");
123
+}
124
+
125
+void button_F_pressed (GtkButton *button, gpointer user_data)
126
+{
127
+	oswald_ui *ui = (oswald_ui *)user_data;
128
+
129
+	g_print("Button-F pressed\n");
130
+}
131
+
98 132
 static void create_mainwin(oswald_ui *ui)
99 133
 {
100 134
 	GtkWidget *hb, *vb, *btn;
... ...
@@ -113,12 +147,16 @@ static void create_mainwin(oswald_ui *ui)
113 147
 
114 148
 	btn = gtk_button_new_with_label(" D ");
115 149
 	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);
116 151
 
117 152
 	btn = gtk_button_new_with_label(" E ");
118 153
 	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);
119 155
 
120 156
 	btn = gtk_button_new_with_label(" F ");
121 157
 	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
+
122 160
 
123 161
 	ui->darea = gtk_drawing_area_new ();
124 162
 	gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5);
... ...
@@ -140,47 +178,54 @@ static void create_mainwin(oswald_ui *ui)
140 178
 
141 179
 	btn = gtk_button_new_with_label(" A ");
142 180
 	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);
143 182
 
144 183
 	btn = gtk_button_new_with_label(" B ");
145 184
 	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);
146 186
 
147 187
 	btn = gtk_button_new_with_label(" C ");
148 188
 	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);
149 190
 
150 191
 	gtk_widget_show_all(ui->mainwin);
151 192
 }
152 193
 
153
-gboolean app_tmo_handler (gpointer userdata)
194
+gboolean one_second_tmo_handler (gpointer userdata)
154 195
 {
155 196
 	oswald_ui *ui = (oswald_ui *)userdata;
156 197
 
157
-	// fprintf(stderr, "tmo...\n");
198
+	oswald_one_second_tick();
158 199
 
159
-	if (ui->OnIdleScreen) {
160
-		update_idle_time_date(ui);
161
-#if 0
162
-	} else {
163
-		// go back to idle screen after IDLE_TIMEOUT seconds
164
-		if ((time(NULL) - ui->idle_tmo) > ui->conf.idle_tmo /*IDLE_TIMEOUT*/)
165
-			create_main_screen(ui);
166
-#endif
167
-	}
200
+	return TRUE;
201
+}
168 202
 
203
+gboolean app_idle_handler (gpointer user_data)
204
+{
205
+	g_print("i");
169 206
 	return TRUE;
170 207
 }
171 208
 
172 209
 int main(int argc , char ** argv)
173 210
 {
174 211
 	oswald_ui ui;
212
+	time_t mt;
213
+	struct tm mtime;
214
+
215
+	ui_g = &ui;
216
+
217
+	mt = time(NULL);
218
+	localtime_r(&mt, &mtime);
175 219
 
176 220
 	gtk_init (&argc, &argv);
177 221
 
178 222
 	create_mainwin(&ui);
179 223
 
180
-	//set_pixel(&ui, 48, 48, TRUE);
181
-	// demo_time(&ui);
182
-	ui.OnIdleScreen = TRUE;
183
-	g_timeout_add_seconds(1, app_tmo_handler, &ui);
224
+	oswald_init();
225
+	oswald_set_time(mtime.tm_hour, mtime.tm_min, mtime.tm_sec);
226
+
227
+	g_timeout_add_seconds(1, one_second_tmo_handler, &ui);
228
+	// g_idle_add(app_idle_handler, &ui);
184 229
 
185 230
 	gtk_main ();
186 231
 	return 0;
Browse code

Add MetaWatch Fonts package, LcdDisplay and start demo

Nils Faerber authored on 31/07/2012 21:42:03
Showing 1 changed files
... ...
@@ -12,19 +12,15 @@
12 12
 
13 13
 #include <gtk/gtk.h>
14 14
 
15
+#include "oswald-ui.h"
16
+#include "Fonts.h" // the MetaWatch fonts
15 17
 
16
-typedef struct {
17
-	GtkWidget *mainwin;
18
-	GtkDrawingArea *darea;
19
-	GdkPixmap *pixmap;
20
-} oswald_ui;
21
-
22
-
18
+#define BITMAP_WIDTH	192
19
+#define BITMAP_HEIGHT	192
23 20
 
24 21
 void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
25 22
 {
26 23
 	GdkRectangle update_rect;
27
-	GdkGC *gc;
28 24
 	gint ix, iy;
29 25
 
30 26
 	ix = x*2;
... ...
@@ -35,10 +31,29 @@ void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
35 31
 	update_rect.width = 10;
36 32
 	update_rect.height = 10;
37 33
 
38
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix, iy);
39
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix+1, iy);
40
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix, iy+1);
41
-	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix+1, iy+1);
34
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy);
35
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy);
36
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy+1);
37
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy+1);
38
+
39
+	gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
40
+}
41
+
42
+void clear_display(oswald_ui *ui)
43
+{
44
+	GdkRectangle update_rect;
45
+
46
+	update_rect.x = 0;
47
+	update_rect.y = 0;
48
+	update_rect.width = BITMAP_WIDTH;
49
+	update_rect.height = BITMAP_HEIGHT;
50
+
51
+	gdk_draw_rectangle (ui->pixmap,
52
+		ui->darea->style->white_gc,
53
+		TRUE,
54
+		0, 0,
55
+		ui->darea->allocation.width,
56
+		ui->darea->allocation.height);
42 57
 
43 58
 	gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
44 59
 }
... ...
@@ -96,18 +111,18 @@ static void create_mainwin(oswald_ui *ui)
96 111
 	vb = gtk_vbox_new(FALSE, 5);
97 112
 	gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
98 113
 
99
-	btn = gtk_button_new_with_label("D");
114
+	btn = gtk_button_new_with_label(" D ");
100 115
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
101 116
 
102
-	btn = gtk_button_new_with_label("E");
117
+	btn = gtk_button_new_with_label(" E ");
103 118
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
104 119
 
105
-	btn = gtk_button_new_with_label("F");
120
+	btn = gtk_button_new_with_label(" F ");
106 121
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
107 122
 
108
-	ui->darea = (GtkDrawingArea *)gtk_drawing_area_new ();
123
+	ui->darea = gtk_drawing_area_new ();
109 124
 	gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5);
110
-	gtk_drawing_area_size (ui->darea, 192, 192);
125
+	gtk_drawing_area_size (GTK_DRAWING_AREA(ui->darea), BITMAP_WIDTH, BITMAP_HEIGHT);
111 126
 
112 127
 	gtk_signal_connect (GTK_OBJECT (ui->darea), "expose_event", (GtkSignalFunc) expose_event, ui);
113 128
 	gtk_signal_connect (GTK_OBJECT (ui->darea), "configure_event", (GtkSignalFunc) configure_event, ui);
... ...
@@ -123,18 +138,37 @@ static void create_mainwin(oswald_ui *ui)
123 138
 	vb = gtk_vbox_new(FALSE, 5);
124 139
 	gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
125 140
 
126
-	btn = gtk_button_new_with_label("A");
141
+	btn = gtk_button_new_with_label(" A ");
127 142
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
128 143
 
129
-	btn = gtk_button_new_with_label("B");
144
+	btn = gtk_button_new_with_label(" B ");
130 145
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
131 146
 
132
-	btn = gtk_button_new_with_label("C");
147
+	btn = gtk_button_new_with_label(" C ");
133 148
 	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
134 149
 
135 150
 	gtk_widget_show_all(ui->mainwin);
136 151
 }
137 152
 
153
+gboolean app_tmo_handler (gpointer userdata)
154
+{
155
+	oswald_ui *ui = (oswald_ui *)userdata;
156
+
157
+	// fprintf(stderr, "tmo...\n");
158
+
159
+	if (ui->OnIdleScreen) {
160
+		update_idle_time_date(ui);
161
+#if 0
162
+	} else {
163
+		// go back to idle screen after IDLE_TIMEOUT seconds
164
+		if ((time(NULL) - ui->idle_tmo) > ui->conf.idle_tmo /*IDLE_TIMEOUT*/)
165
+			create_main_screen(ui);
166
+#endif
167
+	}
168
+
169
+	return TRUE;
170
+}
171
+
138 172
 int main(int argc , char ** argv)
139 173
 {
140 174
 	oswald_ui ui;
... ...
@@ -143,7 +177,10 @@ int main(int argc , char ** argv)
143 177
 
144 178
 	create_mainwin(&ui);
145 179
 
146
-	set_pixel(&ui, 48, 48, TRUE);
180
+	//set_pixel(&ui, 48, 48, TRUE);
181
+	// demo_time(&ui);
182
+	ui.OnIdleScreen = TRUE;
183
+	g_timeout_add_seconds(1, app_tmo_handler, &ui);
147 184
 
148 185
 	gtk_main ();
149 186
 	return 0;
Browse code

Start drawing...

Nils Faerber authored on 31/07/2012 19:28:08
Showing 1 changed files
... ...
@@ -14,7 +14,138 @@
14 14
 
15 15
 
16 16
 typedef struct {
17
-	GtkWidget *main_win;
17
+	GtkWidget *mainwin;
18
+	GtkDrawingArea *darea;
19
+	GdkPixmap *pixmap;
18 20
 } oswald_ui;
19 21
 
20 22
 
23
+
24
+void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
25
+{
26
+	GdkRectangle update_rect;
27
+	GdkGC *gc;
28
+	gint ix, iy;
29
+
30
+	ix = x*2;
31
+	iy = y*2;
32
+
33
+	update_rect.x = ix - 5;
34
+	update_rect.y = iy - 5;
35
+	update_rect.width = 10;
36
+	update_rect.height = 10;
37
+
38
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix, iy);
39
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix+1, iy);
40
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix, iy+1);
41
+	gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix+1, iy+1);
42
+
43
+	gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
44
+}
45
+
46
+static gint
47
+configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
48
+{
49
+	oswald_ui *ui = (oswald_ui *)user_data;
50
+
51
+	if (ui->pixmap)
52
+		gdk_pixmap_unref(ui->pixmap);
53
+
54
+	ui->pixmap = gdk_pixmap_new(widget->window,
55
+		widget->allocation.width,
56
+		widget->allocation.height,
57
+		-1);
58
+	gdk_draw_rectangle (ui->pixmap,
59
+		widget->style->white_gc,
60
+		TRUE,
61
+		0, 0,
62
+		widget->allocation.width,
63
+		widget->allocation.height);
64
+
65
+	return TRUE;
66
+}
67
+
68
+static gint
69
+expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
70
+{
71
+	oswald_ui *ui = (oswald_ui *)user_data;
72
+
73
+	gdk_draw_pixmap(widget->window,
74
+		widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
75
+		ui->pixmap,
76
+		event->area.x, event->area.y,
77
+		event->area.x, event->area.y,
78
+		event->area.width, event->area.height);
79
+
80
+	return FALSE;
81
+}
82
+
83
+static void create_mainwin(oswald_ui *ui)
84
+{
85
+	GtkWidget *hb, *vb, *btn;
86
+
87
+	ui->pixmap = NULL;
88
+
89
+	ui->mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
90
+	// gtk_window_set_default_size (GTK_WINDOW (ui->mainwin), 440, 240);
91
+	g_signal_connect(G_OBJECT(ui->mainwin), "destroy", gtk_main_quit, NULL);
92
+
93
+	hb = gtk_hbox_new(FALSE, 5);
94
+	gtk_container_add(GTK_CONTAINER(ui->mainwin), hb);
95
+
96
+	vb = gtk_vbox_new(FALSE, 5);
97
+	gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
98
+
99
+	btn = gtk_button_new_with_label("D");
100
+	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
101
+
102
+	btn = gtk_button_new_with_label("E");
103
+	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
104
+
105
+	btn = gtk_button_new_with_label("F");
106
+	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
107
+
108
+	ui->darea = (GtkDrawingArea *)gtk_drawing_area_new ();
109
+	gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5);
110
+	gtk_drawing_area_size (ui->darea, 192, 192);
111
+
112
+	gtk_signal_connect (GTK_OBJECT (ui->darea), "expose_event", (GtkSignalFunc) expose_event, ui);
113
+	gtk_signal_connect (GTK_OBJECT (ui->darea), "configure_event", (GtkSignalFunc) configure_event, ui);
114
+	// gtk_signal_connect (GTK_OBJECT (drawing_area), "motion_notify_event", (GtkSignalFunc) motion_notify_event, ui);
115
+	// gtk_signal_connect (GTK_OBJECT (drawing_area), "button_press_event", (GtkSignalFunc) button_press_event, ui);
116
+
117
+	gtk_widget_set_events (GTK_WIDGET(ui->darea), GDK_EXPOSURE_MASK
118
+		| GDK_LEAVE_NOTIFY_MASK
119
+		| GDK_BUTTON_PRESS_MASK
120
+		| GDK_POINTER_MOTION_MASK
121
+		| GDK_POINTER_MOTION_HINT_MASK);
122
+
123
+	vb = gtk_vbox_new(FALSE, 5);
124
+	gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
125
+
126
+	btn = gtk_button_new_with_label("A");
127
+	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
128
+
129
+	btn = gtk_button_new_with_label("B");
130
+	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
131
+
132
+	btn = gtk_button_new_with_label("C");
133
+	gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
134
+
135
+	gtk_widget_show_all(ui->mainwin);
136
+}
137
+
138
+int main(int argc , char ** argv)
139
+{
140
+	oswald_ui ui;
141
+
142
+	gtk_init (&argc, &argv);
143
+
144
+	create_mainwin(&ui);
145
+
146
+	set_pixel(&ui, 48, 48, TRUE);
147
+
148
+	gtk_main ();
149
+	return 0;
150
+}
151
+
Browse code

initial UI stuff

Nils Faerber authored on 31/07/2012 17:51:24
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+#include <stdio.h>
2
+#include <sys/stat.h>
3
+#include <fcntl.h>
4
+#include <stdio.h>
5
+#include <stdlib.h>
6
+#include <unistd.h>
7
+#include <string.h>
8
+#include <poll.h>
9
+#include <sys/socket.h>
10
+#include <sys/un.h>
11
+#include <time.h>
12
+
13
+#include <gtk/gtk.h>
14
+
15
+
16
+typedef struct {
17
+	GtkWidget *main_win;
18
+} oswald_ui;
19
+
20
+