arduino-audio-tools
AudioTimerESP8266.h
1 #pragma once
2 
3 #ifdef ESP8266
4 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerBase.h"
5 #include "Ticker.h"
6 
7 namespace audio_tools {
8 
9 typedef void (*repeating_timer_callback_t)(void* obj);
10 
11 class TimerAlarmRepeatingDriverESP8266;
12 
22  public:
27  static void complexHandler(void* param) {}
28 
32  bool begin(repeating_timer_callback_t callback_f, uint32_t time,
33  TimeUnit unit = MS) override {
34  uint32_t timeUs;
35 
36  // we determine the time in microseconds
37  switch (unit) {
38  case MS:
39  timeUs = time / 1000;
40  break;
41  case US:
42  timeUs = time;
43  break;
44  case HZ:
45  // convert hz to time in us
46  timeUs = AudioTime::toTimeUs(time);
47  break;
48  }
49 
50  ticker.attach_ms(timeUs / 1000, callback_f, (void*)this);
51 
52  return true;
53  }
54 
55  // ends the timer and if necessary the task
56  bool end() override {
57  ticker.detach();
58  return true;
59  }
60 
61  protected:
62  void (*current_timer_callback)();
63  Ticker ticker;
64 };
65 
67 using TimerAlarmRepeatingDriver = TimerAlarmRepeatingDriverESP8266;
68 
69 } // namespace audio_tools
70 
71 #endif
static uint32_t toTimeUs(uint32_t samplingRate, uint8_t limit=10)
converts sampling rate to delay in microseconds (μs)
Definition: AudioTypes.h:256
Definition: AudioTimerBase.h:22
Repeating Timer functions for repeated execution: Plaease use the typedef TimerAlarmRepeating.
Definition: AudioTimerESP8266.h:21
static void complexHandler(void *param)
Definition: AudioTimerESP8266.h:27
bool begin(repeating_timer_callback_t callback_f, uint32_t time, TimeUnit unit=MS) override
Definition: AudioTimerESP8266.h:32
TimeUnit
Time Units.
Definition: AudioTypes.h:45
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:823
TimerAlarmRepeatingDriverAVR TimerAlarmRepeatingDriver
use TimerAlarmRepeating!
Definition: AudioTimerAVR.h:94