Merge develop into main (#304)

## 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::notes::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
This commit is contained in:
Ken Van Hoeylandt
2025-08-23 17:10:18 +02:00
committed by GitHub
parent fbaff8cbac
commit ee5a5a7181
109 changed files with 1396 additions and 744 deletions
+29 -34
View File
@@ -1,19 +1,20 @@
#ifdef ESP_PLATFORM
#include <lwip/esp_netif_net_stack.h>
#include "Tactility/service/wifi/Wifi.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/service/ServiceContext.h"
#include "Tactility/service/wifi/WifiGlobals.h"
#include "Tactility/service/wifi/WifiSettings.h"
#include "Tactility/service/wifi/WifiBootSplashInit.h"
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Timer.h>
#include <lwip/esp_netif_net_stack.h>
#include <freertos/FreeRTOS.h>
#include <atomic>
#include <cstring>
#include <Tactility/kernel/SystemEvents.h>
#include <sys/cdefs.h>
namespace tt::service::wifi {
@@ -36,8 +37,6 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr<Wifi> wifi);
class Wifi {
private:
std::atomic<RadioState> radio_state = RadioState::Off;
bool scan_active = false;
bool secure_connection = false;
@@ -66,14 +65,11 @@ public:
esp_event_handler_instance_t event_handler_any_id = nullptr;
esp_event_handler_instance_t event_handler_got_ip = nullptr;
EventFlag connection_wait_flags;
settings::WifiApSettings connection_target = {
.ssid = { 0 },
.password = { 0 },
.auto_connect = false
};
settings::WifiApSettings connection_target;
bool pause_auto_connect = false; // Pause when manually disconnecting until manually connecting again
bool connection_target_remember = false; // Whether to store the connection_target on successful connection or not
esp_netif_ip_info_t ip_info;
kernel::SystemEventSubscription bootEventSubscription = kernel::NoSystemEventSubscription;
RadioState getRadioState() const {
auto lock = dataMutex.asScopedLock();
@@ -187,8 +183,8 @@ bool isScanning() {
}
}
void connect(const settings::WifiApSettings* ap, bool remember) {
TT_LOG_I(TAG, "connect(%s, %d)", ap->ssid, remember);
void connect(const settings::WifiApSettings& ap, bool remember) {
TT_LOG_I(TAG, "connect(%s, %d)", ap.ssid.c_str(), remember);
auto wifi = wifi_singleton;
if (wifi == nullptr) {
return;
@@ -201,14 +197,14 @@ void connect(const settings::WifiApSettings* ap, bool remember) {
// Manual connect (e.g. via app) should stop auto-connecting until the connection is established
wifi->pause_auto_connect = true;
memcpy(&wifi->connection_target, ap, sizeof(settings::WifiApSettings));
wifi->connection_target = ap;
wifi->connection_target_remember = remember;
if (wifi->getRadioState() == RadioState::Off) {
getMainDispatcher().dispatch([wifi]() { dispatchEnable(wifi); });
getMainDispatcher().dispatch([wifi] { dispatchEnable(wifi); });
}
getMainDispatcher().dispatch([wifi]() { dispatchConnect(wifi); });
getMainDispatcher().dispatch([wifi] { dispatchConnect(wifi); });
}
void disconnect() {
@@ -223,11 +219,7 @@ void disconnect() {
return;
}
wifi->connection_target = (settings::WifiApSettings) {
.ssid = { 0 },
.password = { 0 },
.auto_connect = false
};
wifi->connection_target = settings::WifiApSettings("", "");
// Manual disconnect (e.g. via app) should stop auto-connecting until a new connection is established
wifi->pause_auto_connect = true;
getMainDispatcher().dispatch([wifi]() { dispatchDisconnectButKeepActive(wifi); });
@@ -307,9 +299,9 @@ void setEnabled(bool enabled) {
}
if (enabled) {
getMainDispatcher().dispatch([wifi]() { dispatchEnable(wifi); });
getMainDispatcher().dispatch([wifi] { dispatchEnable(wifi); });
} else {
getMainDispatcher().dispatch([wifi]() { dispatchDisable(wifi); });
getMainDispatcher().dispatch([wifi] { dispatchDisable(wifi); });
}
wifi->pause_auto_connect = false;
@@ -431,8 +423,8 @@ static bool find_auto_connect_ap(std::shared_ptr<Wifi> wifi, settings::WifiApSet
auto ssid = reinterpret_cast<const char*>(wifi->scan_list[i].ssid);
if (settings::contains(ssid)) {
static_assert(sizeof(wifi->scan_list[i].ssid) == (TT_WIFI_SSID_LIMIT + 1), "SSID size mismatch");
if (settings::load(ssid, &settings)) {
if (settings.auto_connect) {
if (settings::load(ssid, settings)) {
if (settings.autoConnect) {
return true;
}
} else {
@@ -451,8 +443,8 @@ static void dispatchAutoConnect(std::shared_ptr<Wifi> wifi) {
settings::WifiApSettings settings;
if (find_auto_connect_ap(wifi, settings)) {
TT_LOG_I(TAG, "Auto-connecting to %s", settings.ssid);
connect(&settings, false);
TT_LOG_I(TAG, "Auto-connecting to %s", settings.ssid.c_str());
connect(settings, false);
// TODO: We currently have to manually reset it because connect() sets it.
// connect() assumes it's only being called by the user and not internally, so it disables auto-connect
wifi->pause_auto_connect = false;
@@ -726,7 +718,7 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
return;
}
TT_LOG_I(TAG, "Connecting to %s", wifi->connection_target.ssid);
TT_LOG_I(TAG, "Connecting to %s", wifi->connection_target.ssid.c_str());
// Stop radio first, if needed
RadioState radio_state = wifi->getRadioState();
@@ -758,11 +750,10 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
config.sta.threshold.rssi = -127;
config.sta.pmf_cfg.capable = true;
static_assert(sizeof(config.sta.ssid) == (sizeof(wifi_singleton->connection_target.ssid)-1), "SSID size mismatch");
memcpy(config.sta.ssid, wifi_singleton->connection_target.ssid, sizeof(config.sta.ssid));
memcpy(config.sta.ssid, wifi_singleton->connection_target.ssid.c_str(), wifi_singleton->connection_target.ssid.size());
if (wifi_singleton->connection_target.password[0] != 0x00) {
memcpy(config.sta.password, wifi_singleton->connection_target.password, sizeof(config.sta.password));
memcpy(config.sta.password, wifi_singleton->connection_target.password.c_str(), wifi_singleton->connection_target.password.size());
config.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
}
@@ -794,9 +785,9 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
wifi->setSecureConnection(config.sta.password[0] != 0x00U);
wifi->setRadioState(RadioState::ConnectionActive);
publish_event_simple(wifi, EventType::ConnectionSuccess);
TT_LOG_I(TAG, "Connected to %s", wifi->connection_target.ssid);
TT_LOG_I(TAG, "Connected to %s", wifi->connection_target.ssid.c_str());
if (wifi->connection_target_remember) {
if (!settings::save(&wifi->connection_target)) {
if (!settings::save(wifi->connection_target)) {
TT_LOG_E(TAG, "Failed to store credentials");
} else {
TT_LOG_I(TAG, "Stored credentials");
@@ -805,7 +796,7 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
} else if (bits & WIFI_FAIL_BIT) {
wifi->setRadioState(RadioState::On);
publish_event_simple(wifi, EventType::ConnectionFailed);
TT_LOG_I(TAG, "Failed to connect to %s", wifi->connection_target.ssid);
TT_LOG_I(TAG, "Failed to connect to %s", wifi->connection_target.ssid.c_str());
} else {
wifi->setRadioState(RadioState::On);
publish_event_simple(wifi, EventType::ConnectionFailed);
@@ -911,13 +902,17 @@ public:
assert(wifi_singleton == nullptr);
wifi_singleton = std::make_shared<Wifi>();
wifi_singleton->bootEventSubscription = kernel::subscribeSystemEvent(kernel::SystemEvent::BootSplash, [](auto) {
bootSplashInit();
});
wifi_singleton->autoConnectTimer = std::make_unique<Timer>(Timer::Type::Periodic, []() { onAutoConnectTimer(); });
// We want to try and scan more often in case of startup or scan lock failure
wifi_singleton->autoConnectTimer->start(std::min(2000, AUTO_SCAN_INTERVAL));
if (settings::shouldEnableOnBoot()) {
TT_LOG_I(TAG, "Auto-enabling due to setting");
getMainDispatcher().dispatch([]() { dispatchEnable(wifi_singleton); });
getMainDispatcher().dispatch([] { dispatchEnable(wifi_singleton); });
}
}