diff options
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/include/touchwheel.hpp | 4 | ||||
| -rw-r--r-- | src/drivers/touchwheel.cpp | 7 |
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, |
