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 +#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 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 +#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