0.1.3 X9C10X

This commit is contained in:
rob tillaart 2022-02-23 15:57:01 +01:00
parent 8abd8cd3bd
commit 32c21b5d9c
6 changed files with 58 additions and 22 deletions

View File

@ -68,10 +68,13 @@ Note: **begin()** has a hard coded 500uS delay so the device can wake up.
Note: multiple devices can be controlled, just by giving them an unique selectPin.
This behaviour is similar to the SPI select pin.
- **void setPosition(uint8_t position)** sets the wiper to a position between 0 and 99.
- **void setPosition(uint8_t position, bool forced = false)** sets the wiper to a position between 0 and 99. The movement is relative to the current (cached) position.
If forced is set to true, the cached position is ignored and the new position will be cached.
- **uint8_t getPosition()** returns the current position.
- **void incr()** moves one position up (if possible).
- **void decr()** moves one position down (if possible).
- **bool incr()** moves one position up (if possible).
Returns true if moved and false if already at end position.
- **bool decr()** moves one position down (if possible).
Returns true if moved and false if already at end position.
- **uint32_t getOhm()** returns the position expressed in Ohm.
The returned value does depend on the value passed in the constructor.
- **uint32_t getMaxOhm()** returns the maximum value ( = parameter from constructor).
@ -155,6 +158,14 @@ Note: check datasheet for the range of the max voltage allowed.
- test different platforms
- improve the hardcoded 500us delay in **begin()**
- add return code to **setPosition() incr() decr()** ?
- add error codes ?
- test **store()**
- in the constructor rename **Ohm** parameter to value?
- The potentiometer can be used as a voltage divider (see above)
so a better parameter name could be the anonymous **value**.
- **getOhm()** ==> **getValue()**
- **getMaxOhm()** ==> **getMaxValue()**
- think milliVolt, ohm, lux, speed, etc.
User can do this too with **getPosition()**

View File

@ -1,14 +1,18 @@
//
// FILE: X9C10X.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino Library for X9C10X series digital potentiometer.
// URL: https://github.com/RobTillaart/X9C10X
//
// HISTORY
// 0.1.0 2022-01-26 initial version
// 0.1.1 2022-02-15 improve conditional delay
// 0.1.2 2022-02-16 improve performance, add sweeper example
// rounding in getOhm(), documentation
// 0.1.3 2022-02-22 add forced parameter to setPosition()
// incr() and decr() return bool (made a step)
//
#include "X9C10X.h"
@ -54,13 +58,27 @@ void X9C10X::begin(uint8_t pulsePin, uint8_t directionPin, uint8_t selectPin, ui
}
// initial implementation, to be optimized.
void X9C10X::setPosition(uint8_t position)
void X9C10X::setPosition(uint8_t position, bool forced)
{
if (position > 99) position = 99;
// reference 0.1.0
// while (position > _position) incr();
// while (position < _position) decr();
// reference 0.1.0
// while (position > _position) incr();
// while (position < _position) decr();
// force to nearest end position first to minimize steps.
if (forced)
{
if (position < 50)
{
_move(X9C10X_DOWN, 99);
_position = 0;
}
else
{
_move(X9C10X_UP, 99);
_position = 99;
}
}
if (position > _position)
{
_move(X9C10X_UP, position - _position);
@ -69,23 +87,26 @@ void X9C10X::setPosition(uint8_t position)
{
_move(X9C10X_DOWN, _position - position);
}
_position = position;
}
void X9C10X::incr()
bool X9C10X::incr()
{
if (_position >= 99) return;
if (_position >= 99) return false;
_position++;
_move(X9C10X_UP);
return true;
}
void X9C10X::decr()
bool X9C10X::decr()
{
if (_position == 0) return;
if (_position == 0) return false;
_position--;
_move(X9C10X_DOWN);
return true;
}

View File

@ -2,14 +2,14 @@
//
// FILE: X9C10X.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino Library for X9C10X series digital potentiometer.
//
// URL: https://github.com/RobTillaart/X9C10X
#include "Arduino.h"
#define X9C10X_LIB_VERSION (F("0.1.2"))
#define X9C10X_LIB_VERSION (F("0.1.3"))
class X9C10X
@ -21,12 +21,15 @@ public:
void begin(uint8_t pulsePin, uint8_t directionPin, uint8_t selectPin, uint8_t position = 0);
// position = 0..99
void setPosition(uint8_t position);
// forced = true will ignore the cached position
// takes up to 150 steps as one cannot read the position from device.
// forced = default false as that is safer and backwards compatible.
void setPosition(uint8_t position, bool forced = false);
uint8_t getPosition() { return _position; };
// step size 1.
void incr();
void decr();
bool incr();
bool decr();
// use with care
uint8_t store();

View File

@ -19,6 +19,7 @@ getOhm KEYWORD2
getMaxOhm KEYWORD2
store KEYWORD2
getType KEYWORD2
# Constants (LITERAL1)

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/X9C10X.git"
},
"version": "0.1.2",
"version": "0.1.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=X9C10X
version=0.1.2
version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for X9C10X series digital potentiometer.