Merge develop into main (#307)
## Launcher - Launcher now has optional power button to show - Launcher layout improvements - Removed text from Launcher (translations with larger amounts of text did not fit small device formats) ## T-Lora Pager - Implement power off (created `BQ25896` driver) - Implemented haptics (created `DRV2605` driver project) and buzz on startup - Reversed scroll wheel - Created `TloraEncoder` device and relocated its logic from `TloraKeyboard` - Disabled SPIRAM test to save 0.5 seconds of boot time (current boot time is very slow) - Update `ST7796` esp_lcd driver to v1.3.4 - Fixed keyboard bug: delete queue in destructor - Fixed driver dependencies: Avoiding usage of global static shared_ptr. Properly constructor-inject everywhere, or use `tt::hal::findDevices()` - I2C configuration is now immutable (you cannot disable it anymore from the I2C Settings app, as it would break crucial drivers) - Renamed I2C and UART subsystems to "Internal" ## Drivers - On/off interface added to `PowerDevice` - Created `tt::hal::Configuration.createDevices`, which is intended to replace all custom create calls for display, keyboard, etc. - Created `EncoderDevice` as a `Device` subtype ## Other Improvements - Changed `findDevices(type, function)` into a templatized function. - Improved SD card mounting ## Fixes - Show Screenshot app again - Fixed Statusbar: some updates were allowed to time out and fail silently: When the Statusbar service would do a state update, the LVGL statusbar would never get updated due to this timeout. - Fixed memory leaks in all `createSdCard()` functions (in most board implementations)
This commit is contained in:
committed by
GitHub
parent
e9f72490fc
commit
50007ea9ed
@@ -1,43 +1,55 @@
|
||||
#include "Tactility/app/display/DisplaySettings.h"
|
||||
#include "Tactility/lvgl/Keyboard.h"
|
||||
#include "Tactility/lvgl/Lvgl.h"
|
||||
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
#include "Tactility/hal/touch/TouchDevice.h"
|
||||
#include <Tactility/app/display/DisplaySettings.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/hal/encoder/EncoderDevice.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/keyboard/KeyboardDevice.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <Tactility/lvgl/Keyboard.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/TactilityHeadless.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "Tactility/lvgl/EspLvglPort.h"
|
||||
#include <Tactility/lvgl/EspLvglPort.h>
|
||||
#endif
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/TactilityHeadless.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
#define TAG "Lvgl"
|
||||
constexpr auto* TAG = "Lvgl";
|
||||
|
||||
static bool started = false;
|
||||
|
||||
static std::shared_ptr<hal::display::DisplayDevice> createDisplay(const hal::Configuration& config) {
|
||||
assert(config.createDisplay);
|
||||
auto display = config.createDisplay();
|
||||
assert(display != nullptr);
|
||||
|
||||
if (!display->start()) {
|
||||
TT_LOG_E(TAG, "Display start failed");
|
||||
return nullptr;
|
||||
// TODO: Move to hal init
|
||||
static void initDisplays(const hal::Configuration& config) {
|
||||
TT_LOG_I(TAG, "Init displays");
|
||||
if (config.createDisplay != nullptr) {
|
||||
auto display = config.createDisplay();
|
||||
if (display != nullptr) {
|
||||
hal::registerDevice(display);
|
||||
}
|
||||
}
|
||||
|
||||
if (display->supportsBacklightDuty()) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
TT_LOG_I(TAG, "Start displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (auto& display : displays) {
|
||||
if (!display->start()) {
|
||||
TT_LOG_E(TAG, "Display start failed");
|
||||
}
|
||||
|
||||
return display;
|
||||
if (display->supportsBacklightDuty()) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
|
||||
auto touch = display->getTouchDevice();
|
||||
if (touch != nullptr) {
|
||||
hal::registerDevice(touch);
|
||||
touch->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init(const hal::Configuration& config) {
|
||||
@@ -49,25 +61,7 @@ void init(const hal::Configuration& config) {
|
||||
}
|
||||
#endif
|
||||
|
||||
auto display = createDisplay(config);
|
||||
if (display == nullptr) {
|
||||
return;
|
||||
}
|
||||
hal::registerDevice(display);
|
||||
|
||||
auto touch = display->getTouchDevice();
|
||||
if (touch != nullptr) {
|
||||
touch->start();
|
||||
hal::registerDevice(touch);
|
||||
}
|
||||
|
||||
auto configuration = hal::getConfiguration();
|
||||
if (configuration->createKeyboard) {
|
||||
auto keyboard = configuration->createKeyboard();
|
||||
if (keyboard != nullptr) {
|
||||
hal::registerDevice(keyboard);
|
||||
}
|
||||
}
|
||||
initDisplays(config);
|
||||
|
||||
start();
|
||||
|
||||
@@ -91,20 +85,27 @@ void start() {
|
||||
|
||||
// Start displays (their related touch devices start automatically within)
|
||||
|
||||
TT_LOG_I(TAG, "Start displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (auto display : displays) {
|
||||
if (display->supportsLvgl() && display->startLvgl()) {
|
||||
auto lvgl_display = display->getLvglDisplay();
|
||||
assert(lvgl_display != nullptr);
|
||||
lv_display_rotation_t rotation = app::display::getRotation();
|
||||
if (rotation != lv_display_get_rotation(lvgl_display)) {
|
||||
lv_display_set_rotation(lvgl_display, rotation);
|
||||
if (display->supportsLvgl()) {
|
||||
if (display->startLvgl()) {
|
||||
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();
|
||||
if (rotation != lv_display_get_rotation(lvgl_display)) {
|
||||
lv_display_set_rotation(lvgl_display, rotation);
|
||||
}
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Start failed for %s", display->getName().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start touch
|
||||
|
||||
TT_LOG_I(TAG, "Start touch devices");
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (auto touch_device : touch_devices) {
|
||||
if (displays.size() > 0) {
|
||||
@@ -112,13 +113,17 @@ void start() {
|
||||
auto display = displays[0];
|
||||
// Start any touch devices that haven't been started yet
|
||||
if (touch_device->supportsLvgl() && touch_device->getLvglIndev() == nullptr) {
|
||||
touch_device->startLvgl(display->getLvglDisplay());
|
||||
if (touch_device->startLvgl(display->getLvglDisplay())) {
|
||||
TT_LOG_I(TAG, "Started %s", touch_device->getName().c_str());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Start failed for %s", touch_device->getName().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start keyboards
|
||||
|
||||
TT_LOG_I(TAG, "Start keyboards");
|
||||
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
|
||||
for (auto keyboard : keyboards) {
|
||||
if (displays.size() > 0) {
|
||||
@@ -128,14 +133,29 @@ void start() {
|
||||
if (keyboard->startLvgl(display->getLvglDisplay())) {
|
||||
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
|
||||
hardware_keyboard_set_indev(keyboard_indev);
|
||||
TT_LOG_I(TAG, "Keyboard started");
|
||||
TT_LOG_I(TAG, "Started %s", keyboard->getName().c_str());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Keyboard start failed");
|
||||
TT_LOG_E(TAG, "Start failed for %s", keyboard->getName().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start encoders
|
||||
TT_LOG_I(TAG, "Start encoders");
|
||||
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
|
||||
for (auto encoder : encoders) {
|
||||
if (displays.size() > 0) {
|
||||
// TODO: Consider implementing support for multiple displays
|
||||
auto display = displays[0];
|
||||
if (encoder->startLvgl(display->getLvglDisplay())) {
|
||||
TT_LOG_I(TAG, "Started %s", encoder->getName().c_str());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Start failed for %s", encoder->getName().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restart services
|
||||
|
||||
if (service::getState("Gui") == service::State::Stopped) {
|
||||
@@ -158,7 +178,7 @@ void start() {
|
||||
}
|
||||
|
||||
void stop() {
|
||||
TT_LOG_I(TAG, "Stop LVGL");
|
||||
TT_LOG_I(TAG, "Stopping LVGL");
|
||||
|
||||
if (!started) {
|
||||
TT_LOG_W(TAG, "Can't stop LVGL: not started");
|
||||
@@ -175,6 +195,7 @@ void stop() {
|
||||
|
||||
// Stop keyboards
|
||||
|
||||
TT_LOG_I(TAG, "Stopping keyboards");
|
||||
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
|
||||
for (auto keyboard : keyboards) {
|
||||
if (keyboard->getLvglIndev() != nullptr) {
|
||||
@@ -184,6 +205,7 @@ void stop() {
|
||||
|
||||
// Stop touch
|
||||
|
||||
TT_LOG_I(TAG, "Stopping touch");
|
||||
// The display generally stops their own touch devices, but we'll clean up anything that didn't
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (auto touch_device : touch_devices) {
|
||||
@@ -192,8 +214,19 @@ void stop() {
|
||||
}
|
||||
}
|
||||
|
||||
// Stop encoders
|
||||
|
||||
TT_LOG_I(TAG, "Stopping encoders");
|
||||
// The display generally stops their own touch devices, but we'll clean up anything that didn't
|
||||
auto encoder_devices = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
|
||||
for (auto encoder_device : encoder_devices) {
|
||||
if (encoder_device->getLvglIndev() != nullptr) {
|
||||
encoder_device->stopLvgl();
|
||||
}
|
||||
}
|
||||
// Stop displays (and their touch devices)
|
||||
|
||||
TT_LOG_I(TAG, "Stopping displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (auto display : displays) {
|
||||
if (display->supportsLvgl() && display->getLvglDisplay() != nullptr && !display->stopLvgl()) {
|
||||
@@ -204,6 +237,8 @@ void stop() {
|
||||
started = false;
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::LvglStopped);
|
||||
|
||||
TT_LOG_I(TAG, "Stopped LVGL");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -111,7 +111,7 @@ static const lv_obj_class_t statusbar_class = {
|
||||
static void statusbar_pubsub_event(TT_UNUSED const void* message, void* obj) {
|
||||
TT_LOG_D(TAG, "event");
|
||||
auto* statusbar = static_cast<Statusbar*>(obj);
|
||||
if (lock(kernel::millisToTicks(100))) {
|
||||
if (lock(portMAX_DELAY)) {
|
||||
update_main(statusbar);
|
||||
lv_obj_invalidate(&statusbar->obj);
|
||||
unlock();
|
||||
@@ -119,7 +119,7 @@ static void statusbar_pubsub_event(TT_UNUSED const void* message, void* obj) {
|
||||
}
|
||||
|
||||
static void onTimeChanged(TT_UNUSED kernel::SystemEvent event) {
|
||||
if (statusbar_data.mutex.lock(100 / portTICK_PERIOD_MS)) {
|
||||
if (statusbar_data.mutex.lock()) {
|
||||
statusbar_data.time_update_timer->stop();
|
||||
statusbar_data.time_update_timer->start(5);
|
||||
|
||||
@@ -136,7 +136,7 @@ static void statusbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
statusbar->pubsub_subscription = statusbar_data.pubsub->subscribe(&statusbar_pubsub_event, statusbar);
|
||||
|
||||
if (!statusbar_data.time_update_timer->isRunning()) {
|
||||
statusbar_data.time_update_timer->start(50 / portTICK_PERIOD_MS);
|
||||
statusbar_data.time_update_timer->start(200 / portTICK_PERIOD_MS);
|
||||
statusbar_data.systemEventSubscription = kernel::subscribeSystemEvent(
|
||||
kernel::SystemEvent::Time,
|
||||
onTimeChanged
|
||||
@@ -210,7 +210,7 @@ static void update_time(Statusbar* statusbar) {
|
||||
static void update_main(Statusbar* statusbar) {
|
||||
update_time(statusbar);
|
||||
|
||||
if (statusbar_lock(50 / portTICK_PERIOD_MS)) {
|
||||
if (statusbar_lock(200 / portTICK_PERIOD_MS)) {
|
||||
for (int i = 0; i < STATUSBAR_ICON_LIMIT; ++i) {
|
||||
update_icon(statusbar->icons[i], &(statusbar_data.icons[i]));
|
||||
}
|
||||
@@ -270,7 +270,7 @@ void statusbar_icon_remove(int8_t id) {
|
||||
void statusbar_icon_set_image(int8_t id, const std::string& image) {
|
||||
TT_LOG_D(TAG, "id %d: set image %s", id, image.empty() ? "(none)" : image.c_str());
|
||||
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
if (statusbar_lock(50 / portTICK_PERIOD_MS)) {
|
||||
if (statusbar_lock()) {
|
||||
StatusbarIcon* icon = &statusbar_data.icons[id];
|
||||
tt_check(icon->claimed);
|
||||
icon->image = image;
|
||||
@@ -282,7 +282,7 @@ void statusbar_icon_set_image(int8_t id, const std::string& image) {
|
||||
void statusbar_icon_set_visibility(int8_t id, bool visible) {
|
||||
TT_LOG_D(TAG, "id %d: set visibility %d", id, visible);
|
||||
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
if (statusbar_lock(50 / portTICK_PERIOD_MS)) {
|
||||
if (statusbar_lock()) {
|
||||
StatusbarIcon* icon = &statusbar_data.icons[id];
|
||||
tt_check(icon->claimed);
|
||||
icon->visible = visible;
|
||||
|
||||
Reference in New Issue
Block a user