mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.1 rotaryDecoderSwitch
This commit is contained in:
parent
f92f1f35bd
commit
fd2cbd578d
@ -10,4 +10,5 @@ jobs:
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
||||
# to suppress long name error
|
||||
# compliance: strict
|
@ -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/).
|
||||
|
||||
|
||||
## [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
|
||||
- add **read1(pin)** see #10
|
||||
- add **write1(pin, value)** experimental see #10
|
||||
|
@ -64,7 +64,8 @@ Note the above mapping is sort of compatible to using the rotaryDecoder class an
|
||||
|
||||
#### 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.
|
||||
count is the number of rotary encoders connected.
|
||||
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
|
||||
|
||||
- **void 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()**
|
||||
- **bool checkChange()** polling to see if one or more RE have changed,
|
||||
without updating the internal counters.
|
||||
- **void update()** update the internal counters of the RE, and the flags if a key is pressed.
|
||||
- **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()**.
|
||||
Since 0.3.1 this function returns the read state, saves an additional read8() call.
|
||||
- **bool checkChange()** used for polling to see if one or more RE have changed.
|
||||
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.
|
||||
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).
|
||||
- **void updateSingle()** update the internal counters of the RE.
|
||||
This will add +1 +2 or +3 as it assumes that the rotary encoder
|
||||
Note that **update()** must be called as soon as possible after the interrupt occurs
|
||||
or as often as possible when polling.
|
||||
Returns false if there is no change since last read.
|
||||
- **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
|
||||
|
||||
- **uint32_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
|
||||
- **bool isKeyPressed(uint8_t re)** returns true is the switch is pressed of the RE selected (re = 0 or 1).
|
||||
- **int32_t getValue(uint8_r re)** returns the RE counter. (re = 0 or 1).
|
||||
If the parameter re > 1 then 0 is returned.
|
||||
- **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!
|
||||
|
||||
|
||||
@ -119,14 +128,13 @@ rotary encoder pins.
|
||||
#### Debugging
|
||||
|
||||
- **int8_t getLastPosition(uint8_r re)** (re = 0 or 1). Returns last position.
|
||||
- **int8_t getRaw()**
|
||||
|
||||
|
||||
## Performance
|
||||
|
||||
As the decoder is based upon a PCF8574, a I2C device, the performance is affected by the
|
||||
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()**
|
||||
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.
|
||||
|
||||
|
||||
| I2C speed | time (us) | delta | %% | Notes |
|
||||
|:-----------:|:-----------:|:-------:|:-----:|:---------|
|
||||
| I2C speed | time (us) | delta | %% | Notes |
|
||||
|:-----------:|:-----------:|:-------:|:-----:|:--------|
|
||||
| 100 KHz | 234 | | |
|
||||
| 200 KHz | 136 | 98 | 42% |
|
||||
| 300 KHz | 100 | 36 | 26% |
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/rotaryDecoderSwitch.git"
|
||||
},
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=rotaryDecoderSwitch
|
||||
version=0.3.0
|
||||
version=0.3.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for rotary decoder + switch with a PCF8574.
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: rotaryDecoderSwitch.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// DATE: 2021-05-17
|
||||
// PURPOSE: Arduino library for rotary decoder (with switch)
|
||||
// URL: https://github.com/RobTillaart/rotaryDecoderSwitch
|
||||
@ -38,7 +38,7 @@ bool rotaryDecoderSwitch::isConnected()
|
||||
}
|
||||
|
||||
|
||||
void rotaryDecoderSwitch::readInitialState()
|
||||
uint8_t rotaryDecoderSwitch::readInitialState()
|
||||
{
|
||||
uint8_t value = read8();
|
||||
_lastValue = value;
|
||||
@ -48,6 +48,7 @@ void rotaryDecoderSwitch::readInitialState()
|
||||
_lastPos[i] = value & 0x03;
|
||||
value >>= 4;
|
||||
}
|
||||
return _lastValue;
|
||||
}
|
||||
|
||||
|
||||
@ -134,13 +135,16 @@ bool rotaryDecoderSwitch::updateSingle()
|
||||
|
||||
int32_t rotaryDecoderSwitch::getValue(uint8_t re)
|
||||
{
|
||||
if (re > 1) return 0;
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: rotaryDecoderSwitch.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// DATE: 2021-05-17
|
||||
// PURPOSE: Arduino library for rotary decoder (with switch)
|
||||
// URL: https://github.com/RobTillaart/rotaryDecoderSwitch
|
||||
@ -11,7 +11,7 @@
|
||||
#include "Arduino.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
|
||||
@ -22,7 +22,7 @@ public:
|
||||
bool begin(uint8_t count = 2);
|
||||
bool isConnected();
|
||||
|
||||
void readInitialState();
|
||||
uint8_t readInitialState();
|
||||
|
||||
// for polling version,
|
||||
// checkChange is bit faster than a call to update
|
||||
@ -35,7 +35,7 @@ public:
|
||||
|
||||
// re = rotary encoder
|
||||
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);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user