Skip to content

Commit 2f8598c

Browse files
committed
add alert type settings
1 parent d9bbab9 commit 2f8598c

File tree

19 files changed

+597
-232
lines changed

19 files changed

+597
-232
lines changed

hal/esp32/app_hal.cpp

Lines changed: 96 additions & 65 deletions
Large diffs are not rendered by default.

hal/esp32/app_hal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void hal_loop(void);
6666

6767
void vibratePin(bool state);
6868

69+
6970
#ifdef __cplusplus
7071
} /* extern "C" */
7172
#endif

hal/esp32/displays/pins.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#define BL -1 // unused (connected on IO extender)
6161
#define VIBRATION_PIN 0 // dummy (connected on IO extender)
6262

63-
#define BUZZER 3
63+
#define BUZZER_PIN 3
6464

6565
#define MAX_FILE_OPEN 10
6666

@@ -91,7 +91,7 @@
9191

9292
#define BL 3
9393

94-
#define BUZZER -1
94+
#define BUZZER_PIN -1
9595

9696
#define MAX_FILE_OPEN 10
9797

@@ -122,7 +122,7 @@
122122

123123
#define BL 2
124124

125-
#define BUZZER -1
125+
#define BUZZER_PIN -1
126126

127127
#define MAX_FILE_OPEN 50
128128

@@ -153,7 +153,7 @@
153153

154154
#define BL 15
155155

156-
#define BUZZER -1 //33
156+
#define BUZZER_PIN -1 //33
157157

158158
#define MAX_FILE_OPEN 20
159159

@@ -162,7 +162,7 @@
162162
#define WIDTH 240
163163
#define HEIGHT 240
164164

165-
#define BUZZER 3
165+
#define BUZZER_PIN 3
166166

167167
#define MAX_FILE_OPEN 10
168168

@@ -193,7 +193,7 @@
193193

194194
#define BL 2
195195

196-
#define BUZZER -1
196+
#define BUZZER_PIN -1
197197

198198
#define MAX_FILE_OPEN 10
199199

hal/esp32/feedback.cpp

Lines changed: 107 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Vibration pattern[] = {
121121

122122
void toneTask(void *param)
123123
{
124-
#if defined(BUZZER) && (BUZZER != -1)
124+
#if defined(BUZZER_PIN) && (BUZZER_PIN != -1)
125125

126126
NoteSequence sequence;
127127

@@ -131,7 +131,7 @@ void toneTask(void *param)
131131
{
132132
playing = true;
133133

134-
ledcAttach(BUZZER, 500, 8);
134+
ledcAttach(BUZZER_PIN, 500, 8);
135135

136136
if (sequence.repeat == 0)
137137
{
@@ -153,66 +153,24 @@ void toneTask(void *param)
153153

154154
if (pitch > 0)
155155
{
156-
ledcWriteTone(BUZZER, pitch);
156+
ledcWriteTone(BUZZER_PIN, pitch);
157157
}
158158
else
159159
{
160-
ledcWriteTone(BUZZER, 0); // Rest
160+
ledcWriteTone(BUZZER_PIN, 0); // Rest
161161
}
162162
vTaskDelay(pdMS_TO_TICKS(duration));
163163
}
164164
}
165165

166-
ledcDetach(BUZZER);
166+
ledcDetach(BUZZER_PIN);
167167

168168
playing = false;
169169
}
170170
}
171171
#endif
172172
}
173173

174-
void startToneSystem()
175-
{
176-
#if defined(BUZZER) && (BUZZER != -1)
177-
178-
if (!noteQueue)
179-
{
180-
noteQueue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(NoteSequence));
181-
}
182-
if (!toneTaskHandle)
183-
{
184-
xTaskCreatePinnedToCore(toneTask, "toneTask", 2048, nullptr, 1, &toneTaskHandle, 0);
185-
}
186-
#endif
187-
}
188-
189-
void feedbackTone(Note *notes, int count, ToneType type, int repeat)
190-
{
191-
#if defined(BUZZER) && (BUZZER != -1)
192-
if (!noteQueue)
193-
startToneSystem();
194-
195-
if (count > MAX_NOTES_PER_SEQUENCE)
196-
count = MAX_NOTES_PER_SEQUENCE;
197-
198-
if (playing && currentToneType >= type)
199-
{
200-
// If the current tone is of the same or higher priority, reset the queue
201-
forceInterrupt = true;
202-
xQueueReset(noteQueue);
203-
}
204-
205-
NoteSequence sequence;
206-
sequence.count = count;
207-
sequence.repeat = repeat;
208-
memcpy(sequence.notes, notes, count * sizeof(Note));
209-
210-
xQueueSend(noteQueue, &sequence, 0);
211-
currentToneType = type;
212-
213-
#endif
214-
}
215-
216174
void vibrationTask(void *param)
217175
{
218176
#if defined(VIBRATION_PIN) && (VIBRATION_PIN != -1)
@@ -248,6 +206,21 @@ void vibrationTask(void *param)
248206
#endif
249207
}
250208

209+
void startToneSystem()
210+
{
211+
#if defined(BUZZER_PIN) && (BUZZER_PIN != -1)
212+
213+
if (!noteQueue)
214+
{
215+
noteQueue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(NoteSequence));
216+
}
217+
if (!toneTaskHandle)
218+
{
219+
xTaskCreatePinnedToCore(toneTask, "toneTask", 2048, nullptr, 1, &toneTaskHandle, 0);
220+
}
221+
#endif
222+
}
223+
251224
void startVibrationSystem()
252225
{
253226
#if defined(VIBRATION_PIN) && (VIBRATION_PIN != -1)
@@ -262,25 +235,99 @@ void startVibrationSystem()
262235
#endif
263236
}
264237

