Exemplo n.º 1
0
// InitJoystick initializes the Joystick Subsystem and add available joysticks
func InitJoystick() {
	if sdl.WasInit(sdl.INIT_JOYSTICK) == 0 {
		sdl.InitSubSystem(sdl.INIT_JOYSTICK)
	}

	if sdl.NumJoysticks() > 0 {
		for i := 0; i < sdl.NumJoysticks(); i++ {
			id := sdl.JoystickID(i)

			addJoystick(id)
		}

		sdl.JoystickEventState(sdl.ENABLE)

		joysticksInitialised = true
	}
}
Exemplo n.º 2
0
// NewJoystickAdaptor returns a new JoystickAdaptor with specified name.
func NewJoystickAdaptor(name string) *JoystickAdaptor {
	return &JoystickAdaptor{
		name: name,
		connect: func(j *JoystickAdaptor) (err error) {
			sdl.Init(sdl.INIT_JOYSTICK)
			if sdl.NumJoysticks() > 0 {
				j.joystick = sdl.JoystickOpen(0)
				return
			}
			return errors.New("No joystick available")
		},
	}
}
Exemplo n.º 3
0
// NewAdaptor returns a new Joystick Adaptor.
func NewAdaptor() *Adaptor {
	return &Adaptor{
		name: "Joystick",
		connect: func(j *Adaptor) (err error) {
			sdl.Init(sdl.INIT_JOYSTICK)
			if sdl.NumJoysticks() > 0 {
				j.joystick = sdl.JoystickOpen(0)
				return
			}
			return errors.New("No joystick available")
		},
	}
}
Exemplo n.º 4
0
func GetJs() (*sdl.Joystick, error) {
	sdl.Init(sdl.INIT_JOYSTICK)
	numJs := sdl.NumJoysticks()
	if numJs == 0 {
		return nil, errors.New("Joystick missing.")
	}

	jsIdx := -1
	for i := 0; i < numJs; i++ {
		if sdl.JoystickNameForIndex(i) == "T.Flight Hotas X" {
			jsIdx = i
			break
		}
	}

	if jsIdx == -1 {
		return nil, errors.New("Unsuported joystick!")
	}

	return sdl.JoystickOpen(jsIdx), nil
}