Skip to content

Commit 32c21b5

Browse files
committed
0.1.3 X9C10X
1 parent 8abd8cd commit 32c21b5

File tree

6 files changed

+58
-22
lines changed

6 files changed

+58
-22
lines changed

libraries/X9C10X/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ Note: **begin()** has a hard coded 500uS delay so the device can wake up.
6868
Note: multiple devices can be controlled, just by giving them an unique selectPin.
6969
This behaviour is similar to the SPI select pin.
7070

71-
- **void setPosition(uint8_t position)** sets the wiper to a position between 0 and 99.
71+
- **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.
72+
If forced is set to true, the cached position is ignored and the new position will be cached.
7273
- **uint8_t getPosition()** returns the current position.
73-
- **void incr()** moves one position up (if possible).
74-
- **void decr()** moves one position down (if possible).
74+
- **bool incr()** moves one position up (if possible).
75+
Returns true if moved and false if already at end position.
76+
- **bool decr()** moves one position down (if possible).
77+
Returns true if moved and false if already at end position.
7578
- **uint32_t getOhm()** returns the position expressed in Ohm.
7679
The returned value does depend on the value passed in the constructor.
7780
- **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.
155158

156159
- test different platforms
157160
- improve the hardcoded 500us delay in **begin()**
158-
- add return code to **setPosition() incr() decr()** ?
159161
- add error codes ?
160162
- test **store()**
163+
- in the constructor rename **Ohm** parameter to value?
164+
- The potentiometer can be used as a voltage divider (see above)
165+
so a better parameter name could be the anonymous **value**.
166+
- **getOhm()** ==> **getValue()**
167+
- **getMaxOhm()** ==> **getMaxValue()**
168+
- think milliVolt, ohm, lux, speed, etc.
169+
User can do this too with **getPosition()**
170+
171+

libraries/X9C10X/X9C10X.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
//
22
// FILE: X9C10X.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.2
4+
// VERSION: 0.1.3
55
// PURPOSE: Arduino Library for X9C10X series digital potentiometer.
6+
// URL: https://github.com/RobTillaart/X9C10X
67
//
78
// HISTORY
89
// 0.1.0 2022-01-26 initial version
910
// 0.1.1 2022-02-15 improve conditional delay
1011
// 0.1.2 2022-02-16 improve performance, add sweeper example
1112
// rounding in getOhm(), documentation
13+
// 0.1.3 2022-02-22 add forced parameter to setPosition()
14+
// incr() and decr() return bool (made a step)
15+
//
1216

1317

1418
#include "X9C10X.h"
@@ -54,13 +58,27 @@ void X9C10X::begin(uint8_t pulsePin, uint8_t directionPin, uint8_t selectPin, ui
5458
}
5559

5660

57-
// initial implementation, to be optimized.
58-
void X9C10X::setPosition(uint8_t position)
61+
void X9C10X::setPosition(uint8_t position, bool forced)
5962
{
6063
if (position > 99) position = 99;
61-
// reference 0.1.0
62-
// while (position > _position) incr();
63-
// while (position < _position) decr();
64+
// reference 0.1.0
65+
// while (position > _position) incr();
66+
// while (position < _position) decr();
67+
68+
// force to nearest end position first to minimize steps.
69+
if (forced)
70+
{
71+
if (position < 50)
72+
{
73+
_move(X9C10X_DOWN, 99);
74+
_position = 0;
75+
}
76+
else
77+
{
78+
_move(X9C10X_UP, 99);
79+
_position = 99;
80+
}
81+
}
6482
if (position > _position)
6583
{
6684
_move(X9C10X_UP, position - _position);
@@ -69,23 +87,26 @@ void X9C10X::setPosition(uint8_t position)
6987
{
7088
_move(X9C10X_DOWN, _position - position);
7189
}
90+
7291
_position = position;
7392
}
7493

7594

76-
void X9C10X::incr()
95+
bool X9C10X::incr()
7796
{
78-
if (_position >= 99) return;
97+
if (_position >= 99) return false;
7998
_position++;
8099
_move(X9C10X_UP);
100+
return true;
81101
}
82102

83103

84-
void X9C10X::decr()
104+
bool X9C10X::decr()
85105
{
86-
if (_position == 0) return;
106+
if (_position == 0) return false;
87107
_position--;
88108
_move(X9C10X_DOWN);
109+
return true;
89110
}
90111

91112

libraries/X9C10X/X9C10X.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
//
33
// FILE: X9C10X.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.2
5+
// VERSION: 0.1.3
66
// PURPOSE: Arduino Library for X9C10X series digital potentiometer.
7-
//
7+
// URL: https://github.com/RobTillaart/X9C10X
88

99

1010
#include "Arduino.h"
1111

12-
#define X9C10X_LIB_VERSION (F("0.1.2"))
12+
#define X9C10X_LIB_VERSION (F("0.1.3"))
1313

1414

1515
class X9C10X
@@ -21,12 +21,15 @@ class X9C10X
2121
void begin(uint8_t pulsePin, uint8_t directionPin, uint8_t selectPin, uint8_t position = 0);
2222

2323
// position = 0..99
24-
void setPosition(uint8_t position);
24+
// forced = true will ignore the cached position
25+
// takes up to 150 steps as one cannot read the position from device.
26+
// forced = default false as that is safer and backwards compatible.
27+
void setPosition(uint8_t position, bool forced = false);
2528
uint8_t getPosition() { return _position; };
2629

2730
// step size 1.
28-
void incr();
29-
void decr();
31+
bool incr();
32+
bool decr();
3033

3134
// use with care
3235
uint8_t store();

libraries/X9C10X/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ getOhm KEYWORD2
1919
getMaxOhm KEYWORD2
2020

2121
store KEYWORD2
22+
getType KEYWORD2
2223

2324

2425
# Constants (LITERAL1)

libraries/X9C10X/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/X9C10X.git"
1717
},
18-
"version": "0.1.2",
18+
"version": "0.1.3",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*",

libraries/X9C10X/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=X9C10X
2-
version=0.1.2
2+
version=0.1.3
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino Library for X9C10X series digital potentiometer.

0 commit comments

Comments
 (0)