summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-26 12:55:46 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-26 12:55:46 +1000
commit9763cc955c4f3b2c2af54b61c2c5ad77afef9603 (patch)
treebdfef9f5685fac3088cf4d59400e888a1b0ffb8b /src
parentc124c8f94dbdb41a7e535b741fe2d2be8e7346c0 (diff)
downloadtangara-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')
-rw-r--r--src/drivers/include/relative_wheel.hpp5
-rw-r--r--src/drivers/include/touchwheel.hpp3
-rw-r--r--src/drivers/relative_wheel.cpp16
-rw-r--r--src/drivers/touchwheel.cpp5
-rw-r--r--src/ui/include/wheel_encoder.hpp3
-rw-r--r--src/ui/screen_menu.cpp40
-rw-r--r--src/ui/wheel_encoder.cpp11
7 files changed, 47 insertions, 36 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;
}
}
diff --git a/src/ui/include/wheel_encoder.hpp b/src/ui/include/wheel_encoder.hpp
index d4975db9..c49e5929 100644
--- a/src/ui/include/wheel_encoder.hpp
+++ b/src/ui/include/wheel_encoder.hpp
@@ -8,6 +8,7 @@
#include <memory>
+#include "core/lv_group.h"
#include "hal/lv_hal_indev.h"
#include "relative_wheel.hpp"
@@ -24,6 +25,8 @@ class TouchWheelEncoder {
private:
lv_indev_drv_t driver_;
lv_indev_t* registration_;
+
+ lv_key_t last_key_;
std::weak_ptr<drivers::RelativeWheel> wheel_;
};
diff --git a/src/ui/screen_menu.cpp b/src/ui/screen_menu.cpp
index 94c8fa06..b6d0606a 100644
--- a/src/ui/screen_menu.cpp
+++ b/src/ui/screen_menu.cpp
@@ -6,8 +6,12 @@
#include "screen_menu.hpp"
+#include "core/lv_event.h"
+#include "esp_log.h"
+
#include "core/lv_group.h"
#include "core/lv_obj_pos.h"
+#include "extra/widgets/list/lv_list.h"
#include "extra/widgets/menu/lv_menu.h"
#include "extra/widgets/spinner/lv_spinner.h"
#include "hal/lv_hal_disp.h"
@@ -17,33 +21,25 @@
namespace ui {
namespace screens {
-Menu::Menu() {
- lv_obj_t* menu = lv_menu_create(root_);
- lv_obj_set_size(menu, lv_disp_get_hor_res(NULL), lv_disp_get_ver_res(NULL));
- lv_obj_center(menu);
-
- lv_obj_t* main_page = lv_menu_page_create(menu, NULL);
-
- lv_obj_t* container;
- lv_obj_t* label;
+static void item_click_cb(lv_event_t* ev) {
+ ESP_LOGI("menu", "clicked!");
+}
- container = lv_menu_cont_create(main_page);
- label = lv_label_create(container);
- lv_label_set_text(label, "I am an item");
+Menu::Menu() {
+ lv_obj_t* list = lv_list_create(root_);
+ lv_obj_set_size(list, lv_disp_get_hor_res(NULL), lv_disp_get_ver_res(NULL));
+ lv_obj_center(list);
- container = lv_menu_cont_create(main_page);
- label = lv_label_create(container);
- lv_label_set_text(label, "I am also an item");
+ lv_obj_t* button;
- container = lv_menu_cont_create(main_page);
- label = lv_label_create(container);
- lv_label_set_text(label, "Item #3");
+ button = lv_list_add_btn(list, NULL, "hi");
+ lv_obj_add_event_cb(button, item_click_cb, LV_EVENT_CLICKED, NULL);
- container = lv_menu_cont_create(main_page);
- label = lv_label_create(container);
- lv_label_set_text(label, "Yay!");
+ button = lv_list_add_btn(list, NULL, "second");
+ lv_obj_add_event_cb(button, item_click_cb, LV_EVENT_CLICKED, NULL);
- lv_menu_set_page(menu, main_page);
+ button = lv_list_add_btn(list, NULL, "third");
+ lv_obj_add_event_cb(button, item_click_cb, LV_EVENT_CLICKED, NULL);
}
Menu::~Menu() {}
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