2014-04-28 04:39:51 -07:00
|
|
|
package beaglebone
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
import (
|
2014-11-03 19:41:34 -08:00
|
|
|
"io"
|
|
|
|
"os"
|
2014-06-12 16:12:38 -07:00
|
|
|
"testing"
|
2014-11-03 19:41:34 -08:00
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/sysfs"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
2014-06-13 16:01:39 -07:00
|
|
|
func initTestBeagleboneAdaptor() *BeagleboneAdaptor {
|
2014-11-03 19:41:34 -08:00
|
|
|
i2cLocation = os.DevNull
|
|
|
|
sysfs.WriteFile = func(path string, data []byte) (i int, err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
a := NewBeagleboneAdaptor("myAdaptor")
|
|
|
|
a.connect = func() {}
|
|
|
|
a.Connect()
|
|
|
|
a.DigitalWrite("P9_12", 1)
|
|
|
|
a.i2cDevice = new(gobot.NullReadWriteCloser)
|
|
|
|
return a
|
2014-06-12 16:12:38 -07:00
|
|
|
}
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-06-13 16:01:39 -07:00
|
|
|
func TestBeagleboneAdaptorFinalize(t *testing.T) {
|
2014-11-03 19:41:34 -08:00
|
|
|
gobot.Assert(t, initTestBeagleboneAdaptor().Finalize(), true)
|
2014-06-12 16:12:38 -07:00
|
|
|
}
|
2014-11-03 19:41:34 -08:00
|
|
|
|
|
|
|
func TestBeagleboneAdaptorDigitalIO(t *testing.T) {
|
2014-06-13 16:01:39 -07:00
|
|
|
a := initTestBeagleboneAdaptor()
|
2014-11-03 19:41:34 -08:00
|
|
|
lastWritePath := ""
|
|
|
|
lastReadPath := ""
|
|
|
|
lastWriteData := []byte{}
|
|
|
|
|
|
|
|
sysfs.WriteFile = func(path string, data []byte) (i int, err error) {
|
|
|
|
lastWritePath = path
|
|
|
|
lastWriteData = data
|
|
|
|
return
|
|
|
|
}
|
|
|
|
sysfs.ReadFile = func(path string) (b []byte, err error) {
|
|
|
|
lastReadPath = path
|
|
|
|
return []byte("1"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
a.DigitalWrite("P9_12", 1)
|
|
|
|
gobot.Assert(t, lastWritePath, "/sys/class/gpio/gpio60/value")
|
|
|
|
gobot.Assert(t, lastWriteData, []byte{49})
|
|
|
|
|
|
|
|
i := a.DigitalRead("P8_31")
|
|
|
|
gobot.Assert(t, lastReadPath, "/sys/class/gpio/gpio10/value")
|
|
|
|
gobot.Assert(t, i, 1)
|
2014-06-12 16:12:38 -07:00
|
|
|
}
|
2014-11-03 19:41:34 -08:00
|
|
|
|
|
|
|
func TestBeagleboneAdaptorI2c(t *testing.T) {
|
2014-06-13 16:01:39 -07:00
|
|
|
a := initTestBeagleboneAdaptor()
|
2014-11-03 19:41:34 -08:00
|
|
|
a.I2cStart(0xff)
|
|
|
|
var _ io.ReadWriteCloser = a.i2cDevice
|
|
|
|
|
|
|
|
a.i2cDevice = new(gobot.NullReadWriteCloser)
|
|
|
|
a.I2cWrite([]byte{0x00, 0x01})
|
|
|
|
gobot.Assert(t, a.I2cRead(2), make([]byte, 2))
|
2014-06-12 16:12:38 -07:00
|
|
|
}
|