Hardware status - automatic recognition?

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
marcel_felde
Posts: 162
Joined: Wed May 09, 2018 12:19 am

Hardware status - automatic recognition?

#1 Post by marcel_felde »

Is it possible to get a regular status update on the position of switches etc.?

For example: Switch moving the landing gear. Place the lever up. Gear goes up. Stop Air Manager. Move switch down. Start Air Manager. Gear stays up. You have to move the switch up and down again to get the gear down.

Image repositioning the aircraft for another approach and having to move all switches, encoders and axis in the cockpit. :shock:

Would be nice to have a regular status update on the position automatically and of course an update on initiation! :)

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

Re: Hardware status - automatic recognition?

#2 Post by SimPassion »

Mostly, x-plane simulation handled this situation while there's an online state changed
not sure, but perhaps this could be handeld by AM/AP itself ... ?

Gilles

marcel_felde
Posts: 162
Joined: Wed May 09, 2018 12:19 am

Re: Hardware status - automatic recognition?

#3 Post by marcel_felde »

The command is send by AM/AP - so X-Plane cannot know the position of a switch until AM/AP sends a signal.

Perhaps defining an interval AM/AP checks for the position of the hardware would be great and checking the position when the flight/aircraft are reset/loaded or a new situation (approach, takeoff, cold and dark...) is selected.

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Hardware status - automatic recognition?

#4 Post by Keith Baxter »

marcel_felde wrote: Tue May 22, 2018 8:52 pm The command is send by AM/AP - so X-Plane cannot know the position of a switch until AM/AP sends a signal.

Perhaps defining an interval AM/AP checks for the position of the hardware would be great and checking the position when the flight/aircraft are reset/loaded or a new situation (approach, takeoff, cold and dark...) is selected.
Two ways that come to my mind if i understand correct.

1) A hardware LED is one.
2) You could wright a small script to show the status of the switch. something like this. Or you could just show the value of bl_switch. 0,1

Code: Select all

function button_3() ---beacon light switch
bl_switch = 0
	bl_switch= bl_switch + 1

	if (bl_switch == 1) then
		bl_on=txt_add("BEACON LIGHT ON", "font:arial.ttf; size:8px; color:#5599FF; halign:center;", -3, 415, 60, 40)
		
	elseif (bl_switch == 0) then
		bl_on=txt_add("BEACON LIGHT OFF", "font:arial.ttf; size:8px; color:#5599FF; halign:center;", -3, 415, 60, 40)

	end

	if (bl_switch > 1) then
		bl_switch = 0
	end			
end
hw_button_add("ARDUINO_MEGA2560_A_D49 ", button_3)
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

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

Re: Hardware status - automatic recognition?

#5 Post by SimPassion »

The caveat is that currently AM/AP seems to react in "On event" manner,
so on load there's no event thrown, we have to check in the script by ourselves the switch position (its electronical state)
then it would be helpful in this situation as you previously stated, to get status on load on each referenced switch, with new featured parameter on existing API request, just a thought ...

Gilles

marcel_felde
Posts: 162
Joined: Wed May 09, 2018 12:19 am

Re: Hardware status - automatic recognition?

#6 Post by marcel_felde »

Keith, it is not about me to see the status of a switch. If I have to check and compare the status of the virtual switch and the real switch, it is even more complicated than moving every switch and lever in the cockpit. :)

If there would be a regular event, where AM/AP check for the position of the hardware, so that virtual and hardware switches are always synchronized, that would be perfect. ;)

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Hardware status - automatic recognition?

#7 Post by JackZ »

What you request seems absolutely unreachable in AM only. A switch is a switch, depending on the way it is physically wired, you can have an Open position meaning two different things (open or close) in the related sim!

Usually to ensure synchronization, the sim state has to be loaded from a known previously recorded situation (Cold and Dark for example) and the hardware set up beforehand, a good habit is to use some sort of Before Sim Startup checklists....

One can imagine a check of all the switches at startup, then a routine sends orders to the sim so it synchronizes to the current hardware position. But you have to do it programmatically by yourself, no magic AM feature can do that for you since it is so specific to the sim & addon you’re using and the way your switches are hardwired

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
Corjan
Posts: 2941
Joined: Thu Nov 19, 2015 9:04 am

Re: Hardware status - automatic recognition?

#8 Post by Corjan »

Hi,


This will require some additional coding to get right, Air Manager won't help you with the actual syncing.

I would recommend something along these lines:

Code: Select all

xpl_dataref_subscribe("SOME_DATAREF", "INT", function(sim_position)
	local switch_position = hw_switch_position(switch_id)
	if (switch_position  ~= sim_position then
		xpl_dataref_write("SOME_DATAREF", "INT", switch_position)
	end
end)
Note that the subscribe callback will be called when the connection with the sim has been established. If there is a mismatch between the sim and the switch, a new value will be pushed.
This is still not a 100% guarantee because it might happen that the simulator ignores the write. But I'm guessing it should be okay.

The code snipplet uses the 'hw_switch_position' function which is not available in AM 3.3 and current AM 3.4 BETA. It will be included in the next BETA.
You can also manually store the switch position as a global variable for now.


Corjan

marcel_felde
Posts: 162
Joined: Wed May 09, 2018 12:19 am

Re: Hardware status - automatic recognition?

#9 Post by marcel_felde »

Thanks for the answer Corjan. Will try that in the next beta!
I would recommend something along these lines:
Would be great if AM/AP will do that globally for the user sometime! Will save us a lot of thinking and code. Imagine that for 100 switches and levers. ;)
You can also manually store the switch position as a global variable for now.
Will still be a missmatch if you move the switch if AM/AP are not running. For example if someone is playing on the switches without the software and systems are running. Which happens a lot. ;)

User avatar
Corjan
Posts: 2941
Joined: Thu Nov 19, 2015 9:04 am

Re: Hardware status - automatic recognition?

#10 Post by Corjan »

Hi,

Might be smart to create some kind of helper function to hide this piece of code. Would certainly help if you have multiple switches etc.
The hardware switch position you receive from the hw_switch_add function is always the correct one. I think the biggest syncing problem is if the simulator is running at that time.

Alternatively, you can create a timer that matches the simulator and hardeware switch values every x ms, but that feels a big ugly :)

Corjan

Post Reply