238+
void feedbackTone(Note *notes, int count, ToneType type, int repeat)
239+
{
240+
#if defined(BUZZER_PIN) && (BUZZER_PIN != -1)
241+
if (check_alert_state(ALERT_SOUND))
242+
{
243+
if (!noteQueue)
244+
startToneSystem();
245+
246+
if (count > MAX_NOTES_PER_SEQUENCE)
247+
count = MAX_NOTES_PER_SEQUENCE;
248+
249+
if (playing && currentToneType >= type)
250+
{
251+
// If the current tone is of the same or higher priority, reset the queue
252+
forceInterrupt = true;
253+
xQueueReset(noteQueue);
254+
}
255+
256+
NoteSequence sequence;
257+
sequence.count = count;
258+
sequence.repeat = repeat;
259+
memcpy(sequence.notes, notes, count * sizeof(Note));
260+
261+
xQueueSend(noteQueue, &sequence, 0);
262+
currentToneType = type;
263+
}
264+
#endif
265+
}
266+
265267
void feedbackVibrate(Vibration *steps, int count, bool force)
266268
{
267269
#if defined(VIBRATION_PIN) && (VIBRATION_PIN != -1)
268-
if (!vibQueue)
269-
startVibrationSystem();
270+
if (check_alert_state(ALERT_VIBRATE))
271+
{
272+
if (!vibQueue)
273+
startVibrationSystem();
270274

271-
if (count > MAX_VIB_PATTERN_LENGTH)
272-
count = MAX_VIB_PATTERN_LENGTH;
275+
if (count > MAX_VIB_PATTERN_LENGTH)
276+
count = MAX_VIB_PATTERN_LENGTH;
273277

274-
if (force && vibrating)
275-
{
276-
xQueueReset(vibQueue);
278+
if (force && vibrating)
279+
{
280+
xQueueReset(vibQueue);
281+
}
282+
283+
VibPattern pattern;
284+
pattern.count = count;
285+
memcpy(pattern.steps, steps, count * sizeof(Vibration));
286+
287+
xQueueSend(vibQueue, &pattern, 0);
277288
}
289+
#endif
290+
}
278291

279-
VibPattern pattern;
280-
pattern.count = count;
281-
memcpy(pattern.steps, steps, count * sizeof(Vibration));
292+
void feedbackRun(ToneType type)
293+
{
294+
switch (type)
295+
{
296+
case T_CALLS:
297+
feedbackTone(tone_call, 8, T_CALLS, 3);
298+
feedbackVibrate(pattern, 4, true);
299+
break;
300+
case T_NOTIFICATION:
301+
feedbackTone(tone_notification, 3, T_NOTIFICATION, 2);
302+
feedbackVibrate(v_notif, 2, true);
303+
break;
304+
case T_TIMER:
305+
feedbackTone(tone_alarm, 7, T_TIMER);
306+
feedbackVibrate(pattern, 4, true);
307+
break;
308+
case T_ALARM:
309+
feedbackTone(tone_timer, 6, T_TIMER, 3);
310+
feedbackVibrate(pattern, 4, true);
311+
break;
312+
case T_SYSTEM:
313+
feedbackTone(tone_button, 1, T_SYSTEM);
314+
feedbackVibrate(pattern, 2, true);
315+
break;
316+
default:
317+
break;
318+
}
282319

283-
xQueueSend(vibQueue, &pattern, 0);
284320

285-
#endif
286-
}
321+
if (check_alert_state(ALERT_SCREEN))
322+
{
323+
switch (type)
324+
{
325+
case T_CALLS:
326+
screen_on(50);
327+
break;
328+
default:
329+
screen_on();
330+
break;
331+
}
332+
}
333+
}

hal/esp32/feedback.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
#define MAX_VIB_PATTERN_LENGTH 16
2525

26-
enum ToneType {
26+
enum ToneType
27+
{
2728
T_ALARM = 0,
2829
T_TIMER,
2930
T_CALLS,
@@ -44,6 +45,14 @@ struct Vibration
4445
int duration;
4546
};
4647

48+
enum AlertType
49+
{
50+
ALERT_POPUP = 0x01,
51+
ALERT_SCREEN = 0x02,
52+
ALERT_SOUND = 0x04,
53+
ALERT_VIBRATE = 0x08
54+
};
55+
4756
extern Vibration pattern[];
4857
extern Vibration v_notif[];
4958

@@ -59,9 +68,15 @@ extern Note tone_simonsays_intro[];
5968
extern Note tone_simonsays_gameover[];
6069

6170
void startToneSystem();
62-
void feedbackTone(Note *notes, int count, ToneType type, int repeat = 0);
63-
6471
void startVibrationSystem();
72+
73+
void feedbackTone(Note *notes, int count, ToneType type, int repeat = 0);
6574
void feedbackVibrate(Vibration *steps, int count, bool force = false);
6675

76+
void screen_on(long extra = 0);
77+
78+
void feedbackRun(ToneType type);
79+
80+
bool check_alert_state(AlertType type);
81+
6782
#endif

0 commit comments

Comments
 (0)