OMOTE/Platformio/OmoteUI/poller.hpp
Matthew Colvin 65162049b3 convert notification driven battery to lvgl timer based polling
using new poller class to simplify the battery interface and
downstream usages of battery.

tweaked poller destructor and remove the default constructor
in preference of using a unique pointer

convert simulator to use a std::thread for lvgl Tick api because
the SDL thread sleep was not true to time. (and is simplified the code...)
2023-09-09 21:47:36 -04:00

23 lines
No EOL
805 B
C++

#include <chrono>
#include <memory>
#include <functional>
#include "lvgl.h"
class poller{
public:
poller(std::function<void()> aOnPollCb, std::chrono::milliseconds pollTime = std::chrono::seconds(5));
virtual ~poller();
void setPollPeriod(std::chrono::milliseconds aPollPeriod){ lv_timer_set_period(mTimer, aPollPeriod.count());}
inline void pause() { lv_timer_pause(mTimer);}
inline void resume() { lv_timer_resume(mTimer);}
inline void reset() { lv_timer_reset(mTimer);}
inline void runNext() { lv_timer_ready(mTimer);}
private:
lv_timer_t* mTimer = nullptr;
std::function<void()> mIntermittentCallback = nullptr;
// Static function registered to every timers callback to pass this object as context
static void onPoll(_lv_timer_t* aTimer);
};