summaryrefslogtreecommitdiff
path: root/src/tangara/input
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-05-10 12:20:51 +1000
committerailurux <ailuruxx@gmail.com>2024-05-10 12:20:51 +1000
commite4ce7c4ac23402e09be8d6a52e0f739c0dff4ff0 (patch)
tree3e04ac08a884fb6d6c887cd70218316a30ae3371 /src/tangara/input
parent5b109ed32709c271a6803382c5738802919c9c69 (diff)
parent2afeb2989b2f845664e12f93e850aab983be12cc (diff)
downloadtangara-fw-e4ce7c4ac23402e09be8d6a52e0f739c0dff4ff0.tar.gz
Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw
Diffstat (limited to 'src/tangara/input')
-rw-r--r--src/tangara/input/input_hook.cpp8
-rw-r--r--src/tangara/input/input_hook.hpp2
-rw-r--r--src/tangara/input/input_touch_wheel.cpp38
-rw-r--r--src/tangara/input/input_trigger.cpp7
-rw-r--r--src/tangara/input/input_trigger.hpp1
5 files changed, 38 insertions, 18 deletions
diff --git a/src/tangara/input/input_hook.cpp b/src/tangara/input/input_hook.cpp
index 6946c07f..95ff8f2c 100644
--- a/src/tangara/input/input_hook.cpp
+++ b/src/tangara/input/input_hook.cpp
@@ -70,8 +70,8 @@ auto TriggerHooks::update(bool pressed, lv_indev_data_t* d) -> void {
}
}
-auto TriggerHooks::override(Trigger::State s,
- std::optional<HookCallback> cb) -> void {
+auto TriggerHooks::override(Trigger::State s, std::optional<HookCallback> cb)
+ -> void {
switch (s) {
case Trigger::State::kClick:
click_.override(cb);
@@ -96,4 +96,8 @@ auto TriggerHooks::hooks() -> std::vector<std::reference_wrapper<Hook>> {
return {click_, long_press_, repeat_};
}
+auto TriggerHooks::cancel() -> void {
+ trigger_.cancel();
+}
+
} // namespace input
diff --git a/src/tangara/input/input_hook.hpp b/src/tangara/input/input_hook.hpp
index 3dc8a2c8..06fcb037 100644
--- a/src/tangara/input/input_hook.hpp
+++ b/src/tangara/input/input_hook.hpp
@@ -58,6 +58,8 @@ class TriggerHooks {
auto name() const -> const std::string&;
auto hooks() -> std::vector<std::reference_wrapper<Hook>>;
+ auto cancel() -> void;
+
// Not copyable or movable.
TriggerHooks(const TriggerHooks&) = delete;
TriggerHooks& operator=(const TriggerHooks&) = delete;
diff --git a/src/tangara/input/input_touch_wheel.cpp b/src/tangara/input/input_touch_wheel.cpp
index 2c4a8b03..75159320 100644
--- a/src/tangara/input/input_touch_wheel.cpp
+++ b/src/tangara/input/input_touch_wheel.cpp
@@ -40,10 +40,10 @@ TouchWheel::TouchWheel(drivers::NvsStorage& nvs, drivers::TouchWheel& wheel)
return true;
}),
centre_("centre", actions::select(), {}, {}, {}),
- up_("up", {}, actions::scrollToTop(), {}, {}),
+ up_("up", {}, {}, actions::scrollToTop(), {}),
right_("right", {}),
- down_("down", {}, actions::scrollToBottom(), {}, {}),
- left_("left", {}, actions::goBack(), {}, {}),
+ down_("down", {}, {}, actions::scrollToBottom(), {}),
+ left_("left", {}, {}, actions::goBack(), {}),
is_scrolling_(false),
threshold_(calculateThreshold(nvs.ScrollSensitivity())),
is_first_read_(true),
@@ -73,20 +73,26 @@ auto TouchWheel::read(lv_indev_data_t* data) -> void {
// If the user is touching the wheel but not scrolling, then they may be
// clicking on one of the wheel's cardinal directions.
- bool pressing = wheel_data.is_wheel_touched && !is_scrolling_;
-
- up_.update(pressing && drivers::TouchWheel::isAngleWithin(
- wheel_data.wheel_position, 0, 32),
- data);
- right_.update(pressing && drivers::TouchWheel::isAngleWithin(
- wheel_data.wheel_position, 192, 32),
- data);
- down_.update(pressing && drivers::TouchWheel::isAngleWithin(
- wheel_data.wheel_position, 128, 32),
- data);
- left_.update(pressing && drivers::TouchWheel::isAngleWithin(
- wheel_data.wheel_position, 64, 32),
+ if (is_scrolling_) {
+ up_.cancel();
+ right_.cancel();
+ down_.cancel();
+ left_.cancel();
+ } else {
+ bool pressing = wheel_data.is_wheel_touched;
+ up_.update(pressing && drivers::TouchWheel::isAngleWithin(
+ wheel_data.wheel_position, 0, 32),
data);
+ right_.update(pressing && drivers::TouchWheel::isAngleWithin(
+ wheel_data.wheel_position, 192, 32),
+ data);
+ down_.update(pressing && drivers::TouchWheel::isAngleWithin(
+ wheel_data.wheel_position, 128, 32),
+ data);
+ left_.update(pressing && drivers::TouchWheel::isAngleWithin(
+ wheel_data.wheel_position, 64, 32),
+ data);
+ }
}
auto TouchWheel::name() -> std::string {
diff --git a/src/tangara/input/input_trigger.cpp b/src/tangara/input/input_trigger.cpp
index 11b4dbe9..eb67bcca 100644
--- a/src/tangara/input/input_trigger.cpp
+++ b/src/tangara/input/input_trigger.cpp
@@ -85,4 +85,11 @@ auto Trigger::update(bool is_pressed) -> State {
return State::kNone;
}
+auto Trigger::cancel() -> void {
+ touch_time_ms_.reset();
+ was_pressed_ = false;
+ was_double_click_ = false;
+ times_long_pressed_ = 0;
+}
+
} // namespace input
diff --git a/src/tangara/input/input_trigger.hpp b/src/tangara/input/input_trigger.hpp
index bcafa8ad..1b0e681d 100644
--- a/src/tangara/input/input_trigger.hpp
+++ b/src/tangara/input/input_trigger.hpp
@@ -30,6 +30,7 @@ class Trigger {
Trigger();
auto update(bool is_pressed) -> State;
+ auto cancel() -> void;
private:
std::optional<uint64_t> touch_time_ms_;