Merge develop into main (#337)

- Implement `UiScale` in `hal::Configuration`: small screens with no touch can now opt for a more optimized experience (e.g. Cardputer, Waveshare 1.47, Waveshare 1.3", etc.)
- Fix for Cardputer UART configuration and added I2C configuration
- Fix for software keyboard bug in Gui
- Removed deprecated fields from `hal::Configuration`
- Updated the simulator devices to use the new HAL config
- add `bool tt::hal::hasDevice(Device::Type)`
- Cleanup of `AppList` app code
- Improve `Gpio` app for small screen devices
- Added various ESP32 GCC wrappers to wrap LVGL functions (with manipulations for small screen devices)
- Moved `Launcher` assets to `assets/` subfolder
- Optimized `Toolbar` for small screen devices
- Stop showing `system/` partition in `FileBrowser` because it's read-only and not very useful. Created `config::SHOW_SYSTEM_PARTITION` to override this behaviour.
- Hide apps when their required hardware isn't available (I2C, UART, PowerDevice)
- Fix for `CYD-2432S032C` DPI setting
This commit is contained in:
Ken Van Hoeylandt 2025-09-15 22:46:12 +02:00 committed by GitHub
parent ce8ac61d42
commit 53b711584f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
43 changed files with 414 additions and 209 deletions

View File

@ -25,7 +25,27 @@ static DeviceVector createDevices() {
extern const Configuration m5stack_cardputer = {
.initBoot = initBoot,
.uiScale = UiScale::Smallest,
.createDevices = createDevices,
.i2c {
i2c::Configuration {
.name = "Port A", // Grove
.port = I2C_NUM_1,
.initMode = i2c::InitMode::Disabled,
.isMutable = true,
.config = (i2c_config_t) {
.mode = I2C_MODE_MASTER,
.sda_io_num = GPIO_NUM_2,
.scl_io_num = GPIO_NUM_1,
.sda_pullup_en = true,
.scl_pullup_en = true,
.master = {
.clk_speed = 400000
},
.clk_flags = 0
}
},
},
.spi {
// Display
spi::Configuration {
@ -79,10 +99,10 @@ extern const Configuration m5stack_cardputer = {
},
.uart {
uart::Configuration {
.name = "Grove",
.name = "Port A",
.port = UART_NUM_1,
.rxPin = GPIO_NUM_32,
.txPin = GPIO_NUM_33,
.rxPin = GPIO_NUM_2,
.txPin = GPIO_NUM_1,
.rtsPin = GPIO_NUM_NC,
.ctsPin = GPIO_NUM_NC,
.rxBufferSize = 1024,
@ -100,6 +120,6 @@ extern const Configuration m5stack_cardputer = {
.backup_before_sleep = 0,
}
}
},
}
}
};

View File

@ -28,12 +28,18 @@ TT_UNUSED static void deinitPower() {
#endif
}
static std::vector<std::shared_ptr<Device>> createDevices() {
return {
std::make_shared<SdlDisplay>(),
std::make_shared<SdlKeyboard>(),
std::make_shared<SimulatorPower>(),
std::make_shared<SimulatorSdCard>()
};
}
extern const Configuration hardware = {
.initBoot = initBoot,
.createDisplay = createDisplay,
.createKeyboard = createKeyboard,
.sdcard = std::make_shared<SimulatorSdCard>(),
.power = simulatorPower,
.createDevices = createDevices,
.i2c = {
i2c::Configuration {
.name = "Internal",

View File

@ -26,8 +26,3 @@ public:
bool supportsDisplayDriver() const override { return false; }
std::shared_ptr<tt::hal::display::DisplayDriver> _Nullable getDisplayDriver() override { return nullptr; }
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
return std::make_shared<SdlDisplay>();
}

View File

@ -23,7 +23,3 @@ public:
lv_indev_t* _Nullable getLvglIndev() override { return handle; }
};
std::shared_ptr<tt::hal::keyboard::KeyboardDevice> createKeyboard() {
return std::make_shared<SdlKeyboard>();
}

View File

@ -1,6 +1,6 @@
#include "SimulatorPower.h"
#define TAG "simulator_power"
constexpr auto* TAG = "SimulatorPower";
bool SimulatorPower::supportsMetric(MetricType type) const {
switch (type) {
@ -34,13 +34,3 @@ bool SimulatorPower::getMetric(MetricType type, MetricData& data) {
return false; // Safety guard for when new enum values are introduced
}
static std::shared_ptr<PowerDevice> power;
std::shared_ptr<PowerDevice> simulatorPower() {
if (power == nullptr) {
power = std::make_shared<SimulatorPower>();
}
return power;
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "Tactility/hal/power/PowerDevice.h"
#include <Tactility/hal/power/PowerDevice.h>
#include <memory>
using tt::hal::power::PowerDevice;
@ -14,8 +14,8 @@ public:
SimulatorPower() = default;
~SimulatorPower() override = default;
std::string getName() const final { return "Power Mock"; }
std::string getDescription() const final { return ""; }
std::string getName() const override { return "Power Mock"; }
std::string getDescription() const override { return ""; }
bool supportsMetric(MetricType type) const override;
bool getMetric(MetricType type, MetricData& data) override;
@ -24,5 +24,3 @@ public:
bool isAllowedToCharge() const override { return allowedToCharge; }
void setAllowedToCharge(bool canCharge) override { allowedToCharge = canCharge; }
};
std::shared_ptr<PowerDevice> simulatorPower();

View File

@ -20,6 +20,7 @@ static bool initBoot() {
extern const Configuration waveshare_s3_lcd_13 = {
.initBoot = initBoot,
.uiScale = UiScale::Smallest,
.createDevices = createDevices,
.i2c = {
//IMU

View File

@ -13,6 +13,7 @@ static DeviceVector createDevices() {
}
extern const Configuration waveshare_s3_touch_43 = {
.uiScale = UiScale::Smallest,
.createDevices = createDevices,
.i2c = {
// There is only 1 (internal for touch, and also serves as "I2C-OUT" port)

View File

@ -22,6 +22,7 @@ static bool initBoot() {
extern const Configuration waveshare_s3_touch_lcd_128 = {
.initBoot = initBoot,
.uiScale = UiScale::Smallest,
.createDevices = createDevices,
.i2c = {
i2c::Configuration {

View File

@ -19,6 +19,7 @@ static std::vector<std::shared_ptr<Device>> createDevices() {
extern const Configuration waveshare_s3_touch_lcd_147 = {
.initBoot = initBoot,
.uiScale = UiScale::Smallest,
.createDevices = createDevices,
.i2c = {
i2c::Configuration {

View File

@ -56,7 +56,15 @@ if (DEFINED ENV{ESP_IDF_VERSION})
add_compile_definitions(LV_CONF_PATH="${LVGL_CONFIG_FULL_PATH}/lv_conf_kconfig.h")
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_log_write" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_button_create" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_dropdown_create" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_list_create" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_list_add_button" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_obj_create" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_obj_set_flex_flow" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_switch_create" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_textarea_create" APPEND)
else ()
message("Building for sim target")
add_compile_definitions(CONFIG_TT_BOARD_ID="simulator")

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -32,9 +32,11 @@
- Toolbar: when the title doesn't fit, scroll the text instead of splitting it onto a new line (try on Waveshare 1.47")
- UI: create UI size classification (e.g. "compact" for tiny screens without touch)
- Bug: Crash handling app cannot be exited with an EncoderDevice. (current work-around is to manually reset the device)
- I2C app should show error when I2C port is disabled when the scan button was manually pressed
## Lower Priority
- Implement system suspend that turns off the screen
- The boot button on some devices can be used as GPIO_NUM_0 at runtime
- Localize all apps
- Support hot-plugging SD card (note: this is not possible if they require the CS pin hack)
@ -53,6 +55,10 @@
- Show a warning screen if firmware encryption or secure boot are off when saving WiFi credentials.
- Remove flex_flow from app_container in Gui.cpp
- Files app: copy/cut/paste actions
- ElfAppManifest: change name (remove "manifest" as it's confusing), remove icon and title, publish snapshot SDK on CDN
- `UiScale` implementation for devices like the CYD 2432S032C
- Bug: CYD 2432S032C screen rotation fails due to touch driver issue
- Calculator app should show regular text input field on non-touch devices that have a keyboard (Cardputer, T-Lora Pager)
# Nice-to-haves

View File

@ -16,7 +16,7 @@ class EstimatedPower final : public PowerDevice {
public:
EstimatedPower(ChargeFromAdcVoltage::Configuration configuration) :
explicit EstimatedPower(ChargeFromAdcVoltage::Configuration configuration) :
chargeFromAdcVoltage(std::make_unique<ChargeFromAdcVoltage>(std::move(configuration))) {}
std::string getName() const override { return "ADC Power Measurement"; }

View File

@ -33,7 +33,17 @@ void run(const Configuration& config);
*/
const Configuration* _Nullable getConfiguration();
/** Provides access to the dispatcher that runs on the main task.
* @warning This dispatcher is used for WiFi and might block for some time during WiFi connection.
* @return the dispatcher
*/
Dispatcher& getMainDispatcher();
} // namespace
namespace hal {
/** While technically this configuration is nullable, it's never null after initHeadless() is called. */
const Configuration* _Nullable getConfiguration();
} // namespace hal
} // namespace tt

View File

@ -11,3 +11,9 @@
#else // Sim
#define TT_FEATURE_SCREENSHOT_ENABLED true
#endif
namespace tt::config {
constexpr auto SHOW_SYSTEM_PARTITION = false;
}

View File

@ -1,26 +0,0 @@
#pragma once
#include "Tactility/hal/Configuration.h"
#include <Tactility/TactilityCore.h>
#include <Tactility/Dispatcher.h>
namespace tt {
/** Initialize the hardware and started the internal services. */
void initHeadless(const hal::Configuration& config);
/** Provides access to the dispatcher that runs on the main task.
* @warning This dispatcher is used for WiFi and might block for some time during WiFi connection.
* @return the dispatcher
*/
Dispatcher& getMainDispatcher();
} // namespace
namespace tt::hal {
/** While technically this configuration is nullable, it's never null after initHeadless() is called. */
const Configuration* _Nullable getConfiguration();
} // namespace

View File

@ -9,14 +9,6 @@ namespace tt::hal {
typedef bool (*InitBoot)();
namespace display { class DisplayDevice; }
namespace keyboard { class KeyboardDevice; }
namespace power { class PowerDevice; }
typedef std::shared_ptr<display::DisplayDevice> (*CreateDisplay)();
typedef std::shared_ptr<keyboard::KeyboardDevice> (*CreateKeyboard)();
typedef std::shared_ptr<power::PowerDevice> (*CreatePower)();
typedef std::vector<std::shared_ptr<Device>> DeviceVector;
typedef std::shared_ptr<Device> (*CreateDevice)();
@ -26,6 +18,14 @@ enum class LvglInit {
None
};
/** Affects LVGL widget style */
enum class UiScale {
/** Ideal for very small non-touch screen devices (e.g. Waveshare S3 LCD 1.3") */
Smallest,
/** Nothing was changed in the LVGL UI/UX */
Default
};
struct Configuration {
/**
* Called before I2C/SPI/etc is initialized.
@ -36,21 +36,8 @@ struct Configuration {
/** Init behaviour: default (esp_lvgl_port for ESP32, nothing for PC) or None (nothing on any platform). Only used in Tactility, not in TactilityHeadless. */
const LvglInit lvglInit = LvglInit::Default;
/** Display HAL functionality. */
[[deprecated("use createDevices")]]
const CreateDisplay _Nullable createDisplay = nullptr;
/** Keyboard HAL functionality. */
[[deprecated("use createDevices")]]
const CreateKeyboard _Nullable createKeyboard = nullptr;
/** An optional SD card interface. */
[[deprecated("use createDevices")]]
const std::shared_ptr<sdcard::SdCardDevice> _Nullable sdcard = nullptr;
/** An optional power interface for battery or other power delivery. */
[[deprecated("use createDevices")]]
const CreatePower _Nullable power = nullptr;
/** Modify LVGL widget size */
const UiScale uiScale = UiScale::Default;
std::function<DeviceVector()> createDevices = [] { return std::vector<std::shared_ptr<Device>>(); };

View File

@ -8,7 +8,6 @@
#include <cassert>
namespace tt::hal {
/** Base class for HAL-related devices. */
class Device {
@ -119,4 +118,7 @@ std::shared_ptr<DeviceType> findFirstDevice(Device::Type type) {
}
}
/** @return true if there are 1 or more devices of the specified type */
bool hasDevice(Device::Type type);
}

View File

@ -1,12 +1,12 @@
#pragma once
#include "../app/AppContext.h"
#include "Tactility/Tactility.h"
#include <lvgl.h>
namespace tt::lvgl {
#define TOOLBAR_HEIGHT 40
#define TOOLBAR_TITLE_FONT_HEIGHT 18
#define TOOLBAR_ACTION_LIMIT 4
/** Create a toolbar widget that shows the app name as title */

View File

@ -1,4 +1,6 @@
#include "Tactility/MountPoints.h"
#include "Tactility/TactilityConfig.h"
#include "Tactility/hal/Device.h"
#include "Tactility/hal/sdcard/SdCardDevice.h"
@ -14,15 +16,6 @@ std::vector<dirent> getMountPoints() {
std::vector<dirent> dir_entries;
dir_entries.clear();
// System partition
auto system_dirent = dirent{
.d_ino = 0,
.d_type = TT_DT_DIR,
.d_name = { 0 }
};
strcpy(system_dirent.d_name, SYSTEM_PARTITION_NAME);
dir_entries.push_back(system_dirent);
// Data partition
auto data_dirent = dirent{
.d_ino = 1,
@ -49,6 +42,17 @@ std::vector<dirent> getMountPoints() {
}
}
if (config::SHOW_SYSTEM_PARTITION) {
// System partition
auto system_dirent = dirent{
.d_ino = 0,
.d_type = TT_DT_DIR,
.d_name = { 0 }
};
strcpy(system_dirent.d_name, SYSTEM_PARTITION_NAME);
dir_entries.push_back(system_dirent);
}
return dir_entries;
}

View File

@ -98,7 +98,6 @@ namespace app {
// List of all apps excluding Boot app (as Boot app calls this function indirectly)
static void registerSystemApps() {
addApp(app::addgps::manifest);
addApp(app::alertdialog::manifest);
addApp(app::applist::manifest);
addApp(app::calculator::manifest);
@ -106,26 +105,25 @@ static void registerSystemApps() {
addApp(app::filebrowser::manifest);
addApp(app::fileselection::manifest);
addApp(app::gpio::manifest);
addApp(app::gpssettings::manifest);
addApp(app::i2cscanner::manifest);
addApp(app::i2csettings::manifest);
addApp(app::imageviewer::manifest);
addApp(app::inputdialog::manifest);
addApp(app::launcher::manifest);
addApp(app::localesettings::manifest);
addApp(app::log::manifest);
addApp(app::notes::manifest);
addApp(app::serialconsole::manifest);
addApp(app::settings::manifest);
addApp(app::selectiondialog::manifest);
addApp(app::systeminfo::manifest);
addApp(app::timedatesettings::manifest);
addApp(app::timezone::manifest);
addApp(app::usbsettings::manifest);
addApp(app::wifiapsettings::manifest);
addApp(app::wificonnect::manifest);
addApp(app::wifimanage::manifest);
#if defined(CONFIG_TINYUSB_MSC_ENABLED) && CONFIG_TINYUSB_MSC_ENABLED
addApp(app::usbsettings::manifest);
#endif
#if TT_FEATURE_SCREENSHOT_ENABLED
addApp(app::screenshot::manifest);
#endif
@ -136,7 +134,18 @@ static void registerSystemApps() {
addApp(app::development::manifest);
#endif
if (hal::findDevices(hal::Device::Type::Power).size() > 0) {
if (!hal::getConfiguration()->i2c.empty()) {
addApp(app::i2cscanner::manifest);
addApp(app::i2csettings::manifest);
}
if (!hal::getConfiguration()->uart.empty()) {
addApp(app::addgps::manifest);
addApp(app::gpssettings::manifest);
addApp(app::serialconsole::manifest);
}
if (hal::hasDevice(hal::Device::Type::Power)) {
addApp(app::power::manifest);
}
}

View File

@ -3,18 +3,14 @@
#include "Tactility/lvgl/Toolbar.h"
#include <Tactility/Assets.h>
#include <Tactility/Check.h>
#include <lvgl.h>
#include <algorithm>
namespace tt::app::applist {
class AppListApp : public App {
private:
static void onAppPressed(lv_event_t* e) {
const auto* manifest = static_cast<const AppManifest*>(lv_event_get_user_data(e));
service::loader::startApp(manifest->id);
@ -23,7 +19,7 @@ private:
static void createAppWidget(const std::shared_ptr<AppManifest>& manifest, lv_obj_t* list) {
const void* icon = !manifest->icon.empty() ? manifest->icon.c_str() : TT_ASSETS_APP_ICON_FALLBACK;
lv_obj_t* btn = lv_list_add_button(list, icon, manifest->name.c_str());
lv_obj_add_event_cb(btn, &onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)manifest.get());
lv_obj_add_event_cb(btn, &onAppPressed, LV_EVENT_SHORT_CLICKED, manifest.get());
}
public:
@ -41,7 +37,7 @@ public:
lv_obj_set_height(list, parent_content_height - toolbar_height);
auto manifests = getApps();
std::sort(manifests.begin(), manifests.end(), SortAppManifestByName);
std::ranges::sort(manifests, SortAppManifestByName);
for (const auto& manifest: manifests) {
if (manifest->type == Type::User || manifest->type == Type::System) {
@ -51,7 +47,6 @@ public:
}
};
extern const AppManifest manifest = {
.id = "AppList",
.name = "Apps",

View File

@ -101,10 +101,20 @@ void GpioApp::stopTask() {
// endregion Task
static int getSquareSpacing(hal::UiScale uiScale) {
if (uiScale == hal::UiScale::Smallest) {
return 0;
} else {
return 4;
}
}
void GpioApp::onShow(AppContext& app, lv_obj_t* parent) {
auto ui_scale = hal::getConfiguration()->uiScale;
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
auto* toolbar = lvgl::toolbar_create(parent, app);
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
@ -113,13 +123,16 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) {
lv_obj_set_width(wrapper, LV_PCT(100));
lv_obj_set_flex_grow(wrapper, 1);
lv_obj_set_style_border_width(wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_pad_all(wrapper, 0, LV_STATE_DEFAULT);
auto* display = lv_obj_get_display(parent);
auto horizontal_px = lv_display_get_horizontal_resolution(display);
auto vertical_px = lv_display_get_vertical_resolution(display);
bool is_landscape_display = horizontal_px > vertical_px;
int32_t x_spacing = 20;
constexpr auto block_width = 16;
const auto square_spacing = getSquareSpacing(ui_scale);
int32_t x_spacing = block_width + square_spacing;
uint8_t column = 0;
const uint8_t offset_from_left_label = 4;
const uint8_t column_limit = is_landscape_display ? 10 : 5;
@ -138,7 +151,7 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) {
// Add a new GPIO status indicator
auto* status_label = lv_label_create(row_wrapper);
lv_obj_set_pos(status_label, (int32_t)((column+1) * x_spacing + offset_from_left_label), 0);
lv_obj_set_pos(status_label, (column+1) * x_spacing + offset_from_left_label, 0);
lv_label_set_text_fmt(status_label, "%s", LV_SYMBOL_STOP);
lv_obj_set_style_text_color(status_label, lv_color_background_darkest(), LV_STATE_DEFAULT);
lvPins[i] = status_label;
@ -153,7 +166,7 @@ void GpioApp::onShow(AppContext& app, lv_obj_t* parent) {
// Add a new row wrapper underneath the last one
auto* new_row_wrapper = createGpioRowWrapper(wrapper);
lv_obj_align_to(new_row_wrapper, row_wrapper, LV_ALIGN_BOTTOM_LEFT, 0, 4);
lv_obj_align_to(new_row_wrapper, row_wrapper, LV_ALIGN_BOTTOM_LEFT, 0, square_spacing);
row_wrapper = new_row_wrapper;
column = 0;

View File

@ -30,7 +30,8 @@ class ImageViewerApp : public App {
lv_obj_align_to(image_wrapper, toolbar, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_obj_set_width(image_wrapper, LV_PCT(100));
auto parent_height = lv_obj_get_height(wrapper);
lv_obj_set_height(image_wrapper, parent_height - TOOLBAR_HEIGHT);
auto toolbar_height = lv_obj_get_height(toolbar);
lv_obj_set_height(image_wrapper, parent_height - toolbar_height);
lv_obj_set_flex_flow(image_wrapper, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(image_wrapper, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_all(image_wrapper, 0, 0);

View File

@ -11,11 +11,20 @@
namespace tt::app::launcher {
constexpr auto* TAG = "Launcher";
constexpr auto BUTTON_SIZE = 64;
static int getButtonSize(hal::UiScale scale) {
if (scale == hal::UiScale::Smallest) {
return 40;
} else {
return 64;
}
}
class LauncherApp final : public App {
static lv_obj_t* createAppButton(lv_obj_t* parent, const char* imageFile, const char* appId, int32_t horizontalMargin) {
static lv_obj_t* createAppButton(lv_obj_t* parent, hal::UiScale uiScale, const char* imageFile, const char* appId, int32_t horizontalMargin) {
auto button_size = getButtonSize(uiScale);
auto* apps_button = lv_button_create(parent);
lv_obj_set_style_pad_all(apps_button, 0, LV_STATE_DEFAULT);
lv_obj_set_style_margin_hor(apps_button, horizontalMargin, LV_STATE_DEFAULT);
@ -28,7 +37,7 @@ class LauncherApp final : public App {
lv_obj_set_style_image_recolor_opa(button_image, LV_OPA_COVER, LV_STATE_DEFAULT);
// Ensure buttons are still tappable when the asset fails to load
// Icon images are 40x40, so we get some extra padding too
lv_obj_set_size(button_image, BUTTON_SIZE, BUTTON_SIZE);
lv_obj_set_size(button_image, button_size, button_size);
lv_obj_add_event_cb(apps_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)appId);
@ -73,6 +82,9 @@ public:
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
auto* buttons_wrapper = lv_obj_create(parent);
auto ui_scale = hal::getConfiguration()->uiScale;
auto button_size = getButtonSize(ui_scale);
lv_obj_align(buttons_wrapper, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_style_pad_all(buttons_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_size(buttons_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
@ -89,17 +101,17 @@ public:
lv_obj_set_flex_flow(buttons_wrapper, LV_FLEX_FLOW_COLUMN);
}
const int32_t available_width = lv_display_get_horizontal_resolution(display) - (3 * BUTTON_SIZE);
const int32_t margin = is_landscape_display ? std::min<int32_t>(available_width / 16, BUTTON_SIZE) : 0;
const int32_t available_width = lv_display_get_horizontal_resolution(display) - (3 * button_size);
const int32_t margin = is_landscape_display ? std::min<int32_t>(available_width / 16, button_size) : 0;
const auto paths = app.getPaths();
const auto apps_icon_path = paths->getSystemPathLvgl("icon_apps.png");
const auto files_icon_path = paths->getSystemPathLvgl("icon_files.png");
const auto settings_icon_path = paths->getSystemPathLvgl("icon_settings.png");
const auto apps_icon_path = paths->getSystemPathLvgl("assets/icon_apps.png");
const auto files_icon_path = paths->getSystemPathLvgl("assets/icon_files.png");
const auto settings_icon_path = paths->getSystemPathLvgl("assets/icon_settings.png");
createAppButton(buttons_wrapper, apps_icon_path.c_str(), "AppList", margin);
createAppButton(buttons_wrapper, files_icon_path.c_str(), "Files", margin);
createAppButton(buttons_wrapper, settings_icon_path.c_str(), "Settings", margin);
createAppButton(buttons_wrapper, ui_scale, apps_icon_path.c_str(), "AppList", margin);
createAppButton(buttons_wrapper, ui_scale, files_icon_path.c_str(), "Files", margin);
createAppButton(buttons_wrapper, ui_scale, settings_icon_path.c_str(), "Settings", margin);
if (shouldShowPowerButton()) {
auto* power_button = lv_btn_create(parent);

View File

@ -1,3 +1,4 @@
#include "Tactility/TactilityConfig.h"
#include "Tactility/lvgl/Toolbar.h"
#include <Tactility/Assets.h>
@ -141,7 +142,12 @@ static void addMemoryBar(lv_obj_t* parent, const char* label, uint64_t free, uin
lv_label_set_text_fmt(bottom_label, "%s / %s %s used", used_converted.c_str(), total_converted.c_str(), unit_label.c_str());
lv_obj_set_width(bottom_label, LV_PCT(100));
lv_obj_set_style_text_align(bottom_label, LV_TEXT_ALIGN_RIGHT, 0);
lv_obj_set_style_pad_bottom(bottom_label, 12, LV_STATE_DEFAULT);
if (hal::getConfiguration()->uiScale == hal::UiScale::Smallest) {
lv_obj_set_style_pad_bottom(bottom_label, 2, LV_STATE_DEFAULT);
} else {
lv_obj_set_style_pad_bottom(bottom_label, 12, LV_STATE_DEFAULT);
}
}
#if configUSE_TRACE_FACILITY
@ -245,9 +251,6 @@ class SystemInfoApp : public App {
uint64_t storage_total = 0;
uint64_t storage_free = 0;
if (esp_vfs_fat_info(file::MOUNT_POINT_SYSTEM, &storage_total, &storage_free) == ESP_OK) {
addMemoryBar(storage_tab, file::MOUNT_POINT_SYSTEM, storage_free, storage_total);
}
if (esp_vfs_fat_info(file::MOUNT_POINT_DATA, &storage_total, &storage_free) == ESP_OK) {
addMemoryBar(storage_tab, file::MOUNT_POINT_DATA, storage_free, storage_total);
@ -264,6 +267,13 @@ class SystemInfoApp : public App {
);
}
}
if (config::SHOW_SYSTEM_PARTITION) {
if (esp_vfs_fat_info(file::MOUNT_POINT_SYSTEM, &storage_total, &storage_free) == ESP_OK) {
addMemoryBar(storage_tab, file::MOUNT_POINT_SYSTEM, storage_free, storage_total);
}
}
#endif
#if configUSE_TRACE_FACILITY

View File

@ -92,4 +92,13 @@ std::vector<std::shared_ptr<Device>> getDevices() {
return devices;
}
bool hasDevice(Device::Type type) {
auto scoped_mutex = mutex.asScopedLock();
scoped_mutex.lock();
auto result_set = devices | std::views::filter([&type](auto& device) {
return device->getType() == type;
});
return !result_set.empty();
}
}

View File

@ -19,29 +19,6 @@ constexpr auto* TAG = "Hal";
void registerDevices(const Configuration& configuration) {
TT_LOG_I(TAG, "Registering devices");
if (configuration.sdcard != nullptr) {
registerDevice(configuration.sdcard);
}
if (configuration.power != nullptr) {
std::shared_ptr<power::PowerDevice> power = configuration.power();
registerDevice(power);
}
if (configuration.createKeyboard) {
auto keyboard = configuration.createKeyboard();
if (keyboard != nullptr) {
registerDevice(std::reinterpret_pointer_cast<Device>(keyboard));
}
}
if (configuration.createDisplay != nullptr) {
auto display = configuration.createDisplay();
if (display != nullptr) {
registerDevice(display);
}
}
auto devices = configuration.createDevices();
for (auto& device : devices) {
registerDevice(device);

View File

@ -5,7 +5,7 @@
#include <ranges>
#include <cstring>
#include <Tactility/TactilityHeadless.h>
#include <Tactility/Tactility.h>
#ifdef ESP_PLATFORM
#include <Tactility/hal/uart/UartEsp.h>
@ -142,7 +142,7 @@ void close(uint32_t uartId) {
std::vector<std::string> getNames() {
std::vector<std::string> names;
#ifdef ESP_PLATFORM
for (auto& config : hal::getConfiguration()->uart) {
for (auto& config : getConfiguration()->uart) {
names.push_back(config.name);
}
#else

View File

@ -8,6 +8,30 @@
namespace tt::lvgl {
static int getToolbarHeight(hal::UiScale uiScale) {
if (uiScale == hal::UiScale::Smallest) {
return 20;
} else {
return 40;
}
}
static int getToolbarFontHeight(hal::UiScale uiScale) {
if (uiScale == hal::UiScale::Smallest) {
return 14;
} else {
return 18;
}
}
static const _lv_font_t* getToolbarFont(hal::UiScale uiScale) {
if (uiScale == hal::UiScale::Smallest) {
return &lv_font_montserrat_14;
} else {
return &lv_font_montserrat_18;
}
}
typedef struct {
lv_obj_t obj;
lv_obj_t* title_label;
@ -19,7 +43,7 @@ typedef struct {
static void toolbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj);
static const lv_obj_class_t toolbar_class = {
static lv_obj_class_t toolbar_class = {
.base_class = &lv_obj_class,
.constructor_cb = &toolbar_constructor,
.destructor_cb = nullptr,
@ -27,7 +51,7 @@ static const lv_obj_class_t toolbar_class = {
.user_data = nullptr,
.name = nullptr,
.width_def = LV_PCT(100),
.height_def = TOOLBAR_HEIGHT,
.height_def = 40,
.editable = false,
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
.instance_size = sizeof(Toolbar),
@ -48,41 +72,46 @@ static void toolbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj) {
lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title) {
LV_LOG_INFO("begin");
auto ui_scale = hal::getConfiguration()->uiScale;
auto toolbar_height = getToolbarHeight(ui_scale);
toolbar_class.height_def = toolbar_height;
lv_obj_t* obj = lv_obj_class_create_obj(&toolbar_class, parent);
lv_obj_class_init_obj(obj);
auto* toolbar = (Toolbar*)obj;
lv_obj_set_style_pad_all(obj, 0, 0);
lv_obj_set_style_pad_gap(obj, 0, 0);
lv_obj_set_style_pad_all(obj, 0, LV_STATE_DEFAULT);
lv_obj_set_style_pad_gap(obj, 0, LV_STATE_DEFAULT);
lv_obj_center(obj);
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
toolbar->close_button = lv_button_create(obj);
lv_obj_set_size(toolbar->close_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4);
lv_obj_set_style_pad_all(toolbar->close_button, 0, 0);
lv_obj_set_style_pad_gap(toolbar->close_button, 0, 0);
lv_obj_set_size(toolbar->close_button, toolbar_height - 4, toolbar_height - 4);
lv_obj_set_style_pad_all(toolbar->close_button, 0, LV_STATE_DEFAULT);
lv_obj_set_style_pad_gap(toolbar->close_button, 0, LV_STATE_DEFAULT);
toolbar->close_button_image = lv_image_create(toolbar->close_button);
lv_obj_align(toolbar->close_button_image, LV_ALIGN_CENTER, 0, 0);
toolbar->title_label = lv_label_create(obj);
lv_obj_set_style_text_font(toolbar->title_label, &lv_font_montserrat_18, 0); // TODO replace with size 18
lv_obj_set_style_text_font(toolbar->title_label, getToolbarFont(ui_scale), LV_STATE_DEFAULT);
lv_label_set_text(toolbar->title_label, title.c_str());
lv_obj_set_style_text_align(toolbar->title_label, LV_TEXT_ALIGN_LEFT, 0);
lv_label_set_long_mode(toolbar->title_label, LV_LABEL_LONG_MODE_SCROLL);
lv_obj_set_style_text_align(toolbar->title_label, LV_TEXT_ALIGN_LEFT, LV_STATE_DEFAULT);
lv_obj_set_flex_grow(toolbar->title_label, 1);
int32_t title_offset_x = (TOOLBAR_HEIGHT - TOOLBAR_TITLE_FONT_HEIGHT - 8) / 4 * 3;
int32_t title_offset_x = (toolbar_height - getToolbarFontHeight(ui_scale) - 8) / 4 * 3;
// Margin top doesn't work
lv_obj_set_style_pad_top(toolbar->title_label, title_offset_x, 0);
lv_obj_set_style_margin_left(toolbar->title_label, 8, 0);
lv_obj_set_style_pad_top(toolbar->title_label, title_offset_x, LV_STATE_DEFAULT);
lv_obj_set_style_margin_left(toolbar->title_label, 8, LV_STATE_DEFAULT);
// Hack for margin bug where buttons in flex get rendered more narrowly
lv_obj_set_style_margin_right(toolbar->title_label, -8, 0);
lv_obj_set_style_margin_right(toolbar->title_label, -8, LV_STATE_DEFAULT);
toolbar->action_container = lv_obj_create(obj);
lv_obj_set_width(toolbar->action_container, LV_SIZE_CONTENT);
lv_obj_set_flex_flow(toolbar->action_container, LV_FLEX_FLOW_ROW);
lv_obj_set_style_pad_all(toolbar->action_container, 0, 0);
lv_obj_set_style_border_width(toolbar->action_container, 0, 0);
lv_obj_set_style_pad_all(toolbar->action_container, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(toolbar->action_container, 0, LV_STATE_DEFAULT);
lv_obj_set_flex_align(toolbar->action_container, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
toolbar_set_nav_action(obj, LV_SYMBOL_CLOSE, &stop_app, nullptr);
@ -110,10 +139,13 @@ lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb
tt_check(toolbar->action_count < TOOLBAR_ACTION_LIMIT, "max actions reached");
toolbar->action_count++;
auto ui_scale = hal::getConfiguration()->uiScale;
auto toolbar_height = getToolbarHeight(ui_scale);
lv_obj_t* action_button = lv_button_create(toolbar->action_container);
lv_obj_set_size(action_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4);
lv_obj_set_style_pad_all(action_button, 0, 0);
lv_obj_set_style_pad_gap(action_button, 0, 0);
lv_obj_set_size(action_button, toolbar_height - 4, toolbar_height - 4);
lv_obj_set_style_pad_all(action_button, 0, LV_STATE_DEFAULT);
lv_obj_set_style_pad_gap(action_button, 0, LV_STATE_DEFAULT);
lv_obj_add_event_cb(action_button, callback, LV_EVENT_SHORT_CLICKED, user_data);
lv_obj_t* action_button_image = lv_image_create(action_button);
lv_image_set_src(action_button_image, icon);
@ -125,14 +157,14 @@ lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb
lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj) {
auto* toolbar = (Toolbar*)obj;
lv_obj_t* widget = lv_switch_create(toolbar->action_container);
lv_obj_set_style_margin_top(widget, 4, 0); // Because aligning doesn't work
lv_obj_set_style_margin_right(widget, 4, 0);
lv_obj_set_style_margin_top(widget, 4, LV_STATE_DEFAULT); // Because aligning doesn't work
lv_obj_set_style_margin_right(widget, 4, LV_STATE_DEFAULT);
return widget;
}
lv_obj_t* toolbar_add_spinner_action(lv_obj_t* obj) {
auto* toolbar = (Toolbar*)obj;
return tt::lvgl::spinner_create(toolbar->action_container);
return spinner_create(toolbar->action_container);
}
} // namespace

View File

@ -1,26 +0,0 @@
#ifdef ESP_PLATFORM
#include "Tactility/app/App.h"
#include "Tactility/service/gui/GuiService.h"
#include <lvgl.h>
#include <Tactility/service/gui/GuiService.h>
extern "C" {
extern lv_obj_t * __real_lv_textarea_create(lv_obj_t * parent);
lv_obj_t * __wrap_lv_textarea_create(lv_obj_t * parent) {
auto textarea = __real_lv_textarea_create(parent);
auto gui_service = tt::service::gui::findService();
if (gui_service != nullptr) {
gui_service->keyboardAddTextArea(textarea);
}
return textarea;
}
}
#endif // ESP_PLATFORM

View File

@ -0,0 +1,23 @@
#ifdef ESP_PLATFORM
#include <Tactility/Tactility.h>
#include <lvgl.h>
extern "C" {
extern lv_obj_t* __real_lv_button_create(lv_obj_t* parent);
lv_obj_t* __wrap_lv_button_create(lv_obj_t* parent) {
auto button = __real_lv_button_create(parent);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_pad_all(button, 2, LV_STATE_DEFAULT);
}
return button;
}
}
#endif // ESP_PLATFORM

View File

@ -0,0 +1,23 @@
#ifdef ESP_PLATFORM
#include <Tactility/Tactility.h>
#include <lvgl.h>
extern "C" {
extern lv_obj_t* __real_lv_dropdown_create(lv_obj_t* parent);
lv_obj_t* __wrap_lv_dropdown_create(lv_obj_t* parent) {
auto dropdown = __real_lv_dropdown_create(parent);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_pad_all(dropdown, 2, LV_STATE_DEFAULT);
}
return dropdown;
}
}
#endif // ESP_PLATFORM

View File

@ -0,0 +1,35 @@
#ifdef ESP_PLATFORM
#include <Tactility/Tactility.h>
#include <lvgl.h>
extern "C" {
extern lv_obj_t* __real_lv_list_create(lv_obj_t* parent);
extern lv_obj_t* __real_lv_list_add_button(lv_obj_t* list, const void* icon, const char* txt);
lv_obj_t* __wrap_lv_list_create(lv_obj_t* parent) {
auto list = __real_lv_list_create(parent);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_pad_row(list, 2, LV_STATE_DEFAULT);
lv_obj_set_style_pad_column(list, 2, LV_STATE_DEFAULT);
}
return list;
}
lv_obj_t* __wrap_lv_list_add_button(lv_obj_t* list, const void* icon, const char* txt) {
auto button = __real_lv_list_add_button(list, icon, txt);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_pad_ver(button, 2, LV_STATE_DEFAULT);
}
return button;
}
}
#endif // ESP_PLATFORM

View File

@ -0,0 +1,35 @@
#ifdef ESP_PLATFORM
#include <Tactility/Tactility.h>
#include <lvgl.h>
extern "C" {
extern void __real_lv_obj_set_flex_flow(lv_obj_t* obj, lv_flex_flow_t flow);
extern lv_obj_t* __real_lv_obj_create(lv_obj_t* parent);
void __wrap_lv_obj_set_flex_flow(lv_obj_t* obj, lv_flex_flow_t flow) {
__real_lv_obj_set_flex_flow(obj, flow);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_pad_row(obj, 2, LV_STATE_DEFAULT);
lv_obj_set_style_pad_column(obj, 2, LV_STATE_DEFAULT);
}
}
lv_obj_t* __wrap_lv_obj_create(lv_obj_t* parent) {
auto obj = __real_lv_obj_create(parent);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_pad_row(obj, 2, LV_STATE_DEFAULT);
lv_obj_set_style_pad_column(obj, 2, LV_STATE_DEFAULT);
lv_obj_set_style_pad_all(obj, 2, LV_STATE_DEFAULT);
lv_obj_set_style_radius(obj, 3, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(obj, 1, LV_STATE_DEFAULT);
}
return obj;
}
}
#endif // ESP_PLATFORM

View File

@ -0,0 +1,23 @@
#ifdef ESP_PLATFORM
#include <Tactility/Tactility.h>
#include <lvgl.h>
extern "C" {
extern lv_obj_t* __real_lv_switch_create(lv_obj_t* parent);
lv_obj_t* __wrap_lv_switch_create(lv_obj_t* parent) {
auto widget = __real_lv_switch_create(parent);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_size(widget, 25, 15, LV_STATE_DEFAULT);
}
return widget;
}
}
#endif // ESP_PLATFORM

View File

@ -0,0 +1,28 @@
#ifdef ESP_PLATFORM
#include <Tactility/app/App.h>
#include <Tactility/service/gui/GuiService.h>
#include <Tactility/Tactility.h>
extern "C" {
extern lv_obj_t* __real_lv_textarea_create(lv_obj_t* parent);
lv_obj_t* __wrap_lv_textarea_create(lv_obj_t* parent) {
auto textarea = __real_lv_textarea_create(parent);
if (tt::hal::getConfiguration()->uiScale == tt::hal::UiScale::Smallest) {
lv_obj_set_style_pad_all(textarea, 2, LV_STATE_DEFAULT);
}
auto gui_service = tt::service::gui::findService();
if (gui_service != nullptr) {
gui_service->keyboardAddTextArea(textarea);
}
return textarea;
}
}
#endif // ESP_PLATFORM

View File

@ -27,7 +27,7 @@ void GuiService::onLoaderEvent(loader::LoaderEvent event) {
int32_t GuiService::guiMain() {
while (true) {
uint32_t flags = Thread::awaitFlags(GUI_THREAD_FLAG_ALL, EventFlag::WaitAny, (uint32_t)portMAX_DELAY);
uint32_t flags = Thread::awaitFlags(GUI_THREAD_FLAG_ALL, EventFlag::WaitAny, portMAX_DELAY);
// When service not started or starting -> exit
State service_state = getState(manifest.id);

View File

@ -59,13 +59,13 @@ void GuiService::keyboardAddTextArea(lv_obj_t* textarea) {
lv_obj_add_event_cb(textarea, show_keyboard, LV_EVENT_FOCUSED, nullptr);
lv_obj_add_event_cb(textarea, hide_keyboard, LV_EVENT_DEFOCUSED, nullptr);
lv_obj_add_event_cb(textarea, hide_keyboard, LV_EVENT_READY, nullptr);
// lv_obj_t auto-remove themselves from the group when they are destroyed (last checked in LVGL 8.3)
lv_group_add_obj(keyboardGroup, textarea);
lvgl::software_keyboard_activate(keyboardGroup);
}
// lv_obj_t auto-remove themselves from the group when they are destroyed (last checked in LVGL 8.3)
lv_group_add_obj(keyboardGroup, textarea);
lvgl::software_keyboard_activate(keyboardGroup);
lvgl::unlock();
}

View File

@ -43,7 +43,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_FLASHMODE_QIO=y
# LVGL
CONFIG_LV_DISP_DEF_REFR_PERIOD=10
CONFIG_LV_DPI_DEF=160
CONFIG_LV_DPI_DEF=139
CONFIG_LV_THEME_DEFAULT_DARK=y
# Fix for IRAM
CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y