MSFS2020 - Manage switch with AirManager & Arduino

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
PilotOlivier
Posts: 12
Joined: Sun Aug 07, 2022 7:17 pm

Re: MSFS2020 - Manage switch with AirManager & Arduino

#11 Post by PilotOlivier »

Thank you so much for your contribution... I understand better and I discovered the BehaviourBug tool the one I need to progress

As you understood, I use the new addon of JustFlgiht "Steam Gauge Overhaul - Analog King Air".

BEACON_LIGHTS_ON & BEACON_LIGHTS_OFF work well (the switch moves in the virtual cockpit and the beacon turns on or off)

To better understand, do you know what the different colors (yellow, purple, blue and green) in BehaviorDebug correspond to?
Capture d’écran 2022-11-01 162742.png
I understand that you prefer to use the EVENT "LIGHT BEACON:1" why this one? and how do we know that it is a BOOL type?

You indicate position==1 .... position==0 also works, I don't understand the logic, do you have any explanation?

Thank you by advance for your support. The topic is helping me a lot and will help all simmers for sure !!
Pilot Olivier

MSFS 2020 - KIng Air 350i - Steam Gauge Overhaul - Analog King Air
Air Manager - SPAD.neXt
Arduino MEGA2560

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

Re: MSFS2020 - Manage switch with AirManager & Arduino

#12 Post by SimPassion »

PilotOlivier wrote: Tue Nov 01, 2022 3:30 pm .../... do you know what the different colors (yellow, purple, blue and green) in BehaviorDebug correspond to?
https://docs.flightsimulator.com/html/D ... nputevents

The registered presets can be expanded by clicking on them to show available preset sections, and each section can be expanded to show the contents of the preset. In the image below, the Electrical section has been expanded and within that the preset ELECTRICAL_Battery_1 is shown:

Image

For each preset, some or all of the following items will be show, coded by color:

Yellow: The default input event registers, <Inc> (increment), Dec (decrement) and <Set>.
Purple: These are registers specific to the preset being examined and are not part of the defaults.
Light Blue: These are the different Key Events that are being intercepted by the preset.
Light Green: This is the SimVar that is being watched and that forces the <Init> to run when it is modified.



I understand that you prefer to use the EVENT "LIGHT BEACON:1" why this one? and how do we know that it is a BOOL type?
You mentioned the LIGHTING_BEACON_1 didn't worked for you, I've also checked at first only based on your original post and indeed it didn't worked for me too. The reason is LIGHTING_BEACON_1 isn't a variable, but rather a preset name. Again, I've highlighted in green the variable name in the screenshot already posted, which bring the variable name itself which is "LIGHT BEACON:1". Again, "LIGHT BEACON:1" is not an event, but rather a variable. Now while testing, I've seen the different values reported as 1.000 or 0.000 (FLOATS values), which would also correspond to 1 = True or 0 = False and this was the case, as using the "FLOAT" parameter didn't worked. The statement is the values are internally translated from Boolean to Float, to bring only numeric representation. Once replaced by a boolean result, bingo the expected behavior occurs in the sim ... So, it's like a try and check : it works, good catch, it don't work, this means the designer did in another way we have to find ...

Image

You indicate position==1 .... position==0 also works, I don't understand the logic, do you have any explanation?
We know we need True or False result. In the case position is 1, the check "if position == 1" will return True and in the case position is 0, the check "if position == 1" will return False. This fulfill the need and in the "fs2020_variable_write("LIGHT BEACON:1","Bool",position == 1)", we have shortened the initial check by removing the "if" and put there an implicit construction which replace a variable or static value. In real time it will be replaced by the result, which will be written to the related simulator variable

.../...
I hope all is clarified and understandable, let me know if this have to be simplified again and requires more explanation
 
Last edited by SimPassion on Wed Nov 02, 2022 9:25 am, edited 1 time in total.

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

Re: MSFS2020 - Manage switch with AirManager & Arduino

#13 Post by Sling »

For specifically hardware only scripts the separate on and off events are the easiest but in many cases they are not provided and in the case of a software switch a toggle event is easier. Even with hardware the toggle event can be made to work if necessary with a little bit of extra code to keep the sim in sync with the hardware.

BTW not all of those coloured items can be accessed externally from the sim currently. Generally you are safe with the cyan and green but not all aircraft have accessible control for everything and you may find cases when there are no options that work with external control. This is related to the B,I,O var issues.

User avatar
PilotOlivier
Posts: 12
Joined: Sun Aug 07, 2022 7:17 pm

Re: MSFS2020 - Manage switch with AirManager & Arduino

#14 Post by PilotOlivier »

Hi SimPassion & Sling

Thank you so much for your explanations, time is coming to apply your advices.
Pilot Olivier

MSFS 2020 - KIng Air 350i - Steam Gauge Overhaul - Analog King Air
Air Manager - SPAD.neXt
Arduino MEGA2560

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

Re: MSFS2020 - Manage switch with AirManager & Arduino

#15 Post by SimPassion »

PilotOlivier wrote: Wed Nov 02, 2022 9:00 am Hi SimPassion & Sling

Thank you so much for your explanations, time is coming to apply your advices.
I have no time to go further previously, so here's now an additional sample based on Tony's advice using the TOGGLE statement (tested working with default KA 350i) :

Code: Select all

local sim_swstate = false

function pr_sim_switch_state(sw_state)
	sim_swstate = sw_state
	print("In-sim switch state " .. tostring(sim_swstate))
end

fs2020_variable_subscribe("LIGHT BEACON:1","Bool",pr_sim_switch_state)

function switch_A1(position)
-- Toggle only if both position and sim_swstate are different	
	if position == 0 and sim_swstate == true then
		fs2020_event("TOGGLE_BEACON_LIGHTS")
	elseif position == 1 and sim_swstate == false then
		fs2020_event("TOGGLE_BEACON_LIGHTS")
	end
	print("Switch A1 position  " .. position)
end

hw_switch_add("ARDUINO_MEGA2560_A_D2", switch_A1)

Post Reply