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:
committed by
GitHub
parent
fbaff8cbac
commit
ee5a5a7181
@@ -1,6 +1,6 @@
|
||||
#include "Tactility/app/AppInstancePaths.h"
|
||||
|
||||
#include <Tactility/Partitions.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
|
||||
#define LVGL_PATH_PREFIX std::string("A:/")
|
||||
#ifdef ESP_PLATFORM
|
||||
@@ -12,38 +12,38 @@
|
||||
namespace tt::app {
|
||||
|
||||
std::string AppInstancePaths::getDataDirectory() const {
|
||||
return PARTITION_PREFIX + DATA_PARTITION_NAME + "/app/" + manifest.id;
|
||||
return PARTITION_PREFIX + file::DATA_PARTITION_NAME + "/app/" + manifest.id;
|
||||
}
|
||||
|
||||
std::string AppInstancePaths::getDataDirectoryLvgl() const {
|
||||
return LVGL_PATH_PREFIX + DATA_PARTITION_NAME + "/app/" + manifest.id;
|
||||
return LVGL_PATH_PREFIX + file::DATA_PARTITION_NAME + "/app/" + manifest.id;
|
||||
}
|
||||
|
||||
std::string AppInstancePaths::getDataPath(const std::string& childPath) const {
|
||||
assert(!childPath.starts_with('/'));
|
||||
return PARTITION_PREFIX + DATA_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
return PARTITION_PREFIX + file::DATA_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
}
|
||||
|
||||
std::string AppInstancePaths::getDataPathLvgl(const std::string& childPath) const {
|
||||
assert(!childPath.starts_with('/'));
|
||||
return LVGL_PATH_PREFIX + DATA_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
return LVGL_PATH_PREFIX + file::DATA_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
}
|
||||
|
||||
std::string AppInstancePaths::getSystemDirectory() const {
|
||||
return PARTITION_PREFIX + SYSTEM_PARTITION_NAME + "/app/" + manifest.id;
|
||||
return PARTITION_PREFIX + file::SYSTEM_PARTITION_NAME + "/app/" + manifest.id;
|
||||
}
|
||||
|
||||
std::string AppInstancePaths::getSystemDirectoryLvgl() const {
|
||||
return LVGL_PATH_PREFIX + SYSTEM_PARTITION_NAME + "/app/" + manifest.id;
|
||||
return LVGL_PATH_PREFIX + file::SYSTEM_PARTITION_NAME + "/app/" + manifest.id;
|
||||
}
|
||||
|
||||
std::string AppInstancePaths::getSystemPath(const std::string& childPath) const {
|
||||
assert(!childPath.starts_with('/'));
|
||||
return PARTITION_PREFIX + SYSTEM_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
return PARTITION_PREFIX + file::SYSTEM_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
}
|
||||
|
||||
std::string AppInstancePaths::getSystemPathLvgl(const std::string& childPath) const {
|
||||
return LVGL_PATH_PREFIX + SYSTEM_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
return LVGL_PATH_PREFIX + file::SYSTEM_PARTITION_NAME + "/app/" + manifest.id + '/' + childPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,9 +1,10 @@
|
||||
#include "Tactility/app/ManifestRegistry.h"
|
||||
#include "Tactility/app/AppRegistration.h"
|
||||
#include "Tactility/app/AppManifest.h"
|
||||
|
||||
#include <Tactility/Mutex.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <Tactility/file/File.h>
|
||||
|
||||
#define TAG "app"
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "Tactility/app/ElfApp.h"
|
||||
#include "Tactility/file/File.h"
|
||||
#include "Tactility/file/FileLock.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
#define TAG "elf_app"
|
||||
constexpr auto* TAG = "ElfApp";
|
||||
|
||||
struct ElfManifest {
|
||||
/** The user-readable name of the app. Used in UI. */
|
||||
@@ -33,6 +33,7 @@ struct ElfManifest {
|
||||
|
||||
static size_t elfManifestSetCount = 0;
|
||||
static ElfManifest elfManifest;
|
||||
static std::shared_ptr<Lock> elfManifestLock = std::make_shared<Mutex>();
|
||||
|
||||
class ElfApp : public App {
|
||||
|
||||
@@ -48,7 +49,7 @@ class ElfApp : public App {
|
||||
assert(elfFileData == nullptr);
|
||||
|
||||
size_t size = 0;
|
||||
hal::sdcard::withSdCardLock<void>(filePath, [this, &size](){
|
||||
file::withLock<void>(filePath, [this, &size]{
|
||||
elfFileData = file::readBinary(filePath, size);
|
||||
});
|
||||
|
||||
@@ -56,25 +57,30 @@ class ElfApp : public App {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_elf_init(&elf) < 0) {
|
||||
if (esp_elf_init(&elf) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to initialize");
|
||||
shouldCleanupElf = true;
|
||||
elfFileData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_elf_relocate(&elf, elfFileData.get()) < 0) {
|
||||
if (esp_elf_relocate(&elf, elfFileData.get()) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to load executable");
|
||||
esp_elf_deinit(&elf);
|
||||
elfFileData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
int argc = 0;
|
||||
char* argv[] = {};
|
||||
|
||||
if (esp_elf_request(&elf, 0, argc, argv) < 0) {
|
||||
if (esp_elf_request(&elf, 0, argc, argv) != ESP_OK) {
|
||||
TT_LOG_W(TAG, "Executable returned error code");
|
||||
esp_elf_deinit(&elf);
|
||||
elfFileData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
shouldCleanupElf = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,10 +101,16 @@ public:
|
||||
explicit ElfApp(std::string filePath) : filePath(std::move(filePath)) {}
|
||||
|
||||
void onCreate(AppContext& appContext) override {
|
||||
// Because we use global variables, we have to ensure that we are not starting 2 apps in parallel
|
||||
// We use a ScopedLock so we don't have to safeguard all branches
|
||||
auto lock = elfManifestLock->asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
auto initial_count = elfManifestSetCount;
|
||||
if (startElf()) {
|
||||
if (elfManifestSetCount > initial_count) {
|
||||
manifest = std::make_unique<ElfManifest>(elfManifest);
|
||||
lock.unlock();
|
||||
|
||||
if (manifest->createData != nullptr) {
|
||||
data = manifest->createData();
|
||||
@@ -181,7 +193,7 @@ void registerElfApp(const std::string& filePath) {
|
||||
if (findAppById(filePath) == nullptr) {
|
||||
auto manifest = AppManifest {
|
||||
.id = getElfAppId(filePath),
|
||||
.name = tt::string::removeFileExtension(tt::string::getLastPathSegment(filePath)),
|
||||
.name = string::removeFileExtension(string::getLastPathSegment(filePath)),
|
||||
.type = Type::User,
|
||||
.location = Location::external(filePath)
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Tactility/app/ManifestRegistry.h"
|
||||
#include "Tactility/app/AppRegistration.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/BootProperties.h>
|
||||
#include <Tactility/CpuAffinity.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "Tactility/app/crashdiagnostics/CrashDiagnostics.h"
|
||||
@@ -24,26 +26,25 @@
|
||||
|
||||
namespace tt::app::boot {
|
||||
|
||||
static std::shared_ptr<tt::hal::display::DisplayDevice> getHalDisplay() {
|
||||
static std::shared_ptr<hal::display::DisplayDevice> getHalDisplay() {
|
||||
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
}
|
||||
|
||||
class BootApp : public App {
|
||||
|
||||
private:
|
||||
Thread thread = Thread(
|
||||
"boot",
|
||||
4096,
|
||||
[] { return bootThreadCallback(); },
|
||||
getCpuAffinityConfiguration().system
|
||||
);
|
||||
|
||||
Thread thread = Thread("boot", 4096, [this]() { return bootThreadCallback(); });
|
||||
|
||||
int32_t bootThreadCallback() {
|
||||
TickType_t start_time = kernel::getTicks();
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootSplash);
|
||||
|
||||
auto hal_display = getHalDisplay();
|
||||
static void setupDisplay() {
|
||||
const auto hal_display = getHalDisplay();
|
||||
assert(hal_display != nullptr);
|
||||
if (hal_display->supportsBacklightDuty()) {
|
||||
uint8_t backlight_duty = 200;
|
||||
app::display::getBacklightDuty(backlight_duty);
|
||||
display::getBacklightDuty(backlight_duty);
|
||||
TT_LOG_I(TAG, "backlight %du", backlight_duty);
|
||||
hal_display->setBacklightDuty(backlight_duty);
|
||||
} else {
|
||||
@@ -52,27 +53,45 @@ private:
|
||||
|
||||
if (hal_display->getGammaCurveCount() > 0) {
|
||||
uint8_t gamma_curve;
|
||||
if (app::display::getGammaCurve(gamma_curve)) {
|
||||
if (display::getGammaCurve(gamma_curve)) {
|
||||
hal_display->setGammaCurve(gamma_curve);
|
||||
TT_LOG_I(TAG, "gamma %du", gamma_curve);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hal::usb::isUsbBootMode()) {
|
||||
TT_LOG_I(TAG, "Rebooting into mass storage device mode");
|
||||
hal::usb::resetUsbBootMode();
|
||||
hal::usb::startMassStorageWithSdmmc();
|
||||
} else {
|
||||
static bool setupUsbBootMode() {
|
||||
if (!hal::usb::isUsbBootMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Rebooting into mass storage device mode");
|
||||
hal::usb::resetUsbBootMode();
|
||||
hal::usb::startMassStorageWithSdmmc();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void waitForMinimalSplashDuration(TickType_t startTime) {
|
||||
const auto end_time = kernel::getTicks();
|
||||
const auto ticks_passed = end_time - startTime;
|
||||
constexpr auto minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS);
|
||||
if (minimum_ticks > ticks_passed) {
|
||||
kernel::delayTicks(minimum_ticks - ticks_passed);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t bootThreadCallback() {
|
||||
const auto start_time = kernel::getTicks();
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootSplash);
|
||||
|
||||
setupDisplay();
|
||||
|
||||
if (!setupUsbBootMode()) {
|
||||
initFromBootApp();
|
||||
|
||||
TickType_t end_time = tt::kernel::getTicks();
|
||||
TickType_t ticks_passed = end_time - start_time;
|
||||
TickType_t minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS);
|
||||
if (minimum_ticks > ticks_passed) {
|
||||
kernel::delayTicks(minimum_ticks - ticks_passed);
|
||||
}
|
||||
|
||||
tt::service::loader::stopApp();
|
||||
waitForMinimalSplashDuration(start_time);
|
||||
service::loader::stopApp();
|
||||
startNextApp();
|
||||
}
|
||||
|
||||
@@ -81,16 +100,20 @@ private:
|
||||
|
||||
static void startNextApp() {
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_PANIC) {
|
||||
app::crashdiagnostics::start();
|
||||
if (esp_reset_reason() == ESP_RST_PANIC) {
|
||||
crashdiagnostics::start();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
auto* config = tt::getConfiguration();
|
||||
assert(!config->launcherAppId.empty());
|
||||
tt::service::loader::startApp(config->launcherAppId);
|
||||
BootProperties boot_properties;
|
||||
if (!loadBootProperties(boot_properties) || boot_properties.launcherAppId.empty()) {
|
||||
TT_LOG_E(TAG, "Launcher not configured");
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
service::loader::startApp(boot_properties.launcherAppId);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -99,9 +122,9 @@ public:
|
||||
auto* image = lv_image_create(parent);
|
||||
lv_obj_set_size(image, LV_PCT(100), LV_PCT(100));
|
||||
|
||||
auto paths = app.getPaths();
|
||||
const auto paths = app.getPaths();
|
||||
const char* logo = hal::usb::isUsbBootMode() ? "logo_usb.png" : "logo.png";
|
||||
auto logo_path = paths->getSystemPathLvgl(logo);
|
||||
const auto logo_path = paths->getSystemPathLvgl(logo);
|
||||
TT_LOG_I(TAG, "%s", logo_path.c_str());
|
||||
lv_image_set_src(image, logo_path.c_str());
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace tt::app::filebrowser {
|
||||
|
||||
#define TAG "filebrowser_app"
|
||||
constexpr auto* TAG = "FileBrowser";
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Tactility/file/File.h>
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Partitions.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
|
||||
#include <cstring>
|
||||
@@ -11,10 +11,10 @@
|
||||
#include <vector>
|
||||
#include <dirent.h>
|
||||
|
||||
#define TAG "filebrowser_app"
|
||||
|
||||
namespace tt::app::filebrowser {
|
||||
|
||||
constexpr auto* TAG = "FileBrowser";
|
||||
|
||||
State::State() {
|
||||
if (kernel::getPlatform() == kernel::PlatformSimulator) {
|
||||
char cwd[PATH_MAX];
|
||||
@@ -43,46 +43,20 @@ bool State::setEntriesForPath(const std::string& path) {
|
||||
TT_LOG_I(TAG, "Changing path: %s -> %s", current_path.c_str(), path.c_str());
|
||||
|
||||
/**
|
||||
* ESP32 does not have a root directory, so we have to create it manually.
|
||||
* We'll add the NVS Flash partitions and the binding for the sdcard.
|
||||
* On PC, the root entry point ("/") is a folder.
|
||||
* On ESP32, the root entry point contains the various mount points.
|
||||
*/
|
||||
bool show_custom_root = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/");
|
||||
if (show_custom_root) {
|
||||
bool get_mount_points = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/");
|
||||
if (get_mount_points) {
|
||||
TT_LOG_I(TAG, "Setting custom root");
|
||||
dir_entries.clear();
|
||||
dir_entries.push_back(dirent{
|
||||
.d_ino = 0,
|
||||
.d_type = file::TT_DT_DIR,
|
||||
.d_name = SYSTEM_PARTITION_NAME
|
||||
});
|
||||
dir_entries.push_back(dirent{
|
||||
.d_ino = 1,
|
||||
.d_type = file::TT_DT_DIR,
|
||||
.d_name = DATA_PARTITION_NAME
|
||||
});
|
||||
|
||||
auto sdcards = tt::hal::findDevices<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard);
|
||||
for (auto& sdcard : sdcards) {
|
||||
auto state = sdcard->getState();
|
||||
if (state == hal::sdcard::SdCardDevice::State::Mounted) {
|
||||
auto mount_name = sdcard->getMountPath().substr(1);
|
||||
auto dir_entry = dirent {
|
||||
.d_ino = 2,
|
||||
.d_type = file::TT_DT_DIR,
|
||||
.d_name = { 0 }
|
||||
};
|
||||
assert(mount_name.length() < sizeof(dirent::d_name));
|
||||
strcpy(dir_entry.d_name, mount_name.c_str());
|
||||
dir_entries.push_back(dir_entry);
|
||||
}
|
||||
}
|
||||
|
||||
dir_entries = file::getMountPoints();
|
||||
current_path = path;
|
||||
selected_child_entry = "";
|
||||
action = ActionNone;
|
||||
return true;
|
||||
} else {
|
||||
dir_entries.clear();
|
||||
// TODO: file Lock
|
||||
int count = file::scandir(path, dir_entries, &file::direntFilterDotEntries, file::direntSortAlphaAndType);
|
||||
if (count >= 0) {
|
||||
TT_LOG_I(TAG, "%s has %u entries", path.c_str(), count);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace tt::app::filebrowser {
|
||||
|
||||
#define TAG "filebrowser_app"
|
||||
constexpr auto* TAG = "FileBrowser";
|
||||
|
||||
bool isSupportedExecutableFile(const std::string& filename) {
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
#include "Tactility/app/alertdialog/AlertDialog.h"
|
||||
#include "Tactility/app/imageviewer/ImageViewer.h"
|
||||
#include "Tactility/app/inputdialog/InputDialog.h"
|
||||
#include "Tactility/app/textviewer/TextViewer.h"
|
||||
#include "Tactility/app/notes/Notes.h"
|
||||
#include "Tactility/app/ElfApp.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
|
||||
#include <Tactility/Tactility.h>
|
||||
#include "Tactility/file/File.h"
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
|
||||
#include <cstring>
|
||||
@@ -20,10 +21,10 @@
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
#endif
|
||||
|
||||
#define TAG "filebrowser_app"
|
||||
|
||||
namespace tt::app::filebrowser {
|
||||
|
||||
constexpr auto* TAG = "FileBrowser";
|
||||
|
||||
// region Callbacks
|
||||
|
||||
static void dirEntryListScrollBeginCallback(lv_event_t* event) {
|
||||
@@ -95,10 +96,10 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
||||
imageviewer::start(processed_filepath);
|
||||
} else if (isSupportedTextFile(filename)) {
|
||||
if (kernel::getPlatform() == kernel::PlatformEsp) {
|
||||
textviewer::start(processed_filepath);
|
||||
notes::start(processed_filepath);
|
||||
} else {
|
||||
// Remove forward slash, because we need a relative path
|
||||
textviewer::start(processed_filepath.substr(1));
|
||||
notes::start(processed_filepath.substr(1));
|
||||
}
|
||||
} else {
|
||||
TT_LOG_W(TAG, "opening files of this type is not supported");
|
||||
@@ -163,7 +164,6 @@ void View::onDirEntryLongPressed(int32_t index) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) {
|
||||
tt_check(list);
|
||||
const char* symbol;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace tt::app::fileselection {
|
||||
|
||||
#define TAG "fileselection_app"
|
||||
constexpr auto* TAG = "FileSelection";
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Tactility/file/File.h>
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Partitions.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
|
||||
#include <cstring>
|
||||
@@ -11,10 +11,10 @@
|
||||
#include <vector>
|
||||
#include <dirent.h>
|
||||
|
||||
#define TAG "fileselection_app"
|
||||
|
||||
namespace tt::app::fileselection {
|
||||
|
||||
constexpr auto* TAG = "FileSelection";
|
||||
|
||||
State::State() {
|
||||
if (kernel::getPlatform() == kernel::PlatformSimulator) {
|
||||
char cwd[PATH_MAX];
|
||||
@@ -49,34 +49,7 @@ bool State::setEntriesForPath(const std::string& path) {
|
||||
bool show_custom_root = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/");
|
||||
if (show_custom_root) {
|
||||
TT_LOG_I(TAG, "Setting custom root");
|
||||
dir_entries.clear();
|
||||
dir_entries.push_back(dirent{
|
||||
.d_ino = 0,
|
||||
.d_type = file::TT_DT_DIR,
|
||||
.d_name = SYSTEM_PARTITION_NAME
|
||||
});
|
||||
dir_entries.push_back(dirent{
|
||||
.d_ino = 1,
|
||||
.d_type = file::TT_DT_DIR,
|
||||
.d_name = DATA_PARTITION_NAME
|
||||
});
|
||||
|
||||
auto sdcards = tt::hal::findDevices<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard);
|
||||
for (auto& sdcard : sdcards) {
|
||||
auto state = sdcard->getState();
|
||||
if (state == hal::sdcard::SdCardDevice::State::Mounted) {
|
||||
auto mount_name = sdcard->getMountPath().substr(1);
|
||||
auto dir_entry = dirent {
|
||||
.d_ino = 2,
|
||||
.d_type = file::TT_DT_DIR,
|
||||
.d_name = { 0 }
|
||||
};
|
||||
assert(mount_name.length() < sizeof(dirent::d_name));
|
||||
strcpy(dir_entry.d_name, mount_name.c_str());
|
||||
dir_entries.push_back(dir_entry);
|
||||
}
|
||||
}
|
||||
|
||||
dir_entries = file::getMountPoints();
|
||||
current_path = path;
|
||||
selected_child_entry = "";
|
||||
return true;
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
#endif
|
||||
|
||||
#define TAG "fileselection_app"
|
||||
|
||||
namespace tt::app::fileselection {
|
||||
|
||||
constexpr auto* TAG = "FileSelection";
|
||||
|
||||
// region Callbacks
|
||||
|
||||
static void onDirEntryPressedCallback(lv_event_t* event) {
|
||||
|
||||
@@ -148,7 +148,7 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) {
|
||||
// Add the GPIO number after the last item on a row
|
||||
auto* postfix = lv_label_create(row_wrapper);
|
||||
lv_label_set_text_fmt(postfix, "%02d", i);
|
||||
lv_obj_set_pos(postfix, (int32_t)((column+1) * x_spacing + offset_from_left_label), 0);
|
||||
lv_obj_set_pos(postfix, (column + 1) * x_spacing + offset_from_left_label, 0);
|
||||
|
||||
// Add a new row wrapper underneath the last one
|
||||
auto* new_row_wrapper = createGpioRowWrapper(wrapper);
|
||||
|
||||
@@ -24,8 +24,6 @@ extern const AppManifest manifest;
|
||||
|
||||
class I2cScannerApp : public App {
|
||||
|
||||
private:
|
||||
|
||||
// Core
|
||||
Mutex mutex = Mutex(Mutex::Type::Recursive);
|
||||
std::unique_ptr<Timer> scanTimer = nullptr;
|
||||
@@ -286,7 +284,7 @@ void I2cScannerApp::startScanning() {
|
||||
lv_obj_clean(scanListWidget);
|
||||
|
||||
scanState = ScanStateScanning;
|
||||
scanTimer = std::make_unique<Timer>(Timer::Type::Once, [](){
|
||||
scanTimer = std::make_unique<Timer>(Timer::Type::Once, []{
|
||||
onScanTimerCallback();
|
||||
});
|
||||
scanTimer->start(10);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "Tactility/app/AppContext.h"
|
||||
#include "Tactility/app/ManifestRegistry.h"
|
||||
#include "Tactility/app/AppRegistration.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/Tactility.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/BootProperties.h>
|
||||
|
||||
#define TAG "launcher"
|
||||
|
||||
@@ -54,10 +54,10 @@ static lv_obj_t* createAppButton(lv_obj_t* parent, const char* title, const char
|
||||
class LauncherApp : public App {
|
||||
|
||||
void onCreate(TT_UNUSED AppContext& app) override {
|
||||
auto* config = getConfiguration();
|
||||
if (!config->autoStartAppId.empty()) {
|
||||
TT_LOG_I(TAG, "auto-starting %s", config->autoStartAppId.c_str());
|
||||
service::loader::startApp(config->autoStartAppId);
|
||||
BootProperties boot_properties;
|
||||
if (loadBootProperties(boot_properties) && !boot_properties.autoStartAppId.empty()) {
|
||||
TT_LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
|
||||
service::loader::startApp(boot_properties.autoStartAppId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#include <Tactility/app/AppManifest.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/lvgl/Keyboard.h>
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
#include <Tactility/Assets.h>
|
||||
#include <lvgl.h>
|
||||
#include "Tactility/app/AppManifest.h"
|
||||
#include "Tactility/app/fileselection/FileSelection.h"
|
||||
#include "Tactility/file/FileLock.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
#include "Tactility/Assets.h"
|
||||
|
||||
#include <Tactility/app/fileselection/FileSelection.h>
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/file/File.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::app::notes {
|
||||
|
||||
constexpr const char* TAG = "Notes";
|
||||
constexpr auto* TAG = "Notes";
|
||||
constexpr auto* NOTES_FILE_ARGUMENT = "file";
|
||||
|
||||
class NotesApp : public App {
|
||||
|
||||
@@ -81,7 +83,7 @@ class NotesApp : public App {
|
||||
|
||||
void openFile(const std::string& path) {
|
||||
// We might be reading from the SD card, which could share a SPI bus with other devices (display)
|
||||
hal::sdcard::withSdCardLock<void>(path, [this, path]() {
|
||||
file::withLock<void>(path, [this, path] {
|
||||
auto data = file::readString(path);
|
||||
if (data != nullptr) {
|
||||
auto lock = lvgl::getSyncLock()->asScopedLock();
|
||||
@@ -96,7 +98,7 @@ class NotesApp : public App {
|
||||
|
||||
bool saveFile(const std::string& path) {
|
||||
// We might be writing to SD card, which could share a SPI bus with other devices (display)
|
||||
return hal::sdcard::withSdCardLock<bool>(path, [this, path]() {
|
||||
return file::withLock<bool>(path, [this, path] {
|
||||
if (file::writeString(path, saveBuffer.c_str())) {
|
||||
TT_LOG_I(TAG, "Saved to %s", path.c_str());
|
||||
filePath = path;
|
||||
@@ -109,11 +111,20 @@ class NotesApp : public App {
|
||||
|
||||
#pragma endregion Open_Events_Functions
|
||||
|
||||
void onCreate(AppContext& appContext) override {
|
||||
auto parameters = appContext.getParameters();
|
||||
std::string file_path;
|
||||
if (parameters != nullptr && parameters->optString(NOTES_FILE_ARGUMENT, file_path)) {
|
||||
if (!file_path.empty()) {
|
||||
filePath = file_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
void onShow(AppContext& context, lv_obj_t* parent) override {
|
||||
lv_obj_remove_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lv_obj_t* toolbar = tt::lvgl::toolbar_create(parent, context);
|
||||
lv_obj_t* toolbar = lvgl::toolbar_create(parent, context);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
uiDropDownMenu = lv_dropdown_create(toolbar);
|
||||
@@ -168,9 +179,8 @@ class NotesApp : public App {
|
||||
lv_label_set_text(uiCurrentFileName, "Untitled");
|
||||
lv_obj_align(uiCurrentFileName, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
//TODO: Move this to SD Card?
|
||||
if (!file::findOrCreateDirectory(context.getPaths()->getDataDirectory(), 0777)) {
|
||||
TT_LOG_E(TAG, "Failed to find or create path %s", context.getPaths()->getDataDirectory().c_str());
|
||||
if (!filePath.empty()) {
|
||||
openFile(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,4 +212,9 @@ extern const AppManifest manifest = {
|
||||
.createApp = create<NotesApp>
|
||||
};
|
||||
|
||||
void start(const std::string& filePath) {
|
||||
auto parameters = std::make_shared<Bundle>();
|
||||
parameters->putString(NOTES_FILE_ARGUMENT, filePath);
|
||||
service::loader::startApp(manifest.id, parameters);
|
||||
}
|
||||
} // namespace tt::app::notes
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Tactility/app/ManifestRegistry.h"
|
||||
#include "Tactility/app/AppRegistration.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
#include "Tactility/lvgl/LabelUtils.h"
|
||||
#include "Tactility/lvgl/Style.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#define TAG "text_viewer"
|
||||
#define TEXT_VIEWER_FILE_ARGUMENT "file"
|
||||
|
||||
namespace tt::app::textviewer {
|
||||
|
||||
class TextViewerApp : public App {
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
auto* wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_width(wrapper, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(wrapper, 1);
|
||||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_all(wrapper, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(wrapper);
|
||||
|
||||
auto* label = lv_label_create(wrapper);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
||||
auto parameters = app.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
bool success = false;
|
||||
std::string file_argument;
|
||||
if (parameters->optString(TEXT_VIEWER_FILE_ARGUMENT, file_argument)) {
|
||||
TT_LOG_I(TAG, "Opening %s", file_argument.c_str());
|
||||
if (lvgl::label_set_text_file(label, file_argument.c_str())) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
lv_label_set_text_fmt(label, "Failed to load %s", file_argument.c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.id = "TextViewer",
|
||||
.name = "Text Viewer",
|
||||
.type = Type::Hidden,
|
||||
.createApp = create<TextViewerApp>
|
||||
};
|
||||
|
||||
void start(const std::string& file) {
|
||||
auto parameters = std::make_shared<Bundle>();
|
||||
parameters->putString(TEXT_VIEWER_FILE_ARGUMENT, file);
|
||||
service::loader::startApp(manifest.id, parameters);
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
|
||||
#include <Tactility/Partitions.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
namespace tt::app::timezone {
|
||||
|
||||
#define TAG "timezone_select"
|
||||
constexpr auto* TAG = "TimeZone";
|
||||
|
||||
#define RESULT_BUNDLE_CODE_INDEX "code"
|
||||
#define RESULT_BUNDLE_NAME_INDEX "name"
|
||||
@@ -62,8 +62,7 @@ void setResultCode(Bundle& bundle, const std::string& code) {
|
||||
|
||||
// endregion
|
||||
|
||||
|
||||
class TimeZoneApp : public App {
|
||||
class TimeZoneApp final : public App {
|
||||
|
||||
Mutex mutex;
|
||||
std::vector<TimeZoneEntry> entries;
|
||||
@@ -123,7 +122,7 @@ class TimeZoneApp : public App {
|
||||
}
|
||||
|
||||
void readTimeZones(std::string filter) {
|
||||
auto path = std::string(MOUNT_POINT_SYSTEM) + "/timezones.csv";
|
||||
auto path = std::string(file::MOUNT_POINT_SYSTEM) + "/timezones.csv";
|
||||
auto* file = fopen(path.c_str(), "rb");
|
||||
if (file == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to open %s", path.c_str());
|
||||
@@ -136,7 +135,7 @@ class TimeZoneApp : public App {
|
||||
std::vector<TimeZoneEntry> new_entries;
|
||||
while (fgets(line, 96, file)) {
|
||||
if (parseEntry(line, name, code)) {
|
||||
if (tt::string::lowercase(name).find(filter) != std::string::npos) {
|
||||
if (string::lowercase(name).find(filter) != std::string::npos) {
|
||||
count++;
|
||||
new_entries.push_back({.name = name, .code = code});
|
||||
|
||||
@@ -165,7 +164,7 @@ class TimeZoneApp : public App {
|
||||
|
||||
void updateList() {
|
||||
if (lvgl::lock(100 / portTICK_PERIOD_MS)) {
|
||||
std::string filter = tt::string::lowercase(std::string(lv_textarea_get_text(filterTextareaWidget)));
|
||||
std::string filter = string::lowercase(std::string(lv_textarea_get_text(filterTextareaWidget)));
|
||||
readTimeZones(filter);
|
||||
lvgl::unlock();
|
||||
} else {
|
||||
@@ -227,7 +226,7 @@ public:
|
||||
}
|
||||
|
||||
void onCreate(AppContext& app) override {
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Once, []() { updateTimerCallback(); });
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Once, [] { updateTimerCallback(); });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -44,10 +44,10 @@ static void onToggleAutoConnect(lv_event_t* event) {
|
||||
bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED);
|
||||
std::string ssid = parameters->getString("ssid");
|
||||
|
||||
service::wifi::settings::WifiApSettings settings {};
|
||||
if (service::wifi::settings::load(ssid.c_str(), &settings)) {
|
||||
settings.auto_connect = is_on;
|
||||
if (!service::wifi::settings::save(&settings)) {
|
||||
service::wifi::settings::WifiApSettings settings;
|
||||
if (service::wifi::settings::load(ssid.c_str(), settings)) {
|
||||
settings.autoConnect = is_on;
|
||||
if (!service::wifi::settings::save(settings)) {
|
||||
TT_LOG_E(TAG, "Failed to save settings");
|
||||
}
|
||||
} else {
|
||||
@@ -98,9 +98,9 @@ class WifiApSettings : public App {
|
||||
lv_obj_align(forget_button_label, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_label_set_text(forget_button_label, "Forget");
|
||||
|
||||
service::wifi::settings::WifiApSettings settings {};
|
||||
if (service::wifi::settings::load(ssid.c_str(), &settings)) {
|
||||
if (settings.auto_connect) {
|
||||
service::wifi::settings::WifiApSettings settings;
|
||||
if (service::wifi::settings::load(ssid.c_str(), settings)) {
|
||||
if (settings.autoConnect) {
|
||||
lv_obj_add_state(auto_connect_switch, LV_STATE_CHECKED);
|
||||
} else {
|
||||
lv_obj_remove_state(auto_connect_switch, LV_STATE_CHECKED);
|
||||
|
||||
@@ -17,9 +17,9 @@ bool State::hasConnectionError() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
void State::setApSettings(const service::wifi::settings::WifiApSettings* newSettings) {
|
||||
void State::setApSettings(const service::wifi::settings::WifiApSettings& newSettings) {
|
||||
lock.lock();
|
||||
memcpy(&this->apSettings, newSettings, sizeof(service::wifi::settings::WifiApSettings));
|
||||
this->apSettings = newSettings;
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
#include "Tactility/lvgl/Spinner.h"
|
||||
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <cstring>
|
||||
#include <Tactility/service/wifi/WifiApSettings.h>
|
||||
#include <Tactility/service/wifi/WifiGlobals.h>
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
@@ -50,14 +51,14 @@ static void onConnect(TT_UNUSED lv_event_t* event) {
|
||||
view.setLoading(true);
|
||||
|
||||
service::wifi::settings::WifiApSettings settings;
|
||||
strcpy((char*)settings.password, password);
|
||||
strcpy((char*)settings.ssid, ssid);
|
||||
settings.password = password;
|
||||
settings.ssid = ssid;
|
||||
settings.channel = 0;
|
||||
settings.auto_connect = TT_WIFI_AUTO_CONNECT; // No UI yet, so use global setting:w
|
||||
settings.autoConnect = TT_WIFI_AUTO_CONNECT; // No UI yet, so use global setting:w
|
||||
|
||||
auto* bindings = &wifi->getBindings();
|
||||
bindings->onConnectSsid(
|
||||
&settings,
|
||||
settings,
|
||||
store,
|
||||
bindings->onConnectSsidContext
|
||||
);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
#define TAG "wifi_connect"
|
||||
#define WIFI_CONNECT_PARAM_SSID "ssid" // String
|
||||
#define WIFI_CONNECT_PARAM_PASSWORD "password" // String
|
||||
@@ -37,7 +36,7 @@ static void eventCallback(const void* message, void* context) {
|
||||
wifi->requestViewUpdate();
|
||||
}
|
||||
|
||||
static void onConnect(const service::wifi::settings::WifiApSettings* ap_settings, bool remember, TT_UNUSED void* parameter) {
|
||||
static void onConnect(const service::wifi::settings::WifiApSettings& ap_settings, bool remember, TT_UNUSED void* parameter) {
|
||||
auto* wifi = static_cast<WifiConnect*>(parameter);
|
||||
wifi->getState().setApSettings(ap_settings);
|
||||
wifi->getState().setConnecting(true);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <format>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
|
||||
namespace tt::app::wifimanage {
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ extern const AppManifest manifest;
|
||||
|
||||
static void onConnect(const char* ssid) {
|
||||
service::wifi::settings::WifiApSettings settings;
|
||||
if (service::wifi::settings::load(ssid, &settings)) {
|
||||
if (service::wifi::settings::load(ssid, settings)) {
|
||||
TT_LOG_I(TAG, "Connecting with known credentials");
|
||||
service::wifi::connect(&settings, false);
|
||||
service::wifi::connect(settings, false);
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Starting connection dialog");
|
||||
wificonnect::start(ssid);
|
||||
|
||||
Reference in New Issue
Block a user