Simulation Instruments

Home›All functions›Controls

Controls

Simulation Instrument Studio 1

button_add

Simulation Instrument Studio 1

Overloads

button_add(img_normal, img_pressed, x, y, width, height, click_press_callback, click_release_callback)

Places a button. The callback runs on press and release.

Parameters

#NameTypeDescription
1img_normalStringThis is the filename of the image you would like to show on your button. Note that this is both filename and extension. Its good practice to always use PNG format for images. JPG and BMP are also supported, but not recommended.
2img_pressedStringThis is the filename of the image you would like to show on your button when the used presses it. Note that this is both filename and extension. Its good practice to always use PNG format for images. JPG and BMP are also supported, but not recommended. This field is optional, you can also provide it with 'nil'.
3xNumberThis is the most left point of the canvas where your button should be shown.
4yNumberThis is the most top point of the canvas where your button should be shown.
5widthNumberThe button width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the button.
6heightNumberThe button height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the button.
7click_press_callbackFunctionThis function will be called when the button is being pressed.
8click_release_callbackFunctionThis function will be called when the button is being released. (Optional)

Example

-- Ident button. Callback gets the button id and true on press.
ident = button_add("ident_up.png", "ident_down.png", 180, 200, 48, 32, function(id, pressed)
    if pressed then
        xpl_command("sim/instruments/transponder_ident")
    end
end)
Photo slot: shots/button_add.png

switch_add

Simulation Instrument Studio 1

Overloads

switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height)
switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height, position_callback)
switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height, position_callback, pressed_callback)
switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height, position_callback, pressed_callback, released_callback)
switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height, mode)
switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height, mode, position_callback)
switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height, mode, position_callback, pressed_callback)
switch_add(img_pos_0, img_pos_1, img_pos_n, x, y, width, height, mode, position_callback, pressed_callback, released_callback)

Places a switch with one image per position.

Parameters

#NameTypeDescription
1img_pos_0StringThe image for the first position. Note that this is both filename and extension. Its good practice to always use PNG format for images. JPG and BMP are also supported, but not recommended.
2img_pos_1StringThe image for the second position
nimg_pos_nStringThe image for all other positions you might need. This is limitless
n+1xNumberThis is the most left point of the canvas where your switch should be shown.
n+2yNumberThis is the most top point of the canvas where your switch should be shown.
n+3widthStringThe switch width
n+4heightStringThe switch height
n+5modeString(Optional) The Switch mode. Can be 'CIRCULAR', 'PRESS', 'HORIZONTAL' or 'VERTICAL'.
n+6position_callbackString(Optional from AM/) This function will be called when the switch changed position.
n+7pressed_callbackString(Optional) This function will be called when the switch is being pressed.
n+8released_callbackString(Optional) This function will be called when the switch is being released.

Example: the simulator drives the switch

A click sends a command. The picture does not move until the sim reports the new key position. Every panel then shows the same key.

-- The simulator owns the key. A click asks for a new position.
-- The picture moves only when the sim reports the key.
-- 0 Off, 1 Mag 1, 2 Mag 2, 3 Both, 4 Start.

function on_click(position, direction)
    local next_pos = position + direction
    if next_pos < 0 or next_pos > 4 then
        return
    end
    if next_pos == 0 then xpl_command("sim/magnetos/magnetos_off_1") end
    if next_pos == 1 then xpl_command("sim/magnetos/magnetos_left_1") end
    if next_pos == 2 then xpl_command("sim/magnetos/magnetos_right_1") end
    if next_pos == 3 then xpl_command("sim/magnetos/magnetos_both_1") end
    if next_pos == 4 then xpl_command("sim/starters/engage_starter_1") end
end

function on_key(key)
    switch_set_position(ignition, key)
end

ignition = switch_add("ign_off.png", "ign_mag1.png", "ign_mag2.png", "ign_both.png", "ign_start.png", 40, 180, 48, 48, on_click)
xpl_dataref_subscribe("sim/cockpit2/engine/actuators/ignition_key[0]", "INT", on_key)

Example: the switch drives the simulator

A click moves the key, then writes that position. Use this when the instrument is the control, not a mirror.

-- The switch owns the key. A click moves it, then tells the sim.
-- 0 Off, 1 Mag 1, 2 Mag 2, 3 Both, 4 Start.

function on_click(position, direction)
    local next_pos = position + direction
    if next_pos < 0 then next_pos = 0 end
    if next_pos > 4 then next_pos = 4 end
    switch_set_position(ignition, next_pos)
    xpl_dataref_write("sim/cockpit2/engine/actuators/ignition_key[0]", "INT", next_pos)
