]> git.karo-electronics.de Git - oswald.git/blob - ui/oswald.h
Bluetooth handling, screen reworks for icons
[oswald.git] / ui / oswald.h
1 #ifndef _OSWALD_H
2 #define _OSWALD_H
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdint.h>
6
7 //#define DEBUG 1
8 #ifdef DEBUG
9 #define dbg_out( args... ) fprintf(stderr, args)
10 #else
11 #define dbg_out( args... ) do {} while (0)
12 #endif
13
14 typedef signed char s8t;
15 typedef unsigned char u8t;
16 typedef signed short s16t;
17 typedef unsigned short u16t;
18 typedef u8t boolean;
19 #ifdef TRUE
20 #undef TRUE
21 #endif
22 #define TRUE 1
23 #ifdef FALSE
24 #undef FALSE
25 #endif
26 #define FALSE 0
27 #ifndef NULL
28 #define NULL 0
29 #endif
30
31 typedef struct {
32         u8t     hour;
33         u8t     minute;
34         u8t     second;
35         u8t     day;
36         u8t     wday; // day in week, 0=sunday, 1=monday,...
37         u8t     month;
38         u16t    year;
39         boolean clk24hr;
40         boolean day_first;
41 } clock_state;
42
43 #define WDAY_SUNDAY     (1 << 0)
44 #define WDAY_MONDAY     (1 << 1)
45 #define WDAY_TUESDAY    (1 << 2)
46 #define WDAY_WEDNESDAY  (1 << 3)
47 #define WDAY_THURSDAY   (1 << 4)
48 #define WDAY_FRIDAY     (1 << 5)
49 #define WDAY_SATURDAY   (1 << 6)
50 typedef struct {
51         u8t     hour;
52         u8t     minute;
53         u8t     wday; // bitfield 0 to 6, 1=sunday, 2=monday, 4=tuesday...
54 } alarm_clk;
55
56 typedef enum {
57         IDLE_SCREEN = 0,
58         ALARM_SETUP_SCREEN,
59         STOP_WATCH_SCREEN,
60         BLUETOOTH_SCREEN,
61         ACCEL_DISPLAY_SCREEN,
62         MENU_TEST_SCREEN,
63 //      APPLICATION_SCREEN,
64         LAST_SCREEN,            // a marker for the last (not valid) screen)
65         DATETIME_SETTING_SCREEN,
66         ALARM_SCREEN,
67         SCREENS_END,
68 } screen_number;
69
70 typedef enum {
71         BUTTON_A = 0,
72         BUTTON_B,
73         BUTTON_C,
74         BUTTON_D,
75         BUTTON_E,
76         BUTTON_F,
77 } watch_button;
78
79 #define EVENT_SCREEN_VISIBLE            (1<<0)          // screen just became visible
80 #define EVENT_SCREEN_DESTROY            (1<<1)          // screen is destroyed
81 #define EVENT_ONE_SEC_TIMER             (1<<2)          // one second timer for reguler clock
82 #define EVENT_HALF_SEC_TIMER            (1<<3)          // half second timer for blinking displays
83 #define EVENT_CS_TIMER                  (1<<4)          // centisecond timer, e.g. for stop watch
84 #define EVENT_USER_BUTTONS              (1<<5)          // button presses
85 #define EVENT_ACCEL_UPDATE              (1<<6)          // accelerometer updates
86 #define EVENT_AMBIENTLIGHT_UPDATE       (1<<7)          // ambient light sensor updates
87 #define EVENT_POWER_CHANGE              (1<<8)          // power source status change
88 #define EVENT_COMMS                     (1<<9)          // communication, like Bluetooth I/O
89 #define EVENT_POWER_STATE               (1<<10)         // power source changed or similar
90
91
92 typedef struct {
93         u16t event_mask;                                // the event the screen wants to receive
94         void (*event_func)(u16t event, void *data);     // callback for events
95         void *user_data;
96 } watch_screen;
97
98 typedef struct {
99         screen_number   screen_id;
100         watch_screen *screen;           // the current screen
101         boolean pending_idle;
102 } watch_state;
103
104 typedef struct {
105         u8t     x;
106         u8t     y;
107         u8t     z;
108 } accel_data_t;
109
110 #define POWER_SOURCE_BATTERY    0
111 #define POWER_SOURCE_EXTERNAL   1
112
113 #define POWER_CHARGER_DONE      0
114 #define POWER_CHARGER_PRECHARGE 1
115 #define POWER_CHARGER_CHARGING  2
116 #define POWER_CHARGER_UNK       3
117
118 typedef struct {
119         u8t     source;
120         u8t     charge_state;
121         u8t     percent;
122         u16t    level;
123 } power_state;
124
125 typedef enum {
126         BLUETOOTH_OFF = 0,
127         BLUETOOTH_ON,
128         BLUETOOTH_CONNECTED,
129         BLUETOOTH_ILL
130 } bluetooth_state;
131
132 #endif