Module FSL2Lua

Library for interacting with FSLabs cockpit controls based on Lvars and mouse macros.

See here on how to use it outside of Copilot.

Functions

checkWithTimeout(timeout, block, ...) Executes the callback until it signals a truthy value or the timeout elapses.
checkWithTimeout(timeout, interval, block, ...)
withTimeout(timeout, block, ...) Executes the callback until the timeout elapses or the first value returned by the callback is anything other than nil.
withTimeout(timeout, interval, block, ...)
repeatWithTimeout(timeout, block, ...) Repeats the callback until the timeout elapses
repeatWithTimeout(timeout, interval, block, ...)
Bind(args) Function for making key bindings.
Bind.cycleSwitch(switch[, ...]) Returns a function that will cycle the switch.
Bind.cycleLandingLights([...]) Returns a function that will cycle the landing light switches and keep them in sync.
Bind.cycleRotaryKnob(knob, steps) Divides the knob in n steps and returns a function that will cycle the knob across those steps.
Bind.toggleButtons(...) Returns a function that will cycle multiple toggle buttons at once and keep their toggle states in sync.

Tables

FSL

FSL

FSL:setPilot(pilot) This function makes references in the root FSL table to all fields in either FSL.CPT or FSL.FO, if the 'pilot' parameter is 1 or 2, respectively.

Class Control

Control:macro(clickType) Invokes the mouse macro with the given click type on the control's mouse rectangle.
Control:isLit() Checks if the control's light is on.
Control:getLvarValue()

Class Button

Button.guard The guard of this button or nil if it doesn't have one.
Button:__call() Presses the button.
Button:rightClick() Simulates a click of the right mouse button on this button.
Button:isDown()
Button:pressForLightState(state) Presses the button if its light's current state doesn't match the passed 'state' parameter.
Button:pressIfLit()
Button:pressIfNotLit()

Class ToggleButton

ToggleButton:setToggleState(state) Sets the toggle state of the button
ToggleButton:toggleDown() Calls setToggleState(true)
ToggleButton:toggleUp() Calls setToggleState(false)

Class Guard

Guard:open()
Guard:lift() Alias for open.
Guard:close()
Guard:isOpen()

Class Switch

Switch:__call(targetPos) Moves the switch to the given position.
Switch:getPosn()

Class PushPullSwitch

PushPullSwitch:push()
PushPullSwitch:pull()

Class RotaryKnob

RotaryKnob:__call(targetPos)
RotaryKnob:rotateLeft() Rotates the knob left by 1 tick.
RotaryKnob:rotateRight() Rotates the knob right by 1 tick.
RotaryKnob:getPosn()
RotaryKnob:rotateBy(ticks[, pause=70]) Rotates the knob by amount of ticks.
RotaryKnob:random([lower=0][, upper=100]) Sets the knob to random position between lower and upper.

Class MCDU

MCDU.LENGTH_LINE Count of cells in a line
MCDU.NUM_LINES Total line count
MCDU.LENGTH Total cell count
MCDU:getArray() Returns the MCDU display as an array of display cells.
MCDU:getString([startpos][, endpos]) Returns the MCDU display as a string.
MCDU:getLineIdx(lineNum) Returns the start index and the end index of a line
MCDU:getLine(lineNum[, disp][, startPos=1][, endPos=MCDU.LENGTH_LINE]) Returns a line of the display
MCDU:getScratchpad([disp]) Returns the last display line
MCDU:type(str) Types str on the keyboard.
MCDU:isOn() Returns false if the display is blank.
MCDU:printCells([startLine=1][, endLine=MCDU.NUM_LINES])


Functions

Methods
checkWithTimeout(timeout, block, ...)
Executes the callback until it signals a truthy value or the timeout elapses.

Parameters:

  • timeout int Timeout in milliseconds
  • block function A callback that should return a truthy first value to signal the condition.
  • ... Arguments to forward to block.

Returns:

    bool True + the rest of the values returned by block if the condition was signaled, false if the timeout has elapsed.
checkWithTimeout(timeout, interval, block, ...)

Parameters:

  • timeout int Timeout in milliseconds
  • interval int Interval to sleep between checks
  • block function A callback that should return a truthy first value to signal the condition.
  • ... Arguments to forward to block.

Returns:

    bool True + the rest of the values returned by block if the condition was signaled, false if the timeout has elapsed.
withTimeout(timeout, block, ...)
Executes the callback until the timeout elapses or the first value returned by the callback is anything other than nil.

Parameters:

  • timeout int Timeout in milliseconds
  • block function
  • ... Arguments to forward to block.

Returns:

    Either nil if the timeout has elapsed, or the values returned by block.
withTimeout(timeout, interval, block, ...)

Parameters:

  • timeout int Timeout in milliseconds
  • interval int Interval to sleep between checks
  • block function
  • ... Arguments to forward to block.

