summaryrefslogtreecommitdiff
path: root/src/input/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-15 14:18:20 +1000
committerjacqueline <me@jacqueline.id.au>2024-04-15 14:18:20 +1000
commit1baaa6dadcea5b8a85f1629e31119f4edba91b75 (patch)
treefeae0c19f1a6744b60f3e59a5d9b8df1c28c6ebf /src/input/include
parentc24dfa6846929e8a7659c4aa2633b82494ac7fe1 (diff)
downloadtangara-fw-1baaa6dadcea5b8a85f1629e31119f4edba91b75.tar.gz
Use more generic 'hooks' for each input device's actions
Diffstat (limited to 'src/input/include')
-rw-r--r--src/input/include/input_hook.hpp47
-rw-r--r--src/input/include/input_hook_actions.hpp28
-rw-r--r--src/input/include/input_nav_buttons.hpp5
-rw-r--r--src/input/include/input_touch_dpad.hpp11
-rw-r--r--src/input/include/input_touch_wheel.hpp10
-rw-r--r--src/input/include/input_volume_buttons.hpp6
6 files changed, 93 insertions, 14 deletions
diff --git a/src/input/include/input_hook.hpp b/src/input/include/input_hook.hpp
new file mode 100644
index 00000000..96b9b5cd
--- /dev/null
+++ b/src/input/include/input_hook.hpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2024 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <functional>
+#include <optional>
+
+#include "hal/lv_hal_indev.h"
+#include "input_trigger.hpp"
+
+namespace input {
+
+using HookCb = std::optional<std::function<void(lv_indev_data_t*)>>;
+
+class Hook {
+ public:
+ Hook(HookCb);
+
+ auto invoke(lv_indev_data_t*) -> void;
+ auto override(HookCb) -> void;
+
+ private:
+ HookCb default_;
+ HookCb override_;
+};
+
+class TriggerHooks {
+ public:
+ TriggerHooks(HookCb cb) : TriggerHooks(cb, cb, cb) {}
+ TriggerHooks(HookCb, HookCb, HookCb);
+
+ auto update(bool, lv_indev_data_t*) -> void;
+ auto override(Trigger::State, HookCb) -> void;
+
+ private:
+ Trigger trigger_;
+
+ Hook 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
new file mode 100644
index 00000000..a05a14e8
--- /dev/null
+++ b/src/input/include/input_hook_actions.hpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2024 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include "hal/lv_hal_indev.h"
+
+namespace input {
+namespace actions {
+
+auto select(lv_indev_data_t*) -> void;
+
+auto scrollUp(lv_indev_data_t*) -> void;
+auto scrollDown(lv_indev_data_t*) -> void;
+
+auto scrollToTop(lv_indev_data_t*) -> void;
+auto scrollToBottom(lv_indev_data_t*) -> void;
+
+auto goBack(lv_indev_data_t*) -> void;
+
+auto volumeUp(lv_indev_data_t*) -> void;
+auto volumeDown(lv_indev_data_t*) -> void;
+
+} // namespace actions
+} // namespace input
diff --git a/src/input/include/input_nav_buttons.hpp b/src/input/include/input_nav_buttons.hpp
index 29a19a16..60566ebc 100644
--- a/src/input/include/input_nav_buttons.hpp
+++ b/src/input/include/input_nav_buttons.hpp
@@ -13,6 +13,7 @@
#include "haptics.hpp"
#include "input_device.hpp"
+#include "input_hook.hpp"
#include "input_trigger.hpp"
#include "touchwheel.hpp"
@@ -27,8 +28,8 @@ class NavButtons : public IInputDevice {
private:
drivers::IGpios& gpios_;
- Trigger up_;
- Trigger down_;
+ TriggerHooks up_;
+ TriggerHooks down_;
};
} // namespace input
diff --git a/src/input/include/input_touch_dpad.hpp b/src/input/include/input_touch_dpad.hpp
index 03936acb..f80400dc 100644
--- a/src/input/include/input_touch_dpad.hpp
+++ b/src/input/include/input_touch_dpad.hpp
@@ -6,13 +6,13 @@
#pragma once
-#include <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 "touchwheel.hpp"
@@ -27,10 +27,11 @@ class TouchDPad : public IInputDevice {
private:
drivers::TouchWheel& wheel_;
- Trigger up_;
- Trigger right_;
- Trigger down_;
- Trigger left_;
+ 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
index c81cbb1a..88ebee40 100644
--- a/src/input/include/input_touch_wheel.hpp
+++ b/src/input/include/input_touch_wheel.hpp
@@ -13,6 +13,7 @@
#include "haptics.hpp"
#include "input_device.hpp"
+#include "input_hook.hpp"
#include "input_trigger.hpp"
#include "nvs.hpp"
#include "property.hpp"
@@ -37,10 +38,11 @@ class TouchWheel : public IInputDevice {
lua::Property sensitivity_;
- Trigger up_;
- Trigger right_;
- Trigger down_;
- Trigger left_;
+ TriggerHooks centre_;
+ TriggerHooks up_;
+ TriggerHooks right_;
+ TriggerHooks down_;
+ TriggerHooks left_;
bool is_scrolling_;
uint8_t threshold_;
diff --git a/src/input/include/input_volume_buttons.hpp b/src/input/include/input_volume_buttons.hpp
index 162ca8d9..68962908 100644
--- a/src/input/include/input_volume_buttons.hpp
+++ b/src/input/include/input_volume_buttons.hpp
@@ -13,7 +13,7 @@
#include "haptics.hpp"
#include "input_device.hpp"
-#include "input_trigger.hpp"
+#include "input_hook.hpp"
#include "touchwheel.hpp"
namespace input {
@@ -27,8 +27,8 @@ class VolumeButtons : public IInputDevice {
private:
drivers::IGpios& gpios_;
- Trigger up_;
- Trigger down_;
+ TriggerHooks up_;
+ TriggerHooks down_;
};
} // namespace input