RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
RBControl_timers.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <esp_timer.h>
4 
5 #include <memory>
6 #include <mutex>
7 #include <vector>
8 
9 namespace rb {
10 
11 class Manager;
12 class Timers;
13 
14 class Timers {
15 public:
16  static constexpr uint16_t INVALID_ID = 0;
17 
21  static void deleteFreeRtOsTimerTask();
22 
23  static Timers& get();
24 
34  uint16_t schedule(uint32_t period_ms, std::function<bool()> callback);
35 
36  bool reset(uint16_t id, uint32_t period_ms);
37  bool cancel(uint16_t id);
38 
39 private:
40  struct timer_t {
41  std::function<bool()> callback;
42  esp_timer_handle_t handle;
43  uint16_t id;
44  };
45 
46  static void timerCallback(void* handleVoid);
47 
48  Timers();
49  ~Timers();
50 
51  void cancelByIdxLocked(size_t idx);
52  uint16_t getFreeIdLocked();
53 
54  std::vector<timer_t> m_timers;
55  std::recursive_mutex m_mutex;
56  uint16_t m_id_counter;
57 };
58 
59 };
Definition: RBControl_timers.hpp:14
bool reset(uint16_t id, uint32_t period_ms)
Definition: RBControl_timers.cpp:71
bool cancel(uint16_t id)
Definition: RBControl_timers.cpp:85
static void deleteFreeRtOsTimerTask()
If you don't plan to use FreeRTOS SW timers, call this to free up 2KB of heap.
Definition: RBControl_timers.cpp:14
uint16_t schedule(uint32_t period_ms, std::function< bool()> callback)
Schedule callback to fire after period (in millisecond).
Definition: RBControl_timers.cpp:45
static Timers & get()
Definition: RBControl_timers.cpp:18
static constexpr uint16_t INVALID_ID
Definition: RBControl_timers.hpp:16
The base namespace. Contains some logging functions, too.
Definition: half_duplex_uart.cpp:53