From 6fd588e970470b15936187980829916d0dbe77bb Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 1 Jun 2023 15:28:32 +1000 Subject: Add touchwheel -> encoder adapter --- src/drivers/include/relative_wheel.hpp | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/drivers/include/relative_wheel.hpp (limited to 'src/drivers/include') 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 + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include +#include +#include + +#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 -- cgit v1.2.3