Module Joystick

HID joystick library.

This library can be used to bind buttons and axes of HID Joystick devices to FSLabs cockpit controls (or other functions if you want).

???

Class AxisProperties

AxisProperties:delta(delta) Sets the axis delta (how much change in position is needed to trigger the callback)
AxisProperties:invert() Inverts the axis
AxisProperties:bounds(lower, upper) Sets the axis lower and upper bounds
AxisProperties:nullzone(lower, upper) Sets the axis null zone

Class AxisCallback

AxisCallback:props() Creates and returns new axis properties for this callback only.

Class Joystick

Joystick.new(vendorId, productId[, deviceNum=0]) Constructor
Joystick:axisProps(axisName[, index=0]) Returns the properties of an axis by its name.
Joystick:axisProps(usageID[, index=0]) Returns the properties of an axis by its usage ID.
Joystick:bindButton(buttonNum, button) Binds a joystick button's press and release actions to those of a virtual cockpit button.
Joystick:bindToggleButton(buttonNum, button) Maps the toggle states of a joystick toggle button to those of a virtual cockpit toggle button.
Joystick:bindPush(buttonNum, switch) Same as bindButton - for pushing the switch.
Joystick:bindPull(buttonNum, switch) Same as bindButton - for pulling the switch.
Joystick:onPress(buttonNum, ...) Binds a callback to a button press.
Joystick:onPressRepeat(buttonNum, ...) Same as onPress, but the callback will be called repeatedly while the button is depressed.
Joystick:onPressRepeat(buttonNum, repeatInterval, ...) Same as onPress, but the callback will be called repeatedly while the button is depressed.
Joystick:onRelease(buttonNum, ...) Binds a callback to a button release.
Joystick:onAxis(axisName, callback) Binds a callback to an axis.
Joystick:onAxis(axisName, axisIndex, callback) Binds a callback to an axis.
Joystick:onAxis(usageId, callback) Binds a callback to axis by the axis' HID usage ID.
Joystick:onAxis(usageId, axisIndex, callback) Binds a callback to axis by the axis' HID usage ID.
Joystick:startLogging() Start printing into the console whenever a button is pressed or an axis is moved.
Joystick.logAllJoysticks() Calls startLogging for all registered Joysticks.


Class AxisProperties

AxisProperties:delta(delta)
Sets the axis delta (how much change in position is needed to trigger the callback)

Parameters:

  • delta number Percent from 0-100.

Returns:

    self
AxisProperties:invert()
Inverts the axis

Returns:

    self
AxisProperties:bounds(lower, upper)
Sets the axis lower and upper bounds

Parameters:

  • lower number Percent from 0-100.
  • upper number Percent from 0-100.

Returns:

    self
AxisProperties:nullzone(lower, upper)
Sets the axis null zone

Parameters:

  • lower number Percent from 0-100.
  • upper number Percent from 0-100.

Returns:

    self

Class AxisCallback

AxisCallback:props()
Creates and returns new axis properties for this callback only.

Returns:

    AxisProperties

Class Joystick

Joystick.new(vendorId, productId[, deviceNum=0])
Constructor

Parameters:

  • vendorId int
  • productId int
  • deviceNum int Specify this parameter if there are multiple devices with the same vendor and product IDs (default 0)
Joystick:axisProps(axisName[, index=0])
Returns the properties of an axis by its name.

Parameters:

  • axisName string
  • index int (default 0)

Returns:

    AxisProperties
Joystick:axisProps(usageID[, index=0])
Returns the properties of an axis by its usage ID.

Parameters:

  • usageID int
  • index int (default 0)

Returns:

    AxisProperties
Joystick:bindButton(buttonNum, button)
Binds a joystick button's press and release actions to those of a virtual cockpit button.

Parameters:

Joystick:bindToggleButton(buttonNum, button)
Maps the toggle states of a joystick toggle button to those of a virtual cockpit toggle button.

Parameters:

Joystick:bindPush(buttonNum, switch)
Same as bindButton - for pushing the switch.

Parameters:

Joystick:bindPull(buttonNum, switch)
Same as bindButton - for pulling the switch.

Parameters:

Joystick:onPress(buttonNum, ...)
Binds a callback to a button press.

Parameters:

  • buttonNum int
  • ... Values in the following format:

    callable1, arg1, arg2, ..., argn, callable2, arg1, arg2, ..., argn, ...

    where a callable can be either a function, callable table, or object followed by a method name: FSL.OVHD_INTLT_Integ_Lt_Knob, "rotateLeft".
Joystick:onPressRepeat(buttonNum, ...)
Same as onPress, but the callback will be called repeatedly while the button is depressed.

Parameters:

Joystick:onPressRepeat(buttonNum, repeatInterval, ...)
Same as onPress, but the callback will be called repeatedly while the button is depressed.

Parameters:

  • buttonNum int
  • repeatInterval int Interval between callback invocations in milliseconds.
  • ... See onPress
Joystick:onRelease(buttonNum, ...)
Binds a callback to a button release.

Parameters:

Joystick:onAxis(axisName, callback)
Binds a callback to an axis.

Parameters:

  • axisName string One of these: X, Y, Z, Rx, Ry, Rz, Slider, Dial
  • callback function A callable to be called when the axis changes its value. The callback will receive the current value (percent from 0-100) as the argument.
Joystick:onAxis(axisName, axisIndex, callback)
Binds a callback to an axis.

Parameters:

  • axisName string One of these: X, Y, Z, Rx, Ry, Rz, Slider, Dial
  • axisIndex int Specify this parameter if there are multiple axes with the same name.
  • callback function A callable to be called when the axis changes its value. The callback will receive the current value (percent from 0-100) as the argument.
Joystick:onAxis(usageId, callback)
Binds a callback to axis by the axis' HID usage ID. You're probably not going to need this.

Parameters:

  • usageId int
  • callback function A function to be called when the axis changes its value. The callback will receive the current value (percent from 0-100) as the argument.
Joystick:onAxis(usageId, axisIndex, callback)
Binds a callback to axis by the axis' HID usage ID. You're probably not going to need this.

Parameters:

  • usageId int
  • axisIndex int Specify this parameter if there are multiple axes with a given usage ID.
  • callback function A function to be called when the axis changes its value. The callback will receive the current value (percent from 0-100) as the argument.
Joystick:startLogging()
Start printing into the console whenever a button is pressed or an axis is moved.
Joystick.logAllJoysticks()
Calls startLogging for all registered Joysticks.
generated by LDoc 1.4.6 Last updated 2021-11-11 17:10:49