diff --git a/platforms/intel-iot/edison/edison_adaptor.go b/platforms/intel-iot/edison/edison_adaptor.go index df97772fe..29f64d9f0 100644 --- a/platforms/intel-iot/edison/edison_adaptor.go +++ b/platforms/intel-iot/edison/edison_adaptor.go @@ -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 } diff --git a/platforms/intel-iot/edison/edison_adaptor_test.go b/platforms/intel-iot/edison/edison_adaptor_test.go index 055f63d23..3def720cd 100644 --- a/platforms/intel-iot/edison/edison_adaptor_test.go +++ b/platforms/intel-iot/edison/edison_adaptor_test.go @@ -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) {