I have searched the Xplane SDK for some dataref to tell me if the FLCHG mode of the autopilot is engaged. The only thing I can find is an old one, sim/cockpit/autopilot/autopilot_state. It returns an INT (decimal) made from different its being turned on by each function. it can range all the way up to 524288 (19 bits) and I am only interested if bit 7 is on or off. I have made the following code which works but god it's ugly. Does anyone have any ideas for a better way. Besides asking for a new dataref from Laminer.
Code: Select all
-- LVL CHG button function
function press_lvl_chg(position)
xpl_command("sim/autopilot/level_change")
end
lvl_chg__switch = switch_add("clear.png" , "sel_btn.png",635,208,60,38,press_lvl_chg)
function lvlchg_chg(state)
if state > 262144 then state = state - 262144 end
if state > 131072 then state = state - 131072 end
if state > 65536 then state = state - 65536 end
if state > 32768 then state = state - 32768 end
if state > 16384 then state = state - 16384 end
if state > 8192 then state = state - 8192 end
if state > 4096 then state = state - 4096 end
if state > 2048 then state = state - 2048 end
if state > 1024 then state = state - 1024 end
if state > 512 then state = state - 512 end
if state > 256 then state = state - 256 end
if state > 128 then state = state - 128 end
if state > 64 then position = 1 else position = 0 end
switch_set_state(lvl_chg__switch, position)
end
xpl_dataref_subscribe("sim/cockpit/autopilot/autopilot_state","INT",lvlchg_chg)