Compare commits

...

2 Commits

Author SHA1 Message Date
Ken Van Hoeylandt
5cc5b50694
Merge develop into main (#312)
- Move various settings to `/data/settings` and `/sdcard/settings`
- Fix for `Gui` and `Statusbar` errors on startup (LVGL start)
- Implement Development service settings as properties file
- Rename `service::findManifestId()` to `service::findManifestById()`
- Renamed various classes like `BootProperties` to `BootSettings`
- Renamed `settings.properties` to `system.properties`. Code was moved to `settings` namespace/folder
- `DevelopmentSettings` is now in `settings` namespace/folder (moved from service)
2025-08-31 20:31:31 +02:00
Rivair Sabino dos Santos
5dfc6d70da
Implemented CYD-2432S028R board and update XPT2046 driver (#308)
- Added CONFIG_TT_BOARD_CYD_2432S028R in Kconfig.
- Included support for CYD2432S028R in Boards.h and board.cmake.
- Updated Xpt2046Touch driver to use configuration->spiDevice instead of SPI2_HOST when creating the SPI handle.
- Note: SD card is not working on this board yet.

This commit introduces full support for the CYD-2432S028R board and improves the touchscreen driver flexibility by allowing dynamic SPI device configuration. SD card functionality still needs to be implemented.
2025-08-31 14:49:55 +02:00
44 changed files with 718 additions and 332 deletions

View File

@ -18,6 +18,15 @@ jobs:
with:
board_id: cyd-2432s024c
arch: esp32
cyd-2432s028r:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "Build"
uses: ./.github/actions/build-firmware
with:
board_id: cyd-2432s028r
arch: esp32
cyd-2432s032c:
runs-on: ubuntu-latest
steps:

View File

@ -13,6 +13,8 @@ menu "Tactility App"
bool "Custom"
config TT_BOARD_CYD_2432S024C
bool "CYD 2432S024C"
config TT_BOARD_CYD_2432S028R
bool "CYD 2432S028R"
config TT_BOARD_CYD_2432S032C
bool "CYD 2432S032C"
config TT_BOARD_CYD_8048S043C

View File

@ -14,6 +14,9 @@
#elif defined(CONFIG_TT_BOARD_CYD_2432S024C)
#include "CYD2432S024C.h"
#define TT_BOARD_HARDWARE &cyd_2432s024c_config
#elif defined(CONFIG_TT_BOARD_CYD_2432S028R)
#include "CYD2432S028R.h"
#define TT_BOARD_HARDWARE &cyd_2432s028r_config
#elif defined(CONFIG_TT_BOARD_CYD_2432S032C)
#include "CYD2432S032C.h"
#define TT_BOARD_HARDWARE &cyd_2432S032c_config

View File

@ -0,0 +1,7 @@
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port ILI934x XPT2046 PwmBacklight driver vfs fatfs
)

View File

@ -0,0 +1,81 @@
#include "CYD2432S028R.h"
#include "hal/YellowDisplay.h"
#include "hal/YellowConstants.h"
#include <Tactility/lvgl/LvglSync.h>
#include <PwmBacklight.h>
#include <Tactility/hal/Configuration.h>
using namespace tt::hal;
bool initBoot() {
//Set the RGB Led Pins to output and turn them off
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT)); //Blue
//0 on, 1 off... yep it's backwards.
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_4, 1)); //Red
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_16, 1)); //Green
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_17, 1)); //Blue
return driver::pwmbacklight::init(CYD2432S028R_LCD_PIN_BACKLIGHT);
}
const Configuration cyd_2432s028r_config = {
.initBoot = initBoot,
.createDisplay = createDisplay,
.sdcard = nullptr,
.power = nullptr,
.i2c = {},
.spi {
//Display
spi::Configuration {
.device = CYD2432S028R_LCD_SPI_HOST,
.dma = SPI_DMA_CH_AUTO,
.config = {
.mosi_io_num = GPIO_NUM_13,
.miso_io_num = GPIO_NUM_12,
.sclk_io_num = GPIO_NUM_14,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.data4_io_num = GPIO_NUM_NC,
.data5_io_num = GPIO_NUM_NC,
.data6_io_num = GPIO_NUM_NC,
.data7_io_num = GPIO_NUM_NC,
.data_io_default_level = false,
.max_transfer_sz = CYD_SPI_TRANSFER_SIZE_LIMIT,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
},
.initMode = spi::InitMode::ByTactility,
.isMutable = false,
.lock = tt::lvgl::getSyncLock()
},
// Touch
spi::Configuration {
.device = CYD2432S028R_TOUCH_SPI_HOST,
.dma = SPI_DMA_CH_AUTO,
.config = {
.mosi_io_num = GPIO_NUM_32,
.miso_io_num = GPIO_NUM_39,
.sclk_io_num = GPIO_NUM_25,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.data4_io_num = GPIO_NUM_NC,
.data5_io_num = GPIO_NUM_NC,
.data6_io_num = GPIO_NUM_NC,
.data7_io_num = GPIO_NUM_NC,
.data_io_default_level = false,
.max_transfer_sz = 0,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
},
.initMode = tt::hal::spi::InitMode::ByTactility,
.isMutable = false,
.lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display
},
}
};

View File

@ -0,0 +1,6 @@
#pragma once
#include <Tactility/hal/Configuration.h>
// Resitive touch version of the 2.8" yellow board
extern const tt::hal::Configuration cyd_2432s028r_config;

View File

@ -0,0 +1,24 @@
#pragma once
// Display backlight (PWM)
#define CYD2432S028R_LCD_PIN_BACKLIGHT GPIO_NUM_21
// Display
#define CYD2432S028R_LCD_SPI_HOST SPI2_HOST
#define CYD2432S028R_LCD_HORIZONTAL_RESOLUTION 240
#define CYD2432S028R_LCD_VERTICAL_RESOLUTION 320
#define CYD2432S028R_LCD_DRAW_BUFFER_HEIGHT (CYD2432S028R_LCD_VERTICAL_RESOLUTION / 10)
#define CYD2432S028R_LCD_DRAW_BUFFER_SIZE (CYD2432S028R_LCD_HORIZONTAL_RESOLUTION * CYD2432S028R_LCD_DRAW_BUFFER_HEIGHT)
#define CYD2432S028R_LCD_PIN_CS GPIO_NUM_15
#define CYD2432S028R_LCD_PIN_DC GPIO_NUM_2
// Touch
#define CYD2432S028R_TOUCH_SPI_HOST SPI3_HOST
#define CYD2432S028R_TOUCH_PIN_CS GPIO_NUM_33
// SDCard
#define SDCARD_SPI_HOST SPI3_HOST
#define SDCARD_PIN_CS GPIO_NUM_5
// SPI Transfer
#define CYD_SPI_TRANSFER_SIZE_LIMIT (CYD2432S028R_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8)

