template<class RegisterType, uint8_t NumEnc, class EncoderPositionType = int32_t, bool InterruptSafe = false>
class RegisterEncoders< RegisterType, NumEnc, EncoderPositionType, InterruptSafe >
Class for keeping track of the position of multiple rotary encoders.
- Template Parameters
-
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 58 of file RegisterEncoders.hpp.
|
void | reset () |
| Reset the positions to zero and the state to 0xFF...FF. More...
|
|
void | reset (RegisterType resetstate) |
| Reset the positions to zero and the state to the given value. More...
|
|
bool | update (RegisterType newstate) |
| Update the encoder positions based on the new state. More...
|
|
EncoderPositionType | read (uint8_t idx) const |
| Read the position of the given encoder. More...
|
|
EncoderPositionType | readAndReset (uint8_t idx) |
| Read the position of the given encoder and reset it to zero. More...
|
|
void | write (uint8_t idx, EncoderPositionType pos) |
| Set the position of the given encoder. More...
|
|
Encoder | operator[] (uint8_t index) |
| Get a proxy to one of the encoders managed by this object. More...
|
|
bool update |
( |
RegisterType |
newstate | ) |
|
|
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.
- Return values
-
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 102 of file RegisterEncoders.hpp.