#include <AH/Hardware/RegisterEncoders.hpp>
Class for keeping track of the position of multiple rotary encoders.
RegisterType | The type of the GPIO registers. |
NumEnc | The number of encoders. |
EncoderPositionType | The type used for saving the encoder positions. int32_t is the default because this matches the Encoder library. You can use small unsigned types such as uint8_t or uint16_t if you're just interrested in the deltas. |
InterruptSafe | Make the update method safe to use inside of an interrupt. It makes the necessary variables volatile and disables interrupts while reading the positions from the main program. |
Definition at line 52 of file RegisterEncoders.hpp.
Classes | |
class | Encoder |
Proxy to access a single encoder of the encoders managed by RegisterEncoders. More... | |
Public Member Functions | |
void | reset () |
Reset the positions to zero and the state to 0xFF...FF. | |
void | reset (RegisterType resetstate) |
Reset the positions to zero and the state to the given value. | |
bool | update (RegisterType newstate) |
Update the encoder positions based on the new state. | |
EncoderPositionType | read (uint8_t idx) const |
Read the position of the given encoder. | |
EncoderPositionType | readAndReset (uint8_t idx) |
Read the position of the given encoder and reset it to zero. | |
void | write (uint8_t idx, EncoderPositionType pos) |
Set the position of the given encoder. | |
Encoder | operator[] (uint8_t index) |
Get a proxy to one of the encoders managed by this object. | |
Private Types | |
using | EncoderPositionStorageType |
using | StateStorageType |
Private Attributes | |
StateStorageType | state = std::numeric_limits<RegisterType>::max() |
Array< EncoderPositionStorageType, NumEnc > | positions {{}} |
|
private |
Definition at line 57 of file RegisterEncoders.hpp.
|
private |
Definition at line 61 of file RegisterEncoders.hpp.
|
inline |
Reset the positions to zero and the state to 0xFF...FF.
Definition at line 70 of file RegisterEncoders.hpp.
|
inline |
Reset the positions to zero and the state to the given value.
Definition at line 76 of file RegisterEncoders.hpp.
|
inline |
Update the encoder positions based on the new state.
Can be called from within an ISR, on the condition that InterruptSafe
is set to true
.
Don't call this function both from the ISR and from your main program, only call it from one of the two.
true | The new state is different from the old state, positions have been updated. |
false | The new state is the same as the old state, nothing updated. |
Definition at line 96 of file RegisterEncoders.hpp.
|
inline |
Read the position of the given encoder.
Does not update the state, just reads it from the buffered position.
Don't call this function from within an ISR.
idx | The index of the encoder to read [0, NumEnc - 1]. |
Definition at line 136 of file RegisterEncoders.hpp.
|
inline |
Read the position of the given encoder and reset it to zero.
Does not update the state, just reads it from the buffered position.
Don't call this function from within an ISR.
idx | The index of the encoder to read [0, NumEnc - 1]. |
Definition at line 157 of file RegisterEncoders.hpp.
|
inline |
Set the position of the given encoder.
Don't call this function from within an ISR.
idx | The index of the encoder to write [0, NumEnc - 1]. |
pos | The position value to write. |
Definition at line 181 of file RegisterEncoders.hpp.
|
inline |
Get a proxy to one of the encoders managed by this object.
index | The index of the encoder to access. |
Definition at line 259 of file RegisterEncoders.hpp.
|
private |
Definition at line 65 of file RegisterEncoders.hpp.
|
private |
Definition at line 66 of file RegisterEncoders.hpp.