end

ignition = switch_add("ign_off.png", "ign_mag1.png", "ign_mag2.png", "ign_both.png", "ign_start.png", 40, 180, 48, 48, on_click)
Photo slot: shots/switch_add.png

switch_get_position

Simulation Instrument Studio 1

Overloads

switch_get_position(hw_switch_id)

Returns the switch position.

Parameters

#NameTypeDescription
1switch_idObjectThe is the reference to the switch. You can get this reference from the switch_add function.

Example

pos = switch_get_position(battery)
if pos == 0 then
    log("battery is off")
end
Photo slot: shots/switch_get_position.png

switch_set_position

Simulation Instrument Studio 1

Overloads

switch_set_position(switch_id,position)

Sets the switch position and shows that image.

Parameters

#NameTypeDescription
1switch_idNumberReference to the switch
2positionNumberThe position you want to switch to get.

Example

-- Restore the last saved battery position
switch_set_position(battery, 1)
Photo slot: shots/switch_set_position.png

dial_add

Simulation Instrument Studio 1

Overloads

dial_add(image, x, y, width, height, direction_callback)
dial_add(image, x, y, width, height, direction_callback, pressed_callback)
dial_add(image, x, y, width, height, direction_callback, pressed_callback, released_callback)
dial_add(image, x, y, width, height, acceleration, direction_callback)
dial_add(image, x, y, width, height, acceleration, direction_callback, pressed_callback)
dial_add(image, x, y, width, height, acceleration, direction_callback, pressed_callback, released_callback)

Places a knob. The callback receives the turn direction.

Parameters

#NameTypeDescription
1imageStringThis is the filename of the image you would like to show on your dial. Note that this is both filename and extension. Its good practice to always use PNG format for images. JPG and BMP are also supported, but not recommended.
2xNumberThis is the most left point of the canvas where your dial should be shown.
3yNumberThis is the most top point of the canvas where your dial should be shown.
4widthNumberThe dial width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the dial.
5heightNumberThe dial height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the dial.
6accelerationNumber(Optional) A multiplier that will make the dial generate extra callbacks when the dial is being rotated faster. The multiplier is the maximum number of callbacks of one dial tick when this dial is being rotated at maximum speed.
7direction_callbackFunctionThis function will be called when dial is being rotated. The function will give one argument, which will provide with a value telling which way the dial is being turned (1=clockwise, -1=counter-clockwise).
8pressed_callbackFunction(Optional) This function will be called when the dial is being pressed.
9released_callbackFunction(Optional) This function will be called when the dial is being released.

Example

-- Heading bug. direction is 1 or -1.
bug = dial_add("bug.png", 100, 100, 40, 40, function(direction)
    heading_bug = heading_bug + direction
    rotate(bug, heading_bug)
end)
Photo slot: shots/dial_add.png

dial_set_acceleration

Simulation Instrument Studio 1

Overloads

dial_set_acceleration(dial_id, acceleration)

Sets how fast a dial accelerates while it is held.

Parameters

#NameTypeDescription
1dial_addIDDial identifier. This can be obtained by calling dial_add.
2accelerationNumberA multiplier that will make the dial generate extra callbacks when the dial is being rotated faster. The multiplier is the maximum number of callbacks of one dial tick when this dial is being rotated at maximum speed.

Example

-- A long hold on the heading bug speeds up
dial_set_acceleration(bug, 2)
Photo slot: shots/dial_set_acceleration.png

slider_add_cir

Simulation Instrument Studio 1

Overloads

slider_add_cir(image, x, y, width, height, radius, start_angle, end_angle, thumb_image, thumb_width, thumb_height, position_callback)
slider_add_cir(image, x, y, width, height, radius, start_angle, end_angle, thumb_image, thumb_width, thumb_height, position_callback, pressed_callback)
slider_add_cir(image, x, y, width, height, radius, start_angle, end_angle, thumb_image, thumb_width, thumb_height, position_callback, pressed_callback, released_callback)

Places a slider.

Parameters

