Make idle selectable
authorNils Faerber <nils.faerber@kernelconcepts.de>
Sun, 12 Aug 2012 02:11:30 +0000 (04:11 +0200)
committerNils Faerber <nils.faerber@kernelconcepts.de>
Sun, 12 Aug 2012 02:11:30 +0000 (04:11 +0200)
ui/Makefile.am
ui/oswald-ui.c
ui/oswald.h
ui/oswald_main.c
ui/oswald_main.h
ui/oswald_screens.c
ui/oswald_screens.h
ui/oswald_watch_faces.c
ui/oswald_watch_faces.h

index d71ba35..7ab936f 100644 (file)
@@ -2,7 +2,8 @@ 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_strings.c oswald_screens.c
+oswald_gui_SOURCES = oswald-ui.c LcdDisplay.c Fonts.c oswald_main.c oswald_watch_faces.c oswald_strings.c oswald_screens.c \
+embedvm.c
 oswald_gui_CFLAGS = -g $(GTK_CFLAGS)
 oswald_gui_LDADD = $(GTK_LIBS)
 
index dbff4ef..a89523b 100644 (file)
@@ -254,7 +254,11 @@ gboolean one_second_tmo_handler (gpointer userdata)
 gboolean app_idle_handler (gpointer user_data)
 {
        g_print("i");
-       return TRUE;
+       if (OswaldState.pending_idle) {
+               // call Oswald's idle function
+               return TRUE;
+       };
+       return FALSE;
 }
 
 int main(int argc , char ** argv)
