summaryrefslogtreecommitdiff
path: root/src/drivers/include/relative_wheel.hpp
blob: b5532a4cccb1145115bcce7c70ea52f2364b2ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * 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 is_clicking() -> bool;
  auto ticks() -> std::int_fast16_t;

  // Not copyable or movable.
  RelativeWheel(const RelativeWheel&) = delete;
  RelativeWheel& operator=(const RelativeWheel&) = delete;

 private:
  TouchWheel& touch_;

  bool is_enabled_;

  bool is_clicking_;
  bool was_clicking_;
  bool is_first_read_;
  std::int_fast16_t ticks_;
  uint8_t last_angle_;
};

}  // namespace drivers