gobot.io/x/gobot@v1.16.0/platforms/joystick/doc.go (about)

     1  /*
     2  Package joystick provides the Gobot adaptor and drivers for game controllers that are compatible with SDL.
     3  
     4  Installing:
     5  
     6  This package requires `sdl2` to be installed on your system
     7  Then install package with:
     8  
     9  	go get gobot.io/x/gobot/platforms/joystick
    10  
    11  Example:
    12  
    13  	package main
    14  
    15  	import (
    16  		"fmt"
    17  
    18  		"gobot.io/x/gobot"
    19  		"gobot.io/x/gobot/platforms/joystick"
    20  	)
    21  
    22  	func main() {
    23  		joystickAdaptor := joystick.NewAdaptor()
    24  		joystick := joystick.NewDriver(joystickAdaptor,
    25  			"./platforms/joystick/configs/dualshock3.json",
    26  		)
    27  
    28  		work := func() {
    29  			joystick.On(joystick.Event("square_press"), func(data interface{}) {
    30  				fmt.Println("square_press")
    31  			})
    32  			joystick.On(joystick.Event("square_release"), func(data interface{}) {
    33  				fmt.Println("square_release")
    34  			})
    35  			joystick.On(joystick.Event("triangle_press"), func(data interface{}) {
    36  				fmt.Println("triangle_press")
    37  			})
    38  			joystick.On(joystick.Event("triangle_release"), func(data interface{}) {
    39  				fmt.Println("triangle_release")
    40  			})
    41  			joystick.On(joystick.Event("left_x"), func(data interface{}) {
    42  				fmt.Println("left_x", data)
    43  			})
    44  			joystick.On(joystick.Event("left_y"), func(data interface{}) {
    45  				fmt.Println("left_y", data)
    46  			})
    47  			joystick.On(joystick.Event("right_x"), func(data interface{}) {
    48  				fmt.Println("right_x", data)
    49  			})
    50  			joystick.On(joystick.Event("right_y"), func(data interface{}) {
    51  				fmt.Println("right_y", data)
    52  			})
    53  		}
    54  
    55  		robot := gobot.NewRobot("joystickBot",
    56  			[]gobot.Connection{joystickAdaptor},
    57  			[]gobot.Device{joystick},
    58  			work,
    59  		)
    60  
    61  		robot.Start()
    62  	}
    63  
    64  For further information refer to joystick README:
    65  https://github.com/hybridgroup/gobot/blob/master/platforms/joystick/README.md
    66  */
    67  package joystick // import "gobot.io/x/gobot/platforms/joystick"