-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRotaryEncoder.h
39 lines (33 loc) · 1.08 KB
/
RotaryEncoder.h
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
/*-----------------------------------------------------------/
/ RotaryEncoder.h
/------------------------------------------------------------/
/ Copyright (c) 2023, Elehobica
/ Released under the BSD-2-Clause
/ refer to https://opensource.org/licenses/BSD-2-Clause
/-----------------------------------------------------------*/
#pragma once
#include <map>
#include "pico/stdlib.h"
namespace gpio
{
class RotaryEncoder
{
public:
RotaryEncoder(const uint pinA, const uint pinB, const uint32_t step = 1, const int32_t initValue = 0, const int32_t min = 0, const int32_t max = 100);
virtual ~RotaryEncoder();
void set(int32_t value);
int32_t get() const;
private:
static std::map<const uint, RotaryEncoder* const> _pinARef;
static std::map<const uint, RotaryEncoder* const> _pinBRef;
const uint _pinA;
const uint _pinB;
const uint32_t _step;
const int32_t _min;
const int32_t _max;
int32_t _rawValue;
void _setRaw(int32_t rawValue);
void _inc(const bool up);
friend void rotaryEncoderCallback(uint gpio, uint32_t events);
};
} // namespace gpio