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)
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?