Skip to content

Commit

Permalink
core: Refactor examples to allow 'metal' development using Gobot adap…
Browse files Browse the repository at this point in the history
…tors/drivers.

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Aug 30, 2016
1 parent fdd5f48 commit a7f2f7b
Show file tree
Hide file tree
Showing 57 changed files with 258 additions and 152 deletions.
2 changes: 1 addition & 1 deletion examples/ardrone.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
drone := ardrone.NewArdroneDriver(ardroneAdaptor, "Drone")

work := func() {
gobot.On(drone.Event("flying"), func(data interface{}) {
drone.On(drone.Event("flying"), func(data interface{}) {
gobot.After(3*time.Second, func() {
drone.Land()
})
Expand Down
4 changes: 2 additions & 2 deletions examples/ardrone_face_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func main() {
detect := false
drone.TakeOff()
var image *cv.IplImage
gobot.On(camera.Event("frame"), func(data interface{}) {
camera.On(camera.Event("frame"), func(data interface{}) {
image = data.(*cv.IplImage)
if !detect {
window.ShowImage(image)
}
})
gobot.On(drone.Event("flying"), func(data interface{}) {
drone.On(drone.Event("flying"), func(data interface{}) {
gobot.After(1*time.Second, func() { drone.Up(0.2) })
gobot.After(2*time.Second, func() { drone.Hover() })
gobot.After(5*time.Second, func() {
Expand Down
14 changes: 7 additions & 7 deletions examples/ardrone_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,34 @@ func main() {
rightStick := pair{x: 0, y: 0}
leftStick := pair{x: 0, y: 0}

gobot.On(joystick.Event("square_press"), func(data interface{}) {
joystick.On(joystick.Event("square_press"), func(data interface{}) {
drone.TakeOff()
})
gobot.On(joystick.Event("triangle_press"), func(data interface{}) {
joystick.On(joystick.Event("triangle_press"), func(data interface{}) {
drone.Hover()
})
gobot.On(joystick.Event("x_press"), func(data interface{}) {
joystick.On(joystick.Event("x_press"), func(data interface{}) {
drone.Land()
})
gobot.On(joystick.Event("left_x"), func(data interface{}) {
joystick.On(joystick.Event("left_x"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.x != val {
leftStick.x = val
}
})
gobot.On(joystick.Event("left_y"), func(data interface{}) {
joystick.On(joystick.Event("left_y"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.y != val {
leftStick.y = val
}
})
gobot.On(joystick.Event("right_x"), func(data interface{}) {
joystick.On(joystick.Event("right_x"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.x != val {
rightStick.x = val
}
})
gobot.On(joystick.Event("right_y"), func(data interface{}) {
joystick.On(joystick.Event("right_y"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.y != val {
rightStick.y = val
Expand Down
2 changes: 1 addition & 1 deletion examples/batty.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ func NewPingDriver(adaptor *loopbackAdaptor, name string, pin string) *pingDrive
}

func (t *pingDriver) Ping() string {
gobot.Publish(t.Event("ping"), "ping")
t.Publish(t.Event("ping"), "ping")
return "pong"
}
4 changes: 2 additions & 2 deletions examples/beaglebone_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func main() {
button := gpio.NewButtonDriver(beagleboneAdaptor, "button", "P8_9")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})

gobot.On(button.Event("release"), func(data interface{}) {
button.On(button.Event("release"), func(data interface{}) {
fmt.Println("button released")
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
sensor.On(sensor.Event("data"), func(data interface{}) {
brightness := uint8(
gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255),
)
Expand Down
4 changes: 2 additions & 2 deletions examples/beaglebone_makey_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func main() {
button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "button", "P8_9")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})

gobot.On(button.Event("release"), func(data interface{}) {
button.On(button.Event("release"), func(data interface{}) {
fmt.Println("button released")
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/bebop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
drone := bebop.NewBebopDriver(bebopAdaptor, "Drone")

work := func() {
gobot.On(drone.Event("flying"), func(data interface{}) {
drone.On(drone.Event("flying"), func(data interface{}) {
gobot.After(10*time.Second, func() {
drone.Land()
})
Expand Down
16 changes: 8 additions & 8 deletions examples/bebop_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {

recording := false

gobot.On(joystick.Event("circle_press"), func(data interface{}) {
joystick.On(joystick.Event("circle_press"), func(data interface{}) {
if recording {
drone.StopRecording()
} else {
Expand All @@ -43,35 +43,35 @@ func main() {
recording = !recording
})

gobot.On(joystick.Event("square_press"), func(data interface{}) {
joystick.On(joystick.Event("square_press"), func(data interface{}) {
drone.HullProtection(true)
drone.TakeOff()
})
gobot.On(joystick.Event("triangle_press"), func(data interface{}) {
joystick.On(joystick.Event("triangle_press"), func(data interface{}) {
drone.Stop()
})
gobot.On(joystick.Event("x_press"), func(data interface{}) {
joystick.On(joystick.Event("x_press"), func(data interface{}) {
drone.Land()
})
gobot.On(joystick.Event("left_x"), func(data interface{}) {
joystick.On(joystick.Event("left_x"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.x != val {
leftStick.x = val
}
})
gobot.On(joystick.Event("left_y"), func(data interface{}) {
joystick.On(joystick.Event("left_y"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.y != val {
leftStick.y = val
}
})
gobot.On(joystick.Event("right_x"), func(data interface{}) {
joystick.On(joystick.Event("right_x"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.x != val {
rightStick.x = val
}
})
gobot.On(joystick.Event("right_y"), func(data interface{}) {
joystick.On(joystick.Event("right_y"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.y != val {
rightStick.y = val
Expand Down
16 changes: 8 additions & 8 deletions examples/bebop_ps3_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func main() {

recording := false

gobot.On(joystick.Event("circle_press"), func(data interface{}) {
joystick.On(joystick.Event("circle_press"), func(data interface{}) {
if recording {
drone.StopRecording()
} else {
Expand All @@ -91,35 +91,35 @@ func main() {
recording = !recording
})

gobot.On(joystick.Event("square_press"), func(data interface{}) {
joystick.On(joystick.Event("square_press"), func(data interface{}) {
drone.HullProtection(true)
drone.TakeOff()
})
gobot.On(joystick.Event("triangle_press"), func(data interface{}) {
joystick.On(joystick.Event("triangle_press"), func(data interface{}) {
drone.Stop()
})
gobot.On(joystick.Event("x_press"), func(data interface{}) {
joystick.On(joystick.Event("x_press"), func(data interface{}) {
drone.Land()
})
gobot.On(joystick.Event("left_x"), func(data interface{}) {
joystick.On(joystick.Event("left_x"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.x != val {
leftStick.x = val
}
})
gobot.On(joystick.Event("left_y"), func(data interface{}) {
joystick.On(joystick.Event("left_y"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.y != val {
leftStick.y = val
}
})
gobot.On(joystick.Event("right_x"), func(data interface{}) {
joystick.On(joystick.Event("right_x"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.x != val {
rightStick.x = val
}
})
gobot.On(joystick.Event("right_y"), func(data interface{}) {
joystick.On(joystick.Event("right_y"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.y != val {
rightStick.y = val
Expand Down
4 changes: 2 additions & 2 deletions examples/chip_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func main() {
button := gpio.NewButtonDriver(chipAdaptor, "button", "XIO-P0")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})

gobot.On(button.Event("release"), func(data interface{}) {
button.On(button.Event("release"), func(data interface{}) {
fmt.Println("button released")
})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/chip_button_led.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ func main() {
led := gpio.NewLedDriver(chipAdaptor, "led", "XIO-P7")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(button.Event("push"), func(data interface{}) {
led.On()
})

gobot.On(button.Event("release"), func(data interface{}) {
button.On(button.Event("release"), func(data interface{}) {
led.Off()
})
}
Expand Down
8 changes: 4 additions & 4 deletions examples/chip_wiichuck.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ func main() {
wiichuck := i2c.NewWiichuckDriver(chipAdaptor, "wiichuck")

work := func() {
gobot.On(wiichuck.Event("joystick"), func(data interface{}) {
wiichuck.On(wiichuck.Event("joystick"), func(data interface{}) {
fmt.Println("joystick", data)
})

gobot.On(wiichuck.Event("c"), func(data interface{}) {
wiichuck.On(wiichuck.Event("c"), func(data interface{}) {
fmt.Println("c")
})

gobot.On(wiichuck.Event("z"), func(data interface{}) {
wiichuck.On(wiichuck.Event("z"), func(data interface{}) {
fmt.Println("z")
})
gobot.On(wiichuck.Event("error"), func(data interface{}) {
wiichuck.On(wiichuck.Event("error"), func(data interface{}) {
fmt.Println("Wiichuck error:", data)
})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/edison_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func main() {
led := gpio.NewLedDriver(e, "myLed", "7")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(button.Event("push"), func(data interface{}) {
led.On()
})
gobot.On(button.Event("release"), func(data interface{}) {
button.On(button.Event("release"), func(data interface{}) {
led.Off()
})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/edison_button_led.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func main() {
led := gpio.NewLedDriver(e, "myLed", "4")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(button.Event("push"), func(data interface{}) {
led.On()
})
gobot.On(button.Event("release"), func(data interface{}) {
button.On(button.Event("release"), func(data interface{}) {
led.Off()
})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/edison_button_led_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func main() {
led := gpio.NewLedDriver(e, "myLed", "4")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(button.Event("push"), func(data interface{}) {
led.On()
})
gobot.On(button.Event("release"), func(data interface{}) {
button.On(button.Event("release"), func(data interface{}) {
led.Off()
})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/edison_grove_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func main() {
button := gpio.NewGroveButtonDriver(e, "button", "2")

work := func() {
gobot.On(button.Event(gpio.Push), func(data interface{}) {
button.On(button.Event(gpio.Push), func(data interface{}) {
fmt.Println("On!")
})

gobot.On(button.Event(gpio.Release), func(data interface{}) {
button.On(button.Event(gpio.Release), func(data interface{}) {
fmt.Println("Off!")
})

Expand Down
2 changes: 1 addition & 1 deletion examples/edison_grove_light_sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
sensor := gpio.NewGroveLightSensorDriver(board, "sensor", "0")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
sensor.On(sensor.Event("data"), func(data interface{}) {
fmt.Println("sensor", data)
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/edison_grove_piezo_vibration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
sensor := gpio.NewGrovePiezoVibrationSensorDriver(board, "sensor", "0")

work := func() {
gobot.On(sensor.Event(gpio.Vibration), func(data interface{}) {
sensor.On(sensor.Event(gpio.Vibration), func(data interface{}) {
fmt.Println("got one!")
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/edison_grove_rotary_sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
sensor := gpio.NewGroveRotaryDriver(board, "sensor", "0")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
sensor.On(sensor.Event("data"), func(data interface{}) {
fmt.Println("sensor", data)
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/edison_grove_sound_sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
sensor := gpio.NewGroveSoundSensorDriver(board, "sensor", "0")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
sensor.On(sensor.Event("data"), func(data interface{}) {
fmt.Println("sensor", data)
})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/edison_grove_touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func main() {
touch := gpio.NewGroveTouchDriver(e, "touch", "2")

work := func() {
gobot.On(touch.Event(gpio.Push), func(data interface{}) {
touch.On(touch.Event(gpio.Push), func(data interface{}) {
fmt.Println("On!")
})

gobot.On(touch.Event(gpio.Release), func(data interface{}) {
touch.On(touch.Event(gpio.Release), func(data interface{}) {
fmt.Println("Off!")
})

Expand Down
2 changes: 1 addition & 1 deletion examples/edison_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
led := gpio.NewLedDriver(e, "led", "3")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
sensor.On(sensor.Event("data"), func(data interface{}) {
brightness := uint8(
gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 4096), 0, 255),
)
Expand Down
Loading

0 comments on commit a7f2f7b

Please sign in to comment.