Repository navigation
Expand file tree
/
Copy pathdab_timer.h
More file actions
428 lines (402 loc) · 11.1 KB
/
Copy pathdab_timer.h
File metadata and controls
428 lines (402 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#pragma once
#include <datetime/datetime.h>
#include <dolphin/dolphin.h>
#include <furi.h>
#include <furi_hal.h>
#include <gui/elements.h>
#include <gui/gui.h>
#include <input/input.h>
#include <locale/locale.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#if __has_include(<cfw/cfw.h>)
#include <cfw/cfw.h>
#endif
#define TIME_LEN 12
#define DATE_LEN 14
#define MERIDIAN_LEN 3
typedef struct {
uint8_t x;
uint8_t y;
} DabTimerClockPoint;
typedef enum {
FaceStylePwn,
FaceStyleOriginal,
FaceStyleOriginalSmall,
FaceStyleCircle,
FaceStyleBinary,
FaceStylePwnInverted,
FaceStyleOriginalInverted,
FaceStyleOriginalSmallInverted,
FaceStyleCircleInverted,
FaceStyleBinaryInverted,
FaceStyleCount,
} FaceStyle;
typedef enum {
SoundAlertOff,
SoundAlertByMin,
SoundAlertMario,
SoundAlertGoGoPoRa,
SoundAlertCont,
SoundAlertCount,
} SoundAlert;
typedef enum {
DabTimerReady,
DabTimerRunning,
DabTimerPaused,
} DabTimerRunState;
typedef enum {
DabTimerCodeIdle,
DabTimerCodeFirstUp,
DabTimerCodeSecondUp,
DabTimerCodeFirstDown,
DabTimerCodeSecondDown,
DabTimerCodeFirstLeft,
DabTimerCodeFirstRight,
DabTimerCodeSecondLeft,
DabTimerCodeSecondRight,
DabTimerCodeExitBack,
DabTimerCodeBackPending,
} DabTimerCodeState;
typedef enum {
DabTimerFaceAngry,
DabTimerFaceAwake,
DabTimerFaceBored,
DabTimerFaceBroken,
DabTimerFaceCool,
DabTimerFaceDebug,
DabTimerFaceDemotivated,
DabTimerFaceExcited,
DabTimerFaceFriend,
DabTimerFaceGrateful,
DabTimerFaceHappy,
DabTimerFaceIntense,
DabTimerFaceLonely,
DabTimerFaceLookLeft,
DabTimerFaceLookLeftHappy,
DabTimerFaceLookRight,
DabTimerFaceLookRightHappy,
DabTimerFaceMotivated,
DabTimerFaceSad,
DabTimerFaceSleep2,
DabTimerFaceSleep,
DabTimerFaceSmart,
DabTimerFaceUpload1,
DabTimerFaceUpload2,
DabTimerFaceUpload,
DabTimerFaceCount,
} DabTimerEmotiveFace;
typedef enum {
DabTimerAlarmWaiting,
DabTimerAlarmFirstPlayed,
DabTimerAlarmSecondPlayed,
DabTimerAlarmFinished,
} DabTimerAlarmPhase;
typedef enum {
DabTimerActionNone = 0,
DabTimerActionStartStop = 1 << 0,
DabTimerActionMinute = 1 << 1,
DabTimerActionMarioFirst = 1 << 2,
DabTimerActionMarioSecond = 1 << 3,
DabTimerActionMarioThird = 1 << 4,
DabTimerActionRangersFirst = 1 << 5,
DabTimerActionRangersSecond = 1 << 6,
DabTimerActionRangersThird = 1 << 7,
DabTimerActionSilent = 1 << 8,
DabTimerActionRainbow = 1 << 9,
DabTimerActionSuccess = 1 << 10,
DabTimerActionXp = 1 << 11,
DabTimerActionSaveGameMode = 1 << 12,
DabTimerActionContinuous = 1 << 13,
} DabTimerAction;
typedef enum {
DabTimerInputIgnored,
DabTimerInputChanged,
DabTimerInputExit,
} DabTimerInputResult;
typedef enum {
DabTimerFlagInput = 1 << 0,
DabTimerFlagTick = 1 << 1,
DabTimerFlagRedraw = 1 << 2,
DabTimerFlagExit = 1 << 3,
} DabTimerThreadFlag;
typedef enum {
DabTimerFeedbackFlagWake = 1 << 0,
} DabTimerFeedbackFlag;
typedef struct {
DateTime datetime;
LocaleDateFormat date_format;
LocaleTimeFormat time_format;
DabTimerRunState run_state;
FaceStyle face_style;
SoundAlert sound_alert;
DabTimerEmotiveFace emotive_face;
uint32_t elapsed_seconds;
uint32_t alert_time;
bool easter_egg;
bool game_mode;
char time_string[TIME_LEN];
char date_string[DATE_LEN];
char circle_date_string[DATE_LEN];
char meridian_string[MERIDIAN_LEN];
char timer_string[20];
char alert_string[11];
} DabTimerModel;
/* Owned by the app thread; only the separately published model is shared with GUI. */
typedef struct {
DabTimerModel model;
DabTimerCodeState code_state;
DabTimerAlarmPhase alarm_phase;
uint32_t alarm_generation;
uint32_t last_tick;
uint32_t tick_frequency;
uint32_t fractional_ticks;
uint32_t last_minute;
uint32_t last_continuous_minute;
uint32_t last_xp_tick;
bool xp_tick_valid;
} DabTimerState;
typedef struct {
FuriMutex* mutex;
FuriMessageQueue* event_queue;
FuriThreadId thread_id;
FuriThread* feedback_thread;
NotificationApp* notification;
DabTimerAction pending_feedback;
SoundAlert feedback_sound;
uint32_t feedback_generation;
bool feedback_stopping;
DabTimerModel model;
} DabTimerApp;
const NotificationSequence dab_timer_alert_silent = {
&message_vibro_on,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_vibro_off,
&message_display_backlight_off,
&message_delay_50,
&message_display_backlight_on,
NULL,
};
const NotificationSequence dab_timer_alert_pr1 = {
&message_vibro_on,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_vibro_off,
&message_display_backlight_off,
&message_delay_50,
&message_display_backlight_on,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
NULL,
};
const NotificationSequence dab_timer_alert_pr2 = {
&message_vibro_on,
&message_note_fs5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_off,
&message_vibro_off,
&message_delay_50,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_on,
&message_delay_50,
&message_note_a5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
NULL,
};
const NotificationSequence dab_timer_alert_pr3 = {
&message_display_backlight_off,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_delay_50,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_delay_100,
NULL,
};
const NotificationSequence dab_timer_alert_mario1 = {
&message_vibro_on,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_vibro_off,
&message_display_backlight_off,
&message_delay_100,
&message_display_backlight_on,
&message_delay_100,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
NULL,
};
const NotificationSequence dab_timer_alert_mario2 = {
&message_vibro_on,
&message_display_backlight_off,
&message_delay_100,
&message_display_backlight_on,
&message_delay_100,
&message_note_c5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_off,
&message_vibro_off,
&message_delay_50,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_on,
NULL,
};
const NotificationSequence dab_timer_alert_mario3 = {
&message_display_backlight_off,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_delay_50,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_delay_100,
&message_note_g4,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_sound_off,
NULL,
};
const NotificationSequence dab_timer_alert_perMin = {
&message_note_g5,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_delay_10,
&message_note_g4,
&message_delay_50,
&message_delay_10,
&message_delay_10,
&message_sound_off,
NULL,
};
const NotificationSequence dab_timer_alert_startStop = {
&message_red_255,
&message_green_255,
&message_blue_255,
&message_note_d6,
&message_delay_100,
&message_delay_10,
&message_delay_10,
&message_sound_off,
NULL,
};
const NotificationMessage message_red_127 = {
.type = NotificationMessageTypeLedRed,
.data.led.value = 0x7F,
};
const NotificationMessage message_green_127 = {
.type = NotificationMessageTypeLedGreen,
.data.led.value = 0x7F,
};
const NotificationMessage message_blue_127 = {
.type = NotificationMessageTypeLedBlue,
.data.led.value = 0x7F,
};
const NotificationSequence sequence_rainbow = {
&message_red_255, &message_green_0, &message_blue_0,
&message_delay_250, &message_red_255, &message_green_127,
&message_blue_0, &message_delay_250, &message_red_255,
&message_green_255, &message_blue_0, &message_delay_250,
&message_red_127, &message_green_255, &message_blue_0,
&message_delay_250, &message_red_0, &message_green_255,
&message_blue_0, &message_delay_250, &message_red_0,
&message_green_255, &message_blue_127, &message_delay_250,
&message_red_0, &message_green_255, &message_blue_255,
&message_delay_250, &message_red_0, &message_green_127,
&message_blue_255, &message_delay_250, &message_red_0,
&message_green_0, &message_blue_255, &message_delay_250,
&message_red_127, &message_green_0, &message_blue_255,
&message_delay_250, &message_red_255, &message_green_0,
&message_blue_255, &message_delay_250, &message_red_255,
&message_green_0, &message_blue_127, &message_delay_250,
&message_red_127, &message_green_127, &message_blue_127,
&message_delay_250, &message_red_255, &message_green_255,
&message_blue_255, &message_delay_250, NULL,
};
/* Keep the original audio/vibration timing without RGB or backlight commands. */
const NotificationSequence dab_timer_alert_continuous = {
&message_vibro_on, &message_note_e5, &message_delay_100, &message_delay_100,
&message_delay_50, &message_sound_off, &message_note_e5, &message_delay_100,
&message_delay_100, &message_delay_50, &message_sound_off, &message_vibro_off,
&message_delay_100, &message_delay_100, &message_note_e5, &message_delay_100,
&message_delay_100, &message_delay_50, &message_sound_off, NULL,
};
const NotificationSequence dab_timer_alert_silent_no_lights = {
&message_vibro_on,
&message_vibro_off,
&message_delay_50,
NULL,
};
const NotificationSequence dab_timer_alert_start_stop_no_lights = {
&message_note_d6,
&message_delay_100,
&message_delay_10,
&message_delay_10,
&message_sound_off,
NULL,
};
const NotificationSequence dab_timer_alert_success_no_lights = {
&message_vibro_on,
&message_note_c5,
&message_delay_50,
&message_vibro_off,
&message_note_e5,
&message_delay_50,
&message_note_g5,
&message_delay_50,
&message_note_c6,
&message_delay_50,
&message_sound_off,
NULL,
};