17
17
* You can get the latest code in this Github repository:
18
18
*
19
19
* https://github.com/pavelmc/yatuli
20
- *
20
+ *
21
21
* This program is free software: you can redistribute it and/or modify
22
22
* it under the terms of the GNU General Public License as published by
23
23
* the Free Software Foundation, either version 3 of the License, or
@@ -56,6 +56,9 @@ void Yatuli::init(uint8_t _pin, int32_t _start, int32_t _end, uint16_t _step, ui
56
56
// some defaults
57
57
base = start;
58
58
value = start;
59
+
60
+ // defaults to unlock state
61
+ lock = false ;
59
62
}
60
63
61
64
@@ -86,11 +89,14 @@ void Yatuli::set(int32_t init_value) {
86
89
* This is the one you NEED to run in every loop cycle to update value
87
90
****************************************************************************/
88
91
void Yatuli::check (void ) {
92
+ // lock flag
93
+ if (lock) return ;
94
+
89
95
// internal vars, statics as they are used repeatedly in this.
90
96
static int16_t lastAdc = adc;
91
97
static uint32_t newTime = millis ();
92
98
static boolean adcDir;
93
-
99
+
94
100
// update adc values
95
101
_osadc ();
96
102
@@ -109,18 +115,18 @@ void Yatuli::check(void) {
109
115
// move
110
116
value += (edgeStep * t);
111
117
base += (edgeStep * t);
112
-
118
+
113
119
// reset pace timer
114
120
newTime = millis () + PACE;
115
121
}
116
122
} else {
117
123
// we are in the operative range
118
124
// flutter fix, from bitx amunters raduino code, author Jerry KE7ER
119
-
125
+
120
126
// direction detectors... (re-using vars)
121
127
up = (adc > lastAdc) && (adcDir == 1 || (adc - lastAdc) > 5 );
122
128
down = (adc < lastAdc) && (adcDir == 0 || (lastAdc - adc) > 5 );
123
-
129
+
124
130
// check it now
125
131
if (up || down) {
126
132
// flag about the direction of the movement
@@ -132,7 +138,7 @@ void Yatuli::check(void) {
132
138
133
139
// force an update
134
140
value = base + (int32_t )(adc / 10 ) * step;
135
-
141
+
136
142
// force a consistent step interval
137
143
value /= step;
138
144
value *= step;
@@ -149,6 +155,9 @@ void Yatuli::check(void) {
149
155
* convenient range of -5115 to +5115
150
156
****************************************************************************/
151
157
void Yatuli::_osadc (void ) {
158
+ // lock flag
159
+ if (lock) return ;
160
+
152
161
// internal var
153
162
int32_t t = 0 ;
154
163
@@ -170,9 +179,12 @@ void Yatuli::_osadc(void) {
170
179
* See OptionSelect example
171
180
****************************************************************************/
172
181
int8_t Yatuli::dir (void ) {
182
+ // lock flag
183
+ if (lock) return ;
184
+
173
185
// internal var
174
186
static int16_t lastAdcDir = adc;
175
-
187
+
176
188
// calc the difference and scale to 20 tick per dial rotation
177
189
int16_t result = (adc - lastAdcDir)/DIRTICKS;
178
190
0 commit comments