Adaptors: Adding a "Board" interface

12 views
Skip to first unread message

Jay Newman

unread,
Jun 14, 2018, 10:43:42 AM6/14/18
to gobotio
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.     


Ron Evans

unread,
Jun 28, 2018, 9:41:19 AM6/28/18
to gobotio
Sorry for the delayed response, but I just noticed this message.

There are already a number of interfaces defined in Gobot, which are then implemented by any Adaptors that are able to do so.

Some examples:


I think this is what you were possibly looking for.

Hope that helps!
Reply all
Reply to author
Forward
0 new messages