edison: auto-detect arduino breakout board, if no specific board is expected

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-04-19 17:33:18 +02:00
parent f63d174d2e
commit 8a50bb24e5
2 changed files with 22 additions and 3 deletions

View File

@ -43,7 +43,6 @@ type Adaptor struct {
func NewAdaptor() *Adaptor {
return &Adaptor{
name: gobot.DefaultName("Edison"),
board: "arduino",
pinmap: arduinoPinMap,
writeFile: writeFile,
readFile: readFile,
@ -67,6 +66,10 @@ func (e *Adaptor) Connect() (err error) {
e.digitalPins = make(map[int]sysfs.DigitalPin)
e.pwmPins = make(map[int]*pwmPin)
if e.board == "" && e.checkForArduino() {
e.board = "arduino"
}
switch e.Board() {
case "sparkfun":
e.pinmap = sparkfunPinMap
@ -206,12 +209,25 @@ func (e *Adaptor) GetDefaultBus() int {
return 1
}
// arduinoSetup does needed setup for the Arduino compatible breakout board
func (e *Adaptor) arduinoSetup() (err error) {
// TODO: also check to see if device labels for
// /sys/class/gpio/gpiochip{200,216,232,248}/label == "pcal9555a"
func (e *Adaptor) checkForArduino() bool {
if err := e.exportTristatePin(); err != nil {
return false
}
return true
}
func (e *Adaptor) exportTristatePin() (err error) {
e.tristate = sysfs.NewDigitalPin(214)
if err = e.tristate.Export(); err != nil {
return err
}
return
}
// arduinoSetup does needed setup for the Arduino compatible breakout board
func (e *Adaptor) arduinoSetup() (err error) {
if err = e.tristate.Direction(sysfs.OUT); err != nil {
return err
}

View File

@ -109,6 +109,7 @@ func TestAdaptorConnect(t *testing.T) {
a, _ := initTestAdaptor()
gobottest.Assert(t, a.Connect(), nil)
gobottest.Assert(t, a.GetDefaultBus(), 6)
gobottest.Assert(t, a.Board(), "arduino")
a = NewAdaptor()
sysfs.SetFilesystem(sysfs.NewMockFilesystem([]string{}))
@ -130,6 +131,7 @@ func TestAdaptorConnectSparkfun(t *testing.T) {
a.SetBoard("sparkfun")
gobottest.Assert(t, a.Connect(), nil)
gobottest.Assert(t, a.GetDefaultBus(), 1)
gobottest.Assert(t, a.Board(), "sparkfun")
}
func TestAdaptorConnectMiniboard(t *testing.T) {
@ -137,6 +139,7 @@ func TestAdaptorConnectMiniboard(t *testing.T) {
a.SetBoard("miniboard")
gobottest.Assert(t, a.Connect(), nil)
gobottest.Assert(t, a.GetDefaultBus(), 1)
gobottest.Assert(t, a.Board(), "miniboard")
}
func TestAdaptorConnectUnknown(t *testing.T) {