mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-27 13:48:56 +08:00
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
"github.com/hybridgroup/gobot/platforms/joystick"
|
|
)
|
|
|
|
func main() {
|
|
gbot := gobot.NewGobot()
|
|
|
|
joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
|
|
stick := joystick.NewJoystickDriver(joystickAdaptor,
|
|
"ps3",
|
|
"./platforms/joystick/configs/dualshock3.json",
|
|
)
|
|
|
|
work := func() {
|
|
stick.On(joystick.SquarePress, func(data interface{}) {
|
|
fmt.Println("square_press")
|
|
})
|
|
stick.On(joystick.SquareRelease, func(data interface{}) {
|
|
fmt.Println("square_release")
|
|
})
|
|
stick.On(joystick.TrianglePress, func(data interface{}) {
|
|
fmt.Println("triangle_press")
|
|
})
|
|
stick.On(joystick.TriangleRelease, func(data interface{}) {
|
|
fmt.Println("triangle_release")
|
|
})
|
|
stick.On(joystick.LeftX, func(data interface{}) {
|
|
fmt.Println("left_x", data)
|
|
})
|
|
stick.On(joystick.LeftY, func(data interface{}) {
|
|
fmt.Println("left_y", data)
|
|
})
|
|
stick.On(joystick.RightX, func(data interface{}) {
|
|
fmt.Println("right_x", data)
|
|
})
|
|
stick.On(joystick.RightY, func(data interface{}) {
|
|
fmt.Println("right_y", data)
|
|
})
|
|
}
|
|
|
|
robot := gobot.NewRobot("joystickBot",
|
|
[]gobot.Connection{joystickAdaptor},
|
|
[]gobot.Device{stick},
|
|
work,
|
|
)
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
gbot.Start()
|
|
}
|