Skip to content

Commit

Permalink
up2: correct i2c default bus information to match correct values
Browse files Browse the repository at this point in the history
Signed-off-by: Ron Evans <[email protected]>
  • Loading branch information
deadprogram committed May 22, 2019
1 parent eb0a5ff commit 90d6f4b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
49 changes: 49 additions & 0 deletions examples/up2_lcd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// +build example
//
// Do not build by default.

package main

import (
"time"

"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/upboard/up2"
)

func main() {
board := up2.NewAdaptor()
screen := i2c.NewGroveLcdDriver(board)

work := func() {
screen.Write("hello")

screen.SetRGB(255, 0, 0)

gobot.After(5*time.Second, func() {
screen.Clear()
screen.Home()
screen.SetRGB(0, 255, 0)
// set a custom character in the first position
screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"])
// add the custom character at the end of the string
screen.Write("goodbye\nhave a nice day " + string(byte(0)))
gobot.Every(500*time.Millisecond, func() {
screen.Scroll(false)
})
})

screen.Home()
time.Sleep(1 * time.Second)
screen.SetRGB(0, 0, 255)
}

robot := gobot.NewRobot("screenBot",
[]gobot.Connection{board},
[]gobot.Device{screen},
work,
)

robot.Start()
}
8 changes: 4 additions & 4 deletions platforms/upboard/up2/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Adaptor struct {
pinmap map[string]sysfsPin
digitalPins map[int]*sysfs.DigitalPin
pwmPins map[int]*sysfs.PWMPin
i2cBuses [2]i2c.I2cDevice
i2cBuses [6]i2c.I2cDevice
mutex *sync.Mutex
spiDefaultBus int
spiDefaultChip int
Expand Down Expand Up @@ -209,12 +209,12 @@ func (c *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
}

// GetConnection returns a connection to a device on a specified bus.
// Valid bus number is [0..1] which corresponds to /dev/i2c-0 through /dev/i2c-1.
// Valid bus number is [5..6] which corresponds to /dev/i2c-5 through /dev/i2c-6.
func (c *Adaptor) GetConnection(address int, bus int) (connection i2c.Connection, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()

if (bus < 0) || (bus > 1) {
if (bus < 5) || (bus > 6) {
return nil, fmt.Errorf("Bus number %d out of range", bus)
}
if c.i2cBuses[bus] == nil {
Expand All @@ -225,7 +225,7 @@ func (c *Adaptor) GetConnection(address int, bus int) (connection i2c.Connection

// GetDefaultBus returns the default i2c bus for this platform
func (c *Adaptor) GetDefaultBus() int {
return 0
return 5
}

// GetSpiConnection returns an spi connection to a device on a specified bus.
Expand Down
6 changes: 3 additions & 3 deletions platforms/upboard/up2/adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func TestAdaptorDigitalReadWriteError(t *testing.T) {
func TestUP2AdaptorI2c(t *testing.T) {
a := NewAdaptor()
fs := sysfs.NewMockFilesystem([]string{
"/dev/i2c-0",
"/dev/i2c-5",
})
sysfs.SetFilesystem(fs)
sysfs.SetSyscall(&sysfs.MockSyscall{})

con, err := a.GetConnection(0xff, 0)
con, err := a.GetConnection(0xff, 5)
gobottest.Assert(t, err, nil)

con.Write([]byte{0x00, 0x01})
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestUP2AdaptorPwmReadError(t *testing.T) {

func TestUP2I2CDefaultBus(t *testing.T) {
a, _ := initTestUP2Adaptor()
gobottest.Assert(t, a.GetDefaultBus(), 0)
gobottest.Assert(t, a.GetDefaultBus(), 5)
}

func TestUP2GetConnectionInvalidBus(t *testing.T) {
Expand Down

0 comments on commit 90d6f4b

Please sign in to comment.