Skip to content

Commit

Permalink
edison: auto-detect arduino breakout board, if no specific board is e…
Browse files Browse the repository at this point in the history
…xpected

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Apr 19, 2017
1 parent f63d174 commit 8a50bb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 19 additions & 3 deletions platforms/intel-iot/edison/edison_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type Adaptor struct {
func NewAdaptor() *Adaptor {
return &Adaptor{
name: gobot.DefaultName("Edison"),
board: "arduino",
pinmap: arduinoPinMap,
writeFile: writeFile,
readFile: readFile,
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions platforms/intel-iot/edison/edison_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
Expand All @@ -130,13 +131,15 @@ 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) {
a, _ := initTestAdaptor()
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) {
Expand Down

0 comments on commit 8a50bb2

Please sign in to comment.