2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2016-02-21 01:41:38 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/joystick"
|
2016-02-21 01:41:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
joystickAdaptor := joystick.NewAdaptor()
|
2018-04-14 19:34:28 +08:00
|
|
|
stick := joystick.NewDriver(joystickAdaptor, "dualshock4")
|
2016-02-21 01:41:38 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.SquarePress, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("square_press")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.SquareRelease, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("square_release")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.TrianglePress, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("triangle_press")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.TriangleRelease, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("triangle_release")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.CirclePress, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("circle_press")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.CircleRelease, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("circle_release")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.XPress, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("x_press")
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.XRelease, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("x_release")
|
|
|
|
})
|
2018-05-25 18:19:22 +08:00
|
|
|
stick.On(joystick.HomePress, func(data interface{}) {
|
|
|
|
fmt.Println("home_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.HomeRelease, func(data interface{}) {
|
|
|
|
fmt.Println("home_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.SharePress, func(data interface{}) {
|
|
|
|
fmt.Println("share_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.ShareRelease, func(data interface{}) {
|
|
|
|
fmt.Println("share_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.OptionsPress, func(data interface{}) {
|
|
|
|
fmt.Println("options_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.OptionsRelease, func(data interface{}) {
|
|
|
|
fmt.Println("options_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.L1Press, func(data interface{}) {
|
|
|
|
fmt.Println("l1_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.L1Release, func(data interface{}) {
|
|
|
|
fmt.Println("l1_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.L2Press, func(data interface{}) {
|
|
|
|
fmt.Println("l2_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.L2Release, func(data interface{}) {
|
|
|
|
fmt.Println("l2_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.R1Press, func(data interface{}) {
|
|
|
|
fmt.Println("r1_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.R1Release, func(data interface{}) {
|
|
|
|
fmt.Println("r1_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.R2Press, func(data interface{}) {
|
|
|
|
fmt.Println("r2_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.R2Release, func(data interface{}) {
|
|
|
|
fmt.Println("r2_release")
|
|
|
|
})
|
|
|
|
|
|
|
|
stick.On(joystick.UpPress, func(data interface{}) {
|
|
|
|
fmt.Println("up_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.UpRelease, func(data interface{}) {
|
|
|
|
fmt.Println("up_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.DownPress, func(data interface{}) {
|
|
|
|
fmt.Println("down_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.DownRelease, func(data interface{}) {
|
|
|
|
fmt.Println("down_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.RightPress, func(data interface{}) {
|
|
|
|
fmt.Println("right_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.RightRelease, func(data interface{}) {
|
|
|
|
fmt.Println("right_release")
|
|
|
|
})
|
|
|
|
stick.On(joystick.LeftPress, func(data interface{}) {
|
|
|
|
fmt.Println("left_press")
|
|
|
|
})
|
|
|
|
stick.On(joystick.LeftRelease, func(data interface{}) {
|
|
|
|
fmt.Println("left_release")
|
|
|
|
})
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.LeftX, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("left_x", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.LeftY, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("left_y", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.RightX, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("right_x", data)
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
stick.On(joystick.RightY, func(data interface{}) {
|
2016-02-21 01:41:38 +08:00
|
|
|
fmt.Println("right_y", data)
|
|
|
|
})
|
2018-05-25 18:19:22 +08:00
|
|
|
stick.On(joystick.L2, func(data interface{}) {
|
|
|
|
fmt.Println("L2", data)
|
|
|
|
})
|
|
|
|
stick.On(joystick.R2, func(data interface{}) {
|
|
|
|
fmt.Println("R2", data)
|
|
|
|
})
|
2016-02-21 01:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("joystickBot",
|
|
|
|
[]gobot.Connection{joystickAdaptor},
|
2016-09-01 18:17:43 +08:00
|
|
|
[]gobot.Device{stick},
|
2016-02-21 01:41:38 +08:00
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2016-02-21 01:41:38 +08:00
|
|
|
}
|