Returns:

    Either nil if the timeout has elapsed, or the values returned by block.
repeatWithTimeout(timeout, block, ...)
Repeats the callback until the timeout elapses

Parameters:

  • timeout int Timeout in milliseconds
  • block function
  • ... Arguments to forward to block.
repeatWithTimeout(timeout, interval, block, ...)

Parameters:

  • timeout int Timeout in milliseconds
  • interval int Interval to sleep between block invocations
  • block function
  • ... Arguments to forward to block.
Bind(args)

Function for making key bindings. The key events for the bindings you define are trapped and not passed on to the sim.

Accepted values for onPress, onRelease, and onPressRepeat are:

  • A function or callable table.

  • An array 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".

Parameters:

  • args A table that may contain the following fields:
    • onPress See above.
    • onPressRepeat See above.
    • onRelease See above.
    • bindButton Button Binds the press and release actions of a physical key or button to those of a virtual cockpit button.
    • bindToggleButton ToggleButton Maps the toggle states of a joystick toggle button to those of a virtual cockpit toggle button.
    • bindPush PushPullSwitch Same as bindButton — for pushing the switch.
    • bindPull PushPullSwitch Same as bindButton — for pulling the switch.
    • extended bool True if the key is an extended key. For example, both the regular and the numpad Enter keys share the same keycode, but only the latter has the extended flag set.
    • key string See the list of keys here

Usage:

    Bind {key = "SHIFT+ALT+PageUp", extended = true, onPress = function() print "hi" end}
    Bind {key = "A", onPress = {FSL.OVHD_EXTLT_Nose_Switch, "TAXI"}}
Bind.cycleSwitch(switch[, ...])
Returns a function that will cycle the switch.

Parameters:

  • switch Switch
  • ... At least two positions to cycle across. If none are specified, the switch will be cycled across all positions. (optional)

Returns:

    function Function that will cycle the switch.

Usage:

    Bind {key = "A", onPress = Bind.cycleSwitch(FSL.OVHD_EXTLT_Strobe_Switch, "OFF", "ON")}
    
    myJoystick:onPress(1, Bind.cycleSwitch(FSL.OVHD_EXTLT_Strobe_Switch))
Bind.cycleLandingLights([...])
Returns a function that will cycle the landing light switches and keep them in sync.

Parameters:

  • ... At least two positions to cycle across. If none are specified, the switches will be cycled across all positions. (optional)

Returns:

    function Function that will cycle the switches.
Bind.cycleRotaryKnob(knob, steps)
Divides the knob in n steps and returns a function that will cycle the knob across those steps.

Parameters:

  • knob RotaryKnob
  • steps int In how many steps to divide the knob.

Returns:

    function Function that will cycle the knob.
Bind.toggleButtons(...)
Returns a function that will cycle multiple toggle buttons at once and keep their toggle states in sync.

Parameters:

Returns:

    function Function that will toggle the buttons.

Tables

FSL

Fields:

  • CPT table containing controls on the left side
  • FO table containing controls on the right side
  • PF table containing controls on the side of the Pilot Flying
    For example, if the PF is the Captain, it will be the same as the CPT table.
    The controls on the PM side are in the root FSL table.

Usage:

    FSL.GSLD_EFIS_VORADF_1_Switch("VOR")

FSL

FSL:setPilot(pilot)
This function makes references in the root FSL table to all fields in either FSL.CPT or FSL.FO, if the 'pilot' parameter is 1 or 2, respectively. For the other side's controls, it makes references in the FSL.PF table.

Copilot will set it depending on the 'PM_seat' option.

Parameters:

  • pilot

Usage:

    local FSL = require "FSL2Lua"
    
    print(FSL.MCDU) -- nil
    print(FSL.GSLD_Chrono_Button) -- nil
    
    FSL:setPilot(1)
    
    print(FSL.MCDU:getString() == FSL.CPT.MCDU:getString()) -- true
    print(FSL.GSLD_Chrono_Button == FSL.CPT.GSLD_Chrono_Button) -- true
    print(FSL.PF.MCDU:getString() == FSL.FO.MCDU:getString()) -- true
    print(FSL.PF.GSLD_Chrono_Button == FSL.FO.GSLD_Chrono_Button) -- true

Class Control

Abstract control
Control:macro(clickType)
Invokes the mouse macro with the given click type on the control's mouse rectangle.

Parameters:

  • clickType string

    One of the following:

    • 'leftPress'
    • 'leftRelease'
    • 'rightPress'
    • 'rightRelease'
    • 'wheelUp'
    • 'wheelDown'
Control:isLit()
Checks if the control's light is on.

Returns:

    bool True if the control has a light and it's on.

    The control needs to have an Lvar associated with its light - otherwise, this function throws an error!

    Unfortunately, overhead-style square buttons don't have such Lvars.

Usage:

    if not FSL.GSLD_EFIS_CSTR_Button:isLit() then
      FSL.GSLD_EFIS_CSTR_Button()
    end
