From 6fd588e970470b15936187980829916d0dbe77bb Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 1 Jun 2023 15:28:32 +1000 Subject: Add touchwheel -> encoder adapter --- src/ui/include/lvgl_task.hpp | 3 ++- src/ui/include/screen.hpp | 28 ++++++++++++++++++++++++++++ src/ui/include/screen_menu.hpp | 29 +++++++++++++++++++++++++++++ src/ui/include/screen_splash.hpp | 30 ++++++++++++++++++++++++++++++ src/ui/include/ui_fsm.hpp | 10 ++++------ src/ui/include/ui_tick.hpp | 11 +++++++++++ src/ui/include/wheel_encoder.hpp | 30 ++++++++++++++++++++++++++++++ 7 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 src/ui/include/screen.hpp create mode 100644 src/ui/include/screen_menu.hpp create mode 100644 src/ui/include/screen_splash.hpp create mode 100644 src/ui/include/ui_tick.hpp create mode 100644 src/ui/include/wheel_encoder.hpp (limited to 'src/ui/include') diff --git a/src/ui/include/lvgl_task.hpp b/src/ui/include/lvgl_task.hpp index 25e7dd14..8e387683 100644 --- a/src/ui/include/lvgl_task.hpp +++ b/src/ui/include/lvgl_task.hpp @@ -14,11 +14,12 @@ #include "freertos/task.h" #include "display.hpp" +#include "relative_wheel.hpp" #include "touchwheel.hpp" namespace ui { -auto StartLvgl(std::weak_ptr touch_wheel, +auto StartLvgl(std::weak_ptr touch_wheel, std::weak_ptr display) -> void; } // namespace ui diff --git a/src/ui/include/screen.hpp b/src/ui/include/screen.hpp new file mode 100644 index 00000000..87a0d9b8 --- /dev/null +++ b/src/ui/include/screen.hpp @@ -0,0 +1,28 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include + +#include "core/lv_obj.h" +#include "core/lv_obj_tree.h" +#include "lvgl.h" + +namespace ui { + +class Screen { + public: + Screen() : root_(lv_obj_create(NULL)) {} + virtual ~Screen() { lv_obj_del(root_); } + + auto root() -> lv_obj_t* { return root_; } + + protected: + lv_obj_t* const root_; +}; + +} // namespace ui diff --git a/src/ui/include/screen_menu.hpp b/src/ui/include/screen_menu.hpp new file mode 100644 index 00000000..a0b07b9e --- /dev/null +++ b/src/ui/include/screen_menu.hpp @@ -0,0 +1,29 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include + +#include "lvgl.h" + +#include "screen.hpp" + +namespace ui { +namespace screens { + +class Menu : public Screen { + public: + Menu(); + ~Menu(); + + private: + lv_obj_t* container_; + lv_obj_t* label_; +}; + +} // namespace screens +} // namespace ui diff --git a/src/ui/include/screen_splash.hpp b/src/ui/include/screen_splash.hpp new file mode 100644 index 00000000..1ee7dd89 --- /dev/null +++ b/src/ui/include/screen_splash.hpp @@ -0,0 +1,30 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include + +#include "lvgl.h" + +#include "screen.hpp" + +namespace ui { +namespace screens { + +class Splash : public Screen { + public: + Splash(); + ~Splash(); + + private: + lv_obj_t* container_; + lv_obj_t* label_; + lv_obj_t* spinner_; +}; + +} // namespace screens +} // namespace ui diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 2afcfa86..d4d23bb0 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -8,9 +8,9 @@ #include +#include "relative_wheel.hpp" #include "tinyfsm.hpp" -#include "database.hpp" #include "display.hpp" #include "screen.hpp" #include "storage.hpp" @@ -22,9 +22,8 @@ namespace ui { class UiState : public tinyfsm::Fsm { public: static auto Init(drivers::GpioExpander* gpio_expander, - std::weak_ptr touchwheel, - std::weak_ptr display, - std::weak_ptr database) -> void; + std::weak_ptr touchwheel, + std::weak_ptr display) -> void; virtual ~UiState() {} @@ -43,9 +42,8 @@ class UiState : public tinyfsm::Fsm { protected: static drivers::GpioExpander* sGpioExpander; - static std::weak_ptr sTouchWheel; + static std::weak_ptr sTouchWheel; static std::weak_ptr sDisplay; - static std::weak_ptr sDatabase; static std::shared_ptr sCurrentScreen; }; diff --git a/src/ui/include/ui_tick.hpp b/src/ui/include/ui_tick.hpp new file mode 100644 index 00000000..37f8a8bd --- /dev/null +++ b/src/ui/include/ui_tick.hpp @@ -0,0 +1,11 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include "esp_timer.h" + +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (esp_timer_get_time() / 1000) diff --git a/src/ui/include/wheel_encoder.hpp b/src/ui/include/wheel_encoder.hpp new file mode 100644 index 00000000..0651ce0b --- /dev/null +++ b/src/ui/include/wheel_encoder.hpp @@ -0,0 +1,30 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include + +#include "hal/lv_hal_indev.h" + +#include "relative_wheel.hpp" + +namespace ui { + +class TouchWheelEncoder { + public: + explicit TouchWheelEncoder(std::weak_ptr wheel); + + auto Read(lv_indev_data_t *data) -> void; + auto registration() -> lv_indev_t* { return registration_; } + + private: + lv_indev_drv_t driver_; + lv_indev_t *registration_; + std::weak_ptr wheel_; +}; + +} // namespace ui -- cgit v1.2.3