Skip to content

Commit

Permalink
Update platforms to support the new Driver and Adaptor interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Nov 16, 2014
1 parent 17cbf2c commit abc1f0b
Show file tree
Hide file tree
Showing 72 changed files with 262 additions and 250 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ PACKAGES := gobot gobot/api gobot/platforms/intel-iot/edison gobot/sysfs $(shell

test:
for package in $(PACKAGES) ; do \
go test github.com/hybridgroup/$$package ; \
go test -a github.com/hybridgroup/$$package ; \
done ; \

cover:
echo "mode: count" > profile.cov ; \
for package in $(PACKAGES) ; do \
go test -covermode=count -coverprofile=tmp.cov github.com/hybridgroup/$$package ; \
go test -a -covermode=count -coverprofile=tmp.cov github.com/hybridgroup/$$package ; \
cat tmp.cov | grep -v "mode: count" >> profile.cov ; \
done ; \
rm tmp.cov ; \
Expand Down
10 changes: 6 additions & 4 deletions platforms/ardrone/ardrone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/hybridgroup/gobot"
)

var _ gobot.AdaptorInterface = (*ArdroneAdaptor)(nil)

// drone defines expected drone behaviour
type drone interface {
Takeoff() bool
Expand Down Expand Up @@ -48,12 +50,12 @@ func NewArdroneAdaptor(name string, v ...string) *ArdroneAdaptor {
}

// Connect returns true when connection to ardrone is established correclty
func (a *ArdroneAdaptor) Connect() bool {
func (a *ArdroneAdaptor) Connect() error {
a.connect(a)
return true
return nil
}

// Finalize returns true when connection is finalized correctly
func (a *ArdroneAdaptor) Finalize() bool {
return true
func (a *ArdroneAdaptor) Finalize() error {
return nil
}
4 changes: 2 additions & 2 deletions platforms/ardrone/ardrone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func initTestArdroneAdaptor() *ArdroneAdaptor {

func TestConnect(t *testing.T) {
a := initTestArdroneAdaptor()
gobot.Assert(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), nil)
}

func TestFinalize(t *testing.T) {
a := initTestArdroneAdaptor()
gobot.Assert(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), nil)
}
10 changes: 6 additions & 4 deletions platforms/ardrone/ardrone_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/hybridgroup/gobot"
)

var _ gobot.DriverInterface = (*ArdroneDriver)(nil)

type ArdroneDriver struct {
gobot.Driver
}
Expand All @@ -30,13 +32,13 @@ func (a *ArdroneDriver) adaptor() *ArdroneAdaptor {
}

// Start returns true if driver is started succesfully
func (a *ArdroneDriver) Start() bool {
return true
func (a *ArdroneDriver) Start() error {
return nil
}

// Halt returns true if driver is halted succesfully
func (a *ArdroneDriver) Halt() bool {
return true
func (a *ArdroneDriver) Halt() error {
return nil
}

// TakeOff makes the drone start flying
Expand Down
4 changes: 2 additions & 2 deletions platforms/ardrone/ardrone_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ func initTestArdroneDriver() *ArdroneDriver {

func TestArdroneDriverStart(t *testing.T) {
d := initTestArdroneDriver()
gobot.Assert(t, d.Start(), true)
gobot.Assert(t, d.Start(), nil)
}

func TestArdroneDriverHalt(t *testing.T) {
d := initTestArdroneDriver()
gobot.Assert(t, d.Halt(), true)
gobot.Assert(t, d.Halt(), nil)
}
func TestArdroneDriverTakeOff(t *testing.T) {
d := initTestArdroneDriver()
Expand Down
9 changes: 5 additions & 4 deletions platforms/beaglebone/beaglebone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hybridgroup/gobot/sysfs"
)

var _ gobot.AdaptorInterface = (*BeagleboneAdaptor)(nil)
var slots = "/sys/devices/bone_capemgr.*"
var ocp = "/sys/devices/ocp.*"
var usrLed = "/sys/devices/ocp.3/gpio-leds.8/leds/beaglebone:green:"
Expand Down Expand Up @@ -143,18 +144,18 @@ func NewBeagleboneAdaptor(name string) *BeagleboneAdaptor {

// Connect returns true on a succesful connection to beaglebone board.
// It initializes digital, pwm and analog pins
func (b *BeagleboneAdaptor) Connect() bool {
func (b *BeagleboneAdaptor) Connect() error {
ensureSlot(b.slots, "cape-bone-iio")
ensureSlot(b.slots, "am33xx_pwm")

g, _ := glob(fmt.Sprintf("%v/helper.*", b.ocp))
b.helper = g[0]

return true
return nil
}

// Finalize returns true when board connection is finalized correctly.
func (b *BeagleboneAdaptor) Finalize() bool {
func (b *BeagleboneAdaptor) Finalize() error {
for _, pin := range b.pwmPins {
if pin != nil {
pin.release()
Expand All @@ -168,7 +169,7 @@ func (b *BeagleboneAdaptor) Finalize() bool {
if b.i2cDevice != nil {
b.i2cDevice.Close()
}
return true
return nil
}

// PwmWrite writes value in specified pin
Expand Down
2 changes: 1 addition & 1 deletion platforms/beaglebone/beaglebone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ func TestBeagleboneAdaptor(t *testing.T) {
a.I2cWrite([]byte{0x00, 0x01})
gobot.Assert(t, a.I2cRead(2), []byte{0x00, 0x01})

gobot.Assert(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), nil)
}
8 changes: 5 additions & 3 deletions platforms/digispark/digispark_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/hybridgroup/gobot"
)

var _ gobot.AdaptorInterface = (*DigisparkAdaptor)(nil)

type DigisparkAdaptor struct {
gobot.Adaptor
littleWire lw
Expand All @@ -28,13 +30,13 @@ func NewDigisparkAdaptor(name string) *DigisparkAdaptor {
}

// Connect starts connection to digispark, returns true if successful
func (d *DigisparkAdaptor) Connect() bool {
func (d *DigisparkAdaptor) Connect() error {
d.connect(d)
return true
return nil
}

// Finalize returns true if finalization is successful
func (d *DigisparkAdaptor) Finalize() bool { return true }
func (d *DigisparkAdaptor) Finalize() error { return nil }

// DigitalWrite writes level to specified pin using littlewire
func (d *DigisparkAdaptor) DigitalWrite(pin string, level byte) {
Expand Down
4 changes: 2 additions & 2 deletions platforms/digispark/digispark_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func initTestDigisparkAdaptor() *DigisparkAdaptor {

func TestDigisparkAdaptorFinalize(t *testing.T) {
a := initTestDigisparkAdaptor()
gobot.Assert(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), nil)
}

func TestDigisparkAdaptorConnect(t *testing.T) {
a := initTestDigisparkAdaptor()
gobot.Assert(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), nil)
}

func TestDigisparkAdaptorIO(t *testing.T) {
Expand Down
12 changes: 7 additions & 5 deletions platforms/firmata/firmata_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/tarm/goserial"
)

var _ gobot.AdaptorInterface = (*FirmataAdaptor)(nil)

type FirmataAdaptor struct {
gobot.Adaptor
board *board
Expand Down Expand Up @@ -36,25 +38,25 @@ func NewFirmataAdaptor(name, port string) *FirmataAdaptor {
}

// Connect returns true if connection to board is succesfull
func (f *FirmataAdaptor) Connect() bool {
func (f *FirmataAdaptor) Connect() error {
f.connect(f)
f.board.connect()
f.SetConnected(true)
return true
return nil
}

// close finishes connection to serial port
// Prints error message on error
func (f *FirmataAdaptor) Disconnect() bool {
func (f *FirmataAdaptor) Disconnect() error {
err := f.board.serial.Close()
if err != nil {
fmt.Println(err)
}
return true
return nil
}

// Finalize disconnects firmata adaptor
func (f *FirmataAdaptor) Finalize() bool { return f.Disconnect() }
func (f *FirmataAdaptor) Finalize() error { return f.Disconnect() }

// InitServo (not yet implemented)
func (f *FirmataAdaptor) InitServo() {}
Expand Down
4 changes: 2 additions & 2 deletions platforms/firmata/firmata_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func initTestFirmataAdaptor() *FirmataAdaptor {

func TestFirmataAdaptorFinalize(t *testing.T) {
a := initTestFirmataAdaptor()
gobot.Assert(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), nil)
}
func TestFirmataAdaptorConnect(t *testing.T) {
a := initTestFirmataAdaptor()
gobot.Assert(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), nil)
}

func TestFirmataAdaptorInitServo(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions platforms/gpio/analog_sensor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/hybridgroup/gobot"
)

var _ gobot.DriverInterface = (*AnalogSensorDriver)(nil)

// Represents an Analog Sensor
type AnalogSensorDriver struct {
gobot.Driver
Expand Down Expand Up @@ -39,7 +41,7 @@ func (a *AnalogSensorDriver) adaptor() AnalogReader {
// Returns true on successful start of the driver.
// Emits the Events:
// "data" int - Event is emitted on change and represents the current reading from the sensor.
func (a *AnalogSensorDriver) Start() bool {
func (a *AnalogSensorDriver) Start() error {
value := 0
gobot.Every(a.Interval(), func() {
newValue := a.Read()
Expand All @@ -48,11 +50,11 @@ func (a *AnalogSensorDriver) Start() bool {
gobot.Publish(a.Event("data"), value)
}
})
return true
return nil
}

// Halt returns true on a successful halt of the driver
func (a *AnalogSensorDriver) Halt() bool { return true }
func (a *AnalogSensorDriver) Halt() error { return nil }

// Read returns the current reading from the Analog Sensor
func (a *AnalogSensorDriver) Read() int {
Expand Down
4 changes: 2 additions & 2 deletions platforms/gpio/analog_sensor_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func initTestAnalogSensorDriver() *AnalogSensorDriver {

func TestAnalogSensorDriverStart(t *testing.T) {
d := initTestAnalogSensorDriver()
gobot.Assert(t, d.Start(), true)
gobot.Assert(t, d.Start(), nil)
}

func TestAnalogSensorDriverHalt(t *testing.T) {
d := initTestAnalogSensorDriver()
gobot.Assert(t, d.Halt(), true)
gobot.Assert(t, d.Halt(), nil)
}

func TestAnalogSensorDriverRead(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions platforms/gpio/button_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/hybridgroup/gobot"
)

var _ gobot.DriverInterface = (*ButtonDriver)(nil)

// Represents a digital Button
type ButtonDriver struct {
gobot.Driver
Expand Down Expand Up @@ -38,7 +40,7 @@ func (b *ButtonDriver) adaptor() DigitalReader {
// Emits the Events:
// "push" int - On button push
// "release" int - On button release
func (b *ButtonDriver) Start() bool {
func (b *ButtonDriver) Start() error {
state := 0
gobot.Every(b.Interval(), func() {
newValue := b.readState()
Expand All @@ -47,11 +49,11 @@ func (b *ButtonDriver) Start() bool {
b.update(newValue)
}
})
return true
return nil
}

// Halt returns true on a successful halt of the driver
func (b *ButtonDriver) Halt() bool { return true }
func (b *ButtonDriver) Halt() error { return nil }

func (b *ButtonDriver) readState() int {
return b.adaptor().DigitalRead(b.Pin())
Expand Down
4 changes: 2 additions & 2 deletions platforms/gpio/button_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func initTestButtonDriver() *ButtonDriver {

func TestButtonDriverStart(t *testing.T) {
d := initTestButtonDriver()
gobot.Assert(t, d.Start(), true)
gobot.Assert(t, d.Start(), nil)
}

func TestButtonDriverHalt(t *testing.T) {
d := initTestButtonDriver()
gobot.Assert(t, d.Halt(), true)
gobot.Assert(t, d.Halt(), nil)
}

func TestButtonDriverReadState(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions platforms/gpio/direct_pin_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/hybridgroup/gobot"
)

var _ gobot.DriverInterface = (*DirectPinDriver)(nil)

// Represents a raw GPIO pin
type DirectPinDriver struct {
gobot.Driver
Expand Down Expand Up @@ -65,10 +67,10 @@ func (d *DirectPinDriver) adaptor() DirectPin {
}

// Starts the DirectPinDriver. Returns true on successful start of the driver
func (d *DirectPinDriver) Start() bool { return true }
func (d *DirectPinDriver) Start() error { return nil }

// Halts the DirectPinDriver. Returns true on successful halt of the driver
func (d *DirectPinDriver) Halt() bool { return true }
func (d *DirectPinDriver) Halt() error { return nil }

// DigitalRead returns the current digital state of the pin
func (d *DirectPinDriver) DigitalRead() int {
Expand Down
4 changes: 2 additions & 2 deletions platforms/gpio/direct_pin_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func initTestDirectPinDriver() *DirectPinDriver {

func TestDirectPinDriverStart(t *testing.T) {
d := initTestDirectPinDriver()
gobot.Assert(t, d.Start(), true)
gobot.Assert(t, d.Start(), nil)
}

func TestDirectPinDriverHalt(t *testing.T) {
d := initTestDirectPinDriver()
gobot.Assert(t, d.Halt(), true)
gobot.Assert(t, d.Halt(), nil)
}

func TestDirectPinDriverDigitalRead(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions platforms/gpio/led_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/hybridgroup/gobot"
)

var _ gobot.DriverInterface = (*LedDriver)(nil)

// Represents a digital Led
type LedDriver struct {
gobot.Driver
Expand Down Expand Up @@ -57,10 +59,10 @@ func (l *LedDriver) adaptor() PwmDigitalWriter {
}

// Start starts the LedDriver. Returns true on successful start of the driver
func (l *LedDriver) Start() bool { return true }
func (l *LedDriver) Start() error { return nil }

// Halt halts the LedDriver. Returns true on successful halt of the driver
func (l *LedDriver) Halt() bool { return true }
func (l *LedDriver) Halt() error { return nil }

// State return true if the led is On and false if the led is Off
func (l *LedDriver) State() bool {
Expand Down
Loading

0 comments on commit abc1f0b

Please sign in to comment.