Skip to content

Commit

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

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Sep 1, 2016
1 parent 290b165 commit e4d38d5
Show file tree
Hide file tree
Showing 73 changed files with 366 additions and 213 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() {
drone.On(drone.Event("flying"), func(data interface{}) {
drone.On(ardrone.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
camera.On(camera.Event("frame"), func(data interface{}) {
camera.On(opencv.Frame, func(data interface{}) {
image = data.(*cv.IplImage)
if !detect {
window.ShowImage(image)
}
})
drone.On(drone.Event("flying"), func(data interface{}) {
drone.On(ardrone.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
18 changes: 9 additions & 9 deletions examples/ardrone_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
gbot := gobot.NewGobot()

joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
joystick := joystick.NewJoystickDriver(joystickAdaptor,
stick := joystick.NewJoystickDriver(joystickAdaptor,
"ps3",
"./platforms/joystick/configs/dualshock3.json",
)
Expand All @@ -31,34 +31,34 @@ func main() {
rightStick := pair{x: 0, y: 0}
leftStick := pair{x: 0, y: 0}

joystick.On(joystick.Event("square_press"), func(data interface{}) {
stick.On(joystick.SquarePress, func(data interface{}) {
drone.TakeOff()
})
joystick.On(joystick.Event("triangle_press"), func(data interface{}) {
stick.On(joystick.TrianglePress, func(data interface{}) {
drone.Hover()
})
joystick.On(joystick.Event("x_press"), func(data interface{}) {
stick.On(joystick.XPress, func(data interface{}) {
drone.Land()
})
joystick.On(joystick.Event("left_x"), func(data interface{}) {
stick.On(joystick.LeftX, func(data interface{}) {
val := float64(data.(int16))
if leftStick.x != val {
leftStick.x = val
}
})
joystick.On(joystick.Event("left_y"), func(data interface{}) {
stick.On(joystick.LeftY, func(data interface{}) {
val := float64(data.(int16))
if leftStick.y != val {
leftStick.y = val
}
})
joystick.On(joystick.Event("right_x"), func(data interface{}) {
stick.On(joystick.RightX, func(data interface{}) {
val := float64(data.(int16))
if rightStick.x != val {
rightStick.x = val
}
})
joystick.On(joystick.Event("right_y"), func(data interface{}) {
stick.On(joystick.RightY, func(data interface{}) {
val := float64(data.(int16))
if rightStick.y != val {
rightStick.y = val
Expand Down Expand Up @@ -106,7 +106,7 @@ func main() {

robot := gobot.NewRobot("ardrone",
[]gobot.Connection{joystickAdaptor, ardroneAdaptor},
[]gobot.Device{joystick, drone},
[]gobot.Device{stick, drone},
work,
)

Expand Down
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() {
button.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("button pressed")
})

button.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, func(data interface{}) {
fmt.Println("button released")
})
}
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() {
button.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("button pressed")
})

button.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, 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() {
drone.On(drone.Event("flying"), func(data interface{}) {
drone.On(bebop.Flying, func(data interface{}) {
gobot.After(10*time.Second, func() {
drone.Land()
})
Expand Down
21 changes: 10 additions & 11 deletions examples/bebop_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
gbot := gobot.NewGobot()

joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
joystick := joystick.NewJoystickDriver(joystickAdaptor,
stick := joystick.NewJoystickDriver(joystickAdaptor,
"ps3",
"./platforms/joystick/configs/dualshock3.json",
)
Expand All @@ -27,14 +27,13 @@ func main() {
drone := bebop.NewBebopDriver(bebopAdaptor, "Drone")

work := func() {

offset := 32767.0
rightStick := pair{x: 0, y: 0}
leftStick := pair{x: 0, y: 0}

recording := false

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

joystick.On(joystick.Event("square_press"), func(data interface{}) {
stick.On(joystick.SquarePress, func(data interface{}) {
drone.HullProtection(true)
drone.TakeOff()
})
joystick.On(joystick.Event("triangle_press"), func(data interface{}) {
stick.On(joystick.TrianglePress, func(data interface{}) {
drone.Stop()
})
joystick.On(joystick.Event("x_press"), func(data interface{}) {
stick.On(joystick.XPress, func(data interface{}) {
drone.Land()
})
joystick.On(joystick.Event("left_x"), func(data interface{}) {
stick.On(joystick.LeftX, func(data interface{}) {
val := float64(data.(int16))
if leftStick.x != val {
leftStick.x = val
}
})
joystick.On(joystick.Event("left_y"), func(data interface{}) {
stick.On(joystick.LeftY, func(data interface{}) {
val := float64(data.(int16))
if leftStick.y != val {
leftStick.y = val
}
})
joystick.On(joystick.Event("right_x"), func(data interface{}) {
stick.On(joystick.RightX, func(data interface{}) {
val := float64(data.(int16))
if rightStick.x != val {
rightStick.x = val
}
})
joystick.On(joystick.Event("right_y"), func(data interface{}) {
stick.On(joystick.RightY, func(data interface{}) {
val := float64(data.(int16))
if rightStick.y != val {
rightStick.y = val
Expand Down Expand Up @@ -119,7 +118,7 @@ func main() {

robot := gobot.NewRobot("bebop",
[]gobot.Connection{joystickAdaptor, bebopAdaptor},
[]gobot.Device{joystick, drone},
[]gobot.Device{stick, drone},
work,
)

Expand Down
20 changes: 10 additions & 10 deletions examples/bebop_ps3_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
gbot := gobot.NewGobot()

joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
joystick := joystick.NewJoystickDriver(joystickAdaptor,
stick := joystick.NewJoystickDriver(joystickAdaptor,
"ps3",
"./platforms/joystick/configs/dualshock3.json",
)
Expand All @@ -82,7 +82,7 @@ func main() {

recording := false

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

joystick.On(joystick.Event("square_press"), func(data interface{}) {
stick.On(joystick.SquarePress, func(data interface{}) {
drone.HullProtection(true)
drone.TakeOff()
})
joystick.On(joystick.Event("triangle_press"), func(data interface{}) {
stick.On(joystick.TrianglePress, func(data interface{}) {
drone.Stop()
})
joystick.On(joystick.Event("x_press"), func(data interface{}) {
stick.On(joystick.XPress, func(data interface{}) {
drone.Land()
})
joystick.On(joystick.Event("left_x"), func(data interface{}) {
stick.On(joystick.LeftX, func(data interface{}) {
val := float64(data.(int16))
if leftStick.x != val {
leftStick.x = val
}
})
joystick.On(joystick.Event("left_y"), func(data interface{}) {
stick.On(joystick.LeftY, func(data interface{}) {
val := float64(data.(int16))
if leftStick.y != val {
leftStick.y = val
}
})
joystick.On(joystick.Event("right_x"), func(data interface{}) {
stick.On(joystick.RightX, func(data interface{}) {
val := float64(data.(int16))
if rightStick.x != val {
rightStick.x = val
}
})
joystick.On(joystick.Event("right_y"), func(data interface{}) {
stick.On(joystick.RightY, func(data interface{}) {
val := float64(data.(int16))
if rightStick.y != val {
rightStick.y = val
Expand Down Expand Up @@ -167,7 +167,7 @@ func main() {

robot := gobot.NewRobot("bebop",
[]gobot.Connection{joystickAdaptor, bebopAdaptor},
[]gobot.Device{joystick, drone},
[]gobot.Device{stick, drone},
work,
)

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() {
button.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("button pressed")
})

button.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, 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() {
button.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
led.On()
})

button.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, func(data interface{}) {
led.Off()
})
}
Expand Down
8 changes: 4 additions & 4 deletions examples/edison_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ func main() {

e := edison.NewEdisonAdaptor("edison")

button := gpio.NewButtonDriver(e, "myButton", "2")
led := gpio.NewLedDriver(e, "myLed", "7")
button := gpio.NewButtonDriver(e, "myButton", "5")
led := gpio.NewLedDriver(e, "myLed", "13")

work := func() {
button.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
led.On()
})
button.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, 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() {
button.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
led.On()
})
button.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, 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() {
button.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
led.On()
})
button.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, 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() {
button.On(button.Event(gpio.Push), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("On!")
})

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

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() {
sensor.On(sensor.Event(gpio.Vibration), func(data interface{}) {
sensor.On(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() {
sensor.On(sensor.Event("data"), func(data interface{}) {
sensor.On(gpio.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() {
sensor.On(sensor.Event("data"), func(data interface{}) {
sensor.On(gpio.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() {
touch.On(touch.Event(gpio.Push), func(data interface{}) {
touch.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("On!")
})

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

Expand Down
Loading

0 comments on commit e4d38d5

Please sign in to comment.