summaryrefslogtreecommitdiff
path: root/src/input/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-05-02 19:12:26 +1000
committerjacqueline <me@jacqueline.id.au>2024-05-02 19:12:26 +1000
commit1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 (patch)
treed162822b8fd7054f81bace0c7a65ab4d5e6f93ef /src/input/include
parenta231fd1c8afedbeb14b0bc77d76bad61db986059 (diff)
downloadtangara-fw-1573a8c4cde1cd9528b422b2dcc598e37ffe94a7.tar.gz
WIP merge cyclically dependent components into one big component
Diffstat (limited to 'src/input/include')
-rw-r--r--src/input/include/device_factory.hpp39
-rw-r--r--src/input/include/feedback_device.hpp32
-rw-r--r--src/input/include/feedback_haptics.hpp26
-rw-r--r--src/input/include/input_device.hpp37
-rw-r--r--src/input/include/input_hook.hpp75
-rw-r--r--src/input/include/input_hook_actions.hpp31
-rw-r--r--src/input/include/input_nav_buttons.hpp38
-rw-r--r--src/input/include/input_touch_dpad.hpp40
-rw-r--r--src/input/include/input_touch_wheel.hpp56
-rw-r--r--src/input/include/input_trigger.hpp42
-rw-r--r--src/input/include/input_volume_buttons.hpp37
-rw-r--r--src/input/include/lvgl_input_driver.hpp112
12 files changed, 0 insertions, 565 deletions
diff --git a/src/input/include/device_factory.hpp b/src/input/include/device_factory.hpp
deleted file mode 100644
index dd9c7133..00000000
--- a/src/input/include/device_factory.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "feedback_device.hpp"
-#include "input_device.hpp"
-#include "input_touch_wheel.hpp"
-#include "nvs.hpp"
-#include "service_locator.hpp"
-
-namespace input {
-
-class DeviceFactory {
- public:
- DeviceFactory(std::shared_ptr<system_fsm::ServiceLocator>);
-
- auto createInputs(drivers::NvsStorage::InputModes mode)
- -> std::vector<std::shared_ptr<IInputDevice>>;
-
- auto createFeedbacks() -> std::vector<std::shared_ptr<IFeedbackDevice>>;
-
- auto touch_wheel() -> std::shared_ptr<TouchWheel> { return wheel_; }
-
- private:
- std::shared_ptr<system_fsm::ServiceLocator> services_;
-
- // HACK: the touchwheel is current a special case, since it's the only input
- // device that has some kind of setting/configuration; scroll sensitivity.
- std::shared_ptr<TouchWheel> wheel_;
-};
-
-} // namespace input
diff --git a/src/input/include/feedback_device.hpp b/src/input/include/feedback_device.hpp
deleted file mode 100644
index 4faeeafd..00000000
--- a/src/input/include/feedback_device.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-
-namespace input {
-
-/*
- * Interface for providing non-visual feedback to the user as a result of LVGL
- * events. 'Feedback Devices' are able to observe all events that are generated
- * by LVGL as a result of Input Devices.
- *
- * Implementations of this interface are a mix of hardware features (e.g. a
- * haptic motor buzzing when your selection changes) and firmware features
- * (e.g. playing audio feedback that describes the selected element).
- */
-class IFeedbackDevice {
- public:
- virtual ~IFeedbackDevice() {}
-
- virtual auto feedback(uint8_t event_type) -> void = 0;
-
- // TODO: Add configuration; likely the same shape of interface that
- // IInputDevice uses.
-};
-
-} // namespace input
diff --git a/src/input/include/feedback_haptics.hpp b/src/input/include/feedback_haptics.hpp
deleted file mode 100644
index a307a429..00000000
--- a/src/input/include/feedback_haptics.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "feedback_device.hpp"
-#include "haptics.hpp"
-
-namespace input {
-
-class Haptics : public IFeedbackDevice {
- public:
- Haptics(drivers::Haptics& haptics_);
-
- auto feedback(uint8_t event_type) -> void override;
-
- private:
- drivers::Haptics& haptics_;
-};
-
-} // namespace input
diff --git a/src/input/include/input_device.hpp b/src/input/include/input_device.hpp
deleted file mode 100644
index d944c3bf..00000000
--- a/src/input/include/input_device.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <functional>
-#include <string>
-#include <vector>
-
-#include "hal/lv_hal_indev.h"
-#include "input_hook.hpp"
-#include "property.hpp"
-
-namespace input {
-
-/*
- * Interface for all device input methods. Each 'Input Device' is polled by
- * LVGL at regular intervals, and can effect the device either via LVGL's input
- * device driver API, or by emitting events for other parts of the system to
- * react to (e.g. issuing a play/pause event, or altering the volume).
- */
-class IInputDevice {
- public:
- virtual ~IInputDevice() {}
-
- virtual auto read(lv_indev_data_t* data) -> void = 0;
-
- virtual auto name() -> std::string = 0;
- virtual auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> {
- return {};
- }
-};
-
-} // namespace input
diff --git a/src/input/include/input_hook.hpp b/src/input/include/input_hook.hpp
deleted file mode 100644
index a8705210..00000000
--- a/src/input/include/input_hook.hpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <functional>
-#include <optional>
-#include <string>
-
-#include "hal/lv_hal_indev.h"
-#include "lua.hpp"
-
-#include "input_trigger.hpp"
-
-namespace input {
-
-struct HookCallback {
- std::string name;
- std::function<void(lv_indev_data_t*)> fn;
-};
-
-class Hook {
- public:
- Hook(std::string name, std::optional<HookCallback> cb);
-
- auto invoke(lv_indev_data_t*) -> void;
- auto override(std::optional<HookCallback>) -> void;
-
- auto name() const -> const std::string& { return name_; }
- auto callback() -> std::optional<HookCallback>;
-
- // Not copyable or movable.
- Hook(const Hook&) = delete;
- Hook& operator=(const Hook&) = delete;
-
- private:
- std::string name_;
- std::optional<HookCallback> default_;
- std::optional<HookCallback> override_;
-};
-
-class TriggerHooks {
- public:
- TriggerHooks(std::string name, std::optional<HookCallback> cb)
- : TriggerHooks(name, cb, cb, cb, cb) {}
- TriggerHooks(std::string name,
- std::optional<HookCallback> click,
- std::optional<HookCallback> double_click,
- std::optional<HookCallback> long_press,
- std::optional<HookCallback> repeat);
-
- auto update(bool, lv_indev_data_t*) -> void;
- auto override(Trigger::State, std::optional<HookCallback>) -> void;
-
- auto name() const -> const std::string&;
- auto hooks() -> std::vector<std::reference_wrapper<Hook>>;
-
- // Not copyable or movable.
- TriggerHooks(const TriggerHooks&) = delete;
- TriggerHooks& operator=(const TriggerHooks&) = delete;
-
- private:
- std::string name_;
- Trigger trigger_;
-
- Hook click_;
- Hook double_click_;
- Hook long_press_;
- Hook repeat_;
-};
-
-} // namespace input
diff --git a/src/input/include/input_hook_actions.hpp b/src/input/include/input_hook_actions.hpp
deleted file mode 100644
index 105bd10d..00000000
--- a/src/input/include/input_hook_actions.hpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include "hal/lv_hal_indev.h"
-#include "input_hook.hpp"
-
-namespace input {
-namespace actions {
-
-auto select() -> HookCallback;
-
-auto scrollUp() -> HookCallback;
-auto scrollDown() -> HookCallback;
-
-auto scrollToTop() -> HookCallback;
-auto scrollToBottom() -> HookCallback;
-
-auto goBack() -> HookCallback;
-
-auto volumeUp() -> HookCallback;
-auto volumeDown() -> HookCallback;
-
-auto allActions() -> std::vector<HookCallback>;
-
-} // namespace actions
-} // namespace input
diff --git a/src/input/include/input_nav_buttons.hpp b/src/input/include/input_nav_buttons.hpp
deleted file mode 100644
index 9feeb375..00000000
--- a/src/input/include/input_nav_buttons.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "gpios.hpp"
-#include "hal/lv_hal_indev.h"
-
-#include "haptics.hpp"
-#include "input_device.hpp"
-#include "input_hook.hpp"
-#include "input_trigger.hpp"
-#include "touchwheel.hpp"
-
-namespace input {
-
-class NavButtons : public IInputDevice {
- public:
- NavButtons(drivers::IGpios&);
-
- auto read(lv_indev_data_t* data) -> void override;
-
- auto name() -> std::string override;
- auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override;
-
- private:
- drivers::IGpios& gpios_;
-
- TriggerHooks up_;
- TriggerHooks down_;
-};
-
-} // namespace input
diff --git a/src/input/include/input_touch_dpad.hpp b/src/input/include/input_touch_dpad.hpp
deleted file mode 100644
index 0c45b2d9..00000000
--- a/src/input/include/input_touch_dpad.hpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "hal/lv_hal_indev.h"
-
-#include "haptics.hpp"
-#include "input_device.hpp"
-#include "input_hook.hpp"
-#include "input_trigger.hpp"
-#include "touchwheel.hpp"
-
-namespace input {
-
-class TouchDPad : public IInputDevice {
- public:
- TouchDPad(drivers::TouchWheel&);
-
- auto read(lv_indev_data_t* data) -> void override;
-
- auto name() -> std::string override;
- auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override;
-
- private:
- drivers::TouchWheel& wheel_;
-
- TriggerHooks centre_;
- TriggerHooks up_;
- TriggerHooks right_;
- TriggerHooks down_;
- TriggerHooks left_;
-};
-
-} // namespace input
diff --git a/src/input/include/input_touch_wheel.hpp b/src/input/include/input_touch_wheel.hpp
deleted file mode 100644
index 764cc68d..00000000
--- a/src/input/include/input_touch_wheel.hpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <sys/_stdint.h>
-#include <cstdint>
-
-#include "hal/lv_hal_indev.h"
-
-#include "haptics.hpp"
-#include "input_device.hpp"
-#include "input_hook.hpp"
-#include "input_trigger.hpp"
-#include "nvs.hpp"
-#include "property.hpp"
-#include "touchwheel.hpp"
-
-namespace input {
-
-class TouchWheel : public IInputDevice {
- public:
- TouchWheel(drivers::NvsStorage&, drivers::TouchWheel&);
-
- auto read(lv_indev_data_t* data) -> void override;
-
- auto name() -> std::string override;
- auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override;
-
- auto sensitivity() -> lua::Property&;
-
- private:
- auto calculateTicks(const drivers::TouchWheelData& data) -> int8_t;
- auto calculateThreshold(uint8_t sensitivity) -> uint8_t;
-
- drivers::NvsStorage& nvs_;
- drivers::TouchWheel& wheel_;
-
- lua::Property sensitivity_;
-
- TriggerHooks centre_;
- TriggerHooks up_;
- TriggerHooks right_;
- TriggerHooks down_;
- TriggerHooks left_;
-
- bool is_scrolling_;
- uint8_t threshold_;
- bool is_first_read_;
- uint8_t last_angle_;
-};
-
-} // namespace input
diff --git a/src/input/include/input_trigger.hpp b/src/input/include/input_trigger.hpp
deleted file mode 100644
index bcafa8ad..00000000
--- a/src/input/include/input_trigger.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-#include <optional>
-
-#include "hal/lv_hal_indev.h"
-
-namespace input {
-
-const uint16_t kDoubleClickDelayMs = 500;
-const uint16_t kLongPressDelayMs = LV_INDEV_DEF_LONG_PRESS_TIME;
-const uint16_t kRepeatDelayMs = LV_INDEV_DEF_LONG_PRESS_REP_TIME;
-
-class Trigger {
- public:
- enum class State {
- kNone,
- kClick,
- kDoubleClick,
- kLongPress,
- kRepeatPress,
- };
-
- Trigger();
-
- auto update(bool is_pressed) -> State;
-
- private:
- std::optional<uint64_t> touch_time_ms_;
- bool was_pressed_;
-
- bool was_double_click_;
- uint16_t times_long_pressed_;
-};
-
-} // namespace input
diff --git a/src/input/include/input_volume_buttons.hpp b/src/input/include/input_volume_buttons.hpp
deleted file mode 100644
index e3246df4..00000000
--- a/src/input/include/input_volume_buttons.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2024 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "gpios.hpp"
-#include "hal/lv_hal_indev.h"
-
-#include "haptics.hpp"
-#include "input_device.hpp"
-#include "input_hook.hpp"
-#include "touchwheel.hpp"
-
-namespace input {
-
-class VolumeButtons : public IInputDevice {
- public:
- VolumeButtons(drivers::IGpios&);
-
- auto read(lv_indev_data_t* data) -> void override;
-
- auto name() -> std::string override;
- auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override;
-
- private:
- drivers::IGpios& gpios_;
-
- TriggerHooks up_;
- TriggerHooks down_;
-};
-
-} // namespace input
diff --git a/src/input/include/lvgl_input_driver.hpp b/src/input/include/lvgl_input_driver.hpp
deleted file mode 100644
index 9adaf143..00000000
--- a/src/input/include/lvgl_input_driver.hpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-#include <deque>
-#include <memory>
-#include <set>
-
-#include "core/lv_group.h"
-#include "device_factory.hpp"
-#include "feedback_device.hpp"
-#include "gpios.hpp"
-#include "hal/lv_hal_indev.h"
-
-#include "input_device.hpp"
-#include "input_hook.hpp"
-#include "lua_thread.hpp"
-#include "nvs.hpp"
-#include "property.hpp"
-#include "touchwheel.hpp"
-
-namespace input {
-
-/*
- * Implementation of an LVGL input device. This class composes multiple
- * IInputDevice and IFeedbackDevice instances together into a single LVGL
- * device.
- */
-class LvglInputDriver {
- public:
- LvglInputDriver(drivers::NvsStorage& nvs, DeviceFactory&);
-
- auto mode() -> lua::Property& { return mode_; }
-
- auto read(lv_indev_data_t* data) -> void;
- auto feedback(uint8_t) -> void;
-
- auto registration() -> lv_indev_t* { return registration_; }
- auto lock(bool l) -> void { is_locked_ = l; }
-
- auto pushHooks(lua_State* L) -> int;
-
- private:
- drivers::NvsStorage& nvs_;
- DeviceFactory& factory_;
-
- lua::Property mode_;
- lv_indev_drv_t driver_;
- lv_indev_t* registration_;
-
- std::vector<std::shared_ptr<IInputDevice>> inputs_;
- std::vector<std::shared_ptr<IFeedbackDevice>> feedbacks_;
-
- /*
- * Key for identifying which device, trigger, and specific hook are being
- * overriden by Lua.
- */
- struct OverrideSelector {
- std::string device_name;
- std::string trigger_name;
- std::string hook_name;
-
- friend bool operator<(const OverrideSelector& l,
- const OverrideSelector& r) {
- return std::tie(l.device_name, l.trigger_name, l.hook_name) <
- std::tie(r.device_name, r.trigger_name, r.hook_name);
- }
- };
-
- /* Userdata object for tracking the Lua mirror of a TriggerHooks object. */
- class LuaTrigger {
- public:
- LuaTrigger(LvglInputDriver&, IInputDevice&, TriggerHooks&);
-
- static auto get(lua_State*, int idx) -> LuaTrigger&;
- static auto luaGc(lua_State*) -> int;
- static auto luaToString(lua_State*) -> int;
- static auto luaNewIndex(lua_State*) -> int;
-
- static constexpr struct luaL_Reg kFuncs[] = {{"__gc", luaGc},
- {"__tostring", luaToString},
- {"__newindex", luaNewIndex},
- {NULL, NULL}};
-
- private:
- LvglInputDriver* driver_;
-
- std::string device_;
- std::string trigger_;
- std::map<std::string, std::string> hooks_;
- };
-
- /* A hook override implemented as a lua callback */
- struct LuaOverride {
- lua_State* L;
- int ref;
- };
-
- std::map<OverrideSelector, LuaOverride> overrides_;
-
- auto setOverride(lua_State* L, const OverrideSelector&) -> void;
- auto applyOverride(const OverrideSelector&, LuaOverride&) -> void;
-
- bool is_locked_;
-};
-
-} // namespace input