View File

@ -0,0 +1,42 @@
#include "YellowDisplay.h"
#include "Xpt2046Touch.h"
#include "YellowConstants.h"
#include <Ili934xDisplay.h>
#include <PwmBacklight.h>
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
auto configuration = std::make_unique<Xpt2046Touch::Configuration>(
CYD2432S028R_TOUCH_SPI_HOST,
CYD2432S028R_TOUCH_PIN_CS,
240,
320,
false,
true,
false
);
return std::make_shared<Xpt2046Touch>(std::move(configuration));
}
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
auto touch = createTouch();
auto configuration = std::make_unique<Ili934xDisplay::Configuration>(
CYD2432S028R_LCD_SPI_HOST,
CYD2432S028R_LCD_PIN_CS,
CYD2432S028R_LCD_PIN_DC,
CYD2432S028R_LCD_HORIZONTAL_RESOLUTION,
CYD2432S028R_LCD_VERTICAL_RESOLUTION,
touch,
false,
true,
false,
false,
CYD2432S028R_LCD_DRAW_BUFFER_SIZE
);
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
auto display = std::make_shared<Ili934xDisplay>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "Tactility/hal/display/DisplayDevice.h"
#include <memory>
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -0,0 +1,26 @@
#include "YellowSdCard.h"
#include "YellowConstants.h"
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <Tactility/lvgl/LvglSync.h>
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createYellowSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
std::make_shared<tt::Mutex>(),
std::vector<gpio_num_t>(),
SDCARD_SPI_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -0,0 +1,8 @@
#pragma once
#include "Tactility/hal/sdcard/SdCardDevice.h"
using tt::hal::sdcard::SdCardDevice;
std::shared_ptr<SdCardDevice> createYellowSdCard();

View File

@ -23,6 +23,8 @@ function(INIT_TACTILITY_GLOBALS SDKCONFIG_FILE)
if (board_id STREQUAL "cyd-2432s024c")
set(TACTILITY_BOARD_PROJECT CYD-2432S024C)
elseif (board_id STREQUAL "cyd-2432s028r")
set(TACTILITY_BOARD_PROJECT CYD-2432S028R)
elseif (board_id STREQUAL "cyd-2432s032c")
set(TACTILITY_BOARD_PROJECT CYD-2432S032C)
elseif (board_id STREQUAL "cyd-4848s040c")

View File

@ -0,0 +1 @@
enableOnBoot=false

View File

@ -2,7 +2,6 @@
## Higher Priority
- Move Development settings from flash to `/data/apps/development/development.properties` (just the "start on boot")
- Move Display settings from flash to `/data/apps/display/display.properties`
- Expose app::Paths to TactilityC
- Call tt::lvgl::isSyncSet after HAL init and show an error (and crash?) when it is not set.

View File

@ -11,7 +11,7 @@ Xpt2046Touch* Xpt2046Touch::instance = nullptr;
bool Xpt2046Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
const esp_lcd_panel_io_spi_config_t io_config = ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG(configuration->spiPinCs);
return esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &outHandle) == ESP_OK;
return esp_lcd_new_panel_io_spi(configuration->spiDevice, &io_config, &outHandle) == ESP_OK;
}
bool Xpt2046Touch::createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& config, esp_lcd_touch_handle_t& panelHandle) {

View File

@ -1,19 +0,0 @@
#pragma once
#include <src/display/lv_display.h>
namespace tt::app::display {
void setBacklightDuty(uint8_t value);
bool getBacklightDuty(uint8_t& duty);
void setGammaCurve(uint8_t curveIndex);
bool getGammaCurve(uint8_t& curveIndex);
void setRotation(lv_display_rotation_t rotation);
lv_display_rotation_t getRotation();
} // namespace

View File

@ -40,7 +40,7 @@ State getState(const std::string& id);
* @param[in] id the id as defined in the manifest
* @return the matching manifest or nullptr when it wasn't found
*/
std::shared_ptr<const ServiceManifest> _Nullable findManifestId(const std::string& id);
std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::string& id);
/** Find a ServiceContext by its manifest id.
* @param[in] id the id as defined in the manifest

View File

@ -2,9 +2,9 @@
#include <string>
namespace tt {
namespace tt::settings {
struct BootProperties {
struct BootSettings {
/** App to start automatically after the splash screen. */
std::string launcherAppId;
/** App to start automatically from the launcher screen. */
@ -12,13 +12,13 @@ struct BootProperties {
};
/**
* Load the boot properties from the relevant file location(s).
* Load the boot properties file from the relevant file location(s).
* It will first attempt to load them from the SD card and if no file was found,
* then it will try to load the one from the data mount point.
*
* @param[out] properties the resulting properties
* @return true when the properties were successfully loaded and the result was set
*/
bool loadBootProperties(BootProperties& properties);
bool loadBootSettings(BootSettings& properties);
}

View File

@ -0,0 +1,32 @@
#pragma once
#include <src/display/lv_display.h>
namespace tt::settings::display {
enum class Orientation {
// In order of rotation (to make it easier to convert to LVGL rotation)
Landscape,
Portrait,
LandscapeFlipped,
PortraitFlipped,
};
struct DisplaySettings {
Orientation orientation;
uint8_t gammaCurve;
uint8_t backlightDuty;
};
/** Compares default settings with the function parameter to return the difference */
lv_display_rotation_t toLvglDisplayRotation(Orientation orientation);
bool load(DisplaySettings& settings);
DisplaySettings loadOrGetDefault();
DisplaySettings getDefault();
bool save(const DisplaySettings& settings);
} // namespace

View File

