9#include <AH/Arduino-Wrapper.h>
12#include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
37template <
class WireType,
class EncoderPositionType = int32_t,
38 bool InterruptSafe =
false>
56 this->wire->beginTransmission(
address);
57 this->wire->write(values, N);
58 this->wire->endTransmission();
69 template <
class... Args>
71 const uint8_t v[] = {addr,
static_cast<uint8_t
>(values)...};
87 this->wire->requestFrom(
address, uint8_t(2));
88 uint8_t a = this->wire->read();
89 uint16_t b = this->wire->read();
constexpr PinStatus_t HIGH
constexpr PinMode_t INPUT_PULLUP
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_EXTERNAL_HEADER()
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
Class for reading 8 rotary encoders using a MCP23017 I²C port expander.
MCP23017Encoders(WireType &wire, uint8_t addr_offset=0, pin_t interrupt_pin=NO_PIN)
Constructor.
typename RegisterEncoderType::Encoder MCP23017Encoder
Proxy to access a single encoder of the 8 encoders managed by MCP23017Encoders.
EncoderPositionType read(uint8_t idx) const
Read the position of the given encoder.
uint16_t readGPIO()
Read the state of all GPIO pins.
static constexpr uint8_t I2C_BASE_ADDRESS
void begin()
Initialize the MCP23017.
MCP23017Encoder operator[](uint8_t index)
Get a proxy to one of the encoders managed by this MCP23017.
EncoderPositionType readAndReset(uint8_t idx)
Read the position of the given encoder and reset it to zero.
void update()
If the state of the MCP23017's GPIO changed, read the new state and update the encoder positions.
void writeI2C(uint8_t addr, Args... values)
Write any data to the MCP23017.
void write(uint8_t idx, EncoderPositionType pos)
Set the position of the given encoder.
void writeI2C(const uint8_t(&values)[N])
Write any data to the MCP23017.
Proxy to access a single encoder of the encoders managed by RegisterEncoders.
Class for keeping track of the position of multiple rotary encoders.
EncoderPositionType read(uint8_t idx) const
Read the position of the given encoder.
bool update(RegisterType newstate)
Update the encoder positions based on the new state.
EncoderPositionType readAndReset(uint8_t idx)
Read the position of the given encoder and reset it to zero.
void reset()
Reset the positions to zero and the state to 0xFF...FF.
void write(uint8_t idx, EncoderPositionType pos)
Set the position of the given encoder.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
PinStatus_t digitalRead(pin_t pin)
An ExtIO version of the Arduino function.