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/drivers | |
| 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/drivers')
| -rw-r--r-- | src/drivers/include/relative_wheel.hpp | 5 | ||||
| -rw-r--r-- | src/drivers/include/touchwheel.hpp | 3 | ||||
| -rw-r--r-- | src/drivers/relative_wheel.cpp | 16 | ||||
| -rw-r--r-- | src/drivers/touchwheel.cpp | 5 |
4 files changed, 20 insertions, 9 deletions
diff --git a/src/drivers/include/relative_wheel.hpp b/src/drivers/include/relative_wheel.hpp index da4f9e3d..8d74d551 100644 --- a/src/drivers/include/relative_wheel.hpp +++ b/src/drivers/include/relative_wheel.hpp @@ -32,12 +32,13 @@ class RelativeWheel { auto Update() -> void; - auto is_pressed() -> bool; + auto is_clicking() -> bool; auto ticks() -> std::int_fast16_t; private: TouchWheel* touch_; - bool is_pressed_; + bool is_clicking_; + bool was_clicking_; bool is_first_read_; std::int_fast16_t ticks_; uint8_t last_angle_; diff --git a/src/drivers/include/touchwheel.hpp b/src/drivers/include/touchwheel.hpp index 1468fc65..5c3442d2 100644 --- a/src/drivers/include/touchwheel.hpp +++ b/src/drivers/include/touchwheel.hpp @@ -17,7 +17,8 @@ namespace drivers { struct TouchWheelData { - bool is_touched = false; + bool is_wheel_touched = false; + bool is_button_touched = false; uint8_t wheel_position = -1; }; diff --git a/src/drivers/relative_wheel.cpp b/src/drivers/relative_wheel.cpp index 4c9e19bb..a631cd2e 100644 --- a/src/drivers/relative_wheel.cpp +++ b/src/drivers/relative_wheel.cpp @@ -15,7 +15,8 @@ namespace drivers { RelativeWheel::RelativeWheel(TouchWheel* touch) : touch_(touch), - is_pressed_(false), + is_clicking_(false), + was_clicking_(false), is_first_read_(true), ticks_(0), last_angle_(0) {} @@ -23,7 +24,12 @@ RelativeWheel::RelativeWheel(TouchWheel* touch) auto RelativeWheel::Update() -> void { touch_->Update(); TouchWheelData d = touch_->GetTouchWheelData(); - is_pressed_ = d.is_touched; + + is_clicking_ = d.is_button_touched; + + if (!d.is_wheel_touched) { + is_first_read_ = true; + } uint8_t new_angle = d.wheel_position; if (is_first_read_) { @@ -61,8 +67,10 @@ auto RelativeWheel::Update() -> void { ticks_ = change; } -auto RelativeWheel::is_pressed() -> bool { - return is_pressed_; +auto RelativeWheel::is_clicking() -> bool { + bool ret = is_clicking_; + is_clicking_ = 0; + return ret; } auto RelativeWheel::ticks() -> std::int_fast16_t { diff --git a/src/drivers/touchwheel.cpp b/src/drivers/touchwheel.cpp index 576b6dad..84d4d67c 100644 --- a/src/drivers/touchwheel.cpp +++ b/src/drivers/touchwheel.cpp @@ -105,8 +105,9 @@ void TouchWheel::Update() { } if (status & 0b1) { // Key detect. Note that the touchwheel keys also trigger this. - // TODO(daniel): Do something with this. - // bool centre_key = ReadRegister(Register::KEY_STATUS_A) & 0b1000; + uint8_t reg = ReadRegister(Register::KEY_STATUS_A); + data_.is_button_touched = reg & 0b1000; + data_.is_wheel_touched = reg & 0b111; } } |
