-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTEJ_Rotary_Encoder.cpp
More file actions
79 lines (63 loc) · 1.23 KB
/
STEJ_Rotary_Encoder.cpp
File metadata and controls
79 lines (63 loc) · 1.23 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "STEJ_Rotary_Encoder.h"
STEJ_Rotary_Encoder::STEJ_Rotary_Encoder(int16_t min, int16_t max, int16_t step, boolean continuous):
m_step(step),
m_continuous(continuous)
{
setMinMax(min, max);
setValue(0);
}
STEJ_Rotary_Encoder::~STEJ_Rotary_Encoder()
{
}
void STEJ_Rotary_Encoder::setValue(int16_t value)
{
m_value = value;
m_changed = true;
}
void STEJ_Rotary_Encoder::setStep(int16_t step)
{
m_step = step;
}
void STEJ_Rotary_Encoder::setMinMax(int16_t min, int16_t max)
{
m_min = min < max ? min : max;
m_max = max > min ? max : min;
}
void STEJ_Rotary_Encoder::setContinuous(boolean continuous)
{
m_continuous = continuous;
}
int16_t STEJ_Rotary_Encoder::read() const
{
m_changed = false;
return m_value;
}
boolean STEJ_Rotary_Encoder::hasChanged() const
{
return m_changed;
}
void STEJ_Rotary_Encoder::move_cw()
{
m_value += m_step;
m_changed = true;
update();
}
void STEJ_Rotary_Encoder::move_ccw()
{
m_value -= m_step;
m_changed = true;
update();
}
void STEJ_Rotary_Encoder::update()
{
if( m_value > m_max )
{
m_value = m_continuous ? m_min : m_max;
m_changed = false;
}
if( m_value < m_min )
{
m_value = m_continuous ? m_max : m_min;
m_changed = false;
}
}