Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <stddef.h>
5
6namespace ersa {
7namespace events {
8
54
56enum class ButtonId : uint8_t {
57 Unknown = 0,
58 Button1, // Top button (S2 on Ampere Works T1E)
59 Button2 // Bottom button (S1 on Ampere Works T1E)
60};
61
63enum class TimeSource : uint8_t {
64 Unknown = 0,
65 Network,
68 Manual
69};
70
76
80 uint32_t epoch{0};
81 uint16_t year{2026};
82 uint8_t month{1};
83 uint8_t day{1};
84 uint8_t hour{0};
85 uint8_t minute{0};
86 uint8_t second{0};
88};
89
92 uint16_t millivolts{0};
93 uint8_t percentage{100};
94 bool connected{false};
95 bool charging{false};
96};
97
100 bool connected{false};
101};
102
105 char caller[32];
106 char number[20];
107 uint8_t state; // 0: Incoming, 1: Active, 2: Ended
108};
109
112 char title[32];
113 char artist[32];
115};
116
119 char title[32];
120 char message[64];
121 char app[20];
122 uint32_t uid;
124};
125
134struct Event {
138 uint32_t timestampMs{0};
139
140 union {
149 };
150
155
157 explicit Event(EventType t, uint32_t ts = 0) : type(t), timestampMs(ts) {
159 }
160
162 static Event createButton(EventType t, ButtonId btn, uint32_t ts = 0) {
163 Event e(t, ts);
164 e.button.button = btn;
165 return e;
166 }
167
169 static Event createMinuteTick(const TimePayload& tp, uint32_t ts = 0) {
171 e.time = tp;
172 return e;
173 }
174
176 static Event createTimeSync(uint32_t epoch, TimeSource source, uint32_t ts = 0) {
178 e.time.epoch = epoch;
179 e.time.source = source;
180 return e;
181 }
182
184 static Event createBatteryChanged(uint16_t mv, uint8_t pct, bool conn, bool chg, uint32_t ts = 0) {
186 e.battery.millivolts = mv;
187 e.battery.percentage = pct;
188 e.battery.connected = conn;
189 e.battery.charging = chg;
190 return e;
191 }
192
198 static Event createCall(EventType t, const char* caller, const char* number, uint8_t state, uint32_t ts = 0) {
199 Event e(t, ts);
200 e.call.state = state;
201 e.call.caller[0] = '\0';
202 e.call.number[0] = '\0';
203 if (caller) {
204 for (size_t i = 0; i < sizeof(e.call.caller) - 1 && caller[i]; ++i) {
205 e.call.caller[i] = caller[i];
206 e.call.caller[i + 1] = '\0';
207 }
208 }
209 if (number) {
210 for (size_t i = 0; i < sizeof(e.call.number) - 1 && number[i]; ++i) {
211 e.call.number[i] = number[i];
212 e.call.number[i + 1] = '\0';
213 }
214 }
215 return e;
216 }
217
219 static Event createMedia(const char* title, const char* artist, bool playing, uint32_t ts = 0) {
221 e.media.playing = playing;
222 e.media.title[0] = '\0';
223 e.media.artist[0] = '\0';
224 if (title) {
225 for (size_t i = 0; i < sizeof(e.media.title) - 1 && title[i]; ++i) {
226 e.media.title[i] = title[i];
227 e.media.title[i + 1] = '\0';
228 }
229 }
230 if (artist) {
231 for (size_t i = 0; i < sizeof(e.media.artist) - 1 && artist[i]; ++i) {
232 e.media.artist[i] = artist[i];
233 e.media.artist[i + 1] = '\0';
234 }
235 }
236 return e;
237 }
238
243 static Event createNotification(const char* title, const char* message, const char* app = "", uint32_t uid = 0, uint32_t ts = 0, bool canDismissRemotely = false) {
245 e.notification.uid = uid;
246 e.notification.canDismissRemotely = canDismissRemotely;
247 e.notification.title[0] = '\0';
248 e.notification.message[0] = '\0';
249 e.notification.app[0] = '\0';
250 if (title) {
251 for (size_t i = 0; i < sizeof(e.notification.title) - 1 && title[i]; ++i) {
252 e.notification.title[i] = title[i];
253 e.notification.title[i + 1] = '\0';
254 }
255 }
256 if (message) {
257 for (size_t i = 0; i < sizeof(e.notification.message) - 1 && message[i]; ++i) {
258 e.notification.message[i] = message[i];
259 e.notification.message[i + 1] = '\0';
260 }
261 }
262 if (app) {
263 for (size_t i = 0; i < sizeof(e.notification.app) - 1 && app[i]; ++i) {
264 e.notification.app[i] = app[i];
265 e.notification.app[i + 1] = '\0';
266 }
267 }
268 return e;
269 }
270};
271
272} // namespace events
273} // namespace ersa
EventType
Definition event.h:14
ButtonId
Definition event.h:56
TimeSource
Definition event.h:63
Definition application.h:10
Definition event.h:91
uint16_t millivolts
Definition event.h:92
bool charging
Definition event.h:95
bool connected
Definition event.h:94
uint8_t percentage
Definition event.h:93
Definition event.h:72
ButtonId button
Definition event.h:74
Definition event.h:104
char number[20]
Definition event.h:106
char caller[32]
Definition event.h:105
uint8_t state
Definition event.h:107
Definition event.h:134
static Event createNotification(const char *title, const char *message, const char *app="", uint32_t uid=0, uint32_t ts=0, bool canDismissRemotely=false)
Definition event.h:243
MediaPayload media
Definition event.h:146
static Event createCall(EventType t, const char *caller, const char *number, uint8_t state, uint32_t ts=0)
Definition event.h:198
Event(EventType t, uint32_t ts=0)
Definition event.h:157
CallPayload call
Definition event.h:145
static Event createMinuteTick(const TimePayload &tp, uint32_t ts=0)
Definition event.h:169
EventType type
Definition event.h:136
static Event createMedia(const char *title, const char *artist, bool playing, uint32_t ts=0)
Definition event.h:219
NotificationPayload notification
Definition event.h:147
ButtonPayload button
Definition event.h:141
static Event createBatteryChanged(uint16_t mv, uint8_t pct, bool conn, bool chg, uint32_t ts=0)
Definition event.h:184
static Event createTimeSync(uint32_t epoch, TimeSource source, uint32_t ts=0)
Definition event.h:176
Event()
Definition event.h:152
void * customPayload
Definition event.h:148
uint32_t timestampMs
Definition event.h:138
static Event createButton(EventType t, ButtonId btn, uint32_t ts=0)
Definition event.h:162
TimePayload time
Definition event.h:142
BatteryPayload battery
Definition event.h:143
NetworkPayload network
Definition event.h:144
Definition event.h:111
bool playing
Definition event.h:114
char title[32]
Definition event.h:112
char artist[32]
Definition event.h:113
Definition event.h:99
bool connected
Definition event.h:100
Definition event.h:118
char title[32]
Definition event.h:119
uint32_t uid
Definition event.h:122
char message[64]
Definition event.h:120
char app[20]
Definition event.h:121
bool canDismissRemotely
Definition event.h:123
Definition event.h:78
uint8_t day
Definition event.h:83
uint8_t hour
Definition event.h:84
uint16_t year
Definition event.h:81
uint8_t second
Definition event.h:86
TimeSource source
Definition event.h:87
uint8_t minute
Definition event.h:85
uint32_t epoch
Definition event.h:80
uint8_t month
Definition event.h:82