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
@@ -38,20 +38,9 @@ void EspNowService::onStop(ServiceContext& service) {
|
||||
// region Enable
|
||||
|
||||
void EspNowService::enable(const EspNowConfig& config) {
|
||||
auto enable_context = std::make_shared<EspNowConfig>(config);
|
||||
getMainDispatcher().dispatch(enableFromDispatcher, enable_context);
|
||||
}
|
||||
|
||||
void EspNowService::enableFromDispatcher(std::shared_ptr<void> context) {
|
||||
auto service = findService();
|
||||
if (service == nullptr) {
|
||||
TT_LOG_E(TAG, "Service not running");
|
||||
return;
|
||||
}
|
||||
|
||||
auto config = std::static_pointer_cast<EspNowConfig>(context);
|
||||
|
||||
service->enableFromDispatcher(*config);
|
||||
getMainDispatcher().dispatch([this, config]() {
|
||||
enableFromDispatcher(config);
|
||||
});
|
||||
}
|
||||
|
||||
void EspNowService::enableFromDispatcher(const EspNowConfig& config) {
|
||||
@@ -101,17 +90,9 @@ void EspNowService::enableFromDispatcher(const EspNowConfig& config) {
|
||||
// region Disable
|
||||
|
||||
void EspNowService::disable() {
|
||||
getMainDispatcher().dispatch(disableFromDispatcher, nullptr);
|
||||
}
|
||||
|
||||
void EspNowService::disableFromDispatcher(TT_UNUSED std::shared_ptr<void> context) {
|
||||
auto service = findService();
|
||||
if (service == nullptr) {
|
||||
TT_LOG_E(TAG, "Service not running");
|
||||
return;
|
||||
}
|
||||
|
||||
service->disableFromDispatcher();
|
||||
getMainDispatcher().dispatch([this]() {
|
||||
disableFromDispatcher();
|
||||
});
|
||||
}
|
||||
|
||||
void EspNowService::disableFromDispatcher() {
|
||||
|
||||
Reference in New Issue
Block a user