Skip to content

Commit

Permalink
Feature: Lock it up!
Browse files Browse the repository at this point in the history
  • Loading branch information
stdevPavelmc committed May 29, 2017
1 parent 818161d commit ac6e159
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Yatuli Changelog File #

==================================================
## Release v0.5 (May 29, 2017) (Public Release) ##

### Improvements ###

* 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.

==================================================
## Release v0.4 (May 22, 2017) (First Public Release) ##

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

See the examples bundled with the lib for use cases.

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Yatuli (Yet Another Tune Library)
version=0.4
version=0.5
author=Pavel Milanes <[email protected]>
maintainer=Pavel Milanes <[email protected]>
sentence=Tune your hardware with a linear potentiometer instead a rotary encoder: be cheap, have Fun!
Expand Down
26 changes: 19 additions & 7 deletions src/yatuli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You can get the latest code in this Github repository:
*
* https://github.com/pavelmc/yatuli
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -56,6 +56,9 @@ void Yatuli::init(uint8_t _pin, int32_t _start, int32_t _end, uint16_t _step, ui
// some defaults
base = start;
value = start;

// defaults to unlock state
lock = false;
}


Expand Down Expand Up @@ -86,11 +89,14 @@ void Yatuli::set(int32_t init_value) {
* This is the one you NEED to run in every loop cycle to update value
****************************************************************************/
void Yatuli::check(void) {
// lock flag
if (lock) return;

// internal vars, statics as they are used repeatedly in this.
static int16_t lastAdc = adc;
static uint32_t newTime = millis();
static boolean adcDir;

// update adc values
_osadc();

Expand All @@ -109,18 +115,18 @@ void Yatuli::check(void) {
// move
value += (edgeStep * t);
base += (edgeStep * t);

// reset pace timer
newTime = millis() + PACE;
}
} else {
// we are in the operative range
// flutter fix, from bitx amunters raduino code, author Jerry KE7ER

// direction detectors... (re-using vars)
up = (adc > lastAdc) && (adcDir == 1 || (adc - lastAdc) > 5);
down = (adc < lastAdc) && (adcDir == 0 || (lastAdc - adc) > 5);

// check it now
if (up || down) {
// flag about the direction of the movement
Expand All @@ -132,7 +138,7 @@ void Yatuli::check(void) {

// force an update
value = base + (int32_t)(adc / 10) * step;

// force a consistent step interval
value /= step;
value *= step;
Expand All @@ -149,6 +155,9 @@ void Yatuli::check(void) {
* convenient range of -5115 to +5115
****************************************************************************/
void Yatuli::_osadc(void) {
// lock flag
if (lock) return;

// internal var
int32_t t = 0;

Expand All @@ -170,9 +179,12 @@ void Yatuli::_osadc(void) {
* See OptionSelect example
****************************************************************************/
int8_t Yatuli::dir(void) {
// lock flag
if (lock) return;

// internal var
static int16_t lastAdcDir = adc;

// calc the difference and scale to 20 tick per dial rotation
int16_t result = (adc - lastAdcDir)/DIRTICKS;

Expand Down
9 changes: 7 additions & 2 deletions src/yatuli.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You can get the latest code in this Github repository:
*
* https://github.com/pavelmc/yatuli
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -66,13 +66,18 @@ class Yatuli {

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

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

// lock feature, when lock is true, we refuse to update the value/dir
// as in a real TX high currents or RF can disturb the ADC and add FMing
// to the real freq.
bool lock;

private:
int32_t start; // start of the range
int32_t end; // stop of the range
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4
v0.5

0 comments on commit ac6e159

Please sign in to comment.