Add calibration methods and app (#520)

This commit is contained in:
NellowTCS
2026-04-13 12:58:27 -06:00
committed by GitHub
parent 4dd2762b79
commit 10ba4f58e2
11 changed files with 724 additions and 380 deletions
+35
View File
@@ -7,7 +7,9 @@
#endif
#include <Tactility/Logger.h>
#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>
@@ -22,6 +24,16 @@ 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 DisplayApp final : public App {
settings::display::DisplaySettings displaySettings;
@@ -119,6 +131,10 @@ class DisplayApp final : public App {
}
}
static void onCalibrateTouchClicked(lv_event_t*) {
app::start("TouchCalibration");
}
public:
void onShow(AppContext& app, lv_obj_t* parent) override {
@@ -278,6 +294,25 @@ 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 {