arduino-audio-tools
AudioTimer.h
1 #pragma once
7 #include "AudioConfig.h"
8 #if defined(USE_TIMER)
9 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerAVR.h"
10 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerBase.h"
11 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerESP32.h"
12 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerESP8266.h"
13 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerMBED.h"
14 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerRP2040.h"
15 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerRenesas.h"
16 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerSTM32.h"
17 #include "AudioTools/CoreAudio/AudioLogger.h"
18 
19 namespace audio_tools {
20 
26  public:
28  TimerAlarmRepeating() = default;
35  p_timer = &timer;
36  };
37  virtual ~TimerAlarmRepeating() = default;
38 
39  bool begin(repeating_timer_callback_t callback_f, uint32_t time,
40  TimeUnit unit = MS) {
41  // stop timer if it is already active
42  if (is_active) end();
43  // start timer
44  is_active = p_timer->begin(callback_f, time, unit);
45  return is_active;
46  }
47  bool end() {
48  is_active = false;
49  return p_timer->end();
50  };
51 
52  void setCallbackParameter(void* obj) { p_timer->setCallbackParameter(obj); }
53 
54  void* callbackParameter() { return p_timer->callbackParameter(); }
55 
56  virtual void setTimer(int timer) { p_timer->setTimer(timer); }
57 
58  virtual void setTimerFunction(TimerFunction function = DirectTimerCallback) {
59  p_timer->setTimerFunction(function);
60  }
61 
62  void setIsSave(bool is_save) { p_timer->setIsSave(is_save); }
63 
65  operator bool() { return is_active; }
66 
68  TimerAlarmRepeatingDriverBase* driver() { return p_timer; }
69 
70  protected:
71  void* object = nullptr;
72  bool is_active = false;
73  TimerAlarmRepeatingDriver timer; // platform specific timer
74  TimerAlarmRepeatingDriverBase* p_timer = &timer;
75 };
76 
77 } // namespace audio_tools
78 
79 #endif
Repeating Timer functions for repeated execution: Plaease use the typedef TimerAlarmRepeating.
Definition: AudioTimerAVR.h:19
Definition: AudioTimerBase.h:22
virtual void setIsSave(bool is_save)
Not used.
Definition: AudioTimerBase.h:37
Common Interface definition for TimerAlarmRepeating.
Definition: AudioTimer.h:25
TimerAlarmRepeatingDriverBase * driver()
Provides access to the driver.
Definition: AudioTimer.h:68
TimerAlarmRepeating(TimerAlarmRepeatingDriverBase &timer)
Construct a new Timer Alarm Repeating object by passing your object which has been customized with so...
Definition: AudioTimer.h:34
TimerAlarmRepeating()=default
Default constructor.
TimeUnit
Time Units.
Definition: AudioTypes.h:45
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:823