Skip to content

Commit ac6e159

Browse files
committed
Feature: Lock it up!
1 parent 818161d commit ac6e159

File tree

6 files changed

+36
-11
lines changed

6 files changed

+36
-11
lines changed

ChangeLog.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Yatuli Changelog File #
22

3+
==================================================
4+
## Release v0.5 (May 29, 2017) (Public Release) ##
5+
6+
### Improvements ###
7+
8+
* Feature: now you has a lock var, when lock is true the code will refuse to update any values coming from the ADC; this is to avoid any form of FM modulation due to voltage variations due to high currents or RF when in use in real transceivers.
9+
310
==================================================
411
## Release v0.4 (May 22, 2017) (First Public Release) ##
512

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This is a kind of linear tuning and in the center with big steps on the edges:
2424
* You can dynamically reset the range and start value while running (useful in setups).
2525
* Negative values are supported in all the range (start, end & value)
2626
* Range is handled by 32 bit signed values, so it will work from -/+ 2.4G values.
27+
* Lock feature, you can lock in the lib when in TX (or wherever you case it).
2728

2829
See the examples bundled with the lib for use cases.
2930

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Yatuli (Yet Another Tune Library)
2-
version=0.4
2+
version=0.5
33
author=Pavel Milanes <[email protected]>
44
maintainer=Pavel Milanes <[email protected]>
55
sentence=Tune your hardware with a linear potentiometer instead a rotary encoder: be cheap, have Fun!

src/yatuli.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You can get the latest code in this Github repository:
1818
*
1919
* https://github.com/pavelmc/yatuli
20-
*
20+
*
2121
* This program is free software: you can redistribute it and/or modify
2222
* it under the terms of the GNU General Public License as published by
2323
* 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
5656
// some defaults
5757
base = start;
5858
value = start;
59+
60+
// defaults to unlock state
61+
lock = false;
5962
}
6063

6164

@@ -86,11 +89,14 @@ void Yatuli::set(int32_t init_value) {
8689
* This is the one you NEED to run in every loop cycle to update value
8790
****************************************************************************/
8891
void Yatuli::check(void) {
92+
// lock flag
93+
if (lock) return;
94+
8995
// internal vars, statics as they are used repeatedly in this.
9096
static int16_t lastAdc = adc;
9197
static uint32_t newTime = millis();
9298
static boolean adcDir;
93-
99+
94100
// update adc values
95101
_osadc();
96102

@@ -109,18 +115,18 @@ void Yatuli::check(void) {
109115
// move
110116
value += (edgeStep * t);
111117
base += (edgeStep * t);
112-
118+
113119
// reset pace timer
114120
newTime = millis() + PACE;
115121
}
116122
} else {
117123
// we are in the operative range
118124
// flutter fix, from bitx amunters raduino code, author Jerry KE7ER
119-
125+
120126
// direction detectors... (re-using vars)
121127
up = (adc > lastAdc) && (adcDir == 1 || (adc - lastAdc) > 5);
122128
down = (adc < lastAdc) && (adcDir == 0 || (lastAdc - adc) > 5);
123-
129+
124130
// check it now
125131
if (up || down) {
126132
// flag about the direction of the movement
@@ -132,7 +138,7 @@ void Yatuli::check(void) {
132138

133139
// force an update
134140
value = base + (int32_t)(adc / 10) * step;
135-
141+
136142
// force a consistent step interval
137143
value /= step;
138144
value *= step;
@@ -149,6 +155,9 @@ void Yatuli::check(void) {
149155
* convenient range of -5115 to +5115
150156
****************************************************************************/
151157
void Yatuli::_osadc(void) {
158+
// lock flag
159+
if (lock) return;
160+
152161
// internal var
153162
int32_t t = 0;
154163

@@ -170,9 +179,12 @@ void Yatuli::_osadc(void) {
170179
* See OptionSelect example
171180
****************************************************************************/
172181
int8_t Yatuli::dir(void) {
182+
// lock flag
183+
if (lock) return;
184+
173185
// internal var
174186
static int16_t lastAdcDir = adc;
175-
187+
176188
// calc the difference and scale to 20 tick per dial rotation
177189
int16_t result = (adc - lastAdcDir)/DIRTICKS;
178190

src/yatuli.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You can get the latest code in this Github repository:
1818
*
1919
* https://github.com/pavelmc/yatuli
20-
*
20+
*
2121
* This program is free software: you can redistribute it and/or modify
2222
* it under the terms of the GNU General Public License as published by
2323
* the Free Software Foundation, either version 3 of the License, or
@@ -66,13 +66,18 @@ class Yatuli {
6666

6767
// Return a relative vector from the last position: -1/0/+1
6868
// it will emit about ~50 steps in one rotation
69-
// WATCH OUT!: int8_t is char in arduino
69+
// WATCH OUT!: int8_t is char in arduino
7070
int8_t dir(void);
7171

7272
// public value
7373
int16_t adc; // oversampled ADC in the range -5115/+5115
7474
int32_t value; // real value in the range
7575

76+
// lock feature, when lock is true, we refuse to update the value/dir
77+
// as in a real TX high currents or RF can disturb the ADC and add FMing
78+
// to the real freq.
79+
bool lock;
80+
7681
private:
7782
int32_t start; // start of the range
7883
int32_t end; // stop of the range

version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.4
1+
v0.5

0 commit comments

Comments
 (0)