Add support for more screens
authorNils Faerber <nils.faerber@kernelconcepts.de>
Mon, 6 Aug 2012 14:12:20 +0000 (16:12 +0200)
committerNils Faerber <nils.faerber@kernelconcepts.de>
Mon, 6 Aug 2012 14:12:20 +0000 (16:12 +0200)
ui/LcdDisplay.c
ui/Makefile.am
ui/oswald-ui.c
ui/oswald.h
ui/oswald_main.c
ui/oswald_strings.c [new file with mode: 0644]
ui/oswald_strings.h [new file with mode: 0644]
ui/oswald_watch_faces.c
ui/oswald_watch_faces.h

index f2652c2..4f6bf99 100644 (file)
@@ -1,9 +1,5 @@
-#include <time.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
 #include "oswald-ui.h"
+#include "oswald_strings.h"
 #include "Fonts.h"
 
 #include "LcdDisplay.h"
@@ -142,13 +138,14 @@ u8t WriteLcdCharacter(u8t x, u8t y, u8t Character)
 
 void WriteLcdString(u8t x, u8t y, u8t *str)
 {
-       register lx, i;
+       register lx, i, strl;
 
-       if (str == NULL || strlen(str)==0)
+       strl = oswald_strlen(str);
+       if (strl == 0)
                return;
 
        lx = x;
-       for (i=0; i<strlen(str); i++) {
+       for (i=0; i<strl; i++) {
                lx += WriteLcdCharacter(lx, y, str[i]);
        }
 }
index a48f380..df3a186 100644 (file)
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4
 
 bin_PROGRAMS = oswald-gui
 
-oswald_gui_SOURCES = oswald-ui.c LcdDisplay.c Fonts.c oswald_main.c oswald_watch_faces.c
+oswald_gui_SOURCES = oswald-ui.c LcdDisplay.c Fonts.c oswald_main.c oswald_watch_faces.c oswald_strings.c
 oswald_gui_CFLAGS = -g $(GTK_CFLAGS)
 oswald_gui_LDADD = $(GTK_LIBS)
 
index e7eb9f2..27e8304 100644 (file)
@@ -13,6 +13,7 @@
 #include <gtk/gtk.h>
 
 #include "Fonts.h" // the MetaWatch fonts
+#include "oswald.h"
 #include "oswald_main.h"
 
 #include "oswald-ui.h"
@@ -86,52 +87,77 @@ expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
        return FALSE;
 }
 
-void button_A_pressed (GtkButton *button, gpointer user_data)
+void button_A_clicked (GtkButton *button, gpointer user_data)
 {
        oswald_ui *ui = (oswald_ui *)user_data;
 
-       g_print("Button-A pressed\n");
+       g_print("Button-A clicked\n");
        oswald_handle_button_press(BUTTON_A);
 }
 
-void button_B_pressed (GtkButton *button, gpointer user_data)
+void button_B_clicked (GtkButton *button, gpointer user_data)
 {
        oswald_ui *ui = (oswald_ui *)user_data;
 
-       g_print("Button-B pressed\n");
+       g_print("Button-B clicked\n");
+       oswald_handle_button_press(BUTTON_B);
 }
 
-void button_C_pressed (GtkButton *button, gpointer user_data)
+void button_C_clicked (GtkButton *button, gpointer user_data)
 {
        oswald_ui *ui = (oswald_ui *)user_data;
 
-       g_print("Button-C pressed\n");
+       g_print("Button-C clicked\n");
+       oswald_handle_button_press(BUTTON_C);
 }
 
-void button_D_pressed (GtkButton *button, gpointer user_data)
+void button_D_clicked (GtkButton *button, gpointer user_data)
 {
        oswald_ui *ui = (oswald_ui *)user_data;
 
-       g_print("Button-D pressed\n");
+       g_print("Button-D clicked\n");
+       oswald_handle_button_press(BUTTON_D);
 }
 
