1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-11 19:29:20 +08:00

Increase beaglebone test coverage

This commit is contained in:
Adrian Zankich 2014-11-19 18:40:06 -08:00
parent b12bfc73f3
commit 0c9b644e6f
2 changed files with 16 additions and 1 deletions

View File

@ -188,7 +188,9 @@ func (b *BeagleboneAdaptor) PwmWrite(pin string, val byte) (err error) {
}
// InitServo starts servo (not yet implemented)
func (b *BeagleboneAdaptor) InitServo() (err error) { return nil }
func (b *BeagleboneAdaptor) InitServo() (err error) {
return errors.New("InitServo is not yet implemented")
}
// ServoWrite writes scaled value to servo in specified pin
func (b *BeagleboneAdaptor) ServoWrite(pin string, val byte) (err error) {
@ -223,6 +225,9 @@ func (b *BeagleboneAdaptor) DigitalWrite(pin string, val byte) (err error) {
return err
}
sysfsPin, err := b.digitalPin(pin, sysfs.OUT)
if err != nil {
return err
}
return sysfsPin.Write(int(val))
}

View File

@ -1,6 +1,7 @@
package beaglebone
import (
"errors"
"strings"
"testing"
@ -46,6 +47,7 @@ func TestBeagleboneAdaptor(t *testing.T) {
return []string{pattern + "5"}, nil
}
gobot.Assert(t, a.PwmWrite("P9_99", 175), errors.New("Not a valid pin"))
a.PwmWrite("P9_14", 175)
gobot.Assert(
t,
@ -87,6 +89,9 @@ func TestBeagleboneAdaptor(t *testing.T) {
i, _ := a.AnalogRead("P9_40")
gobot.Assert(t, i, 567)
i, err := a.AnalogRead("P9_99")
gobot.Assert(t, err, errors.New("Not a valid pin"))
// DigitalIO
a.DigitalWrite("usr1", 1)
gobot.Assert(t,
@ -97,6 +102,8 @@ func TestBeagleboneAdaptor(t *testing.T) {
a.DigitalWrite("P9_12", 1)
gobot.Assert(t, fs.Files["/sys/class/gpio/gpio60/value"].Contents, "1")
gobot.Assert(t, a.DigitalWrite("P9_99", 1), errors.New("Not a valid pin"))
fs.Files["/sys/class/gpio/gpio10/value"].Contents = "1"
i, _ = a.DigitalRead("P8_31")
gobot.Assert(t, i, 1)
@ -110,4 +117,7 @@ func TestBeagleboneAdaptor(t *testing.T) {
gobot.Assert(t, data, []byte{0x00, 0x01})
gobot.Assert(t, a.Finalize(), nil)
gobot.Assert(t, a.InitServo(), errors.New("InitServo is not yet implemented"))
}