Simulation Instruments

Home›All functions›Switch

Switch

Simulation Instrument Studio 1

switch_add

Simulation Instrument Studio 1

Definition

switch_id = switch_add(img_pos_0, img_pos_1, ..., x, y, width, height, click_callback)

Remarks

Add a multi-position switch. Callback receives the new position.

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_set_position

Simulation Instrument Studio 1

Definition

switch_set_position(switch_id, position)

Remarks

Set the switch to a certain position.

Parameters

NameDescription
switch_idId returned by the call that created the object.
positionPosition from 0 to 1, or a switch index.

Example

No sample instrument calls this yet.

switch_set_position(switch_id, position)
Photo slot: shots/switch_set_position.png

switch_get_position

Simulation Instrument Studio 1

Definition

position = switch_get_position(switch_id)

Remarks

Get the current switch position.

Example

No sample instrument calls this yet.

switch_get_position()
Photo slot: shots/switch_get_position.png

touch_setting

Simulation Instrument Studio 1

Definition

touch_setting(node_id, property, value)

Remarks

Sets touch settings for a switch/dial/scrollwheel.

Parameters

NameDescription
node_idId returned by the call that created the object.
propertyTop position in instrument pixels.
valueThe value to write.

Example

No sample instrument calls this yet.

touch_setting(node_id, property, value)
Photo slot: shots/touch_setting.png