0.3.1 rotaryDecoderSwitch

This commit is contained in:
Rob Tillaart 2024-06-24 16:48:34 +02:00
parent f92f1f35bd
commit fd2cbd578d
7 changed files with 49 additions and 27 deletions

View File

@ -10,4 +10,5 @@ jobs:
- uses: arduino/arduino-lint-action@v1 - uses: arduino/arduino-lint-action@v1
with: with:
library-manager: update library-manager: update
compliance: strict # to suppress long name error
# compliance: strict

View File

@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.1] - 2024-06-20
- changed **uint8_t readInitialState()** to return the read state.
- changed **bool setValue(uint8_t re, int32_t value = 0)** to return false
if parameter re is out of range, prevent possible bug.
- changed **int32_t getValue(uint8_t re)** to return 0
if parameter re is out of range, prevent possible bug.
- update readme.md, interface section.
- minor edits
## [0.3.0] - 2024-01-06 ## [0.3.0] - 2024-01-06
- add **read1(pin)** see #10 - add **read1(pin)** see #10
- add **write1(pin, value)** experimental see #10 - add **write1(pin, value)** experimental see #10

View File

@ -64,7 +64,8 @@ Note the above mapping is sort of compatible to using the rotaryDecoder class an
#### Constructor #### Constructor
- **rotaryDecoderSwitch(const int8_t address, TwoWire \*wire = Wire);** constructor to set the address and optional the Wire bus. - **rotaryDecoderSwitch(const int8_t address, TwoWire \*wire = Wire)**
constructor to set the address and optional the Wire bus.
- **bool begin(uint8_t count = 2)** UNO ea. initializes the class. - **bool begin(uint8_t count = 2)** UNO ea. initializes the class.
count is the number of rotary encoders connected. count is the number of rotary encoders connected.
returns true if the PCF8574 is on the I2C bus. returns true if the PCF8574 is on the I2C bus.
@ -73,24 +74,32 @@ returns true if the PCF8574 is on the I2C bus.
#### Core functions #### Core functions
- **void readInitialState()** read the initial state of the 2 rotary encoders. - **uint8_t readInitialState()** read the initial state of the 2 rotary encoders.
Typically called in setup only, or after a sleep e.g. in combination with **setValue()** Typically called in setup only, or after a sleep e.g. in combination with **setValue()**.
- **bool checkChange()** polling to see if one or more RE have changed, Since 0.3.1 this function returns the read state, saves an additional read8() call.
without updating the internal counters. - **bool checkChange()** used for polling to see if one or more RE have changed.
- **void update()** update the internal counters of the RE, and the flags if a key is pressed. This function does NOT update the internal counters.
- **bool update()** returns true if there is a change detected.
It updates the internal counters of the RE.
The counters will add +1 or -1 depending on rotation direction. The counters will add +1 or -1 depending on rotation direction.
Need to be called before **getValue()** or before **getKeyPressed()**. Need to be called before **getValue()** or before **getKeyPressed()**.
Note that **update()** must be called as soon as possible after the interrupt occurs (or as often as possible when polling). Note that **update()** must be called as soon as possible after the interrupt occurs
- **void updateSingle()** update the internal counters of the RE. or as often as possible when polling.
This will add +1 +2 or +3 as it assumes that the rotary encoder Returns false if there is no change since last read.
only goes into a single direction. - **bool updateSingle()** returns true if there is a change detected.
It updates the internal counters of the RE.
This will add +1, +2 or +3 as it assumes that the rotary encoder
only goes into a single direction.
Returns false if there is no change since last read.
#### Counters & keypresses #### Counters & keypresses
- **uint32_t getValue(uint8_r re)** returns the RE counter. (re = 0 or 1). - **int32_t getValue(uint8_r re)** returns the RE counter. (re = 0 or 1).
- **void setValue(uint8_r re, uint32_t value = 0)** (re)set the internal counter to value, default 0 If the parameter re > 1 then 0 is returned.
- **bool isKeyPressed(uint8_t re)** returns true is the switch is pressed of the RE selected (re = 0 or 1). - **bool setValue(uint8_r re, int32_t value = 0)** (re)set the internal counter to value, default 0.
If the parameter re > 1 then false is returned, true otherwise.
- **bool isKeyPressed(uint8_t re)** returns true if the switch is pressed of the RE selected (re = 0 or 1).
Note one needs to call **update()** first! Note one needs to call **update()** first!
@ -119,14 +128,13 @@ rotary encoder pins.
#### Debugging #### Debugging
- **int8_t getLastPosition(uint8_r re)** (re = 0 or 1). Returns last position. - **int8_t getLastPosition(uint8_r re)** (re = 0 or 1). Returns last position.
- **int8_t getRaw()**
## Performance ## Performance
As the decoder is based upon a PCF8574, a I2C device, the performance is affected by the As the decoder is based upon a PCF8574, a I2C device, the performance is affected by the
clock speed of the I2C bus. clock speed of the I2C bus.
All four core functions have one call to **\read8()** which is the most expensive part. All four core functions have one call to **read8()** which is the most expensive part.
Early tests gave the following indicative times (Arduino UNO) for the **update()** Early tests gave the following indicative times (Arduino UNO) for the **update()**
function. function.
@ -135,8 +143,8 @@ Note that above 500 KHz the gain becomes less while reliability of signal decrea
As 400 KHz is a standard I2C clock speed it is the preferred one. As 400 KHz is a standard I2C clock speed it is the preferred one.
| I2C speed | time (us) | delta | %% | Notes | | I2C speed | time (us) | delta | %% | Notes |
|:-----------:|:-----------:|:-------:|:-----:|:---------| |:-----------:|:-----------:|:-------:|:-----:|:--------|
| 100 KHz | 234 | | | | 100 KHz | 234 | | |
| 200 KHz | 136 | 98 | 42% | | 200 KHz | 136 | 98 | 42% |
| 300 KHz | 100 | 36 | 26% | | 300 KHz | 100 | 36 | 26% |

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/rotaryDecoderSwitch.git" "url": "https://github.com/RobTillaart/rotaryDecoderSwitch.git"
}, },
"version": "0.3.0", "version": "0.3.1",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=rotaryDecoderSwitch name=rotaryDecoderSwitch
version=0.3.0 version=0.3.1
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for rotary decoder + switch with a PCF8574. sentence=Arduino library for rotary decoder + switch with a PCF8574.

