hybridgroup.gobot/examples/joystick_xbox360.go

67 lines
1.5 KiB
Go
Raw Normal View History

// +build example
//
// Do not build by default.
2014-04-28 09:02:39 +08:00
package main
import (
"fmt"
2014-07-11 08:21:21 +08:00
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/joystick"
2014-04-28 09:02:39 +08:00
)
func main() {
joystickAdaptor := joystick.NewAdaptor()
stick := joystick.NewDriver(joystickAdaptor,
2014-07-11 08:21:21 +08:00
"./platforms/joystick/configs/joystick/configs/xbox360_power_a_mini_proex.json",
)
2014-04-28 09:02:39 +08:00
work := func() {
stick.On(joystick.APress, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("a_press")
})
stick.On(joystick.ARelease, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("a_release")
})
stick.On(joystick.BPress, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("b_press")
})
stick.On(joystick.BRelease, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("b_release")
})
stick.On(joystick.Up, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("up", data)
})
stick.On(joystick.Down, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("down", data)
})
stick.On(joystick.Left, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("left", data)
})
stick.On(joystick.Right, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("right", data)
})
stick.On(joystick.LeftX, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("left_x", data)
})
stick.On(joystick.LeftY, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("left_y", data)
})
stick.On(joystick.RightX, func(data interface{}) {
2014-04-28 09:02:39 +08:00
fmt.Println("right_x", data)
})
stick.On(joystick.RightY, 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},
[]gobot.Device{stick},
2014-07-09 09:36:14 +08:00
work,
)
robot.Start()
2014-04-28 09:02:39 +08:00
}