Skip to content

Commit

Permalink
Clean up drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 10, 2014
1 parent ab7ae97 commit d3f2213
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 59 deletions.
4 changes: 2 additions & 2 deletions platforms/ardrone/ardrone_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func NewArdroneDriver(adaptor *ArdroneAdaptor, name string) *ArdroneDriver {
adaptor,
),
}
d.Driver.AddEvent("flying")
d.AddEvent("flying")
return d
}
func (a *ArdroneDriver) adaptor() *ArdroneAdaptor {
return a.Driver.Adaptor().(*ArdroneAdaptor)
return a.Adaptor().(*ArdroneAdaptor)
}

func (a *ArdroneDriver) Start() bool {
Expand Down
4 changes: 2 additions & 2 deletions platforms/gpio/analog_sensor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ func NewAnalogSensorDriver(a AnalogReader, name string, pin string) *AnalogSenso
}

d.AddEvent("data")
d.Driver.AddCommand("Read", func(params map[string]interface{}) interface{} {
d.AddCommand("Read", func(params map[string]interface{}) interface{} {
return d.Read()
})

return d
}

func (a *AnalogSensorDriver) adaptor() AnalogReader {
return a.Driver.Adaptor().(AnalogReader)
return a.Adaptor().(AnalogReader)
}

func (a *AnalogSensorDriver) Start() bool {
Expand Down
6 changes: 3 additions & 3 deletions platforms/gpio/button_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func NewButtonDriver(a DigitalReader, name string, pin string) *ButtonDriver {
Active: false,
}

b.Driver.AddEvent("push")
b.Driver.AddEvent("release")
b.AddEvent("push")
b.AddEvent("release")

return b
}

func (b *ButtonDriver) adaptor() DigitalReader {
return b.Driver.Adaptor().(DigitalReader)
return b.Adaptor().(DigitalReader)
}

func (b *ButtonDriver) Start() bool {
Expand Down
17 changes: 9 additions & 8 deletions platforms/gpio/direct_pin_driver.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gpio

import (
"github.com/hybridgroup/gobot"
"strconv"

"github.com/hybridgroup/gobot"
)

type DirectPinDriver struct {
Expand All @@ -19,28 +20,28 @@ func NewDirectPinDriver(a DirectPin, name string, pin string) *DirectPinDriver {
),
}

d.Driver.AddCommand("DigitalRead", func(params map[string]interface{}) interface{} {
d.AddCommand("DigitalRead", func(params map[string]interface{}) interface{} {
return d.DigitalRead()
})
d.Driver.AddCommand("DigitalWrite", func(params map[string]interface{}) interface{} {
d.AddCommand("DigitalWrite", func(params map[string]interface{}) interface{} {
level, _ := strconv.Atoi(params["level"].(string))
d.DigitalWrite(byte(level))
return nil
})
d.Driver.AddCommand("AnalogRead", func(params map[string]interface{}) interface{} {
d.AddCommand("AnalogRead", func(params map[string]interface{}) interface{} {
return d.AnalogRead()
})
d.Driver.AddCommand("AnalogWrite", func(params map[string]interface{}) interface{} {
d.AddCommand("AnalogWrite", func(params map[string]interface{}) interface{} {
level, _ := strconv.Atoi(params["level"].(string))
d.AnalogWrite(byte(level))
return nil
})
d.Driver.AddCommand("PwmWrite", func(params map[string]interface{}) interface{} {
d.AddCommand("PwmWrite", func(params map[string]interface{}) interface{} {
level, _ := strconv.Atoi(params["level"].(string))
d.PwmWrite(byte(level))
return nil
})
d.Driver.AddCommand("ServoWrite", func(params map[string]interface{}) interface{} {
d.AddCommand("ServoWrite", func(params map[string]interface{}) interface{} {
level, _ := strconv.Atoi(params["level"].(string))
d.ServoWrite(byte(level))
return nil
Expand All @@ -50,7 +51,7 @@ func NewDirectPinDriver(a DirectPin, name string, pin string) *DirectPinDriver {
}

func (d *DirectPinDriver) adaptor() DirectPin {
return d.Driver.Adaptor().(DirectPin)
return d.Adaptor().(DirectPin)
}
func (d *DirectPinDriver) Start() bool { return true }
func (d *DirectPinDriver) Halt() bool { return true }
Expand Down
6 changes: 3 additions & 3 deletions platforms/gpio/makey_button_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func NewMakeyButtonDriver(a DigitalReader, name string, pin string) *MakeyButton
Active: false,
}

m.Driver.AddEvent("push")
m.Driver.AddEvent("release")
m.AddEvent("push")
m.AddEvent("release")

return m
}

func (b *MakeyButtonDriver) adaptor() DigitalReader {
return b.Driver.Adaptor().(DigitalReader)
return b.Adaptor().(DigitalReader)
}

func (m *MakeyButtonDriver) Start() bool {
Expand Down
2 changes: 1 addition & 1 deletion platforms/gpio/motor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewMotorDriver(a PwmDigitalWriter, name string, pin string) *MotorDriver {
}

func (m *MotorDriver) adaptor() PwmDigitalWriter {
return m.Driver.Adaptor().(PwmDigitalWriter)
return m.Adaptor().(PwmDigitalWriter)
}

func (m *MotorDriver) Start() bool { return true }
Expand Down
10 changes: 5 additions & 5 deletions platforms/gpio/servo_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ func NewServoDriver(a Servo, name string, pin string) *ServoDriver {
CurrentAngle: 0,
}

s.Driver.AddCommand("Move", func(params map[string]interface{}) interface{} {
s.AddCommand("Move", func(params map[string]interface{}) interface{} {
angle := byte(params["angle"].(float64))
s.Move(angle)
return nil
})
s.Driver.AddCommand("Min", func(params map[string]interface{}) interface{} {
s.AddCommand("Min", func(params map[string]interface{}) interface{} {
s.Min()
return nil
})
s.Driver.AddCommand("Center", func(params map[string]interface{}) interface{} {
s.AddCommand("Center", func(params map[string]interface{}) interface{} {
s.Center()
return nil
})
s.Driver.AddCommand("Max", func(params map[string]interface{}) interface{} {
s.AddCommand("Max", func(params map[string]interface{}) interface{} {
s.Max()
return nil
})
Expand All @@ -43,7 +43,7 @@ func NewServoDriver(a Servo, name string, pin string) *ServoDriver {
}

func (s *ServoDriver) adaptor() Servo {
return s.Driver.Adaptor().(Servo)
return s.Adaptor().(Servo)
}

func (s *ServoDriver) Start() bool { return true }
Expand Down
11 changes: 6 additions & 5 deletions platforms/i2c/blinkm_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package i2c

import (
"fmt"

"github.com/hybridgroup/gobot"
)

Expand All @@ -18,20 +19,20 @@ func NewBlinkMDriver(a I2cInterface, name string) *BlinkMDriver {
),
}

b.Driver.AddCommand("FirmwareVersion", func(params map[string]interface{}) interface{} {
b.AddCommand("FirmwareVersion", func(params map[string]interface{}) interface{} {
return b.FirmwareVersion()
})
b.Driver.AddCommand("Color", func(params map[string]interface{}) interface{} {
b.AddCommand("Color", func(params map[string]interface{}) interface{} {
return b.Color()
})
b.Driver.AddCommand("Rgb", func(params map[string]interface{}) interface{} {
b.AddCommand("Rgb", func(params map[string]interface{}) interface{} {
red := byte(params["red"].(float64))
green := byte(params["green"].(float64))
blue := byte(params["blue"].(float64))
b.Rgb(red, green, blue)
return nil
})
b.Driver.AddCommand("Fade", func(params map[string]interface{}) interface{} {
b.AddCommand("Fade", func(params map[string]interface{}) interface{} {
red := byte(params["red"].(float64))
green := byte(params["green"].(float64))
blue := byte(params["blue"].(float64))
Expand All @@ -43,7 +44,7 @@ func NewBlinkMDriver(a I2cInterface, name string) *BlinkMDriver {
}

func (b *BlinkMDriver) adaptor() I2cInterface {
return b.Driver.Adaptor().(I2cInterface)
return b.Adaptor().(I2cInterface)
}

func (b *BlinkMDriver) Start() bool {
Expand Down
2 changes: 1 addition & 1 deletion platforms/i2c/hmc6352_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewHMC6352Driver(a I2cInterface, name string) *HMC6352Driver {
}

func (h *HMC6352Driver) adaptor() I2cInterface {
return h.Driver.Adaptor().(I2cInterface)
return h.Adaptor().(I2cInterface)
}

func (h *HMC6352Driver) Start() bool {
Expand Down
3 changes: 2 additions & 1 deletion platforms/i2c/wiichuck_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package i2c

import (
"fmt"

"github.com/hybridgroup/gobot"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func NewWiichuckDriver(a I2cInterface, name string) *WiichuckDriver {
}

func (w *WiichuckDriver) adaptor() I2cInterface {
return w.Driver.Adaptor().(I2cInterface)
return w.Adaptor().(I2cInterface)
}

func (w *WiichuckDriver) Start() bool {
Expand Down
7 changes: 4 additions & 3 deletions platforms/joystick/joystick_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package joystick
import (
"encoding/json"
"fmt"
"github.com/hybridgroup/go-sdl2/sdl"
"github.com/hybridgroup/gobot"
"io/ioutil"
"time"

"github.com/hybridgroup/go-sdl2/sdl"
"github.com/hybridgroup/gobot"
)

type JoystickDriver struct {
Expand Down Expand Up @@ -63,7 +64,7 @@ func NewJoystickDriver(a *JoystickAdaptor, name string, config string) *Joystick
}

func (j *JoystickDriver) adaptor() *JoystickAdaptor {
return j.Driver.Adaptor().(*JoystickAdaptor)
return j.Adaptor().(*JoystickAdaptor)
}

func (j *JoystickDriver) Start() bool {
Expand Down
5 changes: 3 additions & 2 deletions platforms/leap/leap_motion_driver.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package leap

import (
"code.google.com/p/go.net/websocket"
"encoding/json"

"code.google.com/p/go.net/websocket"
"github.com/hybridgroup/gobot"
)

Expand All @@ -24,7 +25,7 @@ func NewLeapMotionDriver(a *LeapMotionAdaptor, name string) *LeapMotionDriver {
}

func (l *LeapMotionDriver) adaptor() *LeapMotionAdaptor {
return l.Driver.Adaptor().(*LeapMotionAdaptor)
return l.Adaptor().(*LeapMotionAdaptor)
}
func (l *LeapMotionDriver) Start() bool {
enableGestures := map[string]bool{"enableGestures": true}
Expand Down
17 changes: 9 additions & 8 deletions platforms/neurosky/neurosky_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package neurosky

import (
"bytes"

"github.com/hybridgroup/gobot"
)

Expand Down Expand Up @@ -38,19 +39,19 @@ func NewNeuroskyDriver(a *NeuroskyAdaptor, name string) *NeuroskyDriver {
),
}

n.AddEvent("Extended")
n.AddEvent("Signal")
n.AddEvent("Attention")
n.AddEvent("Meditation")
n.AddEvent("Blink")
n.AddEvent("Wave")
n.AddEvent("EEG")
n.AddEvent("extended")
n.AddEvent("signal")
n.AddEvent("attention")
n.AddEvent("meditation")
n.AddEvent("blink")
n.AddEvent("wave")
n.AddEvent("eeg")

return n
}

func (n *NeuroskyDriver) adaptor() *NeuroskyAdaptor {
return n.Driver.Adaptor().(*NeuroskyAdaptor)
return n.Adaptor().(*NeuroskyAdaptor)
}
func (n *NeuroskyDriver) Start() bool {
go func() {
Expand Down
8 changes: 4 additions & 4 deletions platforms/pebble/pebble_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ func NewPebbleDriver(adaptor *PebbleAdaptor, name string) *PebbleDriver {
p.AddEvent("accel")
p.AddEvent("tap")

p.Driver.AddCommand("PublishEvent", func(params map[string]interface{}) interface{} {
p.AddCommand("PublishEvent", func(params map[string]interface{}) interface{} {
p.PublishEvent(params["name"].(string), params["data"].(string))
return nil
})

p.Driver.AddCommand("SendNotification", func(params map[string]interface{}) interface{} {
p.AddCommand("SendNotification", func(params map[string]interface{}) interface{} {
p.SendNotification(params["message"].(string))
return nil
})

p.Driver.AddCommand("PendingMessage", func(params map[string]interface{}) interface{} {
p.AddCommand("PendingMessage", func(params map[string]interface{}) interface{} {
m := make(map[string]string)
m["result"] = p.PendingMessage()
return m
Expand All @@ -45,7 +45,7 @@ func NewPebbleDriver(adaptor *PebbleAdaptor, name string) *PebbleDriver {
return p
}
func (d *PebbleDriver) adaptor() *PebbleAdaptor {
return d.Driver.Adaptor().(*PebbleAdaptor)
return d.Adaptor().(*PebbleAdaptor)
}

func (d *PebbleDriver) Start() bool { return true }
Expand Down
Loading

0 comments on commit d3f2213

Please sign in to comment.