I realize that adaptors for each platform have to be different because each platform is different. However, there is a common set of functionality that would be nice to have abstracted out from the rest of the adapter.
As I see it, each adapter consists of "protocol" functions to communicate with the platform, and "board" functions which activate low-level hardware features. I think that the "board" functions have more in common than not and should be abstracted into a "Board' interface. The firmata_adaptor already does this:
type firmataBoard interface {
Connect(io.ReadWriteCloser) error
Disconnect() error
Pins() []client.Pin
AnalogWrite(int, int) error
SetPinMode(int, int) error
ReportAnalog(int, int) error
ReportDigital(int, int) error
DigitalWrite(int, int) error
I2cRead(int, int) error
I2cWrite(int, []byte) error
I2cConfig(int) error
ServoConfig(int, int, int) error
WriteSysex(data []byte) error
gobot.Eventer
}
I think that this interface is a good start, though I would add access to SPI because most boards have access to SPI. I would also remove "ServoConfig" and put all the functions to control Servos into a separate interface, because servos are controlled by firmware rather than built-in functionality. Also, there are different types of sevos, including hobby servos (which are becoming more and more powerful all the time), the Robotis servos, and various other kinds of home-built servos, all of which share a lot of functionality.
I hope I did the right thing with the code sample. Please correct me if I was wrong.