diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-26 12:55:46 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-26 12:55:46 +1000 |
| commit | 9763cc955c4f3b2c2af54b61c2c5ad77afef9603 (patch) | |
| tree | bdfef9f5685fac3088cf4d59400e888a1b0ffb8b /src/ui/wheel_encoder.cpp | |
| parent | c124c8f94dbdb41a7e535b741fe2d2be8e7346c0 (diff) | |
| download | tangara-fw-9763cc955c4f3b2c2af54b61c2c5ad77afef9603.tar.gz | |
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
Diffstat (limited to 'src/ui/wheel_encoder.cpp')
| -rw-r--r-- | src/ui/wheel_encoder.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
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 <sys/_stdint.h> +#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<drivers::RelativeWheel> 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 |
