Various improvements (#264)
- Replace C function pointers with C++ `std::function` in `Thread`, `Timer` and `DispatcherThread` - Rename `SystemEvent`-related functions - WiFi: fix auto-connect when WiFi disconnects from bad signal - WiFi: fix auto-connect when WiFi fails to auto-connect - WiFi: implement disconnect() when tapping connected WiFi ap in WiFi management app
This commit is contained in:
committed by
GitHub
parent
d72852a6e2
commit
3f1bfee3f5
@@ -3,23 +3,14 @@
|
||||
|
||||
struct TimerWrapper {
|
||||
std::unique_ptr<tt::Timer> timer;
|
||||
TimerCallback callback;
|
||||
void* _Nullable callbackContext;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
static void callbackWrapper(std::shared_ptr<void> wrapper) {
|
||||
auto timer_wrapper = (TimerWrapper*)wrapper.get();
|
||||
timer_wrapper->callback(timer_wrapper->callbackContext);
|
||||
}
|
||||
|
||||
TimerHandle tt_timer_alloc(TimerType type, TimerCallback callback, void* callbackContext) {
|
||||
auto wrapper = std::make_shared<TimerWrapper>();
|
||||
wrapper->callback = callback;
|
||||
wrapper->callbackContext = callbackContext;
|
||||
wrapper->timer = std::make_unique<tt::Timer>((tt::Timer::Type)type, callbackWrapper, wrapper);
|
||||
wrapper->timer = std::make_unique<tt::Timer>((tt::Timer::Type)type, [callback, callbackContext](){ callback(callbackContext); });
|
||||
return wrapper.get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user