5 position rotary switch that act as Magneto switch integration
5 position rotary switch that act as Magneto switch integration
Hi.
I'm looking for the best way to integrate a 5 position rotary switch that act as Magneto switch inside my DIY cockpit. I'm just using Arduino and Air Manager.
Any idea?
Thanks in advance
I'm looking for the best way to integrate a 5 position rotary switch that act as Magneto switch inside my DIY cockpit. I'm just using Arduino and Air Manager.
Any idea?
Thanks in advance
Re: 5 position rotary switch that act as Magneto switch integration
Use the pre made hardware function?
-
- Posts: 5339
- Joined: Thu Jul 27, 2017 12:22 am
Re: 5 position rotary switch that act as Magneto switch integration
Personal sample (X-Plane only) :
Ralph's suggested sample for multiple sims :
Code: Select all
function pr_starter(starter_state)
xpl_dataref_write("sim/cockpit2/engine/actuators/ignition_key","INT[8]", {starter_state}, 0)
if starter_state == 4 then
xpl_command("sim/starters/engage_start_run")
xpl_command("sim/operation/auto_start")
end
end
hw_sw_starter = hw_switch_add("MAGNETOS KEY", 5,
pr_starter)
if (hw_switch_get_position(hw_sw_starter) ~= nil) then
key_pos = hw_switch_get_position(hw_sw_starter)
xpl_dataref_write("sim/cockpit2/engine/actuators/ignition_key","INT[8]", key_pos, 0)
end
Code: Select all
prop_engine = user_prop_add_integer("Engine number", 1, 4, 1, "Choose the engine number for this switch")
prop_magneto = user_prop_add_enum("Magneto order", "LEFT/RIGHT/BOTH,RIGHT/LEFT/BOTH", "LEFT/RIGHT/BOTH", "Choose the order of your magnetos")
prop_lastpos = user_prop_add_enum("Last position", "Starter,Primer", "Starter", "Choose the function of the last position")
local engn = user_prop_get(prop_engine)
local mago = fif(user_prop_get(prop_magneto) == "LEFT/RIGHT/BOTH", 0, 1)
function starter_pressed()
xpl_command("sim/starters/engage_starter_" .. engn, 1)
fsx_event("MAGNETO" .. engn .. "_START")
fs2020_event("MAGNETO" .. engn .. "_START")
end
function starter_released()
xpl_command("sim/starters/engage_starter_" .. engn, 0)
end
if user_prop_get(prop_lastpos) == "Primer" then
hw_button_add("Starter button", starter_pressed, starter_released)
end
hw_switch_add("Magneto switch", 5, function(position, direction)
if position == 0 then
xpl_command("sim/magnetos/magnetos_off_" .. engn)
fsx_event("MAGNETO" .. engn .. "_OFF")
fs2020_event("MAGNETO" .. engn .. "_OFF")
elseif position == 1 then
if mago == 0 then
xpl_command("sim/magnetos/magnetos_left_" .. engn)
fsx_event("MAGNETO" .. engn .. "_LEFT")
fs2020_event("MAGNETO" .. engn .. "_LEFT")
else
xpl_command("sim/magnetos/magnetos_right_" .. engn)
fsx_event("MAGNETO" .. engn .. "_RIGHT")
fs2020_event("MAGNETO" .. engn .. "_RIGHT")
end
elseif position == 2 then
if mago == 0 then
xpl_command("sim/magnetos/magnetos_right_" .. engn)
fsx_event("MAGNETO" .. engn .. "_RIGHT")
fs2020_event("MAGNETO" .. engn .. "_RIGHT")
else
xpl_command("sim/magnetos/magnetos_left_" .. engn)
fsx_event("MAGNETO" .. engn .. "_LEFT")
fs2020_event("MAGNETO" .. engn .. "_LEFT")
end
elseif position == 3 then
if user_prop_get(prop_lastpos) == "Starter" then
xpl_command("sim/starters/engage_starter_" .. engn, 0)
else
xpl_command("sim/fuel/fuel_pump_" .. engn .. "_prime", 0)
fsx_event("TOGGLE_PRIMER" .. engn)
fs2020_event("TOGGLE_PRIMER" .. engn)
end
xpl_command("sim/magnetos/magnetos_both_" .. engn)
fsx_event("MAGNETO" .. engn .. "_BOTH")
fs2020_event("MAGNETO" .. engn .. "_BOTH")
elseif position == 4 then
if user_prop_get(prop_lastpos) == "Starter" then
xpl_command("sim/starters/engage_starter_" .. engn, 1)
fsx_event("MAGNETO" .. engn .. "_START")
fs2020_event("MAGNETO" .. engn .. "_START")
else
xpl_command("sim/fuel/fuel_pump_" .. engn .. "_prime", 1)
fsx_event("TOGGLE_PRIMER" .. engn)
fs2020_event("TOGGLE_PRIMER" .. engn)
end
end
end)
Re: 5 position rotary switch that act as Magneto switch integration
Hi, thanks for your reply.
I don't understand what is this code and where must I put in.
Could you be clearer?
-
- Posts: 5339
- Joined: Thu Jul 27, 2017 12:22 am
Re: 5 position rotary switch that act as Magneto switch integration
The first sample is in the case you are creating your own instrument and script through the [Create/Edit] tab in Air manager and the second one is the extract of the existing Hardware instrument you can use straight forward by adding it to any panel
-
- Posts: 5339
- Joined: Thu Jul 27, 2017 12:22 am
Re: 5 position rotary switch that act as Magneto switch integration
Right, there's 5 positions on the Magnetos Key, so we have to use 5 input, otherwise it wouldn't work : OFF, RIGHT, LEFT, BOTH, START
Re: 5 position rotary switch that act as Magneto switch integration
Ok. I'll try. ThanksThe first sample is in the case you are creating your own instrument and script through the [Create/Edit] tab in Air manager and the second one is the extract of the existing Hardware instrument you can use straight forward by adding it to any panel
Re: 5 position rotary switch that act as Magneto switch integration
Ok. ThanksRight, there's 5 positions on the Magnetos Key, so we have to use 5 input, otherwise it wouldn't work : OFF, RIGHT, LEFT, BOTH, START
Re: 5 position rotary switch that act as Magneto switch integration
You don’t have to use 5 inputs if you are really desperate to save I/o pins. You can save one input and not use one for off if the code is re-written. More work though for not much gain.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D