1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00
hybridgroup.gobot/examples/joystick_ps3.go

56 lines
1.3 KiB
Go
Raw Normal View History

2014-04-27 18:02:39 -07:00
package main
import (
"fmt"
2014-07-10 17:21:21 -07:00
2014-04-27 18:02:39 -07:00
"github.com/hybridgroup/gobot"
2014-05-22 20:28:26 -07:00
"github.com/hybridgroup/gobot/platforms/joystick"
2014-04-27 18:02:39 -07:00
)
func main() {
2014-05-22 20:28:26 -07:00
gbot := gobot.NewGobot()
2014-07-08 18:36:14 -07:00
2014-05-22 20:28:26 -07:00
joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
2014-07-10 17:21:21 -07:00
joystick := joystick.NewJoystickDriver(joystickAdaptor,
"ps3",
"./platforms/joystick/configs/dualshock3.json",
)
2014-04-27 18:02:39 -07:00
work := func() {
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("square_press"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("square_press")
})
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("square_release"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("square_release")
})
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("triangle_press"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("triangle_press")
})
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("triangle_release"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("triangle_release")
})
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("left_x"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("left_x", data)
})
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("left_y"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("left_y", data)
})
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("right_x"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("right_x", data)
})
2014-07-10 17:21:21 -07:00
gobot.On(joystick.Event("right_y"), func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("right_y", data)
})
}
2014-07-08 18:36:14 -07:00
robot := gobot.NewRobot("joystickBot",
[]gobot.Connection{joystickAdaptor},
2014-07-10 17:21:21 -07:00
[]gobot.Device{joystick},
2014-07-08 18:36:14 -07:00
work,
)
gbot.AddRobot(robot)
2014-04-27 18:02:39 -07:00
2014-05-22 20:28:26 -07:00
gbot.Start()
2014-04-27 18:02:39 -07:00
}