Merge develop into main (#305)

## New features

- Implement translations for apps
- Created `tt::settings::setLanguage` and `::getLanguage()`
- External app errors are now reported to the user via an AlertDialog
- Store system settings in `/data/settings.properties`
- Created a "Region & Language" app and moved the timezone setting there.

## Other changes

- Change `/data` and `/system` filesystem sector size from 4096 to 512 bytes to allow for more small files (60+ files of 4kB were over the limit of 256kB for the filesystem)
- Increased size of `/data` and `/system`
- Moved `tt::time::*` to `tt::settings`
- Removed the timezone setting from the "Time & Date" setting app
- Reverse encoder direction of Lilygo T-Lora Pager
- Improved partability of `Time.cpp` (removed separate set of functions for PC/sim)
This commit is contained in:
Ken Van Hoeylandt
2025-08-28 21:50:29 +02:00
committed by GitHub
parent ee5a5a7181
commit 8c8ccd8783
73 changed files with 1114 additions and 219 deletions
+41 -21
View File
@@ -12,6 +12,7 @@
#include <string>
#include <utility>
#include <Tactility/app/alertdialog/AlertDialog.h>
namespace tt::app {
@@ -39,10 +40,18 @@ class ElfApp : public App {
const std::string filePath;
std::unique_ptr<uint8_t[]> elfFileData;
esp_elf_t elf;
esp_elf_t elf {
.psegment = nullptr,
.svaddr = 0,
.ptext = nullptr,
.pdata = nullptr,
.sec = { },
.entry = nullptr
};
bool shouldCleanupElf = false; // Whether we have to clean up the above "elf" object
std::unique_ptr<ElfManifest> manifest;
void* data = nullptr;
std::string lastError = "";
bool startElf() {
TT_LOG_I(TAG, "Starting ELF %s", filePath.c_str());
@@ -58,14 +67,17 @@ class ElfApp : public App {
}
if (esp_elf_init(&elf) != ESP_OK) {
TT_LOG_E(TAG, "Failed to initialize");
lastError = "Failed to initialize";
TT_LOG_E(TAG, "%s", lastError.c_str());
elfFileData = nullptr;
return false;
}
if (esp_elf_relocate(&elf, elfFileData.get()) != ESP_OK) {
TT_LOG_E(TAG, "Failed to load executable");
esp_elf_deinit(&elf);
auto relocate_result = esp_elf_relocate(&elf, elfFileData.get());
if (relocate_result != 0) {
// Note: the result code mapes to values from cstdlib's errno.h
lastError = std::format("Failed to load executable (error code {})", -relocate_result);
TT_LOG_E(TAG, "%s", lastError.c_str());
elfFileData = nullptr;
return false;
}
@@ -74,7 +86,8 @@ class ElfApp : public App {
char* argv[] = {};
if (esp_elf_request(&elf, 0, argc, argv) != ESP_OK) {
TT_LOG_W(TAG, "Executable returned error code");
lastError = "Executable returned error code";
TT_LOG_E(TAG, "%s", lastError.c_str());
esp_elf_deinit(&elf);
elfFileData = nullptr;
return false;
@@ -106,22 +119,29 @@ public:
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();
}
if (manifest->onCreate != nullptr) {
manifest->onCreate(&appContext, data);
}
}
} else {
elfManifestSetCount = 0;
if (!startElf()) {
service::loader::stopApp();
auto message = lastError.empty() ? "Application failed to start." : std::format("Application failed to start: {}", lastError);
alertdialog::start("Error", message);
return;
}
if (elfManifestSetCount == 0) {
service::loader::stopApp();
alertdialog::start("Error", "Application failed to start: application failed to register itself");
return;
}
manifest = std::make_unique<ElfManifest>(elfManifest);
lock.unlock();
if (manifest->createData != nullptr) {
data = manifest->createData();
}
if (manifest->onCreate != nullptr) {
manifest->onCreate(&appContext, data);
}
}
+14 -5
View File
@@ -1,4 +1,5 @@
#include "Tactility/app/AppContext.h"
#include "Tactility/app/launcher/TextResources.h"
#include "Tactility/app/AppRegistration.h"
#include "Tactility/service/loader/Loader.h"
@@ -7,10 +8,10 @@
#include <lvgl.h>
#include <Tactility/BootProperties.h>
#define TAG "launcher"
namespace tt::app::launcher {
constexpr auto* TAG = "Launcher";
static void onAppPressed(TT_UNUSED lv_event_t* e) {
auto* appId = (const char*)lv_event_get_user_data(e);
service::loader::startApp(appId);
@@ -52,6 +53,7 @@ static lv_obj_t* createAppButton(lv_obj_t* parent, const char* title, const char
}
class LauncherApp : public App {
tt::i18n::TextResources textResources = tt::i18n::TextResources("/system/app/Launcher/i18n");
void onCreate(TT_UNUSED AppContext& app) override {
BootProperties boot_properties;
@@ -62,6 +64,8 @@ class LauncherApp : public App {
}
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
textResources.load();
auto* wrapper = lv_obj_create(parent);
lv_obj_align(wrapper, LV_ALIGN_CENTER, 0, 0);
@@ -87,9 +91,14 @@ class LauncherApp : public App {
auto apps_icon_path = paths->getSystemPathLvgl("icon_apps.png");
auto files_icon_path = paths->getSystemPathLvgl("icon_files.png");
auto settings_icon_path = paths->getSystemPathLvgl("icon_settings.png");
createAppButton(wrapper, "Apps", apps_icon_path.c_str(), "AppList", 0);
createAppButton(wrapper, "Files", files_icon_path.c_str(), "Files", padding);
createAppButton(wrapper, "Settings", settings_icon_path.c_str(), "Settings", padding);
const auto& apps_title = textResources[i18n::Text::APPS];
const auto& files_title = textResources[i18n::Text::FILES];
const auto& settings_title = textResources[i18n::Text::SETTINGS];
createAppButton(wrapper, apps_title.c_str(), apps_icon_path.c_str(), "AppList", 0);
createAppButton(wrapper, files_title.c_str(), files_icon_path.c_str(), "Files", padding);
createAppButton(wrapper, settings_title.c_str(), settings_icon_path.c_str(), "Settings", padding);
}
};
@@ -0,0 +1,168 @@
#include <Tactility/Assets.h>
#include <Tactility/app/timezone/TimeZone.h>
#include <Tactility/app/localesettings/TextResources.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/Time.h>
#include <lvgl.h>
#include <map>
#include <sstream>
#include <Tactility/StringUtils.h>
#include <Tactility/settings/Language.h>
namespace tt::app::localesettings {
constexpr auto* TAG = "LocaleSettings";
extern const AppManifest manifest;
class LocaleSettingsApp : public App {
tt::i18n::TextResources textResources = tt::i18n::TextResources("/system/app/LocaleSettings/i18n");
Mutex mutex = Mutex(Mutex::Type::Recursive);
lv_obj_t* timeZoneLabel = nullptr;
lv_obj_t* regionLabel = nullptr;
lv_obj_t* languageDropdown = nullptr;
lv_obj_t* languageLabel = nullptr;
static void onConfigureTimeZonePressed(TT_UNUSED lv_event_t* event) {
timezone::start();
}
std::map<settings::Language, std::string> languageMap;
std::string getLanguageOptions() const {
std::vector<std::string> items;
for (int i = 0; i < static_cast<int>(settings::Language::count); i++) {
switch (static_cast<settings::Language>(i)) {
case settings::Language::en_GB:
items.push_back(textResources[i18n::Text::EN_GB]);
break;
case settings::Language::en_US:
items.push_back(textResources[i18n::Text::EN_US]);
break;
case settings::Language::fr_FR:
items.push_back(textResources[i18n::Text::FR_FR]);
break;
case settings::Language::nl_BE:
items.push_back(textResources[i18n::Text::NL_BE]);
break;
case settings::Language::nl_NL:
items.push_back(textResources[i18n::Text::NL_NL]);
break;
case settings::Language::count:
break;
}
}
return string::join(items, "\n");
}
void updateViews() {
textResources.load();
lv_label_set_text(regionLabel , textResources[i18n::Text::REGION].c_str());
lv_label_set_text(languageLabel, textResources[i18n::Text::LANGUAGE].c_str());
std::string language_options = getLanguageOptions();
lv_dropdown_set_options(languageDropdown, language_options.c_str());
lv_dropdown_set_selected(languageDropdown, static_cast<uint32_t>(settings::getLanguage()));
}
static void onLanguageSet(lv_event_t* event) {
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto index = lv_dropdown_get_selected(dropdown);
auto language = static_cast<settings::Language>(index);
settings::setLanguage(language);
auto* self = static_cast<LocaleSettingsApp*>(lv_event_get_user_data(event));
self->updateViews();
}
public:
void onShow(AppContext& app, lv_obj_t* parent) override {
textResources.load();
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lvgl::toolbar_create(parent, app);
auto* main_wrapper = lv_obj_create(parent);
lv_obj_set_flex_flow(main_wrapper, LV_FLEX_FLOW_COLUMN);
lv_obj_set_width(main_wrapper, LV_PCT(100));
lv_obj_set_flex_grow(main_wrapper, 1);
auto* region_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_width(region_wrapper, LV_PCT(100));
lv_obj_set_height(region_wrapper, LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(region_wrapper, 0, 0);
lv_obj_set_style_border_width(region_wrapper, 0, 0);
regionLabel = lv_label_create(region_wrapper);
lv_label_set_text(regionLabel , textResources[i18n::Text::REGION].c_str());
lv_obj_align(regionLabel , LV_ALIGN_LEFT_MID, 0, 0);
timeZoneLabel = lv_label_create(region_wrapper);
std::string timeZoneName = settings::getTimeZoneName();
if (timeZoneName.empty()) {
timeZoneName = "not set";
}
lv_label_set_text(timeZoneLabel, timeZoneName.c_str());
// TODO: Find out why Y offset is needed
lv_obj_align_to(timeZoneLabel, regionLabel, LV_ALIGN_OUT_RIGHT_MID, 10, 8);
auto* region_button = lv_button_create(region_wrapper);
lv_obj_align(region_button, LV_ALIGN_TOP_RIGHT, 0, 0);
auto* region_button_image = lv_image_create(region_button);
lv_obj_add_event_cb(region_button, onConfigureTimeZonePressed, LV_EVENT_SHORT_CLICKED, nullptr);
lv_image_set_src(region_button_image, LV_SYMBOL_SETTINGS);
auto* language_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_width(language_wrapper, LV_PCT(100));
lv_obj_set_height(language_wrapper, LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(language_wrapper, 0, 0);
lv_obj_set_style_border_width(language_wrapper, 0, 0);
languageLabel = lv_label_create(language_wrapper);
lv_label_set_text(languageLabel, textResources[i18n::Text::LANGUAGE].c_str());
lv_obj_align(languageLabel, LV_ALIGN_LEFT_MID, 0, 0);
languageDropdown = lv_dropdown_create(language_wrapper);
lv_obj_align(languageDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
std::string language_options = getLanguageOptions();
lv_dropdown_set_options(languageDropdown, language_options.c_str());
lv_dropdown_set_selected(languageDropdown, static_cast<uint32_t>(settings::getLanguage()));
lv_obj_add_event_cb(languageDropdown, onLanguageSet, LV_EVENT_VALUE_CHANGED, this);
}
void onResult(AppContext& app, TT_UNUSED LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
if (result == Result::Ok && bundle != nullptr) {
const auto name = timezone::getResultName(*bundle);
const auto code = timezone::getResultCode(*bundle);
TT_LOG_I(TAG, "Result name=%s code=%s", name.c_str(), code.c_str());
settings::setTimeZone(name, code);
if (!name.empty()) {
if (lvgl::lock(100 / portTICK_PERIOD_MS)) {
lv_label_set_text(timeZoneLabel, name.c_str());
lvgl::unlock();
}
}
}
}
};
extern const AppManifest manifest = {
.id = "LocaleSettings",
.name = "Region & Language",
.icon = TT_ASSETS_APP_ICON_TIME_DATE_SETTINGS,
.type = Type::Settings,
.createApp = create<LocaleSettingsApp>
};
void start() {
service::loader::startApp(manifest.id);
}
} // namespace
@@ -1,33 +1,25 @@
#include "Tactility/app/timezone/TimeZone.h"
#include "Tactility/lvgl/Toolbar.h"
#include "Tactility/service/loader/Loader.h"
#include "Tactility/lvgl/LvglSync.h"
#include <Tactility/Assets.h>
#include <Tactility/time/Time.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/Time.h>
#include <lvgl.h>
#define TAG "text_viewer"
namespace tt::app::timedatesettings {
constexpr auto* TAG = "TimeDate";
extern const AppManifest manifest;
class TimeDateSettingsApp : public App {
private:
Mutex mutex = Mutex(Mutex::Type::Recursive);
lv_obj_t* regionLabelWidget = nullptr;
static void onConfigureTimeZonePressed(TT_UNUSED lv_event_t* event) {
timezone::start();
}
static void onTimeFormatChanged(lv_event_t* event) {
auto* widget = lv_event_get_target_obj(event);
bool show_24 = lv_obj_has_state(widget, LV_STATE_CHECKED);
time::setTimeFormat24Hour(show_24);
settings::setTimeFormat24Hour(show_24);
}
public:
@@ -42,32 +34,6 @@ public:
lv_obj_set_width(main_wrapper, LV_PCT(100));
lv_obj_set_flex_grow(main_wrapper, 1);
auto* region_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_width(region_wrapper, LV_PCT(100));
lv_obj_set_height(region_wrapper, LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(region_wrapper, 0, 0);
lv_obj_set_style_border_width(region_wrapper, 0, 0);
auto* region_prefix_label = lv_label_create(region_wrapper);
lv_label_set_text(region_prefix_label, "Region: ");
lv_obj_align(region_prefix_label, LV_ALIGN_LEFT_MID, 0, 0);
auto* region_label = lv_label_create(region_wrapper);
std::string timeZoneName = time::getTimeZoneName();
if (timeZoneName.empty()) {
timeZoneName = "not set";
}
regionLabelWidget = region_label;
lv_label_set_text(region_label, timeZoneName.c_str());
// TODO: Find out why Y offset is needed
lv_obj_align_to(region_label, region_prefix_label, LV_ALIGN_OUT_RIGHT_MID, 0, 8);
auto* region_button = lv_button_create(region_wrapper);
lv_obj_align(region_button, LV_ALIGN_TOP_RIGHT, 0, 0);
auto* region_button_image = lv_image_create(region_button);
lv_obj_add_event_cb(region_button, onConfigureTimeZonePressed, LV_EVENT_SHORT_CLICKED, nullptr);
lv_image_set_src(region_button_image, LV_SYMBOL_SETTINGS);
auto* time_format_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_width(time_format_wrapper, LV_PCT(100));
lv_obj_set_height(time_format_wrapper, LV_SIZE_CONTENT);
@@ -81,28 +47,12 @@ public:
auto* time_24h_switch = lv_switch_create(time_format_wrapper);
lv_obj_align(time_24h_switch, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(time_24h_switch, onTimeFormatChanged, LV_EVENT_VALUE_CHANGED, nullptr);
if (time::isTimeFormat24Hour()) {
if (settings::isTimeFormat24Hour()) {
lv_obj_add_state(time_24h_switch, LV_STATE_CHECKED);
} else {
lv_obj_remove_state(time_24h_switch, LV_STATE_CHECKED);
}
}
void onResult(AppContext& app, TT_UNUSED LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
if (result == Result::Ok && bundle != nullptr) {
auto name = timezone::getResultName(*bundle);
auto code = timezone::getResultCode(*bundle);
TT_LOG_I(TAG, "Result name=%s code=%s", name.c_str(), code.c_str());
time::setTimeZone(name, code);
if (!name.empty()) {
if (lvgl::lock(100 / portTICK_PERIOD_MS)) {
lv_label_set_text(regionLabelWidget, name.c_str());
lvgl::unlock();
}
}
}
}
};
extern const AppManifest manifest = {