## New
- Read property files with `PropertiesFile`
- Support `boot.properties` so the user can specify the launcher app and an optional app to start after the launcher finishes. (see `BootProperties.cpp`)
- Create registry for CPU affinity and update code to make use of it
- `AppRegistration` and `ServiceRegistration` now also ensure that the `/data` directories always exist for all apps
- `Notes` is now the default app for opening text files. `TextViewer` is removed entirely. Created `tt::app:🎶:start(path)` function.
- WiFi settings moved from NVS to properties file.
- Specify `*.ap.properties` file on the SD card for automatic WiFi settings import on start-up.
- Added `file::getLock(path)` and `file::withLock(path, function)` to do safe file operations on SD cards
## Improvements
- Update TinyUSB to `1.7.6~1`
- Improved `Boot.cpp` code. General code quality fixes and some restructuring to improve readability.
- `tt::string` functionality improvements
- Rename `AppRegistry` to `AppRegistration`
- Rename `ServiceRegistry` to `ServiceRegistration`
- Cleanup in `Notes.cpp`
- `FileTest.cpp` fix for PC
- Created `TestFile` helper class for tests, which automatically deletes files after the test.
- Renamed `Partitions.h` to `MountPoints.h`
- Created `std::string getMountPoints()` function for easy re-use
- Other code quality improvements
- `SdCardDevice`'s `getState()` and `isMounted()` now have a timeout argument
## Fixes
- ELF loading now has a lock so to avoid a bug when 2 ELF apps are loaded in parallel
149 lines
4.1 KiB
C++
149 lines
4.1 KiB
C++
#include "Tactility/app/wifimanage/WifiManagePrivate.h"
|
|
#include "Tactility/app/wifimanage/View.h"
|
|
|
|
#include "Tactility/app/AppContext.h"
|
|
#include "Tactility/app/wifiapsettings/WifiApSettings.h"
|
|
#include "Tactility/service/loader/Loader.h"
|
|
#include "Tactility/service/wifi/WifiSettings.h"
|
|
#include "Tactility/lvgl/LvglSync.h"
|
|
#include "Tactility/app/wificonnect/WifiConnect.h"
|
|
|
|
namespace tt::app::wifimanage {
|
|
|
|
#define TAG "wifi_manage"
|
|
|
|
extern const AppManifest manifest;
|
|
|
|
static void onConnect(const char* ssid) {
|
|
service::wifi::settings::WifiApSettings settings;
|
|
if (service::wifi::settings::load(ssid, settings)) {
|
|
TT_LOG_I(TAG, "Connecting with known credentials");
|
|
service::wifi::connect(settings, false);
|
|
} else {
|
|
TT_LOG_I(TAG, "Starting connection dialog");
|
|
wificonnect::start(ssid);
|
|
}
|
|
}
|
|
|
|
static void onShowApSettings(const char* ssid) {
|
|
wifiapsettings::start(ssid);
|
|
}
|
|
|
|
static void onDisconnect() {
|
|
service::wifi::disconnect();
|
|
}
|
|
|
|
static void onWifiToggled(bool enabled) {
|
|
service::wifi::setEnabled(enabled);
|
|
}
|
|
|
|
static void onConnectToHidden() {
|
|
wificonnect::start();
|
|
}
|
|
|
|
WifiManage::WifiManage() {
|
|
bindings = (Bindings) {
|
|
.onWifiToggled = onWifiToggled,
|
|
.onConnectSsid = onConnect,
|
|
.onDisconnect = onDisconnect,
|
|
.onShowApSettings = onShowApSettings,
|
|
.onConnectToHidden = onConnectToHidden
|
|
};
|
|
}
|
|
|
|
void WifiManage::lock() {
|
|
mutex.lock();
|
|
}
|
|
|
|
void WifiManage::unlock() {
|
|
mutex.unlock();
|
|
}
|
|
|
|
void WifiManage::requestViewUpdate() {
|
|
lock();
|
|
if (isViewEnabled) {
|
|
if (lvgl::lock(1000)) {
|
|
view.update();
|
|
lvgl::unlock();
|
|
} else {
|
|
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
|
|
}
|
|
}
|
|
unlock();
|
|
}
|
|
|
|
static void wifiManageEventCallback(const void* message, void* context) {
|
|
auto* event = (service::wifi::Event*)message;
|
|
auto* wifi = (WifiManage*)context;
|
|
auto radio_state = service::wifi::getRadioState();
|
|
TT_LOG_I(TAG, "Update with state %s", service::wifi::radioStateToString(radio_state));
|
|
wifi->getState().setRadioState(radio_state);
|
|
switch (event->type) {
|
|
using enum tt::service::wifi::EventType;
|
|
case ScanStarted:
|
|
wifi->getState().setScanning(true);
|
|
break;
|
|
case ScanFinished:
|
|
wifi->getState().setScanning(false);
|
|
wifi->getState().updateApRecords();
|
|
break;
|
|
case RadioStateOn:
|
|
if (!service::wifi::isScanning()) {
|
|
service::wifi::scan();
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
wifi->requestViewUpdate();
|
|
}
|
|
|
|
void WifiManage::onShow(AppContext& app, lv_obj_t* parent) {
|
|
wifiSubscription = service::wifi::getPubsub()->subscribe(&wifiManageEventCallback, this);
|
|
|
|
// State update (it has its own locking)
|
|
state.setRadioState(service::wifi::getRadioState());
|
|
state.setScanning(service::wifi::isScanning());
|
|
state.updateApRecords();
|
|
|
|
// View update
|
|
lock();
|
|
isViewEnabled = true;
|
|
state.setConnectSsid("Connected"); // TODO update with proper SSID
|
|
view.init(app, parent);
|
|
view.update();
|
|
unlock();
|
|
|
|
service::wifi::RadioState radio_state = service::wifi::getRadioState();
|
|
bool can_scan = radio_state == service::wifi::RadioState::On ||
|
|
radio_state == service::wifi::RadioState::ConnectionPending ||
|
|
radio_state == service::wifi::RadioState::ConnectionActive;
|
|
TT_LOG_I(TAG, "%s %d", service::wifi::radioStateToString(radio_state), (int)service::wifi::isScanning());
|
|
if (can_scan && !service::wifi::isScanning()) {
|
|
service::wifi::scan();
|
|
}
|
|
}
|
|
|
|
void WifiManage::onHide(TT_UNUSED AppContext& app) {
|
|
lock();
|
|
service::wifi::getPubsub()->unsubscribe(wifiSubscription);
|
|
wifiSubscription = nullptr;
|
|
isViewEnabled = false;
|
|
unlock();
|
|
}
|
|
|
|
extern const AppManifest manifest = {
|
|
.id = "WifiManage",
|
|
.name = "Wi-Fi",
|
|
.icon = LV_SYMBOL_WIFI,
|
|
.type = Type::Settings,
|
|
.createApp = create<WifiManage>
|
|
};
|
|
|
|
void start() {
|
|
service::loader::startApp(manifest.id);
|
|
}
|
|
|
|
} // namespace
|