Hi Robert,
I am playing with MCP23017 (
IO Pi 32 Channel Port Expander) and your Pi4J library for a couple of days.
I have some feedback.
First of all, I don't like MCP23017GpioProvider constructor. Basically there is no way to specify initial values of registers. There is no way skip this initialization neither.
In my case this is really annoying. I connected MCP23017 to
SainSmart 16-Channel 12V Relay Module that turns on relays on low-level input. As result during initialization of MCP23017GpioProvider all relays are switched on then immediately switched off when provisionDigitalOutputPin sets the default value.
My idea is to add a capability to describe pins *before* initializing controllers. It can be done by introducing following classes:
public abstract class AbstractPinDefinition {
final Pin pin;
final String name;
protected AbstractPinDefinition ( Pin pin, String name ) { ... }
}
public class OutputPinDefinition extends AbstractPinDefinition {
final PinState initialState; // can be null
public OutputPinDefinition ( Pin pin, String name, PinState initialState ) { ... }
}
public class InputPinDefinition extends AbstractPinDefinition {
final PinPullResistance pullResistance;
public OutputPinDefinition ( Pin pin, String name, PinPullResistance pullResistance ) { ... }
}
etc...
Then add constructor:
public MCP23017GpioProvider(int busNumber, int address, GpioController gpio, AbstractPinDefinition... pins) throws IOException
This constructor should process and checks all definitions, set initial values then write them to registers. It also should register these pins (provisionPin) but without changing their modes and states.
I am an experienced Java developer and I can do it by myself. But I think that this improvement of interface makes sense for anybody who will use your library with MCP23017 and probably other port expanders.
Alex