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