From 9763cc955c4f3b2c2af54b61c2c5ad77afef9603 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 26 Jun 2023 12:55:46 +1000 Subject: Improve encoder driver It actually works and clicks now! Still a bit rough though. Need to dive into lvgl internals to work out what it's doing with enc_diff --- src/ui/wheel_encoder.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/ui/wheel_encoder.cpp') diff --git a/src/ui/wheel_encoder.cpp b/src/ui/wheel_encoder.cpp index 3b817f61..432a81b4 100644 --- a/src/ui/wheel_encoder.cpp +++ b/src/ui/wheel_encoder.cpp @@ -5,6 +5,8 @@ */ #include "wheel_encoder.hpp" +#include +#include "core/lv_group.h" #include "hal/lv_hal_indev.h" namespace ui { @@ -17,7 +19,7 @@ void encoder_read(lv_indev_drv_t* drv, lv_indev_data_t* data) { TouchWheelEncoder::TouchWheelEncoder( std::weak_ptr wheel) - : wheel_(wheel) { + : last_key_(0), wheel_(wheel) { lv_indev_drv_init(&driver_); driver_.type = LV_INDEV_TYPE_ENCODER; driver_.read_cb = encoder_read; @@ -29,15 +31,14 @@ TouchWheelEncoder::TouchWheelEncoder( auto TouchWheelEncoder::Read(lv_indev_data_t* data) -> void { auto lock = wheel_.lock(); if (lock == nullptr) { - data->state = LV_INDEV_STATE_RELEASED; - data->enc_diff = 0; return; } lock->Update(); - data->state = - lock->is_pressed() ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; + data->enc_diff = lock->ticks(); + data->state = + lock->is_clicking() ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; } } // namespace ui -- cgit v1.2.3