@@ -121,7 +121,7 @@ Vibration pattern[] = {
121121
122122void  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- 
216174void  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+ 
251224void  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+ 
265267void  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+ }
0 commit comments