hybridgroup.gobot/examples/joystick_xbox360.go

68 lines
1.7 KiB
Go
Raw Normal View History

2014-04-28 09:02:39 +08:00
package main
import (
"fmt"
2014-07-11 08:21:21 +08:00
2014-04-28 09:02:39 +08:00
"github.com/hybridgroup/gobot"
2014-05-23 11:28:26 +08:00
"github.com/hybridgroup/gobot/platforms/joystick"
2014-04-28 09:02:39 +08:00
)
func main() {
2014-05-23 11:28:26 +08:00
gbot := gobot.NewGobot()
2014-07-09 09:36:14 +08:00
2014-05-23 11:28:26 +08:00
joystickAdaptor := joystick.NewJoystickAdaptor("xbox360")
2014-07-11 08:21:21 +08:00
joystick := joystick.NewJoystickDriver(joystickAdaptor,
"xbox360",
"./platforms/joystick/configs/joystick/configs/xbox360_power_a_mini_proex.json",
)
2014-04-28 09:02:39 +08:00
work := func() {
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("a_press"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("a_press")
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("a_release"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("a_release")
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("b_press"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("b_press")
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("b_release"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("b_release")
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("up"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("up", data)
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("down"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("down", data)
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("left"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("left", data)
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("right"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("right", data)
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("left_x"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("left_x", data)
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("left_y"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("left_y", data)
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("right_x"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("right_x", data)
})
2014-07-11 08:21:21 +08:00
gobot.On(joystick.Event("right_y"), func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("right_y", data)
})
}
2014-07-09 09:36:14 +08:00
robot := gobot.NewRobot("joystickBot",
[]gobot.Connection{joystickAdaptor},
2014-07-11 08:21:21 +08:00
[]gobot.Device{joystick},
2014-07-09 09:36:14 +08:00
work,
)
gbot.AddRobot(robot)
2014-04-28 09:02:39 +08:00
2014-05-23 11:28:26 +08:00
gbot.Start()
2014-04-28 09:02:39 +08:00
}