code.witches.io/go/sdl2@v0.1.1/joystick.go (about)

     1  package sdl
     2  
     3  // #include <SDL2/SDL_joystick.h>
     4  import "C"
     5  import (
     6  	"unsafe"
     7  )
     8  
     9  type JoystickID int32
    10  
    11  type Joystick = C.SDL_Joystick
    12  
    13  func JoystickOpen(deviceIndex int) (*Joystick, error) {
    14  	ptr := C.SDL_JoystickOpen(C.int(deviceIndex))
    15  	if ptr == nil {
    16  		return nil, GetError()
    17  	}
    18  	return (*Joystick)(unsafe.Pointer(ptr)), nil
    19  }
    20  
    21  func JoystickClose(joystick *Joystick) {
    22  	C.SDL_JoystickClose(joystick)
    23  }
    24  
    25  func JoystickInstanceID(joystick *Joystick) (JoystickID, error) {
    26  	id := C.SDL_JoystickInstanceID(joystick)
    27  	if id < 0 {
    28  		return 0, GetError()
    29  	}
    30  	return JoystickID(id), nil
    31  }