-void button_E_pressed (GtkButton *button, gpointer user_data)
+void button_E_clicked (GtkButton *button, gpointer user_data)
 {
        oswald_ui *ui = (oswald_ui *)user_data;
 
-       g_print("Button-E pressed\n");
+       g_print("Button-E clicked\n");
+       oswald_handle_button_press(BUTTON_E);
 }
 
-void button_F_pressed (GtkButton *button, gpointer user_data)
+void button_F_clicked (GtkButton *button, gpointer user_data)
 {
        oswald_ui *ui = (oswald_ui *)user_data;
 
-       g_print("Button-F pressed\n");
+       g_print("Button-F clicked\n");
+       oswald_handle_button_press(BUTTON_F);
+}
+
+gboolean button_F_pr (GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+       oswald_ui *ui = (oswald_ui *)user_data;
+       static gint32 press_time;
+
+       GdkEventButton *bev = (GdkEventButton *)event;
+       if (bev->type == GDK_BUTTON_PRESS) {
+               press_time = bev->time;
+               return FALSE;
+       };
+       if (bev->type == GDK_BUTTON_RELEASE) {
+               if (bev->time > (press_time+1000)) {
+                       g_print("Button-F long press\n");
+                       return TRUE;
+               };
+       };
+
+       return FALSE;
 }
 
 static void create_mainwin(oswald_ui *ui)
 {
-       GtkWidget *hb, *vb, *btn;
+       GtkWidget *mvb, *hb, *vb, *btn, *sc, *l;
 
        ui->pixmap = NULL;
 
@@ -139,24 +165,28 @@ static void create_mainwin(oswald_ui *ui)
        // gtk_window_set_default_size (GTK_WINDOW (ui->mainwin), 440, 240);
        g_signal_connect(G_OBJECT(ui->mainwin), "destroy", gtk_main_quit, NULL);
 
+       mvb = gtk_vbox_new(FALSE, 5);
+       gtk_container_add(GTK_CONTAINER(ui->mainwin), mvb);
+
        hb = gtk_hbox_new(FALSE, 5);
-       gtk_container_add(GTK_CONTAINER(ui->mainwin), hb);
+       gtk_box_pack_start (GTK_BOX(mvb), hb, FALSE, FALSE, 5);
 
        vb = gtk_vbox_new(FALSE, 5);
        gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
 
        btn = gtk_button_new_with_label(" D ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
-       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_pressed), ui);
+       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui);
 
        btn = gtk_button_new_with_label(" E ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
-       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_pressed), ui);
+       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui);
 
        btn = gtk_button_new_with_label(" F ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
-       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_pressed), ui);
-
+       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_clicked), ui);
+       g_signal_connect(G_OBJECT(btn), "button-press-event", G_CALLBACK(button_F_pr), ui);
+       g_signal_connect(G_OBJECT(btn), "button-release-event", G_CALLBACK(button_F_pr), ui);
 
        ui->darea = gtk_drawing_area_new ();
        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)
 
        btn = gtk_button_new_with_label(" A ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
-       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_A_pressed), ui);
+       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_A_clicked), ui);
 
        btn = gtk_button_new_with_label(" B ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
-       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_B_pressed), ui);
+       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_B_clicked), ui);
 
        btn = gtk_button_new_with_label(" C ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
-       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_C_pressed), ui);
+       g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_C_clicked), ui);
+
+       sc = gtk_vscale_new_with_range (0, 255, 1);
+       gtk_box_pack_start (GTK_BOX(hb), sc, FALSE, FALSE, 5);
+
+       hb = gtk_hbox_new(FALSE, 0);
+       gtk_box_pack_start (GTK_BOX(mvb), hb, FALSE, FALSE, 5);
+
+       l = gtk_label_new("X:");
+       gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
+       sc = gtk_hscale_new_with_range (0, 255, 1);
+       gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
+
+       l = gtk_label_new("Y:");
+       gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
+       sc = gtk_hscale_new_with_range (0, 255, 1);
+       gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
+
+       l = gtk_label_new("Z:");
+       gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
+       sc = gtk_hscale_new_with_range (0, 255, 1);
+       gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
 
        gtk_widget_show_all(ui->mainwin);
 }
