2014-04-28 09:02:39 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-11 08:21:21 +08:00
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/joystick"
|
2014-04-28 09:02:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
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() {
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.APress, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("a_press")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.ARelease, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("a_release")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.BPress, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("b_press")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.BRelease, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("b_release")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.Up, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("up", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.Down, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("down", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.Left, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("left", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.Right, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("right", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.LeftX, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("left_x", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.LeftY, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("left_y", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.RightX, func(data interface{}) {
|
2014-04-28 09:02:39 +08:00
|
|
|
fmt.Println("right_x", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
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},
|
2016-09-01 18:17:43 +08:00
|
|
|
[]gobot.Device{stick},
|
2014-07-09 09:36:14 +08:00
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2014-04-28 09:02:39 +08:00
|
|
|
}
|