up2: correct i2c default bus information to match correct values
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
parent
6d38c67cff
commit
870455ade1
|
@ -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()
|
||||
}
|
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
|
|
@ -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})
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue