Skip to content

Commit

Permalink
core: Convert all examples to use new Adaptor/Driver signatures
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Oct 3, 2016
1 parent e3404a1 commit acfdbee
Show file tree
Hide file tree
Showing 116 changed files with 385 additions and 385 deletions.
14 changes: 8 additions & 6 deletions examples/batty.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func main() {
return params["a"]
})

loopback := NewLoopbackAdaptor("loopback", "/dev/null")
ping := NewPingDriver(loopback, "ping", "1")
loopback := NewLoopbackAdaptor("/dev/null")
ping := NewPingDriver(loopback, "1")

work := func() {
gobot.Every(5*time.Second, func() {
Expand Down Expand Up @@ -49,11 +49,12 @@ type loopbackAdaptor struct {
func (t *loopbackAdaptor) Finalize() (errs []error) { return }
func (t *loopbackAdaptor) Connect() (errs []error) { return }
func (t *loopbackAdaptor) Name() string { return t.name }
func (t *loopbackAdaptor) SetName(n string) { t.name = n }
func (t *loopbackAdaptor) Port() string { return t.port }

func NewLoopbackAdaptor(name, port string) *loopbackAdaptor {
func NewLoopbackAdaptor(port string) *loopbackAdaptor {
return &loopbackAdaptor{
name: name,
name: "Loopback",
port: port,
}
}
Expand All @@ -71,12 +72,13 @@ type pingDriver struct {
func (t *pingDriver) Start() (errs []error) { return }
func (t *pingDriver) Halt() (errs []error) { return }
func (t *pingDriver) Name() string { return t.name }
func (t *pingDriver) SetName(n string) { t.name = n }
func (t *pingDriver) Pin() string { return t.pin }
func (t *pingDriver) Connection() gobot.Connection { return t.connection }

func NewPingDriver(adaptor *loopbackAdaptor, name string, pin string) *pingDriver {
func NewPingDriver(adaptor *loopbackAdaptor, pin string) *pingDriver {
t := &pingDriver{
name: name,
name: "Ping",
connection: adaptor,
pin: pin,
Eventer: gobot.NewEventer(),
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_basic_direct_pin.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package main

import (
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {

// Use Gobot to control BeagleBone's digital pins directly

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "myDevice", "P9_12")
beagleboneAdaptor := beaglebone.NewAdaptor()
gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "P9_12")

// Initialize the internal representation of the pinout
beagleboneAdaptor.Connect()
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_blink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_12")
beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewLedDriver(beagleboneAdaptor, "P9_12")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_blink_usr_led.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "usr0")
beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewLedDriver(beagleboneAdaptor, "usr0")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_blinkm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/i2c"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/i2c"
)

func main() {
gbot := gobot.NewGobot()
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
blinkm := i2c.NewBlinkMDriver(beagleboneAdaptor, "blinkm")
beagleboneAdaptor := beaglebone.NewAdaptor()
blinkm := i2c.NewBlinkMDriver(beagleboneAdaptor)

work := func() {
gobot.Every(3*time.Second, func() {
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
button := gpio.NewButtonDriver(beagleboneAdaptor, "button", "P8_9")
beagleboneAdaptor := beaglebone.NewAdaptor()
button := gpio.NewButtonDriver(beagleboneAdaptor, "P8_9")

work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
Expand Down
8 changes: 4 additions & 4 deletions examples/beaglebone_direct_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
led := gpio.NewDirectPinDriver(beagleboneAdaptor, "led", "P8_10")
button := gpio.NewDirectPinDriver(beagleboneAdaptor, "button", "P8_9")
beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_10")
button := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_9")

work := func() {
gobot.Every(500*time.Millisecond, func() {
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_led_brightness.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")
beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewLedDriver(beagleboneAdaptor, "P9_14")

work := func() {
brightness := uint8(0)
Expand Down
8 changes: 4 additions & 4 deletions examples/beaglebone_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"fmt"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "sensor", "P9_33")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")
beagleboneAdaptor := beaglebone.NewAdaptor()
sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "P9_33")
led := gpio.NewLedDriver(beagleboneAdaptor, "P9_14")

work := func() {
sensor.On(sensor.Event("data"), func(data interface{}) {
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_makey_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "button", "P8_9")
beagleboneAdaptor := beaglebone.NewAdaptor()
button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "P8_9")

work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
Expand Down
6 changes: 3 additions & 3 deletions examples/beaglebone_servo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
servo := gpio.NewServoDriver(beagleboneAdaptor, "servo", "P9_14")
beagleboneAdaptor := beaglebone.NewAdaptor()
servo := gpio.NewServoDriver(beagleboneAdaptor, "P9_14")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
4 changes: 2 additions & 2 deletions examples/bebop.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func main() {
gbot := gobot.NewGobot()

bebopAdaptor := bebop.NewBebopAdaptor("Drone")
drone := bebop.NewBebopDriver(bebopAdaptor, "Drone")
bebopAdaptor := bebop.NewAdaptor()
drone := bebop.NewDriver(bebopAdaptor)

work := func() {
drone.On(bebop.Flying, func(data interface{}) {
Expand Down
9 changes: 4 additions & 5 deletions examples/bebop_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ type pair struct {
func main() {
gbot := gobot.NewGobot()

joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
stick := joystick.NewJoystickDriver(joystickAdaptor,
"ps3",
joystickAdaptor := joystick.NewAdaptor()
stick := joystick.NewDriver(joystickAdaptor,
"./platforms/joystick/configs/dualshock3.json",
)

bebopAdaptor := bebop.NewBebopAdaptor("Drone")
drone := bebop.NewBebopDriver(bebopAdaptor, "Drone")
bebopAdaptor := bebop.NewAdaptor()
drone := bebop.NewDriver(bebopAdaptor)

work := func() {
offset := 32767.0
Expand Down
9 changes: 4 additions & 5 deletions examples/bebop_ps3_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ func ffmpeg() (stdin io.WriteCloser, stderr io.ReadCloser, err error) {
func main() {
gbot := gobot.NewGobot()

joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
stick := joystick.NewJoystickDriver(joystickAdaptor,
"ps3",
joystickAdaptor := joystick.NewAdaptor()
stick := joystick.NewDriver(joystickAdaptor,
"./platforms/joystick/configs/dualshock3.json",
)

bebopAdaptor := bebop.NewBebopAdaptor("Drone")
drone := bebop.NewBebopDriver(bebopAdaptor, "Drone")
bebopAdaptor := bebop.NewAdaptor()
drone := bebop.NewDriver(bebopAdaptor)

work := func() {
video, _, _ := ffmpeg()
Expand Down
4 changes: 2 additions & 2 deletions examples/ble_battery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func main() {
gbot := gobot.NewGobot()

bleAdaptor := ble.NewBLEClientAdaptor("ble", os.Args[1])
battery := ble.NewBLEBatteryDriver(bleAdaptor, "battery")
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
battery := ble.NewBatteryDriver(bleAdaptor)

work := func() {
gobot.Every(5*time.Second, func() {
Expand Down
4 changes: 2 additions & 2 deletions examples/ble_device_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
func main() {
gbot := gobot.NewGobot()

bleAdaptor := ble.NewBLEClientAdaptor("ble", os.Args[1])
info := ble.NewBLEDeviceInformationDriver(bleAdaptor, "info")
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
info := ble.NewDeviceInformationDriver(bleAdaptor)

work := func() {
fmt.Println("Model number:", info.GetModelNumber())
Expand Down
6 changes: 3 additions & 3 deletions examples/chip_blink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/chip"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

chipAdaptor := chip.NewChipAdaptor("chip")
led := gpio.NewLedDriver(chipAdaptor, "led", "XIO-P0")
chipAdaptor := chip.NewAdaptor()
led := gpio.NewLedDriver(chipAdaptor, "XIO-P0")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
6 changes: 3 additions & 3 deletions examples/chip_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/chip"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

chipAdaptor := chip.NewChipAdaptor("chip")
button := gpio.NewButtonDriver(chipAdaptor, "button", "XIO-P0")
chipAdaptor := chip.NewAdaptor()
button := gpio.NewButtonDriver(chipAdaptor, "XIO-P0")

work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
Expand Down
8 changes: 4 additions & 4 deletions examples/chip_button_led.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package main

import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/chip"
"github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
gbot := gobot.NewGobot()

chipAdaptor := chip.NewChipAdaptor("chip")
button := gpio.NewButtonDriver(chipAdaptor, "button", "XIO-P6")
led := gpio.NewLedDriver(chipAdaptor, "led", "XIO-P7")
chipAdaptor := chip.NewAdaptor()
button := gpio.NewButtonDriver(chipAdaptor, "XIO-P6")
led := gpio.NewLedDriver(chipAdaptor, "XIO-P7")

work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
Expand Down
6 changes: 3 additions & 3 deletions examples/chip_grove_accelerometer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/i2c"
"github.com/hybridgroup/gobot/platforms/chip"
"github.com/hybridgroup/gobot/platforms/i2c"
)

func main() {
gbot := gobot.NewGobot()

board := chip.NewChipAdaptor("chip")
accel := i2c.NewGroveAccelerometerDriver(board, "accel")
board := chip.NewAdaptor()
accel := i2c.NewGroveAccelerometerDriver(board)

work := func() {
gobot.Every(500*time.Millisecond, func() {
Expand Down
Loading

0 comments on commit acfdbee

Please sign in to comment.