5 position rotary switch that act as Magneto switch integration

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
m4biz
Posts: 27
Joined: Thu Aug 25, 2022 4:45 pm

5 position rotary switch that act as Magneto switch integration

#1 Post by m4biz »

Hi.
I'm looking for the best way to integrate a 5 position rotary switch that act as Magneto switch inside my DIY cockpit.
magneto.png
magneto.png (151.04 KiB) Viewed 1675 times
rotatory.png
rotatory.png (153.09 KiB) Viewed 1675 times
I'm just using Arduino and Air Manager.
Any idea?
Thanks in advance

User avatar
Ralph
Posts: 7924
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: 5 position rotary switch that act as Magneto switch integration

#2 Post by Ralph »

Use the pre made hardware function?

SimPassion
Posts: 5339
Joined: Thu Jul 27, 2017 12:22 am

Re: 5 position rotary switch that act as Magneto switch integration

#3 Post by SimPassion »

Personal sample (X-Plane only) :

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
Ralph's suggested sample for multiple sims :

image.png

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)

m4biz
Posts: 27
Joined: Thu Aug 25, 2022 4:45 pm

Re: 5 position rotary switch that act as Magneto switch integration

#4 Post by m4biz »

Ralph wrote: Fri Jun 02, 2023 9:22 am Use the pre made hardware function?
Hi Ralph, thanks for you reply.
I've found what you say:
But the question is: must I use N. 5 input channel on my Arduino board?
By this way would reamin very few input channels for other uses.
2023-03-07_111722.png

m4biz
Posts: 27
Joined: Thu Aug 25, 2022 4:45 pm

Re: 5 position rotary switch that act as Magneto switch integration

#5 Post by m4biz »

SimPassion wrote: Fri Jun 02, 2023 10:49 am Personal sample (X-Plane only) :
Hi, thanks for your reply.
I don't understand what is this code and where must I put in.
Could you be clearer?

SimPassion
Posts: 5339
Joined: Thu Jul 27, 2017 12:22 am

Re: 5 position rotary switch that act as Magneto switch integration

#6 Post by SimPassion »

m4biz wrote: Fri Jun 02, 2023 3:58 pm
SimPassion wrote: Fri Jun 02, 2023 10:49 am Personal sample (X-Plane only) :
Hi, thanks for your reply.
I don't understand what is this code and where must I put in.
Could you be clearer?
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

SimPassion
Posts: 5339
Joined: Thu Jul 27, 2017 12:22 am

Re: 5 position rotary switch that act as Magneto switch integration

#7 Post by SimPassion »

m4biz wrote: Fri Jun 02, 2023 2:35 pm
Ralph wrote: Fri Jun 02, 2023 9:22 am Use the pre made hardware function?
Hi Ralph, thanks for you reply.
I've found what you say:
But the question is: must I use N. 5 input channel on my Arduino board?
By this way would reamin very few input channels for other uses.
2023-03-07_111722.png
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

m4biz
Posts: 27
Joined: Thu Aug 25, 2022 4:45 pm

Re: 5 position rotary switch that act as Magneto switch integration

#8 Post by m4biz »

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
Ok. I'll try. Thanks

m4biz
Posts: 27
Joined: Thu Aug 25, 2022 4:45 pm

Re: 5 position rotary switch that act as Magneto switch integration

#9 Post by m4biz »

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
Ok. Thanks

User avatar
Sling
Posts: 5239
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: 5 position rotary switch that act as Magneto switch integration

#10 Post by Sling »

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.

Post Reply