I need a better way XPL Dataref

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
jml79
Posts: 87
Joined: Wed Jan 06, 2016 4:33 am

I need a better way XPL Dataref

#1 Post by jml79 »

I am trying to modify Russ's excellent x737 MCP to be as usable as possible using the default dataref's. This should make it usable in almost any aircraft.

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)

User avatar
Ralph
Posts: 7933
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: I need a better way XPL Dataref

#2 Post by Ralph »

Did you have a look at the 'Autopilot Modes' instrument from Russ?

jml79
Posts: 87
Joined: Wed Jan 06, 2016 4:33 am

Re: I need a better way XPL Dataref

#3 Post by jml79 »

Nope. I'll do that.

Thanks.

User avatar
russ
Posts: 593
Joined: Tue Oct 27, 2015 5:37 pm

Re: I need a better way XPL Dataref

#4 Post by russ »

preview.png
I wrote the autopilot modes instrument to try to understand the modes of the X-P autopilot and how they work. It checks for changes in the autopilot mode and displays them. You can operate the autopilot and see as the modes change to try to understand how the X-P autopilot controls work.

There are older deprecated mode datarefs for many individual modes but you really need to look at a single dataref: sim/cockpit/autopilot/autopilot_state

the bits of this interger variable are set to reflect mode state. I used the Lua function bit32.extract to check the appropriate bits
My work was based on the following article:

http://www.xsquawkbox.net/xpsdk/mediawi ... ilot_state

Using this dataref will future proof your instrument. Unfortunately I didn't understand this when I created the x737 mcp and haven't had time to upgrade it....I'm at the beach for another month in Grand Cayman so feel free to upgrade it yourself if you like.
Russ Barlow
Air Manager Evangelist

jml79
Posts: 87
Joined: Wed Jan 06, 2016 4:33 am

Re: I need a better way XPL Dataref

#5 Post by jml79 »

That was the ticket. The bit32.extract was exactly what is was looking for. I'll post a beta version of the AP for testing if anyone is interested. It has presented some challenges. :D

Post Reply