#NameTypeDescription
1imageStringThe background image. Note that this is both filename and extension. Only PNG files are accepted.
2xNumberThis is the most left point of the canvas where your slider should be shown.
3yNumberThis is the most top point of the canvas where your slider should be shown.
4widthNumberThe slider width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider.
5heightNumberThe slider height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider.
6radiusNumberThe distance between the center of the slider and the center of the thumb.
7start_angleNumberThe start angle where the slider starts, in degrees. This position is determined as 0.0.
8end_angleNumberThe end angle where the slider ends, in degrees. This position is determined as 1.0.
9thumb_imageStringThe thumb image. Note that this is both filename and extension. Only PNG files are accepted.
10thumb_widthNumberThe slider thumb width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider thumb.
11thumb_heightNumberThe slider thumb height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider thumb.
12position_callbackFunctionThis function will be called when the slider changed position. The position ranges from 0.0 to 1.0.
13pressed_callbackFunction(Optional) This function will be called when the slider is being pressed.
14released_callbackFunction(Optional) This function will be called when the slider is being released.

Example

-- A round trim wheel
trim = slider_add_cir(160, 160, 50, -1, 1, function(v)
    rotate(trim_mark, v * 40)
end)

Example: a stop, and an endless ring

-- Mixture. Travel is the bottom half, 90 to 270 degrees.
function on_mix(pos)
    xpl_dataref_write("sim/cockpit2/engine/actuators/mixture_ratio[0]", "FLOAT", pos)
end
mixture = slider_add_cir("ring.png", 20, 20, 160, 160, 70, 90, 270, "thumb.png", 16, 28, on_mix)

-- Heading bug. No end angle, so it keeps turning.
function on_bug(pos)
    rotate(bug, pos * 360)
end
bug = slider_add_cir("ring.png", 200, 20, 160, 160, 70, 0, nil, "thumb.png", 16, 28, on_bug)
Photo slot: shots/slider_add_cir.png

slider_add_hor

Simulation Instrument Studio 1

Overloads

slider_add_hor(image, x, y, width, height, thumb_image, thumb_width, thumb_height, position_callback)
slider_add_hor(image, x, y, width, height, thumb_image, thumb_width, thumb_height, position_callback, pressed_callback)
slider_add_hor(image, x, y, width, height, thumb_image, thumb_width, thumb_height, position_callback, pressed_callback, released_callback)

Places a slider.

Parameters

#NameTypeDescription
1imageStringThe background image. Note that this is both filename and extension. Only PNG files are accepted.
2xNumberThis is the most left point of the canvas where your slider should be shown.
3yNumberThis is the most top point of the canvas where your slider should be shown.
4widthNumberThe slider width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider.
5heightNumberThe slider height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider.
6thumb_imageStringThe thumb image. This is the image that is moved. Note that this is both filename and extension. Only PNG files are accepted.
7thumb_widthNumberThe slider thumb width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider thumb.
8thumb_heightNumberThe slider thumb height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider thumb.
9position_callbackFunctionThis function will be called when the user want to change position. Position ranges from 0.0 to 1.0. Note that you have to set the actual position of the slider with function slider_set_position.
10pressed_callbackFunction(Optional) This function will be called when the slider is being pressed.
11released_callbackFunction(Optional) This function will be called when the slider is being released.

Example

-- Dimmer, left is night, right is day
dimmer = slider_add_hor(20, 220, 160, 16, 0, 1, function(v)
    opacity(face, v)
end)
Photo slot: shots/slider_add_hor.png

slider_add_ver

Simulation Instrument Studio 1

Overloads

slider_add_ver(image, x, y, width, height, tick_image, tick_width, tick_height, position_callback)
slider_add_ver(image, x, y, width, height, tick_image, tick_width, tick_height, position_callback, pressed_callback)
slider_add_ver(image, x, y, width, height, tick_image, tick_width, tick_height, position_callback, pressed_callback, released_callback)

Places a slider.

Parameters

#NameTypeDescription
1imageStringThe background image. Note that this is both filename and extension. Only PNG files are accepted.
2xNumberThis is the most left point of the canvas where your slider should be shown.
3yNumberThis is the most top point of the canvas where your slider should be shown.
4widthNumberThe slider width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider.
5heightNumberThe slider height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider.
6tick_imageStringThe tick image. Note that this is both filename and extension. Only PNG files are accepted.
7tick_widthNumberThe slider tick width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider tick.
8tick_heightNumberThe slider tick height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the slider tick.
9position_callbackFunctionThis function will be called when the user want to change position. Position ranges from 0.0 to 1.0. Note that you have to set the actual position of the slider with function slider_set_position.
10pressed_callbackFunction(Optional) This function will be called when the slider is being pressed.
11released_callbackFunction(Optional) This function will be called when the slider is being released.

Example

-- Cabin altitude set, bottom is 0
cabin = slider_add_ver(210, 20, 16, 140, 0, 10000, function(ft)
    txt_set(cabin_txt, tostring(math.floor(ft)))
end)
Photo slot: shots/slider_add_ver.png

slider_set_position

