]> git.karo-electronics.de Git - oswald.git/blob - ui/oswald.h
8d16b2e3b01b8f9f6f7c6d67264dd73c564f6324
[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         ALARM_SETUP_SCREEN,
57         STOP_WATCH_SCREEN,
58         BLUETOOTH_SCREEN,
59         ACCEL_DISPLAY_SCREEN,
60         INFO_SCREEN,
61         LAST_SCREEN,            // a marker for the last (not valid) screen)
62         MENU_TEST_SCREEN,
63         APPLICATION_SCREEN,
64         DATETIME_SETTING_SCREEN,
65         ALARM_SCREEN,
66         SCREENS_END,
67 } screen_number;
68
69 typedef enum {
70         BUTTON_A = 0,
71         BUTTON_B,
72         BUTTON_C,
73         BUTTON_D,
74         BUTTON_E,
75         BUTTON_F,
76 } watch_button;
77
78 #define EVENT_SCREEN_VISIBLE            (1<<0)          // screen just became visible
79 #define EVENT_SCREEN_DESTROY            (1<<1)          // screen is destroyed
80 #define EVENT_ONE_SEC_TIMER             (1<<2)          // one second timer for reguler clock
81 #define EVENT_HALF_SEC_TIMER            (1<<3)          // half second timer for blinking displays
82 #define EVENT_CS_TIMER                  (1<<4)          // centisecond timer, e.g. for stop watch
83 #define EVENT_USER_BUTTONS              (1<<5)          // button presses
84 #define EVENT_ACCEL_UPDATE              (1<<6)          // accelerometer updates
85 #define EVENT_AMBIENTLIGHT_UPDATE       (1<<7)          // ambient light sensor updates
86 #define EVENT_POWER_CHANGE              (1<<8)          // power source status change
87 #define EVENT_COMMS                     (1<<9)          // communication, like Bluetooth I/O
88 #define EVENT_POWER_STATE               (1<<10)         // power source changed or similar
89
90 typedef enum {
91         EVENT_RET_UNHANDLED = 0,
92         EVENT_RET_HANDLED,
93         EVENT_RET_ERR
94 } event_ret_t;
95
96 typedef struct {
97         uint16_t event_mask;                            // the event the screen wants to receive
98         event_ret_t (*event_func)(uint16_t event, void *data);  // callback for events
99         void *user_data;
100 } watch_screen;
101
102 typedef struct {
103         screen_number   screen_id;
104         watch_screen *screen;           // the current screen
105         boolean pending_idle;
106 } watch_state;
107
108 typedef struct {
109         int8_t  x;
110         int8_t  y;
111         int8_t  z;
112 } accel_data_t;
113
114 #define POWER_SOURCE_BATTERY    0
115 #define POWER_SOURCE_EXTERNAL   1
116
117 #define POWER_CHARGER_DONE      0
118 #define POWER_CHARGER_PRECHARGE 1
119 #define POWER_CHARGER_CHARGING  2
120 #define POWER_CHARGER_UNK       3
121
122 typedef struct {
123         uint8_t source;
124         uint8_t charge_state;
125         uint8_t percent;
126         uint16_t        level;
127 } power_state;
128
129 typedef enum {
130         BLUETOOTH_OFF = 0,
131         BLUETOOTH_ON,
132         BLUETOOTH_CONNECTED,
133         BLUETOOTH_ILL
134 } bluetooth_state;
135
136 #endif