summaryrefslogtreecommitdiff
path: root/src/drivers/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-01 15:28:32 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-01 15:28:54 +1000
commit6fd588e970470b15936187980829916d0dbe77bb (patch)
tree1b1e73ef52bef2e41499ee5ceadc45efd408050b /src/drivers/include
parentdb2e29a72d9b934e7b58f1d20ac3768eae484ab5 (diff)
downloadtangara-fw-6fd588e970470b15936187980829916d0dbe77bb.tar.gz
Add touchwheel -> encoder adapter
Diffstat (limited to 'src/drivers/include')
-rw-r--r--src/drivers/include/relative_wheel.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/drivers/include/relative_wheel.hpp b/src/drivers/include/relative_wheel.hpp
new file mode 100644
index 00000000..3ff64b70
--- /dev/null
+++ b/src/drivers/include/relative_wheel.hpp
@@ -0,0 +1,44 @@
+/*
+ * 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 "gpio_expander.hpp"
+#include "touchwheel.hpp"
+
+namespace drivers {
+
+class RelativeWheel {
+ public:
+ static auto Create(TouchWheel *touch) -> RelativeWheel* { return new RelativeWheel(touch); }
+
+ explicit RelativeWheel(TouchWheel *touch);
+
+ // Not copyable or movable.
+ RelativeWheel(const RelativeWheel&) = delete;
+ RelativeWheel& operator=(const RelativeWheel&) = delete;
+
+ auto Update() -> void;
+
+ auto is_pressed() -> bool;
+ auto ticks() -> std::int_fast16_t;
+
+ private:
+ TouchWheel *touch_;
+ bool is_pressed_;
+ bool is_first_read_;
+ std::int_fast16_t ticks_;
+ uint8_t last_angle_;
+};
+
+} // namespace drivers