i am making my first steps with lua and need some help when it comes to hardware switches.
For testing i use the C172 switch panel, i am using FSX.
Here is the code from the switchpanel:
Code: Select all
-- FUEL PUMP SWITCH
function fuel_pump_click_callback(position)
if position == 0 then
xpl_dataref_write("sim/cockpit/engine/fuel_pump_on", "INT[8]", {1})
fsx_event("TOGGLE_ELECT_FUEL_PUMP1")
fs2020_event("TOGGLE_ELECT_FUEL_PUMP")
elseif position == 1 then
xpl_dataref_write("sim/cockpit/engine/fuel_pump_on", "INT[8]", {0})
fsx_event("TOGGLE_ELECT_FUEL_PUMP1")
fs2020_event("TOGGLE_ELECT_FUEL_PUMP")
end
end
fuel_pump_switch_id = switch_add("toggle_off.png", "toggle_on.png", 160,202,63,63,fuel_pump_click_callback)
function new_fuel_pump_switch_pos(sw_on)
if sw_on[1] == 0 then
switch_set_position(fuel_pump_switch_id, 0)
elseif sw_on[1] == 1 then
switch_set_position(fuel_pump_switch_id, 1)
end
end
function new_fuel_pump_switch_pos_fsx(sw_on)
sw_on = fif(sw_on, 1, 0)
new_fuel_pump_switch_pos({sw_on})
end
xpl_dataref_subscribe("sim/cockpit/engine/fuel_pump_on", "INT[8]",new_fuel_pump_switch_pos)
fsx_variable_subscribe("GENERAL ENG FUEL PUMP SWITCH:1", "Bool", new_fuel_pump_switch_pos_fsx)
fs2020_variable_subscribe("GENERAL ENG FUEL PUMP SWITCH:1", "Bool", new_fuel_pump_switch_pos_fsx)
-- END FUEL PUMP SWITCH
Code: Select all
hw_switch_add("ARDUINO_UNO_A_D9", fuel_pump_click_callback)
hw_switch_add("ARDUINO_UNO_A_D8", beacon_click_callback)
hw_switch_add("ARDUINO_UNO_A_D10", landing_click_callback)
hw_switch_add("ARDUINO_UNO_A_D11", taxi_click_callback)
hw_switch_add("ARDUINO_UNO_A_D12", nav_click_callback)
hw_switch_add("ARDUINO_UNO_A_D13", strobe_click_callback)
I need to sync the panel switch with my current button setting, so when i start everything and my hardware switch is on 1, while the panel software switch is 0, its out of sync.
The general ideal should be, read the hardware switch -> set the softwareswitch.
Found the same Problem described and solved here: https://siminnovations.com/forums/viewt ... 416#p30416
I think i have to combine https://siminnovations.com/wiki/index.p ... t_position & https://siminnovations.com/wiki/index.p ... t_position
Maybe anyone can help me with this basic concept?