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
#
Name
Type
Description
1
img_normal
String
This 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.
2
img_pressed
String
This 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'.
3
x
Number
This is the most left point of the canvas where your button should be shown.
4
y
Number
This is the most top point of the canvas where your button should be shown.
5
width
Number
The 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.
6
height
Number
The 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.
7
click_press_callback
Function
This function will be called when the button is being pressed.
8
click_release_callback
Function
This 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
#
Name
Type
Description
1
img_pos_0
String
The 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.
2
img_pos_1
String
The image for the second position
n
img_pos_n
String
The image for all other positions you might need. This is limitless
n+1
x
Number
This is the most left point of the canvas where your switch should be shown.
n+2
y
Number
This is the most top point of the canvas where your switch should be shown.
n+3
width
String
The switch width
n+4
height
String
The switch height
n+5
mode
String
(Optional) The Switch mode. Can be 'CIRCULAR', 'PRESS', 'HORIZONTAL' or 'VERTICAL'.
n+6
position_callback
String
(Optional from AM/) This function will be called when the switch changed position.
n+7
pressed_callback
String
(Optional) This function will be called when the switch is being pressed.
n+8
released_callback
String
(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
#
Name
Type
Description
1
switch_id
Object
The is the reference to the switch. You can get this reference from the switch_add function.
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
#
Name
Type
Description
1
image
String
This 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.
2
x
Number
This is the most left point of the canvas where your dial should be shown.
3
y
Number
This is the most top point of the canvas where your dial should be shown.
4
width
Number
The 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.
5
height
Number
The 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.
6
acceleration
Number
(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.
7
direction_callback
Function
This 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).
8
pressed_callback
Function
(Optional) This function will be called when the dial is being pressed.
9
released_callback
Function
(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
#
Name
Type
Description
1
dial_add
ID
Dial identifier. This can be obtained by calling dial_add.
2
acceleration
Number
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.
The background image. Note that this is both filename and extension. Only PNG files are accepted.
2
x
Number
This is the most left point of the canvas where your slider should be shown.
3
y
Number
This is the most top point of the canvas where your slider should be shown.
4
width
Number
The 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.
5
height
Number
The 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.
6
radius
Number
The distance between the center of the slider and the center of the thumb.
7
start_angle
Number
The start angle where the slider starts, in degrees. This position is determined as 0.0.
8
end_angle
Number
The end angle where the slider ends, in degrees. This position is determined as 1.0.
9
thumb_image
String
The thumb image. Note that this is both filename and extension. Only PNG files are accepted.
10
thumb_width
Number
The 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.
11
thumb_height
Number
The 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.
12
position_callback
Function
This function will be called when the slider changed position. The position ranges from 0.0 to 1.0.
13
pressed_callback
Function
(Optional) This function will be called when the slider is being pressed.
14
released_callback
Function
(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
#
Name
Type
Description
1
image
String
The background image. Note that this is both filename and extension. Only PNG files are accepted.
2
x
Number
This is the most left point of the canvas where your slider should be shown.
3
y
Number
This is the most top point of the canvas where your slider should be shown.
4
width
Number
The 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.
5
height
Number
The 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.
6
thumb_image
String
The thumb image. This is the image that is moved. Note that this is both filename and extension. Only PNG files are accepted.
7
thumb_width
Number
The 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.
8
thumb_height
Number
The 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.
9
position_callback
Function
This 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.
10
pressed_callback
Function
(Optional) This function will be called when the slider is being pressed.
11
released_callback
Function
(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
#
Name
Type
Description
1
image
String
The background image. Note that this is both filename and extension. Only PNG files are accepted.
2
x
Number
This is the most left point of the canvas where your slider should be shown.
3
y
Number
This is the most top point of the canvas where your slider should be shown.
4
width
Number
The 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.
5
height
Number
The 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.
6
tick_image
String
The tick image. Note that this is both filename and extension. Only PNG files are accepted.
7
tick_width
Number
The 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.
8
tick_height
Number
The 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.
9
position_callback
Function
This 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.
10
pressed_callback
Function
(Optional) This function will be called when the slider is being pressed.
11
released_callback
Function
(Optional) This function will be called when the slider is being released.
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
#
Name
Type
Description
1
segment_image
String
The 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.
2
x
Number
This is the most left point of the canvas where your scroll wheel should be shown.
3
y
Number
This is the most top point of the canvas where your scroll wheel should be shown.
4
width
Number
The scroll wheel width on the canvas.
5
height
Number
The scroll wheel height on the canvas.
7
segment_width
Number
The 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.
8
segment_height
Number
The 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.
9
direction_callback
Function
This 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.
10
pressed_callback
Function
(Optional) This function will be called when the scroll wheel is being pressed.
11
released_callback
Function
(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
#
Name
Type
Description
1
segment_image
String
The 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.
2
x
Number
This is the most left point of the canvas where your scroll wheel should be shown.
3
y
Number
This is the most top point of the canvas where your scroll wheel should be shown.
4
width
Number
The scroll wheel width on the canvas.
5
height
Number
The scroll wheel height on the canvas.
7
segment_width
Number
The 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.
8
segment_height
Number
The 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.
9
direction_callback
Function
This 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.
10
pressed_callback
Function
(Optional) This function will be called when the scroll wheel is being pressed.
11
released_callback
Function
(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
#
Name
Type
Description
1
hw_switch_id
Object
The is the reference to the switch. You can get this reference from the hw_switch_add function.