summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/CMakeLists.txt3
-rw-r--r--src/drivers/include/relative_wheel.hpp52
-rw-r--r--src/drivers/relative_wheel.cpp92
3 files changed, 1 insertions, 146 deletions
diff --git a/src/drivers/CMakeLists.txt b/src/drivers/CMakeLists.txt
index 0b7ead94..891115d4 100644
--- a/src/drivers/CMakeLists.txt
+++ b/src/drivers/CMakeLists.txt
@@ -5,8 +5,7 @@
idf_component_register(
SRCS "touchwheel.cpp" "i2s_dac.cpp" "gpios.cpp" "adc.cpp" "storage.cpp"
"i2c.cpp" "bluetooth.cpp" "spi.cpp" "display.cpp" "display_init.cpp"
- "samd.cpp" "relative_wheel.cpp" "wm8523.cpp" "nvs.cpp" "haptics.cpp"
- "spiffs.cpp"
+ "samd.cpp" "wm8523.cpp" "nvs.cpp" "haptics.cpp" "spiffs.cpp"
INCLUDE_DIRS "include"
REQUIRES "esp_adc" "fatfs" "result" "lvgl" "span" "tasks" "nvs_flash" "spiffs"
"bt" "tinyfsm" "util")
diff --git a/src/drivers/include/relative_wheel.hpp b/src/drivers/include/relative_wheel.hpp
deleted file mode 100644
index e1106143..00000000
--- a/src/drivers/include/relative_wheel.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <stdint.h>
-#include <cstdint>
-#include <functional>
-
-#include "esp_err.h"
-#include "result.hpp"
-
-#include "gpios.hpp"
-#include "touchwheel.hpp"
-
-namespace drivers {
-
-class RelativeWheel {
- public:
- explicit RelativeWheel(TouchWheel& touch);
-
- auto Update() -> void;
- auto SetEnabled(bool) -> void;
-
- auto SetSensitivity(uint8_t) -> void;
- auto GetSensitivity() -> uint8_t;
-
- auto is_clicking() const -> bool;
- auto ticks() const -> std::int_fast16_t;
-
- // Not copyable or movable.
- RelativeWheel(const RelativeWheel&) = delete;
- RelativeWheel& operator=(const RelativeWheel&) = delete;
-
- private:
- TouchWheel& touch_;
-
- bool is_enabled_;
- uint8_t sensitivity_;
- uint8_t threshold_;
-
- bool is_clicking_;
- bool was_clicking_;
- bool is_first_read_;
- std::int_fast16_t ticks_;
- uint8_t last_angle_;
-};
-
-} // namespace drivers
diff --git a/src/drivers/relative_wheel.cpp b/src/drivers/relative_wheel.cpp
deleted file mode 100644
index e90143ae..00000000
--- a/src/drivers/relative_wheel.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#include "relative_wheel.hpp"
-
-#include <stdint.h>
-#include <cstdint>
-
-#include "esp_log.h"
-
-namespace drivers {
-
-RelativeWheel::RelativeWheel(TouchWheel& touch)
- : touch_(touch),
- is_enabled_(true),
- sensitivity_(128),
- threshold_(10),
- is_clicking_(false),
- was_clicking_(false),
- is_first_read_(true),
- ticks_(0),
- last_angle_(0) {}
-
-auto RelativeWheel::Update() -> void {
- TouchWheelData d = touch_.GetTouchWheelData();
-
- is_clicking_ = d.is_button_touched;
-
- if (is_clicking_) {
- ticks_ = 0;
- return;
- }
-
- if (!d.is_wheel_touched) {
- ticks_ = 0;
- is_first_read_ = true;
- return;
- }
-
- uint8_t new_angle = d.wheel_position;
- if (is_first_read_) {
- is_first_read_ = false;
- last_angle_ = new_angle;
- return;
- }
-
- int delta = 128 - last_angle_;
- uint8_t rotated_angle = new_angle + delta;
- if (rotated_angle < 128 - threshold_) {
- ticks_ = 1;
- last_angle_ = new_angle;
- } else if (rotated_angle > 128 + threshold_) {
- ticks_ = -1;
- last_angle_ = new_angle;
- } else {
- ticks_ = 0;
- }
-}
-
-auto RelativeWheel::SetEnabled(bool en) -> void {
- is_enabled_ = en;
-}
-
-auto RelativeWheel::SetSensitivity(uint8_t val) -> void {
- sensitivity_ = val;
- int tmax = 35;
- int tmin = 5;
- threshold_ = (((255. - sensitivity_)/255.)*(tmax - tmin) + tmin);
-}
-
-auto RelativeWheel::GetSensitivity() -> uint8_t {
- return sensitivity_;
-}
-
-auto RelativeWheel::is_clicking() const -> bool {
- if (!is_enabled_) {
- return false;
- }
- return is_clicking_;
-}
-
-auto RelativeWheel::ticks() const -> std::int_fast16_t {
- if (!is_enabled_) {
- return 0;
- }
- return ticks_;
-}
-
-} // namespace drivers