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

55 lines
1.2 KiB
Go
Raw Normal View History

// +build example
//
// Do not build by default.
2014-04-27 18:02:39 -07:00
package main
import (
"fmt"
2014-07-10 17:21:21 -07:00
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/joystick"
2014-04-27 18:02:39 -07:00
)
func main() {
joystickAdaptor := joystick.NewAdaptor()
stick := joystick.NewDriver(joystickAdaptor,
2014-07-10 17:21:21 -07:00
"./platforms/joystick/configs/dualshock3.json",
)
2014-04-27 18:02:39 -07:00
work := func() {
stick.On(joystick.SquarePress, func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("square_press")
})
stick.On(joystick.SquareRelease, func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("square_release")
})
stick.On(joystick.TrianglePress, func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("triangle_press")
})
stick.On(joystick.TriangleRelease, func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("triangle_release")
})
stick.On(joystick.LeftX, func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("left_x", data)
})
stick.On(joystick.LeftY, func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("left_y", data)
})
stick.On(joystick.RightX, func(data interface{}) {
2014-04-27 18:02:39 -07:00
fmt.Println("right_x", data)
})
stick.On(joystick.RightY, 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},
[]gobot.Device{stick},
2014-07-08 18:36:14 -07:00
work,
)
robot.Start()
2014-04-27 18:02:39 -07:00
}