index c49acec..6e641eb 100644 (file)
@@ -67,18 +67,13 @@ typedef enum {
 typedef struct {
        u16t event_mask;                                // the event the screen wants to receive
        void (*event_func)(u16t event, void *data);     // callback for events
-//     void (*button_func)(watch_button button);       // handles button presses
-//     void (*screendraw_func)(void);                  // callback for screen update
-//     void *user_data;
+       void *user_data;
 } watch_screen;
 
 typedef struct {
        screen_number   screen_id;
-       // void (*draw_watchface_func)(boolean show_seconds);
-       boolean idle_show_seconds;
        watch_screen *screen;           // the current screen
-       // void (*user_button_func)(watch_button button);
-       // void (*user_screendraw_func)(void);
+       boolean pending_idle;
 } watch_state;
 
 #endif
index 90be0d0..82b8567 100644 (file)
@@ -1,10 +1,9 @@
 #include "oswald.h"
 #include "oswald_watch_faces.h"
 #include "oswald_screens.h"
-#if 0
-#include "Fonts.h"
-#include "LcdDisplay.h"
-#endif
+
+#include "embedvm.h"
+
 #include "oswald_main.h"
 
 /*
@@ -99,7 +98,7 @@ void oswald_handle_button_press(watch_button button)
 
 void oswald_init(void)
 {
-       OswaldScreens[IDLE_SCREEN].event_mask = EVENT_ONE_SEC_TIMER;
+       OswaldScreens[IDLE_SCREEN].event_mask = EVENT_USER_BUTTONS | EVENT_ONE_SEC_TIMER;
        OswaldScreens[IDLE_SCREEN].event_func = idle_handle_events;
 
        OswaldScreens[ACCEL_DISPLAY_SCREEN].event_mask = EVENT_USER_BUTTONS;
@@ -114,7 +113,6 @@ void oswald_init(void)
 
        OswaldState.screen_id = IDLE_SCREEN;
        OswaldState.screen = &OswaldScreens[OswaldState.screen_id];
-       OswaldState.idle_show_seconds = FALSE;
 
        if (OswaldState.screen->event_func != NULL)
                OswaldState.screen->event_func(EVENT_SCREEN_VISIBLE, NULL);
index a11252d..679c03f 100644 (file)
@@ -9,9 +9,14 @@ extern watch_screen OswaldScreens[];
 
 /* gets triggered by OS timer function */
 void oswald_one_second_tick();
+
+/* sets internal 'RTC' time */
 void oswald_set_time(u8t hour, u8t minute, u8t second);
 
 void oswald_handle_button_press(watch_button button);
+void oswald_handle_accel_event(u8t x, u8t y, u8t z);
+void oswald_handle_ambientlight_event(u8t light_level);
+void oswald_handle_idle_event(void);
 void oswald_init(void);
 
 #endif
index b6158d8..7790b70 100644 (file)
@@ -5,24 +5,58 @@
 
 #include "oswald_screens.h"
 
+typedef struct {
+       void (*screendraw_func)(boolean shoq_seconds);
+       boolean show_seconds;
+       boolean analogue;
+} idle_data_t;
+static idle_data_t idle_screen = {
+       DrawLcdDigitalClock,
+       FALSE,
+       FALSE,
+};
 void idle_handle_user_buttons(watch_button button)
 {
+       switch (button) {
+               case BUTTON_D:
+                       if (idle_screen.show_seconds)
+                               idle_screen.show_seconds = FALSE;
+                       else
+                               idle_screen.show_seconds = TRUE;
+                       break;
+               case BUTTON_E:
+                       if (idle_screen.analogue == TRUE) {
+                               idle_screen.analogue = FALSE;
+                               idle_screen.screendraw_func = DrawLcdDigitalClock;
+                       } else {
+                               idle_screen.analogue = TRUE;
+                               idle_screen.screendraw_func = DrawLcdAnaClock;
+                       };
+                       break;
+               default:
+                       break;
+       };
+       idle_screen.screendraw_func(idle_screen.show_seconds);
 }
+
 void idle_handle_events(u16t event, void *data)
 {
        switch (event) {
                case EVENT_ONE_SEC_TIMER:
                case EVENT_SCREEN_VISIBLE:
-                       DrawLcdDigitalClock();
+                       idle_screen.screendraw_func(idle_screen.show_seconds);
                        break;
                case EVENT_USER_BUTTONS:
                        dbg_out("button event %d\n", *(int *)data);
+                       idle_handle_user_buttons(*(watch_button *)data);
                        break;
                default:
                        break;
        };
 }
 
+
 void draw_accel_screen(void)
 {
        lcd_clear_display();
@@ -34,6 +68,7 @@ void draw_accel_screen(void)
        WriteLcdString(2, 34, "Y:");
        WriteLcdString(20, 34, "123");
 }
+
 void accel_handle_events(u16t event, void *data)
 {
        switch (event) {
@@ -48,6 +83,7 @@ void accel_handle_events(u16t event, void *data)
        };
 }
 
+
 void draw_datetime_setup_screen(void)
 {
        lcd_clear_display();
@@ -57,6 +93,7 @@ void draw_datetime_setup_screen(void)
        WriteLcdString(2, 34, "22:39");
        WriteLcdString(2, 50, "07.08.2012");
 }
+
 void datetime_setup_events(u16t event, void *data)
 {
        switch (event) {
@@ -71,7 +108,11 @@ void datetime_setup_events(u16t event, void *data)
        };
 }
 
-static u8t test_menu_pos = 0;
+
+typedef struct {
+       u8t menu_pos;
+} test_menu_t;
+static test_menu_t test_menu = { 0 };
 
 void draw_menu_test_screen(void)
 {
@@ -85,19 +126,19 @@ void draw_menu_test_screen(void)
        WriteLcdString(2, 47, "Item 4");
        WriteLcdString(2, 56, "Item 5");
 
-       WriteLcdString(50, 20+(9*test_menu_pos), "*");
+       WriteLcdString(50, 20+(9*test_menu.menu_pos), "*");
 }
 
 static void handle_menu_user_buttons(watch_button button)
 {
        switch (button) {
                case BUTTON_A:
-                       test_menu_pos--;
-                       test_menu_pos%=5;
+                       test_menu.menu_pos--;
+                       test_menu.menu_pos%=5;
                        break;
                case BUTTON_B:
-                       test_menu_pos++;
-                       test_menu_pos%=5;
+                       test_menu.menu_pos++;
+                       test_menu.menu_pos%=5;
                        break;
                default:
                        break;
@@ -113,7 +154,7 @@ void test_menu_handle_events(u16t event, void *data)
                        handle_menu_user_buttons(*(watch_button *)data);
                        break;
                case EVENT_SCREEN_VISIBLE:
-                       test_menu_pos = 0;
+                       test_menu.menu_pos = 0;
                        draw_menu_test_screen();
                        break;
                default:
index 54ea831..5df7c59 100644 (file)
@@ -1,16 +1,13 @@
 #ifndef _OSWALD_SCREENS_H
 #define _OSWALD_SCREENS_H
 
-void idle_handle_user_buttons(watch_button button);
+
 void idle_handle_events(u16t event, void *data);
 
-void draw_accel_screen(void);
 void accel_handle_events(u16t event, void *data);
 
-void draw_datetime_setup_screen(void);
 void datetime_setup_events(u16t event, void *data);
 
-void draw_menu_test_screen(void);
 void test_menu_handle_events(u16t event, void *data);
 
 #endif
index bd6aa26..f8897df 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "oswald_watch_faces.h"
 
-void DrawLcdAnaClock(void)
+void DrawLcdAnaClock(boolean show_seconds)
 {
        unsigned char *bbuf;
        char daystr[5];
@@ -52,7 +52,7 @@ void DrawLcdAnaClock(void)
        tmp = 48 + (40. * sin(((2. * M_PI) / 60.) * (double)minute));
        y =  tmp;
        DrawLcdLineBresenhamWW(48, 48, x, y, 2);
-       if (OswaldState.idle_show_seconds) {
+       if (show_seconds) {
                // Seconds
                tmp = 48. + (40. * cos(((2. * M_PI) / 60.) * (double)seconds));
                x =  tmp;
@@ -65,7 +65,7 @@ void DrawLcdAnaClock(void)
        // mw_buf_print(mwbuf, 74, 45, daystr, 0, MW_WHITE, MW_BLACK);
 }
 
-void DrawLcdDigitalClock(void)
+void DrawLcdDigitalClock(boolean show_seconds)
 {
        gint gRow = 3;
        gint gColumn = 4;
@@ -79,7 +79,7 @@ void DrawLcdDigitalClock(void)
        gRow += WriteLcdCharacter(gRow, gColumn, TIME_CHARACTER_COLON_INDEX);
        gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute / 10));
        gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute % 10));
-       if (OswaldState.idle_show_seconds) {
+       if (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 30fd56f..9918a7b 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef _OSWALD_WATCH_FACES_H
 #define _OSWALD_WATCH_FACES_H
 
-void DrawLcdAnaClock(void);
-void DrawLcdDigitalClock(void);
+void DrawLcdAnaClock(boolean show_seconds);
+void DrawLcdDigitalClock(boolean show_seconds);
 
 #endif