@ -1,16 +0,0 @@
#pragma once
#include "Language.h"
namespace tt::settings {
struct SettingsProperties {
Language language;
bool timeFormat24h;
};
bool loadSettingsProperties(SettingsProperties& properties);
bool saveSettingsProperties(const SettingsProperties& properties);
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "Language.h"
namespace tt::settings {
struct SystemSettings {
Language language;
bool timeFormat24h;
};
bool loadSystemSettings(SystemSettings& properties);
bool saveSystemSettings(const SystemSettings& properties);
}

View File

@ -74,17 +74,6 @@ public:
*/
void setEnabled(bool enabled);
/**
* @return true if the service will enable itself when it is started (e.g. on boot, or manual start)
*/
bool isEnabledOnStart() const;
/**
* Set whether the service should auto-enable when it is started.
* @param enabled
*/
void setEnabledOnStart(bool enabled);
bool isStarted() const;
// region Internal API

View File

@ -0,0 +1,12 @@
#pragma once
#ifdef ESP_PLATFORM
namespace tt::service::development {
void setEnableOnBoot(bool enable);
bool shouldEnableOnBoot();
}
#endif // ESP_PLATFORM

View File

@ -1,18 +1,16 @@
#include "Tactility/TactilityCore.h"
#include "Tactility/app/AppContext.h"
#include "Tactility/app/display/DisplaySettings.h"
#include "Tactility/service/loader/Loader.h"
#include "Tactility/lvgl/Style.h"
#include "Tactility/hal/display/DisplayDevice.h"
#include <Tactility/TactilityCore.h>
#include <Tactility/TactilityPrivate.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/CpuAffinity.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/usb/Usb.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/BootSettings.h>
#include <Tactility/settings/DisplaySettings.h>
#include <lvgl.h>
#include <Tactility/BootProperties.h>
#include <Tactility/CpuAffinity.h>
#ifdef ESP_PLATFORM
#include "Tactility/app/crashdiagnostics/CrashDiagnostics.h"
@ -42,25 +40,25 @@ class BootApp : public App {
static void setupDisplay() {
const auto hal_display = getHalDisplay();
assert(hal_display != nullptr);
settings::display::DisplaySettings settings;
if (settings::display::load(settings)) {
if (hal_display->getGammaCurveCount() > 0) {
hal_display->setGammaCurve(settings.gammaCurve);
TT_LOG_I(TAG, "Gamma curve %du", settings.gammaCurve);
}
} else {
settings = settings::display::getDefault();
}
if (hal_display->supportsBacklightDuty()) {
uint8_t backlight_duty = 200;
display::getBacklightDuty(backlight_duty);
TT_LOG_I(TAG, "backlight %du", backlight_duty);
hal_display->setBacklightDuty(backlight_duty);
TT_LOG_I(TAG, "Backlight %du", settings.backlightDuty);
hal_display->setBacklightDuty(settings.backlightDuty);
} else {
TT_LOG_I(TAG, "no backlight");
}
if (hal_display->getGammaCurveCount() > 0) {
uint8_t gamma_curve;
if (display::getGammaCurve(gamma_curve)) {
hal_display->setGammaCurve(gamma_curve);
TT_LOG_I(TAG, "gamma %du", gamma_curve);
}
}
}
static bool setupUsbBootMode() {
if (!hal::usb::isUsbBootMode()) {
return false;
@ -107,8 +105,8 @@ class BootApp : public App {
}
#endif
BootProperties boot_properties;
if (!loadBootProperties(boot_properties) || boot_properties.launcherAppId.empty()) {
settings::BootSettings boot_properties;
if (!settings::loadBootSettings(boot_properties) || boot_properties.launcherAppId.empty()) {
TT_LOG_E(TAG, "Launcher not configured");
stop();
return;

View File

@ -1,17 +1,17 @@
#ifdef ESP_PLATFORM
#include "Tactility/app/AppManifest.h"
#include "Tactility/lvgl/Style.h"
#include "Tactility/lvgl/Toolbar.h"
#include "Tactility/service/development/DevelopmentService.h"
#include <Tactility/Timer.h>
#include <Tactility/service/wifi/Wifi.h>
#include <cstring>
#include <lvgl.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/development/DevelopmentService.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/service/wifi/Wifi.h>
#include <Tactility/Timer.h>
#include <cstring>
#include <lvgl.h>
#include <Tactility/service/development/DevelopmentSettings.h>
namespace tt::app::development {
@ -49,10 +49,9 @@ class DevelopmentApp final : public App {
auto* widget = static_cast<lv_obj_t*>(lv_event_get_target(event));
if (code == LV_EVENT_VALUE_CHANGED) {
bool is_on = lv_obj_has_state(widget, LV_STATE_CHECKED);
auto* app = static_cast<DevelopmentApp*>(lv_event_get_user_data(event));
bool is_changed = is_on != app->service->isEnabledOnStart();
bool is_changed = is_on != service::development::shouldEnableOnBoot();
if (is_changed) {
app->service->setEnabledOnStart(is_on);
service::development::setEnableOnBoot(is_on);
}
}
}
@ -125,7 +124,7 @@ public:
enableOnBootSwitch = lv_switch_create(wrapper);
lv_obj_add_event_cb(enableOnBootSwitch, onEnableOnBootSwitchChanged, LV_EVENT_VALUE_CHANGED, this);
lv_obj_align(enableOnBootSwitch, LV_ALIGN_TOP_RIGHT, 0, 0);
if (service->isEnabledOnStart()) {
if (service::development::shouldEnableOnBoot()) {
lv_obj_add_state(enableOnBootSwitch, LV_STATE_CHECKED);
} else {
lv_obj_remove_state(enableOnBootSwitch, LV_STATE_CHECKED);

View File

@ -1,105 +1,70 @@
#include "Tactility/app/display/DisplaySettings.h"
#include "Tactility/hal/display/DisplayDevice.h"
#include "Tactility/lvgl/Toolbar.h"
#include <Tactility/settings/DisplaySettings.h>
#include <Tactility/Assets.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Tactility.h>
#include <lvgl.h>
namespace tt::app::display {
#define TAG "display"
static bool backlight_duty_set = false;
static uint8_t backlight_duty = 255;
static uint8_t gamma = 255;
#define ROTATION_DEFAULT 0
#define ROTATION_180 1
#define ROTATION_270 2
#define ROTATION_90 3
constexpr auto* TAG = "Display";
static std::shared_ptr<hal::display::DisplayDevice> getHalDisplay() {
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
}
static lv_display_rotation_t orientationSettingToDisplayRotation(uint32_t setting) {
switch (setting) {
case ROTATION_180:
return LV_DISPLAY_ROTATION_180;
case ROTATION_270:
return LV_DISPLAY_ROTATION_270;
case ROTATION_90:
return LV_DISPLAY_ROTATION_90;
default:
return LV_DISPLAY_ROTATION_0;
}
}
class DisplayApp final : public App {
static uint32_t displayOrientationToOrientationSetting(lv_display_rotation_t orientation) {
switch (orientation) {
case LV_DISPLAY_ROTATION_90:
return ROTATION_90;
case LV_DISPLAY_ROTATION_180:
return ROTATION_180;
case LV_DISPLAY_ROTATION_270:
return ROTATION_270;
default:
return ROTATION_DEFAULT;
}
}
class DisplayApp : public App {
settings::display::DisplaySettings displaySettings;
bool displaySettingsUpdated = false;
static void onBacklightSliderEvent(lv_event_t* event) {
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto hal_display = getHalDisplay();
assert(hal_display != nullptr);
if (hal_display->supportsBacklightDuty()) {
int32_t slider_value = lv_slider_get_value(slider);
backlight_duty = static_cast<uint8_t>(slider_value);
backlight_duty_set = true;
hal_display->setBacklightDuty(backlight_duty);
app->displaySettings.backlightDuty = static_cast<uint8_t>(slider_value);
app->displaySettingsUpdated = true;
hal_display->setBacklightDuty(app->displaySettings.backlightDuty);
}
}
static void onGammaSliderEvent(lv_event_t* event) {
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto hal_display = hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
assert(hal_display != nullptr);
if (hal_display->getGammaCurveCount() > 0) {
int32_t slider_value = lv_slider_get_value(slider);
gamma = static_cast<uint8_t>(slider_value);
hal_display->setGammaCurve(gamma);
setGammaCurve(gamma);
app->displaySettings.gammaCurve = static_cast<uint8_t>(slider_value);
app->displaySettingsUpdated = true;
hal_display->setGammaCurve(app->displaySettings.gammaCurve);
}
}
static void onOrientationSet(lv_event_t* event) {
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t selected = lv_dropdown_get_selected(dropdown);
TT_LOG_I(TAG, "Selected %ld", selected);
lv_display_rotation_t rotation = orientationSettingToDisplayRotation(selected);
if (lv_display_get_rotation(lv_display_get_default()) != rotation) {
lv_display_set_rotation(lv_display_get_default(), rotation);
setRotation(rotation);
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
TT_LOG_I(TAG, "Selected %ld", selected_index);
auto selected_orientation = static_cast<settings::display::Orientation>(selected_index);
if (selected_orientation != app->displaySettings.orientation) {
app->displaySettings.orientation = selected_orientation;
app->displaySettingsUpdated = true;
lv_display_set_rotation(lv_display_get_default(), settings::display::toLvglDisplayRotation(selected_orientation));
}
}
public:
void onShow(AppContext& app, lv_obj_t* parent) override {
displaySettings = settings::display::loadOrGetDefault();
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
auto hal_display = getHalDisplay();
@ -126,14 +91,9 @@ public:
lv_obj_set_width(brightness_slider, LV_PCT(50));
lv_obj_align(brightness_slider, LV_ALIGN_TOP_RIGHT, -8, 0);
lv_slider_set_range(brightness_slider, 0, 255);
lv_obj_add_event_cb(brightness_slider, onBacklightSliderEvent, LV_EVENT_VALUE_CHANGED, nullptr);
lv_obj_add_event_cb(brightness_slider, onBacklightSliderEvent, LV_EVENT_VALUE_CHANGED, this);
uint8_t value;
if (getBacklightDuty(value)) {
lv_slider_set_value(brightness_slider, value, LV_ANIM_OFF);
} else {
lv_slider_set_value(brightness_slider, 0, LV_ANIM_OFF);
}
lv_slider_set_value(brightness_slider, displaySettings.backlightDuty, LV_ANIM_OFF);
}
if (hal_display->getGammaCurveCount() > 0) {
@ -151,14 +111,10 @@ public:
lv_obj_set_width(gamma_slider, LV_PCT(50));
lv_obj_align(gamma_slider, LV_ALIGN_TOP_RIGHT, -8, 0);
lv_slider_set_range(gamma_slider, 0, hal_display->getGammaCurveCount());
lv_obj_add_event_cb(gamma_slider, onGammaSliderEvent, LV_EVENT_VALUE_CHANGED, nullptr);
lv_obj_add_event_cb(gamma_slider, onGammaSliderEvent, LV_EVENT_VALUE_CHANGED, this);
uint8_t curve_index;
if (getGammaCurve(curve_index)) {
lv_slider_set_value(gamma_slider, curve_index, LV_ANIM_OFF);
} else {
lv_slider_set_value(gamma_slider, 0, LV_ANIM_OFF);
}
uint8_t curve_index = displaySettings.gammaCurve;
lv_slider_set_value(gamma_slider, curve_index, LV_ANIM_OFF);
}
auto* orientation_wrapper = lv_obj_create(main_wrapper);
@ -170,31 +126,20 @@ public:
lv_label_set_text(orientation_label, "Orientation");
lv_obj_align(orientation_label, LV_ALIGN_TOP_LEFT, 0, 8);
auto lvgl_display = lv_obj_get_display(parent);
auto horizontal_px = lv_display_get_horizontal_resolution(lvgl_display);
auto vertical_px = lv_display_get_vertical_resolution(lvgl_display);
bool is_landscape_display = horizontal_px > vertical_px;
auto* orientation_dropdown = lv_dropdown_create(orientation_wrapper);
if (is_landscape_display) {
lv_dropdown_set_options(orientation_dropdown, "Landscape\nLandscape (flipped)\nPortrait Left\nPortrait Right");
} else {
lv_dropdown_set_options(orientation_dropdown, "Portrait\nPortrait (flipped)\nLandscape Left\nLandscape Right");
}
// Note: order correlates with settings::display::Orientation item order
lv_dropdown_set_options(orientation_dropdown, "Landscape\nPortrait Right\nLandscape Flipped\nPortrait Left");
lv_obj_align(orientation_dropdown, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_set_style_border_color(orientation_dropdown, lv_color_hex(0xFAFAFA), LV_PART_MAIN);
lv_obj_set_style_border_width(orientation_dropdown, 1, LV_PART_MAIN);
lv_obj_add_event_cb(orientation_dropdown, onOrientationSet, LV_EVENT_VALUE_CHANGED, nullptr);
uint32_t orientation_selected = displayOrientationToOrientationSetting(
lv_display_get_rotation(lv_display_get_default())
);
lv_dropdown_set_selected(orientation_dropdown, orientation_selected);
lv_obj_add_event_cb(orientation_dropdown, onOrientationSet, LV_EVENT_VALUE_CHANGED, this);
auto orientation = settings::display::toLvglDisplayRotation(displaySettings.orientation);
lv_dropdown_set_selected(orientation_dropdown, orientation);
}
void onHide(TT_UNUSED AppContext& app) override {
if (backlight_duty_set) {
setBacklightDuty(backlight_duty);
if (displaySettingsUpdated) {
settings::display::save(displaySettings);
}
}
};

View File

@ -1,54 +0,0 @@
#include "Tactility/app/display/DisplaySettings.h"
#include <Tactility/Preferences.h>
namespace tt::app::display {
tt::Preferences preferences("display");
constexpr const char* BACKLIGHT_DUTY_KEY = "backlight_duty";
constexpr const char* GAMMA_CURVE_KEY = "gamma";
constexpr const char* ROTATION_KEY = "rotation";
void setBacklightDuty(uint8_t value) {
preferences.putInt32(BACKLIGHT_DUTY_KEY, (int32_t)value);
}
bool getBacklightDuty(uint8_t& duty) {
int32_t result;
if (preferences.optInt32(BACKLIGHT_DUTY_KEY, result)) {
duty = (uint8_t)(result % 256);
return true;
} else {
return false;
}
}
void setRotation(lv_display_rotation_t rotation) {
preferences.putInt32(ROTATION_KEY, (int32_t)rotation);
}
lv_display_rotation_t getRotation() {
int32_t rotation;
if (preferences.optInt32(ROTATION_KEY, rotation)) {
return (lv_display_rotation_t)rotation;
} else {
return LV_DISPLAY_ROTATION_0;
}
}
void setGammaCurve(uint8_t curveIndex) {
preferences.putInt32(GAMMA_CURVE_KEY, (int32_t)curveIndex);
}
bool getGammaCurve(uint8_t& curveIndex) {
int32_t result;
if (preferences.optInt32(GAMMA_CURVE_KEY, result)) {
curveIndex = (uint8_t)(result % 256);
return true;
} else {
return false;
}
}
} // namespace

View File

@ -1,12 +1,12 @@
#include "Tactility/app/AppContext.h"
#include "Tactility/app/AppRegistration.h"
#include "Tactility/service/loader/Loader.h"
#include <Tactility/Tactility.h>
#include <lvgl.h>
#include <Tactility/BootProperties.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppRegistration.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/BootSettings.h>
#include <lvgl.h>
namespace tt::app::launcher {
@ -63,8 +63,8 @@ class LauncherApp final : public App {
public:
void onCreate(TT_UNUSED AppContext& app) override {
BootProperties boot_properties;
if (loadBootProperties(boot_properties) && !boot_properties.autoStartAppId.empty()) {
settings::BootSettings boot_properties;
if (settings::loadBootSettings(boot_properties) && !boot_properties.autoStartAppId.empty()) {
TT_LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
service::loader::startApp(boot_properties.autoStartAppId);
}

View File

@ -1,4 +1,3 @@
#include <Tactility/app/display/DisplaySettings.h>
#include <Tactility/hal/Configuration.h>
#include <Tactility/hal/encoder/EncoderDevice.h>
#include <Tactility/hal/display/DisplayDevice.h>
@ -9,6 +8,7 @@
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/settings/DisplaySettings.h>
#include <Tactility/TactilityHeadless.h>
#ifdef ESP_PLATFORM
@ -93,7 +93,8 @@ void start() {
TT_LOG_I(TAG, "Started %s", display->getName().c_str());
auto lvgl_display = display->getLvglDisplay();
assert(lvgl_display != nullptr);
lv_display_rotation_t rotation = app::display::getRotation();
auto settings = settings::display::loadOrGetDefault();
lv_display_rotation_t rotation = settings::display::toLvglDisplayRotation(settings.orientation);
if (rotation != lv_display_get_rotation(lvgl_display)) {
lv_display_set_rotation(lvgl_display, rotation);
}
@ -158,16 +159,24 @@ void start() {
// Restart services
if (service::getState("Gui") == service::State::Stopped) {
service::startService("Gui");
} else {
TT_LOG_E(TAG, "Gui service is not in Stopped state");
// We search for the manifest first, because during the initial start() during boot
// the service won't be registered yet.
if (service::findManifestById("Gui") != nullptr) {
if (service::getState("Gui") == service::State::Stopped) {
service::startService("Gui");
} else {
TT_LOG_E(TAG, "Gui service is not in Stopped state");
}
}
if (service::getState("Statusbar") == service::State::Stopped) {
service::startService("Statusbar");
} else {
TT_LOG_E(TAG, "Statusbar service is not in Stopped state");
// We search for the manifest first, because during the initial start() during boot
// the service won't be registered yet.
if (service::findManifestById("Statusbar") != nullptr) {
if (service::getState("Statusbar") == service::State::Stopped) {
service::startService("Statusbar");
} else {
TT_LOG_E(TAG, "Statusbar service is not in Stopped state");
}
}
// Finalize

View File

@ -1,7 +1,7 @@
#include "Tactility/service/ServiceRegistration.h"
#include <Tactility/service/ServiceRegistration.h>
#include "Tactility/service/ServiceInstance.h"
#include "Tactility/service/ServiceManifest.h"
#include <Tactility/service/ServiceInstance.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/Mutex.h>
@ -9,7 +9,7 @@
namespace tt::service {
#define TAG "service_registry"
constexpr auto* TAG = "ServiceRegistry";
typedef std::unordered_map<std::string, std::shared_ptr<const ServiceManifest>> ManifestMap;
typedef std::unordered_map<std::string, std::shared_ptr<ServiceInstance>> ServiceInstanceMap;
@ -44,7 +44,7 @@ void addService(const ServiceManifest& manifest, bool autoStart) {
addService(std::make_shared<const ServiceManifest>(manifest), autoStart);
}
std::shared_ptr<const ServiceManifest> _Nullable findManifestId(const std::string& id) {
std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::string& id) {
manifest_mutex.lock();
auto iterator = service_manifest_map.find(id);
auto manifest = iterator != service_manifest_map.end() ? iterator->second : nullptr;
@ -63,7 +63,7 @@ static std::shared_ptr<ServiceInstance> _Nullable findServiceInstanceById(const
// TODO: Return proper error/status instead of BOOL?
bool startService(const std::string& id) {
TT_LOG_I(TAG, "Starting %s", id.c_str());
auto manifest = findManifestId(id);
auto manifest = findManifestById(id);
if (manifest == nullptr) {
TT_LOG_E(TAG, "manifest not found for service %s", id.c_str());
return false;

View File

@ -1,24 +1,24 @@
#ifdef ESP_PLATFORM
#include "Tactility/service/development/DevelopmentService.h"
#include <Tactility/service/development/DevelopmentService.h>
#include "Tactility/network/HttpdReq.h"
#include "Tactility/network/Url.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/service/ServiceManifest.h"
#include "Tactility/service/ServiceRegistration.h"
#include "Tactility/service/wifi/Wifi.h"
#include <Tactility/app/App.h>
#include <Tactility/app/AppRegistration.h>
#include <Tactility/app/ElfApp.h>
#include <Tactility/file/File.h>
#include <Tactility/network/HttpdReq.h>
#include <Tactility/network/Url.h>
#include <Tactility/service/development/DevelopmentSettings.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/service/wifi/Wifi.h>
#include <Tactility/StringUtils.h>
#include <Tactility/TactilityHeadless.h>
#include <cstring>
#include <esp_wifi.h>
#include <ranges>
#include <sstream>
#include <Tactility/Preferences.h>
#include <Tactility/StringUtils.h>
#include <Tactility/app/App.h>
#include <Tactility/app/ElfApp.h>
#include <Tactility/app/AppRegistration.h>
#include <Tactility/file/File.h>
namespace tt::service::development {
@ -39,7 +39,7 @@ void DevelopmentService::onStart(ServiceContext& service) {
[this](kernel::SystemEvent) { onNetworkDisconnected(); }
);
setEnabled(isEnabledOnStart());
setEnabled(shouldEnableOnBoot());
}
void DevelopmentService::onStop(ServiceContext& service) {
@ -76,18 +76,6 @@ bool DevelopmentService::isEnabled() const {
return enabled;
}
bool DevelopmentService::isEnabledOnStart() const {
Preferences preferences = Preferences(manifest.id.c_str());
bool enabled_on_boot = false;
preferences.optBool("enabledOnBoot", enabled_on_boot);
return enabled_on_boot;
}
void DevelopmentService::setEnabledOnStart(bool enabled) {
Preferences preferences = Preferences(manifest.id.c_str());
preferences.putBool("enabledOnBoot", enabled);
}
// region Enable/disable
void DevelopmentService::startServer() {

View File

@ -0,0 +1,55 @@
#ifdef ESP_PLATFORM
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Log.h>
#include <Tactility/service/development/DevelopmentSettings.h>
#include <map>
#include <string>
namespace tt::service::development {
constexpr auto* TAG = "DevSettings";
constexpr auto* SETTINGS_FILE = "/data/settings/development.properties";
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
struct DevelopmentSettings {
bool enableOnBoot;
};
static bool load(DevelopmentSettings& settings) {
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
return false;
}
if (!map.contains(SETTINGS_KEY_ENABLE_ON_BOOT)) {
return false;
}
auto enable_on_boot_string = map[SETTINGS_KEY_ENABLE_ON_BOOT];
settings.enableOnBoot = (enable_on_boot_string == "true");
return true;
}
static bool save(const DevelopmentSettings& settings) {
std::map<std::string, std::string> map;
map[SETTINGS_KEY_ENABLE_ON_BOOT] = settings.enableOnBoot ? "true" : "false";
return file::savePropertiesFile(SETTINGS_FILE, map);
}
void setEnableOnBoot(bool enable) {
DevelopmentSettings properties { .enableOnBoot = enable };
if (!save(properties)) {
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
}
}
bool shouldEnableOnBoot() {
DevelopmentSettings settings;
if (!load(settings)) {
return false;
}
return settings.enableOnBoot;
}
}
#endif // ESP_PLATFORM

View File

@ -15,7 +15,7 @@ namespace tt::service::wifi::settings {
constexpr auto* TAG = "WifiApSettings";
constexpr auto* AP_SETTINGS_FORMAT = "/data/service/Wifi/{}.ap.properties";
constexpr auto* AP_SETTINGS_FORMAT = "/data/settings/{}.ap.properties";
constexpr auto* AP_PROPERTIES_KEY_SSID = "ssid";
constexpr auto* AP_PROPERTIES_KEY_PASSWORD = "password";

View File

@ -78,9 +78,9 @@ static void importWifiAp(const std::string& filePath) {
}
static void importWifiApSettings(std::shared_ptr<hal::sdcard::SdCardDevice> sdcard) {
// auto lock = sdcard->getLock()->asScopedLock();
// lock.lock();
auto path = sdcard->getMountPath();
auto lock = sdcard->getLock()->asScopedLock();
lock.lock();
auto path = file::getChildPath(sdcard->getMountPath(), "settings");
std::vector<dirent> dirent_list;
if (file::scandir(path, dirent_list, [](const dirent* entry) {

View File

@ -8,14 +8,14 @@
namespace tt::service::wifi::settings {
constexpr auto* TAG = "WifiSettings";
constexpr auto* SETTINGS_FILE = "/data/service/Wifi/wifi.properties";
constexpr auto* SETTINGS_FILE = "/data/settings/wifi.properties";
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
struct WifiProperties {
struct WifiSettings {
bool enableOnBoot;
};
static bool load(WifiProperties& properties) {
static bool load(WifiSettings& settings) {
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
return false;
@ -26,29 +26,29 @@ static bool load(WifiProperties& properties) {
}
auto enable_on_boot_string = map[SETTINGS_KEY_ENABLE_ON_BOOT];
properties.enableOnBoot = (enable_on_boot_string == "true");
settings.enableOnBoot = (enable_on_boot_string == "true");
return true;
}
static bool save(const WifiProperties& properties) {
static bool save(const WifiSettings& settings) {
std::map<std::string, std::string> map;
map[SETTINGS_KEY_ENABLE_ON_BOOT] = properties.enableOnBoot ? "true" : "false";
map[SETTINGS_KEY_ENABLE_ON_BOOT] = settings.enableOnBoot ? "true" : "false";
return file::savePropertiesFile(SETTINGS_FILE, map);
}
void setEnableOnBoot(bool enable) {
WifiProperties properties { .enableOnBoot = enable };
if (!save(properties)) {
WifiSettings settings { .enableOnBoot = enable };
if (!save(settings)) {
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
}
}
bool shouldEnableOnBoot() {
WifiProperties properties;
if (!load(properties)) {
WifiSettings settings;
if (!load(settings)) {
return false;
}
return properties.enableOnBoot;
return settings.enableOnBoot;
}
} // namespace

View File

@ -1,20 +1,18 @@
#include "Tactility/BootProperties.h"
#include "Tactility/MountPoints.h"
#include "Tactility/file/PropertiesFile.h"
#include "Tactility/hal/sdcard/SdCardDevice.h"
#include <Tactility/Log.h>
#include <Tactility/MountPoints.h>
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Log.h>
#include <Tactility/settings/BootSettings.h>
#include <cassert>
#include <format>
#include <string>
#include <vector>
namespace tt {
namespace tt::settings {
constexpr auto* TAG = "BootProperties";
constexpr auto* PROPERTIES_FILE_FORMAT = "{}/boot.properties";
constexpr auto* PROPERTIES_FILE_FORMAT = "{}/settings/boot.properties";
constexpr auto* PROPERTIES_KEY_LAUNCHER_APP_ID = "launcherAppId";
constexpr auto* PROPERTIES_KEY_AUTO_START_APP_ID = "autoStartAppId";
@ -29,7 +27,7 @@ static std::string getPropertiesFilePath() {
return std::format(PROPERTIES_FILE_FORMAT, file::MOUNT_POINT_DATA);
}
bool loadBootProperties(BootProperties& properties) {
bool loadBootSettings(BootSettings& properties) {
const std::string path = getPropertiesFilePath();
if (!file::loadPropertiesFile(path, [&properties](auto& key, auto& value) {
if (key == PROPERTIES_KEY_AUTO_START_APP_ID) {

View File

@ -0,0 +1,166 @@
#include <Tactility/settings/DisplaySettings.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/hal/Device.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <map>
#include <string>
#include <utility>
namespace tt::settings::display {
constexpr auto* TAG = "DisplaySettings";
constexpr auto* SETTINGS_FILE = "/data/settings/display.properties";
constexpr auto* SETTINGS_KEY_ORIENTATION = "orientation";
constexpr auto* SETTINGS_KEY_GAMMA_CURVE = "gammaCurve";
constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
static Orientation getDefaultOrientation() {
auto* display = lv_display_get_default();
if (display == nullptr) {
return Orientation::Landscape;
}
if (lv_display_get_physical_horizontal_resolution(display) > lv_display_get_physical_vertical_resolution(display)) {
return Orientation::Landscape;
} else {
return Orientation::Portrait;
}
}
static std::string toString(Orientation orientation) {
switch (orientation) {
using enum Orientation;
case Portrait:
return "Portrait";
case Landscape:
return "Landscape";
case PortraitFlipped:
return "PortraitFlipped";
case LandscapeFlipped:
return "LandscapeFlipped";
default:
std::unreachable();
}
}
static bool fromString(const std::string& str, Orientation& orientation) {
if (str == "Portrait") {
orientation = Orientation::Portrait;
return true;
} else if (str == "Landscape") {
orientation = Orientation::Landscape;
return true;
} else if (str == "PortraitFlipped") {
orientation = Orientation::PortraitFlipped;
return true;
} else if (str == "LandscapeFlipped") {
orientation = Orientation::LandscapeFlipped;
return true;
} else {
return false;
}
}
bool load(DisplaySettings& settings) {
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
return false;
}
auto orientation_entry = map.find(SETTINGS_KEY_ORIENTATION);
Orientation orientation;
if (orientation_entry == map.end() || !fromString(orientation_entry->second, orientation)) {
orientation = getDefaultOrientation();
}
auto gamma_entry = map.find(SETTINGS_KEY_GAMMA_CURVE);
int gamma_curve = 0;
if (gamma_entry != map.end()) {
gamma_curve = atoi(gamma_entry->second.c_str());
}
auto backlight_duty_entry = map.find(SETTINGS_KEY_BACKLIGHT_DUTY);
int backlight_duty = 200; // default
if (backlight_duty_entry != map.end()) {
backlight_duty = atoi(backlight_duty_entry->second.c_str());
if (backlight_duty_entry->second != "0" && backlight_duty == 0) {
backlight_duty = 200;
}
}
settings.orientation = orientation;
settings.gammaCurve = gamma_curve;
settings.backlightDuty = backlight_duty;
return true;
}
DisplaySettings getDefault() {
return DisplaySettings {
.orientation = getDefaultOrientation(),
.gammaCurve = 1,
.backlightDuty = 200
};
}
DisplaySettings loadOrGetDefault() {
DisplaySettings settings;
if (!load(settings)) {
settings = getDefault();
}
return settings;
}
bool save(const DisplaySettings& settings) {
std::map<std::string, std::string> map;
map[SETTINGS_KEY_BACKLIGHT_DUTY] = std::to_string(settings.backlightDuty);
map[SETTINGS_KEY_GAMMA_CURVE] = std::to_string(settings.gammaCurve);
map[SETTINGS_KEY_ORIENTATION] = toString(settings.orientation);
return file::savePropertiesFile(SETTINGS_FILE, map);
}
lv_display_rotation_t toLvglDisplayRotation(Orientation orientation) {
auto* lvgl_display = lv_display_get_default();
auto rotation = lv_display_get_rotation(lvgl_display);
bool is_originally_landscape;
// The lvgl resolution code compensates for rotation. We have to revert the compensation to get the real display resolution
// TODO: Use info from display driver
if (rotation == LV_DISPLAY_ROTATION_0 || rotation == LV_DISPLAY_ROTATION_180) {
is_originally_landscape = lv_display_get_physical_horizontal_resolution(lvgl_display) > lv_display_get_physical_vertical_resolution(lvgl_display);
} else {
is_originally_landscape = lv_display_get_physical_horizontal_resolution(lvgl_display) < lv_display_get_physical_vertical_resolution(lvgl_display);
}
if (is_originally_landscape) {
// Landscape display
switch (orientation) {
case Orientation::Landscape:
return LV_DISPLAY_ROTATION_0;
case Orientation::Portrait:
return LV_DISPLAY_ROTATION_90;
case Orientation::LandscapeFlipped:
return LV_DISPLAY_ROTATION_180;
case Orientation::PortraitFlipped:
return LV_DISPLAY_ROTATION_270;
default:
return LV_DISPLAY_ROTATION_0;
}
} else {
// Portrait display
switch (orientation) {
case Orientation::Landscape:
return LV_DISPLAY_ROTATION_90;
case Orientation::Portrait:
return LV_DISPLAY_ROTATION_0;
case Orientation::LandscapeFlipped:
return LV_DISPLAY_ROTATION_270;
case Orientation::PortraitFlipped:
return LV_DISPLAY_ROTATION_180;
default:
return LV_DISPLAY_ROTATION_0;
}
}
}
} // namespace

View File

@ -1,25 +1,25 @@
#include <Tactility/Log.h>
#include <Tactility/settings/Language.h>
#include <utility>
#include <Tactility/settings/SettingsProperties.h>
#include <Tactility/settings/SystemSettings.h>
namespace tt::settings {
constexpr auto* TAG = "Language";
void setLanguage(Language newLanguage) {
SettingsProperties properties;
if (!loadSettingsProperties(properties)) {
SystemSettings properties;
if (!loadSystemSettings(properties)) {
return;
}
properties.language = newLanguage;
saveSettingsProperties(properties);
saveSystemSettings(properties);
}
Language getLanguage() {
SettingsProperties properties;
if (!loadSettingsProperties(properties)) {
SystemSettings properties;
if (!loadSystemSettings(properties)) {
return Language::en_US;
} else {
return properties.language;

View File

@ -2,18 +2,18 @@
#include <Tactility/file/FileLock.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/settings/Language.h>
#include <Tactility/settings/SettingsProperties.h>
#include <Tactility/settings/SystemSettings.h>
namespace tt::settings {
constexpr auto* TAG = "SettingsProperties";
constexpr auto* FILE_PATH = "/data/settings.properties";
constexpr auto* TAG = "SystemSettings";
constexpr auto* FILE_PATH = "/data/system.properties";
static Mutex mutex = Mutex();
static bool cached = false;
static SettingsProperties cachedProperties;
static SystemSettings cachedProperties;
static bool loadSettingsPropertiesFromFile(SettingsProperties& properties) {
static bool loadSystemSettingsFromFile(SystemSettings& properties) {
std::map<std::string, std::string> map;
if (!file::withLock<bool>(FILE_PATH, [&map] {
return file::loadPropertiesFile(FILE_PATH, map);
@ -39,12 +39,12 @@ static bool loadSettingsPropertiesFromFile(SettingsProperties& properties) {
return true;
}
bool loadSettingsProperties(SettingsProperties& properties) {
bool loadSystemSettings(SystemSettings& properties) {
auto scoped_lock = mutex.asScopedLock();
scoped_lock.lock();
if (!cached) {
if (!loadSettingsPropertiesFromFile(cachedProperties)) {
if (!loadSystemSettingsFromFile(cachedProperties)) {
return false;
}
cached = true;
@ -54,7 +54,7 @@ bool loadSettingsProperties(SettingsProperties& properties) {
return true;
}
bool saveSettingsProperties(const SettingsProperties& properties) {
bool saveSystemSettings(const SystemSettings& properties) {
auto scoped_lock = mutex.asScopedLock();
scoped_lock.lock();

View File

@ -2,7 +2,7 @@
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Preferences.h>
#include <Tactility/settings/SettingsProperties.h>
#include <Tactility/settings/SystemSettings.h>
#ifdef ESP_PLATFORM
#include <ctime>
@ -60,8 +60,8 @@ std::string getTimeZoneCode() {
}
bool isTimeFormat24Hour() {
SettingsProperties properties;
if (!loadSettingsProperties(properties)) {
SystemSettings properties;
if (!loadSystemSettings(properties)) {
return true;
} else {
return properties.timeFormat24h;
@ -69,13 +69,13 @@ bool isTimeFormat24Hour() {
}
void setTimeFormat24Hour(bool show24Hour) {
SettingsProperties properties;
if (!loadSettingsProperties(properties)) {
SystemSettings properties;
if (!loadSystemSettings(properties)) {
return;
}
properties.timeFormat24h = show24Hour;
saveSettingsProperties(properties);
saveSystemSettings(properties);
}
}

View File

@ -0,0 +1,52 @@
# Software defaults
# Increase stack size for WiFi (fixes crash after scan)
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=3072
CONFIG_LV_FONT_MONTSERRAT_14=y
CONFIG_LV_FONT_MONTSERRAT_18=y
CONFIG_LV_USE_USER_DATA=y
CONFIG_LV_USE_FS_STDIO=y
CONFIG_LV_FS_STDIO_LETTER=65
CONFIG_LV_FS_STDIO_PATH=""
CONFIG_LV_FS_STDIO_CACHE_SIZE=4096
CONFIG_LV_USE_LODEPNG=y
CONFIG_LV_USE_BUILTIN_MALLOC=n
CONFIG_LV_USE_CLIB_MALLOC=y
CONFIG_LV_USE_MSGBOX=n
CONFIG_LV_USE_SPINNER=n
CONFIG_LV_USE_WIN=n
CONFIG_LV_USE_SNAPSHOT=y
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2
CONFIG_FREERTOS_SMP=n
CONFIG_FREERTOS_UNICORE=n
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_FATFS_LFN_HEAP=y
CONFIG_FATFS_VOLUME_COUNT=3
CONFIG_FATFS_SECTOR_512=y
CONFIG_WL_SECTOR_SIZE_512=y
CONFIG_WL_SECTOR_SIZE=512
CONFIG_WL_SECTOR_MODE_SAFE=y
CONFIG_WL_SECTOR_MODE=1
# Hardware: Main
CONFIG_TT_BOARD_NAME="CYD 2432S028R"
CONFIG_TT_BOARD_ID="cyd-2432s028r"
CONFIG_TT_BOARD_CYD_2432S028R=y
CONFIG_IDF_TARGET="esp32"
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_FLASHMODE_QIO=y
# LVGL
CONFIG_LV_DISP_DEF_REFR_PERIOD=10
CONFIG_LV_DPI_DEF=160
CONFIG_LV_THEME_DEFAULT_DARK=y
# Fix for IRAM
CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y
CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=y
CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y