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