index c2ea5d3..ed7f54a 100644 (file)
@@ -3,6 +3,8 @@
 
 typedef signed char s8t;
 typedef unsigned char u8t;
+typedef signed short s16t;
+typedef unsigned short u16t;
 typedef u8t boolean;
 #ifdef TRUE
 #undef TRUE
@@ -27,7 +29,11 @@ typedef struct {
 
 typedef enum {
        IDLE_SCREEN = 0,
-       APPLICATION_SCREEN,
+       SETTING_DATETIME_SCREEN,
+//     SCREEN2_SCREEN,
+//     SCREEN3_SCREEN,
+//     APPLICATION_SCREEN,
+       LAST_SCREEN,            // a marker for the last (not valid) screen)
 } screen_number;
 
 typedef enum {
@@ -39,12 +45,17 @@ typedef enum {
        BUTTON_F,
 } watch_button;
 
+typedef struct {
+       void (*button_func)(watch_button button);
+} watch_screen;
+
 typedef struct {
        screen_number   screen;
-       void (*idle_draw_func)(boolean show_seconds);
+       // void (*draw_watchface_func)(boolean show_seconds);
        boolean idle_show_seconds;
+       void (*user_button_func)(watch_button button);
+       void (*user_screendraw_func)(void);
 } watch_state;
 
-
 #endif
 
index 9dd69cc..dc8cfa1 100644 (file)
@@ -1,5 +1,7 @@
 #include "oswald.h"
 #include "oswald_watch_faces.h"
+#include "Fonts.h"
+#include "LcdDisplay.h"
 
 #include "oswald_main.h"
 
@@ -13,21 +15,13 @@ watch_state OswaldState;
 
 void update_screen(void)
 {
-       switch (OswaldState.screen) {
-               case IDLE_SCREEN:
-                       if (OswaldState.idle_draw_func != NULL)
-                               OswaldState.idle_draw_func(OswaldState.idle_show_seconds);
-                       break;
-               case APPLICATION_SCREEN:
-                       break;
-               deafault:
-                       break;
-       };
+       if (OswaldState.user_screendraw_func != NULL)
+               OswaldState.user_screendraw_func();
 }
 
 void oswald_change_to_screen(screen_number screen)
 {
-       // we spare the update if no change
+       // we spare the update if no change happened
        if (OswaldState.screen != screen) {
                OswaldState.screen = screen;
                update_screen();
@@ -67,14 +61,65 @@ void oswald_one_second_tick(void)
        update_screen();
 }
 
+void draw_accel_screen(void)
+{
+       lcd_clear_display();
+       SetFont(MetaWatch16);
+       WriteLcdString(2, 2, "X:");
+       WriteLcdString(20, 2, "123");
+       WriteLcdString(2, 18, "Z:");
+       WriteLcdString(20, 18, "123");
+       WriteLcdString(2, 34, "Y:");
+       WriteLcdString(20, 34, "123");
+}
+
+void idle_handle_user_buttons(watch_button button)
+{
+}
+
 void oswald_handle_button_press(watch_button button)
 {
+       switch (button) {
+               case BUTTON_A:
+               case BUTTON_B:
+               case BUTTON_D:
+               case BUTTON_E:
+                       if (OswaldState.user_button_func != NULL)
+                               OswaldState.user_button_func(button);
+                       break;
+               case BUTTON_C:
+                       // next screen
+                       OswaldState.screen++;
+                       if (OswaldState.screen >= LAST_SCREEN) {
+                               OswaldState.screen = IDLE_SCREEN;
+                               OswaldState.user_button_func = idle_handle_user_buttons;
+                               OswaldState.user_screendraw_func = DrawLcdDigitalClock;
+                       } else {
+                               switch (OswaldState.screen) {
+                                       case SETTING_DATETIME_SCREEN:
+                                               OswaldState.user_button_func = idle_handle_user_buttons;
+                                               OswaldState.user_screendraw_func = draw_accel_screen;
+                                               break;
+                                       default:
+                                               break;
+                               };
+                       };
+                       update_screen();
+                       break;
+               case BUTTON_F:
+                       // backlight on/off
+                       break;
+               default:
+                       // should never get here
+                       break;
+       };
 }
 
 void oswald_init(void)
 {
        OswaldState.screen = IDLE_SCREEN;
-       OswaldState.idle_draw_func = DrawLcdDigitalClock;
        OswaldState.idle_show_seconds = FALSE;
+       OswaldState.user_screendraw_func = DrawLcdDigitalClock;
+       OswaldState.user_button_func = idle_handle_user_buttons;
 }
 
diff --git a/ui/oswald_strings.c b/ui/oswald_strings.c
new file mode 100644 (file)
index 0000000..e04da9b
--- /dev/null
@@ -0,0 +1,16 @@
+#include "oswald.h"
+
+#include "oswald_strings.h"
+
+u16t oswald_strlen(u8t *string)
+{
+       register i=0;
+
+       if (string == NULL)
+               return 0;
+
+       while (string[i] != 0) i++;
+
+       return i;
+}
+
diff --git a/ui/oswald_strings.h b/ui/oswald_strings.h
new file mode 100644 (file)
index 0000000..962cbd0
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _OSWALD_STRINGS_H
+#define _OSWALD_STRINGS_H
+
+u16t oswald_strlen(u8t *string);
+
+#endif
+
index f8897df..bd6aa26 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "oswald_watch_faces.h"
 
-void DrawLcdAnaClock(boolean show_seconds)
+void DrawLcdAnaClock(void)
 {
        unsigned char *bbuf;
        char daystr[5];
@@ -52,7 +52,7 @@ void DrawLcdAnaClock(boolean show_seconds)
        tmp = 48 + (40. * sin(((2. * M_PI) / 60.) * (double)minute));
        y =  tmp;
        DrawLcdLineBresenhamWW(48, 48, x, y, 2);
-       if (show_seconds) {
+       if (OswaldState.idle_show_seconds) {
                // Seconds
                tmp = 48. + (40. * cos(((2. * M_PI) / 60.) * (double)seconds));
                x =  tmp;
@@ -65,7 +65,7 @@ void DrawLcdAnaClock(boolean show_seconds)
        // mw_buf_print(mwbuf, 74, 45, daystr, 0, MW_WHITE, MW_BLACK);
 }
 
-void DrawLcdDigitalClock(boolean show_seconds)
+void DrawLcdDigitalClock(void)
 {
        gint gRow = 3;
        gint gColumn = 4;
@@ -79,7 +79,7 @@ void DrawLcdDigitalClock(boolean show_seconds)
        gRow += WriteLcdCharacter(gRow, gColumn, TIME_CHARACTER_COLON_INDEX);
        gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute / 10));
        gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute % 10));
-       if (show_seconds) {
+       if (OswaldState.idle_show_seconds) {
                gRow += WriteLcdCharacter(gRow, gColumn, TIME_CHARACTER_COLON_INDEX);
                gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.second / 10));
                gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.second % 10));
index 9918a7b..30fd56f 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef _OSWALD_WATCH_FACES_H
 #define _OSWALD_WATCH_FACES_H
 
-void DrawLcdAnaClock(boolean show_seconds);
-void DrawLcdDigitalClock(boolean show_seconds);
+void DrawLcdAnaClock(void);
+void DrawLcdDigitalClock(void);
 
 #endif