Refactor app loading and window management (#609)

This commit is contained in:
Ken Van Hoeylandt
2026-08-11 23:40:59 +02:00
committed by GitHub
parent dc3f6104b8
commit 37c507544b
243 changed files with 16034 additions and 10865 deletions
+24
View File
@@ -1,5 +1,6 @@
#include <tactility/device.h>
#include <tactility/drivers/display.h>
#include <tactility/drivers/sdcard.h>
#include <tactility/drivers/spi_controller.h>
#include <tactility/filesystem/file_mutex.h>
#include <tactility/filesystem/file_system.h>
@@ -75,6 +76,29 @@ void initFileMutexForLvgl() {
return true;
});
// SDMMC-backed SD cards aren't parented under SPI_CONTROLLER_TYPE, so the pass above never
// sees them - but on some chips (classic ESP32) SDMMC and SPI still contend for DMA/bus
// access. Lock every SD card mount if a display exists anywhere, regardless of bus topology.
if (!device_exists_of_type(&DISPLAY_TYPE)) {
return;
}
file_system_for_each(nullptr, [](FileSystem* fs, void* context) {
char mount_path[64];
if (file_system_get_path(fs, mount_path, sizeof(mount_path)) != ERROR_NONE) {
return true;
}
auto* owner = file_system_get_owner(fs);
if (owner == nullptr || device_get_type(owner) != &SDCARD_TYPE) {
return true;
}
LOG_I(TAG, "Adding file mutex for %s (SD card) - a display is present and may contend for bus/DMA resources", mount_path);
file_mutex_register(&lvgl_mutex, mount_path);
return true;
});
}
}
+24 -46
View File
@@ -1,50 +1,31 @@
#include "Tactility/file/PropertiesFile.h"
#include <Tactility/StringUtils.h>
#include <Tactility/file/File.h>
#include <tactility/log.h>
#include <tactility/properties_file.h>
namespace tt::file {
constexpr auto* TAG = "PropertiesFile";
bool getKeyValuePair(const std::string& input, std::string& key, std::string& value) {
auto index = input.find('=');
if (index == std::string::npos) {
bool loadPropertiesFile(const std::string& filePath, std::function<void(const std::string& key, const std::string& value)> callback) {
// Matches the original semantics: a missing file is a real failure the caller checks for
// (e.g. "no saved settings yet"), unlike properties_file_open() itself, which treats a
// missing file as a fresh, empty store to be created on close().
if (!isFile(filePath)) {
return false;
}
key = input.substr(0, index);
value = input.substr(index + 1);
return true;
}
bool loadPropertiesFile(const std::string& filePath, std::function<void(const std::string& key, const std::string& value)> callback) {
// Reading properties is a common operation; make this debug-level to avoid
// flooding the serial console under frequent polling.
LOG_D(TAG, "Reading properties file %s", filePath.c_str());
uint16_t line_count = 0;
std::string key_prefix = "";
// Malformed lines are skipped, valid lines are loaded and callback is called
return readLines(filePath, true, [&key_prefix, &line_count, &filePath, &callback](const std::string& line) {
line_count++;
std::string key, value;
// Trim all whitespace including \r\n (Windows line endings)
auto trimmed_line = string::trim(line, " \t\r\n");
if (!trimmed_line.starts_with("#") && !trimmed_line.empty()) {
if (trimmed_line.starts_with("[")) {
key_prefix = trimmed_line;
} else {
if (getKeyValuePair(trimmed_line, key, value)) {
std::string trimmed_key = key_prefix + string::trim(key, " \t");
std::string trimmed_value = string::trim(value, " \t");
callback(trimmed_key, trimmed_value);
} else {
LOG_E(TAG, "Failed to parse line %d of %s (skipped)", line_count, filePath.c_str());
// Continue loading other lines
}
}
}
});
PropertiesFile* file = properties_file_open(filePath.c_str());
if (file == nullptr) {
return false;
}
properties_file_for_each(file, [](const char* key, const char* value, void* context) {
auto* typed_callback = static_cast<std::function<void(const std::string&, const std::string&)>*>(context);
(*typed_callback)(key, value);
}, &callback);
properties_file_close(file);
return true;
}
bool loadPropertiesFile(const std::string& filePath, std::map<std::string, std::string>& outProperties) {
@@ -54,19 +35,16 @@ bool loadPropertiesFile(const std::string& filePath, std::map<std::string, std::
}
bool savePropertiesFile(const std::string& filePath, const std::map<std::string, std::string>& properties) {
FileMutexGuard guard(filePath);
LOG_I(TAG, "Saving properties file %s", filePath.c_str());
FILE* file = fopen(filePath.c_str(), "w");
PropertiesFile* file = properties_file_open(filePath.c_str());
if (file == nullptr) {
LOG_E(TAG, "Failed to open %s", filePath.c_str());
return false;
}
for (const auto& [key, value]: properties) { fprintf(file, "%s=%s\n", key.c_str(), value.c_str()); }
for (const auto& [key, value] : properties) {
properties_file_set(file, key.c_str(), value.c_str());
}
fclose(file);
properties_file_close(file);
return true;
}