Control:getLvarValue()

Returns:

    int

Class Button

Button.guard
The guard of this button or nil if it doesn't have one.
Button:__call()
Presses the button.

Usage:

    FSL.OVHD_ELEC_BAT_1_Button()
Button:rightClick()
Simulates a click of the right mouse button on this button. This function was written because I know that the PA button on the ACP has a special function if you click on it with the right mouse button. I don't think it's useful for anything else.
Button:isDown()

Returns:

    bool True if the button is depressed.
Button:pressForLightState(state)
Presses the button if its light's current state doesn't match the passed 'state' parameter.

Parameters:

  • state Truthy for 'the light should be on', falsy for 'the light should be off'.
Button:pressIfLit()
Button:pressIfNotLit()

Class ToggleButton

Buttons that toggle between their 'up' and 'down' positions, such as most of the overhead buttons.

Subclass of Button

ToggleButton:setToggleState(state)
Sets the toggle state of the button

Parameters:

  • state Truthy for 'down', falsy for 'up'
ToggleButton:toggleDown()
Calls setToggleState(true)
ToggleButton:toggleUp()
Calls setToggleState(false)

Class Guard

Guard:open()
Guard:lift()
Alias for open.
Guard:close()
Guard:isOpen()

Returns:

    bool

Class Switch

All controls that have named positions
Switch:__call(targetPos)
Moves the switch to the given position.

Parameters:

  • targetPos string A valid position for this switch. You can find the list of positions for a given switch in the list of controls.

Usage:

    FSL.GSLD_EFIS_VORADF_1_Switch "VOR"
Switch:getPosn()

Returns:

    string Current position of the switch in uppercase.

Class PushPullSwitch

PushPullSwitch:push()
PushPullSwitch:pull()

Class RotaryKnob

RotaryKnob:__call(targetPos)

Parameters:

  • targetPos number Relative position from 0-100.

Usage:

    FSL.OVHD_INTLT_Integ_Lt_Knob(42)
RotaryKnob:rotateLeft()
Rotates the knob left by 1 tick.
RotaryKnob:rotateRight()
Rotates the knob right by 1 tick.
RotaryKnob:getPosn()

Returns:

    number Relative position from 0-100.
RotaryKnob:rotateBy(ticks[, pause=70])
Rotates the knob by amount of ticks.

Parameters:

  • ticks number positive to rotate right, negative to rotate left
  • pause number milliseconds to sleep between each tick (default 70)
RotaryKnob:random([lower=0][, upper=100])
Sets the knob to random position between lower and upper.

Parameters:

  • lower number (default 0)
  • upper number (default 100)

Class MCDU

MCDU.LENGTH_LINE
Count of cells in a line
  • LENGTH_LINE int
MCDU.NUM_LINES
Total line count
  • NUM_LINES int
MCDU.LENGTH
Total cell count
  • LENGTH int
MCDU:getArray()
Returns the MCDU display as an array of display cells.

Returns:

    table

    Array of tables representing display cells.

    Each cell table has three fields:

    • char: The character displayed in the cell (nil if the cell is blank)
    • color: The color of the character, one of these :
      • 'cyan'
      • 'grey'
      • 'green'
      • 'magenta'
      • 'amber'
      • 'white'
    • isBold: bool
MCDU:getString([startpos][, endpos])
Returns the MCDU display as a string.

Parameters:

  • startpos number (optional)
  • endpos number (optional)

Returns:

    string

Usage:

    if not FSL.MCDU:getString():find "MCDU MENU" then
      FSL.PED_MCDU_KEY_MENU()
    end
MCDU:getLineIdx(lineNum)
Returns the start index and the end index of a line

Parameters:

  • lineNum int

Returns:

  1. int Start index
  2. int End index
MCDU:getLine(lineNum[, disp][, startPos=1][, endPos=MCDU.LENGTH_LINE])
Returns a line of the display

Parameters:

  • lineNum int
  • disp string If you already have a display string, you can pass it here. (optional)
  • startPos int (default 1)
  • endPos int (default MCDU.LENGTH_LINE)

Returns:

    string
MCDU:getScratchpad([disp])
Returns the last display line

Parameters:

  • disp string If you already have a display string, you can pass it here. (optional)

Returns:

    string
MCDU:type(str)
Types str on the keyboard.

Parameters:

Usage:

    FSL.CPT.MCDU:type "hello"
MCDU:isOn()
Returns false if the display is blank.

Returns:

    bool
MCDU:printCells([startLine=1][, endLine=MCDU.NUM_LINES])

Prints information about each display cell in the following order:

  • Display index

  • Position in the line

  • The character

  • The code of the character

  • Color

  • Whether it's bold

Parameters:

  • startLine int (default 1)
  • endLine int (default MCDU.NUM_LINES)
generated by LDoc 1.4.6 Last updated 2021-11-11 17:10:49