View File

@ -1,7 +1,7 @@
// //
// FILE: rotaryDecoderSwitch.cpp // FILE: rotaryDecoderSwitch.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.0 // VERSION: 0.3.1
// DATE: 2021-05-17 // DATE: 2021-05-17
// PURPOSE: Arduino library for rotary decoder (with switch) // PURPOSE: Arduino library for rotary decoder (with switch)
// URL: https://github.com/RobTillaart/rotaryDecoderSwitch // URL: https://github.com/RobTillaart/rotaryDecoderSwitch
@ -38,7 +38,7 @@ bool rotaryDecoderSwitch::isConnected()
} }
void rotaryDecoderSwitch::readInitialState() uint8_t rotaryDecoderSwitch::readInitialState()
{ {
uint8_t value = read8(); uint8_t value = read8();
_lastValue = value; _lastValue = value;
@ -48,6 +48,7 @@ void rotaryDecoderSwitch::readInitialState()
_lastPos[i] = value & 0x03; _lastPos[i] = value & 0x03;
value >>= 4; value >>= 4;
} }
return _lastValue;
} }
@ -134,13 +135,16 @@ bool rotaryDecoderSwitch::updateSingle()
int32_t rotaryDecoderSwitch::getValue(uint8_t re) int32_t rotaryDecoderSwitch::getValue(uint8_t re)
{ {
if (re > 1) return 0;
return _encoder[re]; return _encoder[re];
} }
void rotaryDecoderSwitch::setValue(uint8_t re, int32_t value) bool rotaryDecoderSwitch::setValue(uint8_t re, int32_t value)
{ {
if (re > 1) return false;
_encoder[re] = value; _encoder[re] = value;
return true;
} }

View File

@ -2,7 +2,7 @@
// //
// FILE: rotaryDecoderSwitch.h // FILE: rotaryDecoderSwitch.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.0 // VERSION: 0.3.1
// DATE: 2021-05-17 // DATE: 2021-05-17
// PURPOSE: Arduino library for rotary decoder (with switch) // PURPOSE: Arduino library for rotary decoder (with switch)
// URL: https://github.com/RobTillaart/rotaryDecoderSwitch // URL: https://github.com/RobTillaart/rotaryDecoderSwitch
@ -11,7 +11,7 @@
#include "Arduino.h" #include "Arduino.h"
#include "Wire.h" #include "Wire.h"
#define ROTARY_DECODER_SWITCH_LIB_VERSION (F("0.3.0")) #define ROTARY_DECODER_SWITCH_LIB_VERSION (F("0.3.1"))
class rotaryDecoderSwitch class rotaryDecoderSwitch
@ -22,7 +22,7 @@ public:
bool begin(uint8_t count = 2); bool begin(uint8_t count = 2);
bool isConnected(); bool isConnected();
void readInitialState(); uint8_t readInitialState();
// for polling version, // for polling version,
// checkChange is bit faster than a call to update // checkChange is bit faster than a call to update
@ -35,7 +35,7 @@ public:
// re = rotary encoder // re = rotary encoder
int32_t getValue(uint8_t re); int32_t getValue(uint8_t re);
void setValue(uint8_t re, int32_t value = 0); bool setValue(uint8_t re, int32_t value = 0);
bool isKeyPressed(uint8_t re); bool isKeyPressed(uint8_t re);