summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-11 15:16:35 +1000
committerjacqueline <me@jacqueline.id.au>2024-04-11 15:16:35 +1000
commit33919e9e3f419e13318fa6b8217d8c8dcd86c1eb (patch)
tree9e3a1209c8f17f9a6d57249fae7067cbb81e0227 /src/drivers
parented82063af5f83530afa5cfb5bf5bd516f3d05f2a (diff)
downloadtangara-fw-33919e9e3f419e13318fa6b8217d8c8dcd86c1eb.tar.gz
Migrate all existing control schemes to the cool new world
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/include/touchwheel.hpp4
-rw-r--r--src/drivers/touchwheel.cpp7
2 files changed, 11 insertions, 0 deletions
diff --git a/src/drivers/include/touchwheel.hpp b/src/drivers/include/touchwheel.hpp
index 9d002156..18ace2b4 100644
--- a/src/drivers/include/touchwheel.hpp
+++ b/src/drivers/include/touchwheel.hpp
@@ -24,6 +24,10 @@ struct TouchWheelData {
class TouchWheel {
public:
+ static auto isAngleWithin(int16_t wheel_angle,
+ int16_t target_angle,
+ int threshold) -> bool;
+
static auto Create() -> TouchWheel* { return new TouchWheel(); }
TouchWheel();
~TouchWheel();
diff --git a/src/drivers/touchwheel.cpp b/src/drivers/touchwheel.cpp
index a20f434b..41b9a6af 100644
--- a/src/drivers/touchwheel.cpp
+++ b/src/drivers/touchwheel.cpp
@@ -28,6 +28,13 @@ namespace drivers {
static const uint8_t kTouchWheelAddress = 0x1C;
static const gpio_num_t kIntPin = GPIO_NUM_25;
+auto TouchWheel::isAngleWithin(int16_t wheel_angle,
+ int16_t target_angle,
+ int threshold) -> bool {
+ int16_t difference = (wheel_angle - target_angle + 127 + 255) % 255 - 127;
+ return difference <= threshold && difference >= -threshold;
+}
+
TouchWheel::TouchWheel() {
gpio_config_t int_config{
.pin_bit_mask = 1ULL << kIntPin,