New kernel drivers and device migrations (#563)
This commit is contained in:
committed by
GitHub
parent
955416dac8
commit
8af6204ba1
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
|
||||
@@ -24,16 +23,6 @@ static std::shared_ptr<hal::display::DisplayDevice> getHalDisplay() {
|
||||
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
}
|
||||
|
||||
static bool hasCalibratableTouchDevice() {
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (const auto& touch_device : touch_devices) {
|
||||
if (touch_device != nullptr && touch_device->supportsCalibration()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class HalDisplayApp final : public App {
|
||||
|
||||
settings::display::DisplaySettings displaySettings;
|
||||
@@ -131,10 +120,6 @@ class HalDisplayApp final : public App {
|
||||
}
|
||||
}
|
||||
|
||||
static void onCalibrateTouchClicked(lv_event_t*) {
|
||||
app::start("TouchCalibration");
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
@@ -294,25 +279,6 @@ public:
|
||||
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCalibratableTouchDevice()) {
|
||||
auto* calibrate_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(calibrate_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(calibrate_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(calibrate_wrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* calibrate_label = lv_label_create(calibrate_wrapper);
|
||||
lv_label_set_text(calibrate_label, "Touch calibration");
|
||||
lv_obj_align(calibrate_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
auto* calibrate_button = lv_button_create(calibrate_wrapper);
|
||||
lv_obj_align(calibrate_button, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(calibrate_button, onCalibrateTouchClicked, LV_EVENT_SHORT_CLICKED, this);
|
||||
|
||||
auto* calibrate_button_label = lv_label_create(calibrate_button);
|
||||
lv_label_set_text(calibrate_button_label, "Calibrate");
|
||||
lv_obj_center(calibrate_button_label);
|
||||
}
|
||||
}
|
||||
|
||||
void onHide(AppContext& app) override {
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <sdkconfig.h>
|
||||
#endif
|
||||
|
||||
namespace tt::app::kerneldisplay {
|
||||
|
||||
constexpr auto* TAG = "KernelDisplay";
|
||||
@@ -250,9 +254,6 @@ public:
|
||||
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: no touch calibration section here - unlike HalDisplayApp, the kernel PointerApi has
|
||||
// no calibration support yet.
|
||||
}
|
||||
|
||||
void onHide(AppContext& app) override {
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace tt::app::power {
|
||||
|
||||
#define TAG "power"
|
||||
@@ -30,20 +32,32 @@ std::shared_ptr<PowerApp> optApp() {
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr PowerSupplyProperty DISPLAYED_PROPERTIES[] = {
|
||||
POWER_SUPPLY_PROP_IS_CHARGING,
|
||||
POWER_SUPPLY_PROP_VOLTAGE,
|
||||
POWER_SUPPLY_PROP_CAPACITY,
|
||||
POWER_SUPPLY_PROP_CURRENT,
|
||||
};
|
||||
} // namespace
|
||||
|
||||
struct PropertyWidget {
|
||||
PowerSupplyProperty property;
|
||||
lv_obj_t* label;
|
||||
};
|
||||
|
||||
struct DeviceEntry {
|
||||
::Device* device = nullptr;
|
||||
lv_obj_t* enableSwitch = nullptr;
|
||||
lv_obj_t* quickChargeSwitch = nullptr;
|
||||
std::vector<PropertyWidget> propertyWidgets;
|
||||
};
|
||||
|
||||
class PowerApp : public App {
|
||||
|
||||
Timer update_timer = Timer(Timer::Type::Periodic, kernel::millisToTicks(1000),[]() { onTimer(); });
|
||||
|
||||
::Device* power = nullptr;
|
||||
|
||||
lv_obj_t* enableLabel = nullptr;
|
||||
lv_obj_t* enableSwitch = nullptr;
|
||||
lv_obj_t* quickChargeLabel = nullptr;
|
||||
lv_obj_t* quickChargeSwitch = nullptr;
|
||||
lv_obj_t* batteryVoltageLabel = nullptr;
|
||||
lv_obj_t* chargeStateLabel = nullptr;
|
||||
lv_obj_t* chargeLevelLabel = nullptr;
|
||||
lv_obj_t* currentLabel = nullptr;
|
||||
std::vector<DeviceEntry> entries;
|
||||
|
||||
static void onTimer() {
|
||||
auto app = optApp();
|
||||
@@ -52,22 +66,31 @@ class PowerApp : public App {
|
||||
}
|
||||
}
|
||||
|
||||
static bool collectDevice(::Device* device, void* context) {
|
||||
auto* devices = static_cast<std::vector<::Device*>*>(context);
|
||||
devices->push_back(device);
|
||||
return true;
|
||||
}
|
||||
|
||||
void onPowerEnabledChanged(lv_event_t* event) {
|
||||
lv_event_code_t code = lv_event_get_code(event);
|
||||
auto* enable_switch = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||
bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED);
|
||||
auto* device = static_cast<::Device*>(lv_event_get_user_data(event));
|
||||
|
||||
if (power_supply_is_allowed_to_charge(power) != is_on) {
|
||||
power_supply_set_allowed_to_charge(power, is_on);
|
||||
if (power_supply_is_allowed_to_charge(device) != is_on) {
|
||||
power_supply_set_allowed_to_charge(device, is_on);
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void onPowerEnabledChangedCallback(lv_event_t* event) {
|
||||
auto* app = (PowerApp*)lv_event_get_user_data(event);
|
||||
app->onPowerEnabledChanged(event);
|
||||
auto app = optApp();
|
||||
if (app != nullptr) {
|
||||
app->onPowerEnabledChanged(event);
|
||||
}
|
||||
}
|
||||
|
||||
void onQuickChargeChanged(lv_event_t* event) {
|
||||
@@ -75,97 +98,61 @@ class PowerApp : public App {
|
||||
auto* qc_switch = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||
bool is_on = lv_obj_has_state(qc_switch, LV_STATE_CHECKED);
|
||||
auto* device = static_cast<::Device*>(lv_event_get_user_data(event));
|
||||
|
||||
if (power_supply_is_quick_charge_enabled(power) != is_on) {
|
||||
power_supply_set_quick_charge_enabled(power, is_on);
|
||||
if (power_supply_is_quick_charge_enabled(device) != is_on) {
|
||||
power_supply_set_quick_charge_enabled(device, is_on);
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void onQuickChargeChangedCallback(lv_event_t* event) {
|
||||
auto* app = (PowerApp*)lv_event_get_user_data(event);
|
||||
app->onQuickChargeChanged(event);
|
||||
auto app = optApp();
|
||||
if (app != nullptr) {
|
||||
app->onQuickChargeChanged(event);
|
||||
}
|
||||
}
|
||||
|
||||
static void setPropertyLabelText(lv_obj_t* label, PowerSupplyProperty property, const PowerSupplyPropertyValue& value) {
|
||||
switch (property) {
|
||||
case POWER_SUPPLY_PROP_IS_CHARGING:
|
||||
lv_label_set_text_fmt(label, "Charging: %s", value.int_value ? "yes" : "no");
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_VOLTAGE:
|
||||
lv_label_set_text_fmt(label, "Battery voltage: %d mV", value.int_value);
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_CAPACITY:
|
||||
lv_label_set_text_fmt(label, "Charge level: %d%%", value.int_value);
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_CURRENT:
|
||||
lv_label_set_text_fmt(label, "Current: %d mA", value.int_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void updateUi() {
|
||||
if (chargeStateLabel == nullptr) {
|
||||
if (entries.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* charge_state;
|
||||
PowerSupplyPropertyValue property_value;
|
||||
if (power_supply_get_property(power, POWER_SUPPLY_PROP_IS_CHARGING, &property_value) == ERROR_NONE) {
|
||||
charge_state = property_value.int_value ? "yes" : "no";
|
||||
} else {
|
||||
charge_state = "N/A";
|
||||
}
|
||||
|
||||
int charge_level;
|
||||
bool charge_level_scaled_set = false;
|
||||
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CAPACITY, &property_value) == ERROR_NONE) {
|
||||
charge_level = property_value.int_value;
|
||||
charge_level_scaled_set = true;
|
||||
}
|
||||
|
||||
bool charging_enabled_set = power_supply_supports_charge_control(power);
|
||||
bool charging_enabled_and_allowed = charging_enabled_set && power_supply_is_allowed_to_charge(power);
|
||||
|
||||
bool quick_charge_set = power_supply_supports_quick_charge(power);
|
||||
bool quick_charge_enabled = quick_charge_set && power_supply_is_quick_charge_enabled(power);
|
||||
|
||||
int current;
|
||||
bool current_set = false;
|
||||
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CURRENT, &property_value) == ERROR_NONE) {
|
||||
current = property_value.int_value;
|
||||
current_set = true;
|
||||
}
|
||||
|
||||
int battery_voltage;
|
||||
bool battery_voltage_set = false;
|
||||
if (power_supply_get_property(power, POWER_SUPPLY_PROP_VOLTAGE, &property_value) == ERROR_NONE) {
|
||||
battery_voltage = property_value.int_value;
|
||||
battery_voltage_set = true;
|
||||
}
|
||||
|
||||
lvgl::lock(kernel::millisToTicks(1000));
|
||||
|
||||
if (charging_enabled_set) {
|
||||
lv_obj_set_state(enableSwitch, LV_STATE_CHECKED, charging_enabled_and_allowed);
|
||||
lv_obj_remove_flag(enableSwitch, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(enableLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_obj_add_flag(enableSwitch, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(enableLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
for (auto& entry : entries) {
|
||||
if (entry.enableSwitch != nullptr) {
|
||||
lv_obj_set_state(entry.enableSwitch, LV_STATE_CHECKED, power_supply_is_allowed_to_charge(entry.device));
|
||||
}
|
||||
|
||||
if (quick_charge_set) {
|
||||
lv_obj_set_state(quickChargeSwitch, LV_STATE_CHECKED, quick_charge_enabled);
|
||||
lv_obj_remove_flag(quickChargeSwitch, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(quickChargeLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_obj_add_flag(quickChargeSwitch, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(quickChargeLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
if (entry.quickChargeSwitch != nullptr) {
|
||||
lv_obj_set_state(entry.quickChargeSwitch, LV_STATE_CHECKED, power_supply_is_quick_charge_enabled(entry.device));
|
||||
}
|
||||
|
||||
lv_label_set_text_fmt(chargeStateLabel, "Charging: %s", charge_state);
|
||||
|
||||
if (battery_voltage_set) {
|
||||
lv_label_set_text_fmt(batteryVoltageLabel, "Battery voltage: %d mV", battery_voltage);
|
||||
} else {
|
||||
lv_label_set_text_fmt(batteryVoltageLabel, "Battery voltage: N/A");
|
||||
}
|
||||
|
||||
if (charge_level_scaled_set) {
|
||||
lv_label_set_text_fmt(chargeLevelLabel, "Charge level: %d%%", charge_level);
|
||||
} else {
|
||||
lv_label_set_text_fmt(chargeLevelLabel, "Charge level: N/A");
|
||||
}
|
||||
|
||||
if (current_set) {
|
||||
lv_label_set_text_fmt(currentLabel, "Current: %d mA", current);
|
||||
} else {
|
||||
lv_label_set_text_fmt(currentLabel, "Current: N/A");
|
||||
PowerSupplyPropertyValue value;
|
||||
for (auto& widget : entry.propertyWidgets) {
|
||||
if (power_supply_get_property(entry.device, widget.property, &value) == ERROR_NONE) {
|
||||
setPropertyLabelText(widget.label, widget.property, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lvgl::unlock();
|
||||
@@ -173,9 +160,7 @@ class PowerApp : public App {
|
||||
|
||||
public:
|
||||
|
||||
void onCreate(AppContext& app) override {
|
||||
power = device_find_first_active_by_type(&POWER_SUPPLY_TYPE);
|
||||
}
|
||||
void onCreate(AppContext& app) override {}
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
@@ -183,7 +168,10 @@ public:
|
||||
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
if (power == nullptr) {
|
||||
std::vector<::Device*> devices;
|
||||
device_for_each_of_type(&POWER_SUPPLY_TYPE, &devices, collectDevice);
|
||||
|
||||
if (devices.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -193,60 +181,75 @@ public:
|
||||
lv_obj_set_flex_grow(wrapper, 1);
|
||||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
// Row: charge enable/disable
|
||||
lv_obj_t* switch_container = lv_obj_create(wrapper);
|
||||
lv_obj_set_width(switch_container, LV_PCT(100));
|
||||
lv_obj_set_height(switch_container, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(switch_container, 0, 0);
|
||||
lv_obj_set_style_pad_gap(switch_container, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(switch_container);
|
||||
entries.clear();
|
||||
entries.reserve(devices.size());
|
||||
|
||||
enableLabel = lv_label_create(switch_container);
|
||||
lv_label_set_text(enableLabel, "Charging enabled");
|
||||
lv_obj_set_align(enableLabel, LV_ALIGN_LEFT_MID);
|
||||
for (size_t i = 0; i < devices.size(); i++) {
|
||||
::Device* device = devices[i];
|
||||
|
||||
lv_obj_t* enable_switch = lv_switch_create(switch_container);
|
||||
lv_obj_add_event_cb(enable_switch, onPowerEnabledChangedCallback, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_obj_set_align(enable_switch, LV_ALIGN_RIGHT_MID);
|
||||
enableSwitch = enable_switch;
|
||||
DeviceEntry entry;
|
||||
entry.device = device;
|
||||
|
||||
// Row: quick charge enable/disable
|
||||
lv_obj_t* qc_container = lv_obj_create(wrapper);
|
||||
lv_obj_set_width(qc_container, LV_PCT(100));
|
||||
lv_obj_set_height(qc_container, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(qc_container, 0, 0);
|
||||
lv_obj_set_style_pad_gap(qc_container, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(qc_container);
|
||||
lv_obj_t* header = lv_label_create(wrapper);
|
||||
lv_label_set_text_fmt(header, "%s:", device->name);
|
||||
|
||||
quickChargeLabel = lv_label_create(qc_container);
|
||||
lv_label_set_text(quickChargeLabel, "Quick charge");
|
||||
lv_obj_set_align(quickChargeLabel, LV_ALIGN_LEFT_MID);
|
||||
if (power_supply_supports_charge_control(device)) {
|
||||
lv_obj_t* switch_container = lv_obj_create(wrapper);
|
||||
lv_obj_set_width(switch_container, LV_PCT(100));
|
||||
lv_obj_set_height(switch_container, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(switch_container, 0, 0);
|
||||
lv_obj_set_style_pad_gap(switch_container, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(switch_container);
|
||||
|
||||
lv_obj_t* qc_switch = lv_switch_create(qc_container);
|
||||
lv_obj_add_event_cb(qc_switch, onQuickChargeChangedCallback, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_obj_set_align(qc_switch, LV_ALIGN_RIGHT_MID);
|
||||
quickChargeSwitch = qc_switch;
|
||||
lv_obj_t* label = lv_label_create(switch_container);
|
||||
lv_label_set_text(label, "Charging enabled");
|
||||
lv_obj_set_align(label, LV_ALIGN_LEFT_MID);
|
||||
|
||||
chargeStateLabel = lv_label_create(wrapper);
|
||||
chargeLevelLabel = lv_label_create(wrapper);
|
||||
batteryVoltageLabel = lv_label_create(wrapper);
|
||||
currentLabel = lv_label_create(wrapper);
|
||||
lv_obj_t* enable_switch = lv_switch_create(switch_container);
|
||||
lv_obj_add_event_cb(enable_switch, onPowerEnabledChangedCallback, LV_EVENT_VALUE_CHANGED, device);
|
||||
lv_obj_set_align(enable_switch, LV_ALIGN_RIGHT_MID);
|
||||
lv_obj_set_state(enable_switch, LV_STATE_CHECKED, power_supply_is_allowed_to_charge(device));
|
||||
entry.enableSwitch = enable_switch;
|
||||
}
|
||||
|
||||
updateUi();
|
||||
if (power_supply_supports_quick_charge(device)) {
|
||||
lv_obj_t* qc_container = lv_obj_create(wrapper);
|
||||
lv_obj_set_width(qc_container, LV_PCT(100));
|
||||
lv_obj_set_height(qc_container, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(qc_container, 0, 0);
|
||||
lv_obj_set_style_pad_gap(qc_container, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(qc_container);
|
||||
|
||||
lv_obj_t* label = lv_label_create(qc_container);
|
||||
lv_label_set_text(label, "Quick charge");
|
||||
lv_obj_set_align(label, LV_ALIGN_LEFT_MID);
|
||||
|
||||
lv_obj_t* qc_switch = lv_switch_create(qc_container);
|
||||
lv_obj_add_event_cb(qc_switch, onQuickChargeChangedCallback, LV_EVENT_VALUE_CHANGED, device);
|
||||
lv_obj_set_align(qc_switch, LV_ALIGN_RIGHT_MID);
|
||||
lv_obj_set_state(qc_switch, LV_STATE_CHECKED, power_supply_is_quick_charge_enabled(device));
|
||||
entry.quickChargeSwitch = qc_switch;
|
||||
}
|
||||
|
||||
PowerSupplyPropertyValue value;
|
||||
for (auto property : DISPLAYED_PROPERTIES) {
|
||||
if (power_supply_get_property(device, property, &value) == ERROR_NONE) {
|
||||
lv_obj_t* label = lv_label_create(wrapper);
|
||||
lv_obj_set_style_margin_left(label, 24, LV_STATE_DEFAULT);
|
||||
setPropertyLabelText(label, property, value);
|
||||
entry.propertyWidgets.push_back({ property, label });
|
||||
}
|
||||
}
|
||||
|
||||
entries.push_back(entry);
|
||||
}
|
||||
|
||||
update_timer.start();
|
||||
}
|
||||
|
||||
void onHide(AppContext& app) override {
|
||||
update_timer.stop();
|
||||
enableLabel = nullptr;
|
||||
enableSwitch = nullptr;
|
||||
quickChargeLabel = nullptr;
|
||||
quickChargeSwitch = nullptr;
|
||||
chargeStateLabel = nullptr;
|
||||
chargeLevelLabel = nullptr;
|
||||
batteryVoltageLabel = nullptr;
|
||||
currentLabel = nullptr;
|
||||
entries.clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,14 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <sdkconfig.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TT_TOUCH_CALIBRATION_REQUIRED
|
||||
#include <Tactility/app/touchcalibration/TouchCalibration.h>
|
||||
#endif
|
||||
|
||||
namespace tt::app::setup {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
@@ -139,6 +147,13 @@ public:
|
||||
|
||||
void onCreate(AppContext& app) override {
|
||||
steps = {
|
||||
#if defined(CONFIG_TT_TOUCH_CALIBRATION_REQUIRED)
|
||||
{
|
||||
.title = "Touch Calibration",
|
||||
.description = "Let's calibrate the touch screen.",
|
||||
.run = [] { touchcalibration::start(); }
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.title = "Time Zone Setup",
|
||||
.description = "Let's set the time zone.",
|
||||
|
||||
@@ -166,16 +166,16 @@ class TimeZoneApp final : public App {
|
||||
}
|
||||
|
||||
void updateList() {
|
||||
if (lvgl::lock(100 / portTICK_PERIOD_MS)) {
|
||||
if (lvgl::lock(200 / portTICK_PERIOD_MS)) {
|
||||
std::string filter = string::lowercase(std::string(lv_textarea_get_text(filterTextareaWidget)));
|
||||
readTimeZones(filter);
|
||||
lvgl::unlock();
|
||||
readTimeZones(filter);
|
||||
} else {
|
||||
LOG_E(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
|
||||
LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "TimeZone LVGL");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lvgl::lock(100 / portTICK_PERIOD_MS)) {
|
||||
if (lvgl::lock(200 / portTICK_PERIOD_MS)) {
|
||||
if (mutex.lock(100 / portTICK_PERIOD_MS)) {
|
||||
lv_obj_clean(listWidget);
|
||||
|
||||
@@ -189,6 +189,8 @@ class TimeZoneApp final : public App {
|
||||
}
|
||||
|
||||
lvgl::unlock();
|
||||
} else {
|
||||
LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "TimeZone LVGL");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#include <Tactility/Tactility.h>
|
||||
|
||||
#include <Tactility/app/touchcalibration/TouchCalibration.h>
|
||||
|
||||
#if defined(CONFIG_TT_TOUCH_CALIBRATION_SUPPORTED)
|
||||
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/settings/TouchCalibrationSettings.h>
|
||||
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/lvgl_module.h>
|
||||
#include <tactility/lvgl_pointer.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <lvgl.h>
|
||||
@@ -30,6 +33,7 @@ class TouchCalibrationApp final : public App {
|
||||
|
||||
Sample samples[4] = {};
|
||||
uint8_t sampleCount = 0;
|
||||
bool calibrationApplied = false;
|
||||
|
||||
lv_obj_t* root = nullptr;
|
||||
lv_obj_t* target = nullptr;
|
||||
@@ -73,12 +77,33 @@ class TouchCalibrationApp final : public App {
|
||||
}
|
||||
|
||||
void finishCalibration() {
|
||||
constexpr int32_t MIN_RANGE = 20;
|
||||
const int32_t xLow = (static_cast<int32_t>(samples[0].x) + static_cast<int32_t>(samples[3].x)) / 2;
|
||||
const int32_t xHigh = (static_cast<int32_t>(samples[1].x) + static_cast<int32_t>(samples[2].x)) / 2;
|
||||
const int32_t yLow = (static_cast<int32_t>(samples[0].y) + static_cast<int32_t>(samples[1].y)) / 2;
|
||||
const int32_t yHigh = (static_cast<int32_t>(samples[2].y) + static_cast<int32_t>(samples[3].y)) / 2;
|
||||
|
||||
const int32_t xMin = (static_cast<int32_t>(samples[0].x) + static_cast<int32_t>(samples[3].x)) / 2;
|
||||
const int32_t xMax = (static_cast<int32_t>(samples[1].x) + static_cast<int32_t>(samples[2].x)) / 2;
|
||||
const int32_t yMin = (static_cast<int32_t>(samples[0].y) + static_cast<int32_t>(samples[1].y)) / 2;
|
||||
const int32_t yMax = (static_cast<int32_t>(samples[2].y) + static_cast<int32_t>(samples[3].y)) / 2;
|
||||
// Targets sit TARGET_MARGIN in from each edge (see getTargetPoint()), not at the screen
|
||||
// edges themselves - xLow/xHigh/yLow/yHigh are raw samples at those inset positions, not
|
||||
// at 0/width or 0/height. Extrapolate them out to the true edges so the saved range (which
|
||||
// lvgl_pointer.h maps onto the full [0, resolution) display range) lines up correctly
|
||||
// across the whole screen instead of being off by a margin's worth of scale and offset.
|
||||
const auto width = lv_obj_get_content_width(root);
|
||||
const auto height = lv_obj_get_content_height(root);
|
||||
const int32_t xSpan = static_cast<int32_t>(width) - 2 * TARGET_MARGIN;
|
||||
const int32_t ySpan = static_cast<int32_t>(height) - 2 * TARGET_MARGIN;
|
||||
|
||||
if (xSpan <= 0 || ySpan <= 0) {
|
||||
lv_label_set_text(titleLabel, "Calibration Failed");
|
||||
lv_label_set_text(hintLabel, "Screen too small. Tap to close.");
|
||||
lv_obj_add_flag(target, LV_OBJ_FLAG_HIDDEN);
|
||||
setResult(Result::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
const int32_t xMin = xLow - (xHigh - xLow) * TARGET_MARGIN / xSpan;
|
||||
const int32_t xMax = xHigh + (xHigh - xLow) * TARGET_MARGIN / xSpan;
|
||||
const int32_t yMin = yLow - (yHigh - yLow) * TARGET_MARGIN / ySpan;
|
||||
const int32_t yMax = yHigh + (yHigh - yLow) * TARGET_MARGIN / ySpan;
|
||||
|
||||
settings::touch::TouchCalibrationSettings settings = settings::touch::getDefault();
|
||||
settings.enabled = true;
|
||||
@@ -87,7 +112,7 @@ class TouchCalibrationApp final : public App {
|
||||
settings.yMin = yMin;
|
||||
settings.yMax = yMax;
|
||||
|
||||
if ((xMax - xMin) < MIN_RANGE || (yMax - yMin) < MIN_RANGE || !settings::touch::isValid(settings)) {
|
||||
if (!settings::touch::isValid(settings)) {
|
||||
lv_label_set_text(titleLabel, "Calibration Failed");
|
||||
lv_label_set_text(hintLabel, "Range invalid. Tap to close.");
|
||||
lv_obj_add_flag(target, LV_OBJ_FLAG_HIDDEN);
|
||||
@@ -103,6 +128,20 @@ class TouchCalibrationApp final : public App {
|
||||
return;
|
||||
}
|
||||
|
||||
LvglPointerCalibration calibration = {
|
||||
.x_min = xMin,
|
||||
.x_max = xMax,
|
||||
.y_min = yMin,
|
||||
.y_max = yMax,
|
||||
};
|
||||
lvgl_lock();
|
||||
auto* indev = lvgl_pointer_get_default();
|
||||
if (indev != nullptr) {
|
||||
lvgl_pointer_set_calibration(indev, &calibration);
|
||||
}
|
||||
lvgl_unlock();
|
||||
calibrationApplied = true;
|
||||
|
||||
LOG_I(TAG, "Saved calibration x=[%d, %d] y=[%d, %d]", xMin, xMax, yMin, yMax);
|
||||
lv_label_set_text(titleLabel, "Calibration Complete");
|
||||
lv_label_set_text(hintLabel, "Touch anywhere to continue.");
|
||||
@@ -141,14 +180,36 @@ public:
|
||||
|
||||
void onCreate(AppContext& app) override {
|
||||
(void)app;
|
||||
settings::touch::setRuntimeCalibrationEnabled(false);
|
||||
settings::touch::invalidateCache();
|
||||
// Clear any active calibration so the taps sampled below are raw, uncalibrated coordinates.
|
||||
lvgl_lock();
|
||||
auto* indev = lvgl_pointer_get_default();
|
||||
if (indev != nullptr) {
|
||||
lvgl_pointer_set_calibration(indev, nullptr);
|
||||
}
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
void onDestroy(AppContext& app) override {
|
||||
(void)app;
|
||||
settings::touch::setRuntimeCalibrationEnabled(true);
|
||||
settings::touch::invalidateCache();
|
||||
// finishCalibration() already applied a new calibration on success. On cancel/failure,
|
||||
// restore whatever calibration was on disk before onCreate() cleared it above.
|
||||
if (calibrationApplied) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings::touch::TouchCalibrationSettings settings;
|
||||
lvgl_lock();
|
||||
auto* indev = lvgl_pointer_get_default();
|
||||
if (indev != nullptr && settings::touch::load(settings) && settings.enabled && settings::touch::isValid(settings)) {
|
||||
LvglPointerCalibration calibration = {
|
||||
.x_min = settings.xMin,
|
||||
.x_max = settings.xMax,
|
||||
.y_min = settings.yMin,
|
||||
.y_max = settings.yMax,
|
||||
};
|
||||
lvgl_pointer_set_calibration(indev, &calibration);
|
||||
}
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
@@ -196,9 +257,11 @@ public:
|
||||
extern const AppManifest manifest = {
|
||||
.appId = "TouchCalibration",
|
||||
.appName = "Touch Calibration",
|
||||
.appCategory = Category::System,
|
||||
.appFlags = AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden,
|
||||
.appCategory = Category::Settings,
|
||||
.appFlags = AppManifest::Flags::HideStatusBar,
|
||||
.createApp = create<TouchCalibrationApp>
|
||||
};
|
||||
|
||||
} // namespace tt::app::touchcalibration
|
||||
|
||||
#endif // defined(CONFIG_TT_TOUCH_CALIBRATION_SUPPORTED)
|
||||
|
||||
Reference in New Issue
Block a user