Simulation Instrument Studio 1

Overloads

slider_set_position(slider_id,position)

Sets the slider position, from 0 to 1.

Parameters

#NameTypeDescription
1slider_idStringReference to the slider
2positionNumberThe position you want to slider to get.

Example

-- Center the trim on launch
slider_set_position(trim, 0)
Photo slot: shots/slider_set_position.png

scrollwheel_add_hor

Simulation Instrument Studio 1

Overloads

scrollwheel_add_hor(segment_image, x, y, width, height, segment_width, segment_height, direction_callback)
scrollwheel_add_hor(segment_image, x, y, width, height, segment_width, segment_height, direction_callback, pressed_callback)
scrollwheel_add_hor(segment_image, x, y, width, height, segment_width, segment_height, direction_callback, pressed_callback, released_callback)

Places a scroll wheel. The callback receives the scroll direction.

Parameters

#NameTypeDescription
1segment_imageStringThe segment image. The scroll wheel is drawn by repeating a certain segment image. Make sure to design this segment image to pit perfectly next to each other. Note that this is both filename and extension. Only PNG files are accepted.
2xNumberThis is the most left point of the canvas where your scroll wheel should be shown.
3yNumberThis is the most top point of the canvas where your scroll wheel should be shown.
4widthNumberThe scroll wheel width on the canvas.
5heightNumberThe scroll wheel height on the canvas.
7segment_widthNumberThe scroll wheel segment width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the scroll wheel segment.
8segment_heightNumberThe scroll wheel segment height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the scroll wheel segment.
9direction_callbackFunctionThis function will be called when the user manipulates the scroll wheel. A direction argument is supplied, where -1 is scrolled left, and 1 is scrolled right.
10pressed_callbackFunction(Optional) This function will be called when the scroll wheel is being pressed.
11released_callbackFunction(Optional) This function will be called when the scroll wheel is being released.

Example

-- Scroll the comm frequency
comm = scrollwheel_add_hor(40, 180, 120, 28, function(dir)
    freq = freq + dir * 0.025
end)
Photo slot: shots/scrollwheel_add_hor.png

scrollwheel_add_ver

Simulation Instrument Studio 1

Overloads

scrollwheel_add_ver(segment_image, x, y, width, height, segment_width, segment_height, direction_callback)
scrollwheel_add_ver(segment_image, x, y, width, height, segment_width, segment_height, direction_callback, pressed_callback)
scrollwheel_add_ver(segment_image, x, y, width, height, segment_width, segment_height, direction_callback, pressed_callback, released_callback)

Places a scroll wheel. The callback receives the scroll direction.

Parameters

#NameTypeDescription
1segment_imageStringThe segment image. The scroll wheel is drawn by repeating a certain segment image. Make sure to design this segment image to fit perfectly next to each other. Note that this is both filename and extension. Only PNG files are accepted.
2xNumberThis is the most left point of the canvas where your scroll wheel should be shown.
3yNumberThis is the most top point of the canvas where your scroll wheel should be shown.
4widthNumberThe scroll wheel width on the canvas.
5heightNumberThe scroll wheel height on the canvas.
7segment_widthNumberThe scroll wheel segment width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the scroll wheel segment.
8segment_heightNumberThe scroll wheel segment height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the scroll wheel segment.
9direction_callbackFunctionThis function will be called when the user manipulates the scroll wheel. A direction argument is supplied, where -1 is scrolled up, and 1 is scrolled down.
10pressed_callbackFunction(Optional) This function will be called when the scroll wheel is being pressed.
11released_callbackFunction(Optional) This function will be called when the scroll wheel is being released.

Example

-- Scroll the altitude preselect, 100 ft a click
alt_sel = scrollwheel_add_ver(200, 40, 28, 80, function(dir)
    target = target + dir * 100
end)
Photo slot: shots/scrollwheel_add_ver.png

hw_button_add

Simulation Instrument Studio 1

Overloads

hw_button_add()
Photo slot: shots/hw_button_add.png

hw_switch_add

Simulation Instrument Studio 1

Overloads

hw_switch_add()
Photo slot: shots/hw_switch_add.png

hw_switch_get_position

Simulation Instrument Studio 1

Overloads

hw_switch_get_position(hw_switch_id)

A hardware pin call. It talks to a board on USB serial or TCP 4731.

Parameters

#NameTypeDescription
1hw_switch_idObjectThe is the reference to the switch. You can get this reference from the hw_switch_add function.

Example

-- Pin on the board at 4731
id = hw_switch_get_position(0)
Photo slot: shots/hw_switch_get_position.png