mn_timer_esp32.hpp
Go to the documentation of this file.
1 
19 #ifndef MINLIB_ESP32_TIMER_
20 #define MINLIB_ESP32_TIMER_
21 
22 #include "mn_config.hpp"
23 
24 #include <esp_timer.h>
25 
26 #include "mn_itimer.hpp"
27 
28 
29 namespace mn {
30  namespace esp32 {
31 
39  class basic_esp32_timer : public ITimer {
40  public:
51  basic_esp32_timer(const char * strName, unsigned int uiPeriod, bool bIsOneShot = true);
52 
53  virtual ~basic_esp32_timer() { destroy(); }
54 
65  virtual int create();
66 
74  virtual int destroy(unsigned int timeout = (unsigned int) 0xffffffffUL);
75 
84  virtual int active(unsigned int timeout = (unsigned int) 0xffffffffUL);
85 
94  virtual int inactive(unsigned int timeout = (unsigned int) 0xffffffffUL);
95 
105  virtual int reset(unsigned int timeout = (unsigned int) 0xffffffffUL);
106 
114  virtual bool set_period(unsigned int uiNewPeriod, unsigned int timeout = (unsigned int) 0xffffffffUL);
120  virtual unsigned int get_period() { return m_uiPeriod; }
121 
126  virtual void* get_handle();
127 
131  virtual void set_id(int nId) { /* NOT IMPL */ }
132 
139  virtual bool is_running() { return m_bIsRunning; }
140 
141  virtual operator bool() { return is_running(); }
142  protected:
147  virtual void on_timer() = 0;
148 
152  virtual void on_enter() { }
156  virtual void on_exit() { }
157  private:
162  static void runtimerstub(void* xTimer);
163  private:
167  esp_timer_handle_t m_pHandle;
168 
176  unsigned int m_uiPeriod;
180  const char* m_strName;
181 
186 
190  bool m_bIsInit;
191  };
192 
194  }
195 }
196 #endif
Definition: mn_itimer.hpp:28
Definition: mn_timer_esp32.hpp:39
virtual void * get_handle()
Definition: mn_timer_esp32.cpp:119
virtual int inactive(unsigned int timeout=(unsigned int) 0xffffffffUL)
Definition: mn_timer_esp32.cpp:92
virtual unsigned int get_period()
Definition: mn_timer_esp32.hpp:120
virtual void set_id(int nId)
Definition: mn_timer_esp32.hpp:131
virtual ~basic_esp32_timer()
Definition: mn_timer_esp32.hpp:53
bool m_bIsOneShot
Definition: mn_timer_esp32.hpp:172
unsigned int m_uiPeriod
Definition: mn_timer_esp32.hpp:176
virtual int reset(unsigned int timeout=(unsigned int) 0xffffffffUL)
Definition: mn_timer_esp32.cpp:101
virtual int active(unsigned int timeout=(unsigned int) 0xffffffffUL)
Definition: mn_timer_esp32.cpp:77
basic_esp32_timer(const char *strName, unsigned int uiPeriod, bool bIsOneShot=true)
Definition: mn_timer_esp32.cpp:36
const char * m_strName
Definition: mn_timer_esp32.hpp:180
virtual void on_enter()
Definition: mn_timer_esp32.hpp:152
static void runtimerstub(void *xTimer)
Definition: mn_timer_esp32.cpp:123
virtual int create()
Definition: mn_timer_esp32.cpp:43
esp_timer_handle_t m_pHandle
Definition: mn_timer_esp32.hpp:167
virtual void on_exit()
Definition: mn_timer_esp32.hpp:156
bool m_bIsRunning
Definition: mn_timer_esp32.hpp:185
bool m_bIsInit
Definition: mn_timer_esp32.hpp:190
virtual bool is_running()
Definition: mn_timer_esp32.hpp:139
virtual bool set_period(unsigned int uiNewPeriod, unsigned int timeout=(unsigned int) 0xffffffffUL)
Definition: mn_timer_esp32.cpp:109
virtual int destroy(unsigned int timeout=(unsigned int) 0xffffffffUL)
Definition: mn_timer_esp32.cpp:65
Definition: mn_allocator_typetraits.hpp:25