Help with adjusting script to work with MIP light test switch

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
cypherdious
Posts: 23
Joined: Tue Nov 23, 2021 10:52 am

Help with adjusting script to work with MIP light test switch

#1 Post by cypherdious »

Hi everyone,

I am new here and a total newbie. But have picked up very basic LUA scripting by using available scripts for using hardware to control Xplane.

I am planning to build an OVHD panel and before I actually take on the tasks, I have started looking at creating instrument scripts in Air Manager.
I have managed to use a script for the APU off-on-start and I am using this as a basis for scripting the MIP light test switch which is test-bright-dim.
The issue I have is with the value of the dataref. The APU is basically all +ve value (0, 1, 2) while the light test switch has a negative number (-1, 0, 1).

I read up on the post "Keith's LUA help thread" and this was discussed but I went through the whole thread and couldn't find where Keith was able to resolve
the light test switch issue with the -ve number. The topic on that ended abruptly. Anyway, I used the APU script because its basically the same format being
a 3 ways switch and I couldn't get the switch to control the xp switch properly. Here is the script I have.

Code: Select all

--global vars
xp_switch_pos = 0
hw_switch_pos = 0
state1 = 0
state2 = 0

function read_pin()
--pin3 false = dim		(-1) --> 0 (by adding 1)
--pin4 false = test		(1) --> 2 (by adding 1)
--pin4 and 3 true = bright	(0) --> 1 (by adding 1)
--Numbers between brackets correspond to the numbers from the dataref

state1 = hw_input_read(pin3)
	if state1 == false then
		hw_switch_pos = 1+1					--test
		print (hw_switch_pos, state1)
	end

state2 = hw_input_read(pin4)
	if state2 == false then
		hw_switch_pos = -1+1					--dim
		print (hw_switch_pos, state2)
	
	end

	if state1 == true and state2 == true then
		hw_switch_pos = 0+1					--bright
	end

		if hw_switch_pos == 1 and xp_switch_pos == 2 then 			--from test to bright
			xpl_command("laminar/B738/toggle_switch/bright_test_dn", 1)
		elseif hw_switch_pos == 0 and xp_switch_pos == 2 then			--from bright to dim 
			xpl_command("laminar/B738/toggle_switch/bright_test_dn", 1)
			xp_switch_pos = 0
		elseif hw_switch_pos == 1 and xp_switch_pos == 0 then			--from dim to bright
			xpl_command("laminar/B738/toggle_switch/bright_test_dn", 0)
			xp_switch_pos = 2
		elseif hw_switch_pos == 2 and xp_switch_pos == 2 then			--from bright to test
			xpl_command("laminar/B738/toggle_switch/bright_test_up", 1)
		end
 
end
pin4 = hw_input_add("ARDUINO_MEGA2560_A_D11", read_pin)
pin3 = hw_input_add("ARDUINO_MEGA2560_A_D10", read_pin)
Pardon the mess. I actually don't fully grasp the code but I rewrote the script by comparing against the APU script. I made sure the value produced
is all +ve as suggested by someone from the above thread I mentioned.

Can someone help me to tidy this up so it will work. I have been cracking my head and searching online without success. Thanks.

Al

P.S. How do I print out the value for each position of the hw_switch and xp_switch so I can check if the values match up?

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

Re: Help with adjusting script to work with MIP light test switch

#2 Post by Keith Baxter »

Hi

I read my name in your post. This gives me heart that all my posting is doing something to help others.

I have not had the time to look into your issue but will do so and will revert.

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 

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

Re: Help with adjusting script to work with MIP light test switch

#3 Post by Keith Baxter »

Hi,

After a quick look.

You cannot use the same callback for ..

Code: Select all

pin4 = hw_input_add("ARDUINO_MEGA2560_A_D11", read_pin)
pin3 = hw_input_add("ARDUINO_MEGA2560_A_D10", read_pin)
Am will always use the last pin callback and ignore any earlier callbacks.
So pin4 will be ignored.

It is better to use the switch function for this application.

Also when using multiple print() statements. To ID the different statements it is best to add some form of text to identify what statement/data is printed..

Code: Select all

print ("MY First Switch Position   "..hw_switch_pos, state1)
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 

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

Re: Help with adjusting script to work with MIP light test switch

#4 Post by Keith Baxter »

I think this instrument I played around with will give you a heads up. The graphics are not up to standard and need a lot of work. I think the switch you want is within the code.
If you run the instrument within create/edit and manipulate switch "CPT Light Test" within the console <Hardware> you will see that the switch works within the sim.

Just shout if you need further assistance. Happy to do so here or on the discord.

Welcome to use any part as it is all open source.
EDIT: My bad... the .png files are not my work and not open source. They come from various sources I do not remember as it was a dev instrument i did about 2&a half years ago.. The Annunciations were extracted from the airframe library and I think the switches from @russ instruments. Not sure.

NOTE: The sim needs to run for the instrument to work.
WIP Boeing 737-800X - CPT DU Control panel.siff
(243.49 KiB) Downloaded 108 times
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 

cypherdious
Posts: 23
Joined: Tue Nov 23, 2021 10:52 am

Re: Help with adjusting script to work with MIP light test switch

#5 Post by cypherdious »

Keith Baxter wrote: Fri Nov 26, 2021 6:52 pm Hi,

After a quick look.

You cannot use the same callback for ..

Code: Select all

pin4 = hw_input_add("ARDUINO_MEGA2560_A_D11", read_pin)
pin3 = hw_input_add("ARDUINO_MEGA2560_A_D10", read_pin)
Am will always use the last pin callback and ignore any earlier callbacks.
So pin4 will be ignored.

It is better to use the switch function for this application.

Also when using multiple print() statements. To ID the different statements it is best to add some form of text to identify what statement/data is printed..

Code: Select all

print ("MY First Switch Position   "..hw_switch_pos, state1)
Keith
Hi Keith, thank you for the response. I tried your suggestion to use switch instead of input function. But I am sure I am still missing some codes in the script as that didn't do anything for the XP switches. I will look into the siff file you have attached. Appreciate the share. How do I open the file by the way?

The funny thing is that for the APU switch, this same script works. That led me to believe that my IF and ELSEIF function is not properly written for the light test switch.

I will further into your script and see if I can pick up something there. Thanks.

cypherdious
Posts: 23
Joined: Tue Nov 23, 2021 10:52 am

Re: Help with adjusting script to work with MIP light test switch

#6 Post by cypherdious »

Keith Baxter wrote: Fri Nov 26, 2021 7:21 pm Just shout if you need further assistance. Happy to do so here or on the discord.

Welcome to use any part as it is all open source.
EDIT: My bad... the .png files are not my work and not open source. They come from various sources I do not remember as it was a dev instrument i did about 2&a half years ago.. The Annunciations were extracted from the airframe library and I think the switches from @russ instruments. Not sure.

NOTE: The sim needs to run for the instrument to work.
WIP Boeing 737-800X - CPT DU Control panel.siff

Keith
Thanks Keith. Will take you up on the offer. Definitely need the help. Will check out Discord and let you know once its up. Thanks.

Post Reply