Replace Tactility SystemEvents with new kernel implementation (#598)
TactilityKernel now has a system event API to replace the one from the Tactility subproject. It also implements several tests for it.
This commit is contained in:
committed by
GitHub
parent
6e55e71e67
commit
acb2f1d4c7
@@ -4,7 +4,8 @@
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <Tactility/SystemEvents.h>
|
||||
#include <tactility/system_event.h>
|
||||
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/settings/TrackballSettings.h>
|
||||
|
||||
@@ -15,8 +16,6 @@ constexpr auto* TAG = "tdeck-plus";
|
||||
|
||||
extern "C" {
|
||||
|
||||
static tt::kernel::SystemEventSubscription tdeck_boot_splash_subscription = tt::kernel::NoSystemEventSubscription;
|
||||
|
||||
void init_trackball() {
|
||||
auto tbSettings = tt::settings::trackball::loadOrGetDefault();
|
||||
lvgl_lock();
|
||||
@@ -31,6 +30,10 @@ void init_trackball() {
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
static void on_boot_completed(struct SystemEvent* /*event*/, void* /*context*/) {
|
||||
init_trackball();
|
||||
}
|
||||
|
||||
static error_t start() {
|
||||
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
|
||||
@@ -42,16 +45,13 @@ static error_t start() {
|
||||
// Avoids crash when no SD card is inserted. It's unknown why, but likely is related to power draw.
|
||||
delay_millis(100);
|
||||
|
||||
tdeck_boot_splash_subscription = tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
init_trackball();
|
||||
});
|
||||
system_event_subscribe(KERNEL_EVENT_BOOT_COMPLETED, on_boot_completed, nullptr);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
tt::kernel::unsubscribeSystemEvent(tdeck_boot_splash_subscription);
|
||||
tdeck_boot_splash_subscription = tt::kernel::NoSystemEventSubscription;
|
||||
system_event_unsubscribe(KERNEL_EVENT_BOOT_COMPLETED, on_boot_completed);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#include <Tactility/SystemEvents.h>
|
||||
#include <tactility/system_event.h>
|
||||
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/settings/TrackballSettings.h>
|
||||
@@ -17,22 +18,24 @@ constexpr auto* TAG = "tdeck";
|
||||
|
||||
extern "C" {
|
||||
|
||||
static void on_boot_completed(struct SystemEvent* /*event*/, void* /*context*/) {
|
||||
auto tbSettings = tt::settings::trackball::loadOrGetDefault();
|
||||
lvgl_lock();
|
||||
if (trackball::init() != nullptr) {
|
||||
trackball::setMode(tbSettings.trackballMode == tt::settings::trackball::TrackballMode::Pointer
|
||||
? trackball::Mode::Pointer
|
||||
: trackball::Mode::Encoder);
|
||||
trackball::setEncoderSensitivity(tbSettings.encoderSensitivity);
|
||||
trackball::setPointerSensitivity(tbSettings.pointerSensitivity);
|
||||
trackball::setEnabled(tbSettings.trackballEnabled);
|
||||
}
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
void subscribe_events() {
|
||||
// The kernel trackball device is already started by kernel_init(); this just registers it as an
|
||||
// LVGL input device and applies persisted settings, both of which require LVGL to be up first.
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto tbSettings = tt::settings::trackball::loadOrGetDefault();
|
||||
lvgl_lock();
|
||||
if (trackball::init() != nullptr) {
|
||||
trackball::setMode(tbSettings.trackballMode == tt::settings::trackball::TrackballMode::Pointer
|
||||
? trackball::Mode::Pointer
|
||||
: trackball::Mode::Encoder);
|
||||
trackball::setEncoderSensitivity(tbSettings.encoderSensitivity);
|
||||
trackball::setPointerSensitivity(tbSettings.pointerSensitivity);
|
||||
trackball::setEnabled(tbSettings.trackballEnabled);
|
||||
}
|
||||
lvgl_unlock();
|
||||
});
|
||||
system_event_subscribe(KERNEL_EVENT_BOOT_COMPLETED, on_boot_completed, nullptr);
|
||||
}
|
||||
|
||||
static error_t start() {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <Tactility/SystemEvents.h>
|
||||
#include <tactility/system_event.h>
|
||||
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
|
||||
#include <lilygo/drivers/tpager_encoder_input.h>
|
||||
@@ -10,22 +11,21 @@ constexpr auto* TAG = "T-Lora Pager";
|
||||
|
||||
extern "C" {
|
||||
|
||||
tt::kernel::SystemEventSubscription event_subscription = tt::kernel::NoSystemEventSubscription;
|
||||
static void on_boot_completed(struct SystemEvent* /*event*/, void* /*context*/) {
|
||||
// The kernel tpager_encoder device is already started by kernel_init(); this just
|
||||
// registers it as an LVGL input device, which requires LVGL to be up first.
|
||||
lvgl_lock();
|
||||
tpager_encoder::init();
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
static error_t start() {
|
||||
event_subscription = tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent) {
|
||||
// The kernel tpager_encoder device is already started by kernel_init(); this just
|
||||
// registers it as an LVGL input device, which requires LVGL to be up first.
|
||||
lvgl_lock();
|
||||
tpager_encoder::init();
|
||||
lvgl_unlock();
|
||||
});
|
||||
system_event_subscribe(KERNEL_EVENT_BOOT_COMPLETED, on_boot_completed, nullptr);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
tt::kernel::unsubscribeSystemEvent(event_subscription);
|
||||
event_subscription = tt::kernel::NoSystemEventSubscription;
|
||||
system_event_unsubscribe(KERNEL_EVENT_BOOT_COMPLETED, on_boot_completed);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user