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
@@ -37,7 +37,7 @@ private:
|
||||
static int32_t bootThreadCallback(TT_UNUSED void* context) {
|
||||
TickType_t start_time = kernel::getTicks();
|
||||
|
||||
kernel::systemEventPublish(kernel::SystemEvent::BootSplash);
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootSplash);
|
||||
|
||||
auto hal_display = getHalDisplay();
|
||||
assert(hal_display != nullptr);
|
||||
|
||||
@@ -21,7 +21,7 @@ private:
|
||||
Mutex mutex;
|
||||
|
||||
static lv_obj_t* createGpioRowWrapper(lv_obj_t* parent);
|
||||
static void onTimer(TT_UNUSED std::shared_ptr<void> context);
|
||||
void onTimer();
|
||||
|
||||
public:
|
||||
|
||||
@@ -49,9 +49,9 @@ void GpioApp::updatePinStates() {
|
||||
}
|
||||
|
||||
void GpioApp::updatePinWidgets() {
|
||||
auto scoped_lvgl_lock = lvgl::getSyncLock()->scoped();
|
||||
auto scoped_lvgl_lock = lvgl::getSyncLock()->asScopedLock();
|
||||
auto scoped_gpio_lock = mutex.asScopedLock();
|
||||
if (scoped_gpio_lock.lock() && scoped_lvgl_lock->lock(100)) {
|
||||
if (scoped_gpio_lock.lock() && scoped_lvgl_lock.lock(lvgl::defaultLockTime)) {
|
||||
for (int j = 0; j < GPIO_NUM_MAX; ++j) {
|
||||
int level = pinStates[j];
|
||||
lv_obj_t* label = lvPins[j];
|
||||
@@ -79,24 +79,17 @@ lv_obj_t* GpioApp::createGpioRowWrapper(lv_obj_t* parent) {
|
||||
|
||||
// region Task
|
||||
|
||||
void GpioApp::onTimer(TT_UNUSED std::shared_ptr<void> context) {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext->getManifest().id == manifest.id) {
|
||||
auto app = std::static_pointer_cast<GpioApp>(appContext->getApp());
|
||||
if (app != nullptr) {
|
||||
app->updatePinStates();
|
||||
app->updatePinWidgets();
|
||||
}
|
||||
}
|
||||
void GpioApp::onTimer() {
|
||||
updatePinStates();
|
||||
updatePinWidgets();
|
||||
}
|
||||
|
||||
void GpioApp::startTask() {
|
||||
mutex.lock();
|
||||
assert(timer == nullptr);
|
||||
timer = std::make_unique<Timer>(
|
||||
Timer::Type::Periodic,
|
||||
&onTimer
|
||||
);
|
||||
timer = std::make_unique<Timer>(Timer::Type::Periodic, [this]() {
|
||||
onTimer();
|
||||
});
|
||||
timer->start(100 / portTICK_PERIOD_MS);
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
@@ -39,12 +39,6 @@ private:
|
||||
PubSub::SubscriptionHandle serviceStateSubscription = nullptr;
|
||||
std::shared_ptr<service::gps::GpsService> service;
|
||||
|
||||
static void onUpdateCallback(TT_UNUSED std::shared_ptr<void> context) {
|
||||
auto appPtr = std::static_pointer_cast<GpsSettingsApp*>(context);
|
||||
auto app = *appPtr;
|
||||
app->updateViews();
|
||||
}
|
||||
|
||||
static void onServiceStateChangedCallback(const void* data, void* context) {
|
||||
auto* app = (GpsSettingsApp*)context;
|
||||
app->onServiceStateChanged();
|
||||
@@ -266,13 +260,13 @@ private:
|
||||
if (wants_on != is_on) {
|
||||
// start/stop are potentially blocking calls, so we use a dispatcher to not block the UI
|
||||
if (wants_on) {
|
||||
getMainDispatcher().dispatch([](auto service) {
|
||||
std::static_pointer_cast<service::gps::GpsService>(service)->startReceiving();
|
||||
}, service);
|
||||
getMainDispatcher().dispatch([this]() {
|
||||
service->startReceiving();
|
||||
});
|
||||
} else {
|
||||
getMainDispatcher().dispatch([](auto service) {
|
||||
std::static_pointer_cast<service::gps::GpsService>(service)->stopReceiving();
|
||||
}, service);
|
||||
getMainDispatcher().dispatch([this]() {
|
||||
service->stopReceiving();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -280,7 +274,9 @@ private:
|
||||
public:
|
||||
|
||||
GpsSettingsApp() {
|
||||
timer = std::make_unique<Timer>(Timer::Type::Periodic, onUpdateCallback, appReference);
|
||||
timer = std::make_unique<Timer>(Timer::Type::Periodic, [this]() {
|
||||
updateViews();
|
||||
});
|
||||
service = service::gps::findGpsService();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ private:
|
||||
|
||||
static void onSelectBusCallback(lv_event_t* event);
|
||||
static void onPressScanCallback(lv_event_t* event);
|
||||
static void onScanTimerCallback(std::shared_ptr<void> context);
|
||||
static void onScanTimerCallback();
|
||||
|
||||
void onSelectBus(lv_event_t* event);
|
||||
void onPressScan(lv_event_t* event);
|
||||
@@ -180,7 +180,7 @@ void I2cScannerApp::onPressScanCallback(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
void I2cScannerApp::onScanTimerCallback(TT_UNUSED std::shared_ptr<void> context) {
|
||||
void I2cScannerApp::onScanTimerCallback() {
|
||||
auto app = optApp();
|
||||
if (app != nullptr) {
|
||||
app->onScanTimer();
|
||||
@@ -284,10 +284,9 @@ void I2cScannerApp::startScanning() {
|
||||
lv_obj_clean(scanListWidget);
|
||||
|
||||
scanState = ScanStateScanning;
|
||||
scanTimer = std::make_unique<Timer>(
|
||||
Timer::Type::Once,
|
||||
onScanTimerCallback
|
||||
);
|
||||
scanTimer = std::make_unique<Timer>(Timer::Type::Once, [](){
|
||||
onScanTimerCallback();
|
||||
});
|
||||
scanTimer->start(10);
|
||||
mutex.unlock();
|
||||
} else {
|
||||
|
||||
@@ -33,7 +33,7 @@ class PowerApp : public App {
|
||||
|
||||
private:
|
||||
|
||||
Timer update_timer = Timer(Timer::Type::Periodic, &onTimer, nullptr);
|
||||
Timer update_timer = Timer(Timer::Type::Periodic, []() { onTimer(); });
|
||||
|
||||
std::shared_ptr<hal::power::PowerDevice> power;
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
lv_obj_t* chargeLevelLabel = nullptr;
|
||||
lv_obj_t* currentLabel = nullptr;
|
||||
|
||||
static void onTimer(TT_UNUSED std::shared_ptr<void> context) {
|
||||
static void onTimer() {
|
||||
auto app = optApp();
|
||||
if (app != nullptr) {
|
||||
app->updateUi();
|
||||
|
||||
@@ -72,15 +72,10 @@ static void onModeSetCallback(TT_UNUSED lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void onTimerCallback(TT_UNUSED std::shared_ptr<void> context) {
|
||||
auto app = optApp();
|
||||
if (app != nullptr) {
|
||||
app->onTimerTick();
|
||||
}
|
||||
}
|
||||
|
||||
ScreenshotApp::ScreenshotApp() {
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, onTimerCallback, nullptr);
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, [this]() {
|
||||
onTimerTick();
|
||||
});
|
||||
}
|
||||
|
||||
ScreenshotApp::~ScreenshotApp() {
|
||||
@@ -90,8 +85,8 @@ ScreenshotApp::~ScreenshotApp() {
|
||||
}
|
||||
|
||||
void ScreenshotApp::onTimerTick() {
|
||||
auto lvgl_lock = lvgl::getSyncLock()->scoped();
|
||||
if (lvgl_lock->lock(50 / portTICK_PERIOD_MS)) {
|
||||
auto lock = lvgl::getSyncLock()->asScopedLock();
|
||||
if (lock.lock(lvgl::defaultLockTime)) {
|
||||
updateScreenshotMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ private:
|
||||
lv_obj_add_event_cb(btn, &onListItemSelectedCallback, LV_EVENT_SHORT_CLICKED, (void*)index);
|
||||
}
|
||||
|
||||
static void updateTimerCallback(std::shared_ptr<void> context) {
|
||||
static void updateTimerCallback() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
auto app = std::static_pointer_cast<TimeZoneApp>(appContext->getApp());
|
||||
@@ -231,7 +231,7 @@ public:
|
||||
}
|
||||
|
||||
void onCreate(AppContext& app) override {
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Once, updateTimerCallback, nullptr);
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Once, []() { updateTimerCallback(); });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -69,7 +69,13 @@ static void connect(lv_event_t* event) {
|
||||
if (ssid != nullptr) {
|
||||
TT_LOG_I(TAG, "Clicked AP: %s", ssid);
|
||||
auto* bindings = (Bindings*)lv_event_get_user_data(event);
|
||||
bindings->onConnectSsid(ssid);
|
||||
|
||||
std::string connection_target = service::wifi::getConnectionTarget();
|
||||
if (connection_target == ssid) {
|
||||
bindings->onDisconnect();
|
||||
} else {
|
||||
bindings->onConnectSsid(ssid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user