MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

05/03/2024 - This forum is read-only

The community support for MobiFlight has moved exclusively over to our Discord server. Register for free and enjoy more interactive functions like image and video upload, voice chat. More than 7,000 registered users around the world make it a great experience!

See you on our MobiFlight Community Discord server.

A HUGE Thank You to everyone who participated in the forum, especially obviously to Pizman and Stephan who did an outstanding job over so many years providing an incredible service to the MobiFlight community.

The forum is still providing a lot of good content, hence we keep this information accessible.

Go to page 1Go to page 0123Go to page 2Go to page 3
Avatar
jumpin84
Posts: 10
Hi, if you want to use buttons with complex payware aircrafts (e.g. PMDG, A2A, Majestics), then you got to set the Lvars. Cause it took me a little time to get familiar with it and indeed it's very simple, if you know what to do, i decided to post a little instruction here.

The Basics:
1. Set a fsuipc-user-offset with Mobiflight
2. Create a LUA-Script, which sets the Lvar dependnig on the user-offset
3. Run the LUA-Script


1. Create a new Mobiflight-Input to set a free-user-fsuicp-offset. (66C0 - 66FF). For a simple On/Off Switch choose Value Type "Int" and Size in Bytes "1". On Press Value 1. On Release Value 0.

2. First you got to know the Lvar-name you want to change. If you have a working Linda-Config for your aircraft, take a look at the actions.lua.
Then create your lua script and copy it to FSX/Modules folder. Filename: e.g. yourname.lua

Here is a small example how to set the Taxi-Lights and Landing Lights of the Majestics Dash8-400: There are Approach and Flare Lights i concluded to use only one switch

iconCode:
function Lights_Taxi(offset, value)
	if (value == 1) then ipc.writeLvar("OHD_EXT_LIGHTS_L_TAXI_SW", 1) 
	else ipc.writeLvar("OHD_EXT_LIGHTS_L_TAXI_SW", 0) 
	end
end

function Lights_Landing(offset, value)
	if (value == 1) then 
			ipc.writeLvar("OHD_EXT_LIGHTS_L_FLARE_SW", 1)
			ipc.writeLvar("OHD_EXT_LIGHTS_L_APPR_SW", 1)
	else 	ipc.writeLvar("OHD_EXT_LIGHTS_L_FLARE_SW", 0)
			ipc.writeLvar("OHD_EXT_LIGHTS_L_APPR_SW", 0)
	end
end

event.offset("66C0","UB","Lights_Taxi")
event.offset("66C2","UB","Lights_Landing")


3. Now start FSX and open FSUIPC Options and Settings. Goto the Buttons+Switches or Key Presses tab and assign your lua script to a button or key. Should be in the "Control sent when button pressed"-List under "Lua yourname". Press ok and the assigned key and it should work.


Greets
2016-02-12 12:05
Avatar
DocMoebiuz
Moderator
From: EDSH, Germany
Posts: 1516
Thanks for sharing this with us. That's really a great explanation. I gonna make it sticky.
Have a great day!
Sebastian

MobiFlight - Simply build your own home cockpit for your favorite flight sim - MSFS2020, FSX, Prepar3D (FSUIPC), X-Plane (XPUIPC)
2016-02-12 19:06
Avatar
q400
Posts: 1
I would like to know where to find the dash offsets .
ex: green LED of power apu
I wonder if with the offset number or can put in mobiflight and cause it to light the LED
2016-08-27 02:39
Avatar
zenit_swe
Posts: 10
This may be a very stupid question, but how about just reading Lvars in order to display the value in a 7 segment display? I have a fully functional COM/NAV panel so I thought it wouldn't be that hard to build an auto pilot panel. However, I would like to use it with my Aerosoft A320 and that's where I'm running into a problem that I can't seem to wrap my little head around.

I got the LUA script for the A320 with all the functions for reading and writing the Lvars but I'm just sitting here with a Mega board and a MAX7219 7 segment display trying to figure out what to do in order to just get the FCU altitude on to that display. I'm probably missing the basic knowledge on the relationship between FSX, FSUIPC, LUA and Arduino.
2016-09-04 09:45
Avatar
zenit_swe
Posts: 10
I managed to solve it, so please forget that last comment :-)
2016-09-06 10:01
Avatar
DocMoebiuz
Moderator
From: EDSH, Germany
Posts: 1516
Hi,

can you share your solution for your problem? That would be great!
Have a great day!
Sebastian

MobiFlight - Simply build your own home cockpit for your favorite flight sim - MSFS2020, FSX, Prepar3D (FSUIPC), X-Plane (XPUIPC)
2016-09-09 06:52
Avatar
slammer88
From: LTBJ, Turkey
Posts: 160
I think this is the answer that i'm looking for to merge some of the coupled switches into one, but i have actually no idea about how to create a new Lua and make it read by MobiFlight :(
2016-09-12 15:56
Avatar
zenit_swe
Posts: 10
As we say here in Sweden, better late than never! Here comes a little explanation of how I was able to read the AP altitude of my Aerosoft A320, and set it using an encoder. Remember that I'm a total newbie in this particular area and I'm still learning. This step was the first in my project to build some panels for the A320 and that panel is still a work in progress.

The L:Var for that one is AB_AP_ALT_Select. Here is the LUA script I used to "assign" that L:Var to an offset:

iconCode:
first = true

while true do
    if first then
        initialALTVal = ipc.readLvar("L:AB_AP_ALT_Select")
        ipc.writeUD(0x66C0, initialALTVal)
        first = false
    else
        currentALTVal = ipc.readUD(0x66C0)
        ipc.writeLvar("L:AB_AP_ALT_Select", currentALTVal)
    end
end


The file is saved in <FSX root folder>\Modules, I named it a320_test.lua. The offset (0x66C0) is the first in the range that FSUIPC have dedicated for us to use for whatever we like.

One important thing I've learned about L:Vars and offsets is that L:Vars contains the value that is present in the simulator and the offset contains the value that is present on your panel. In this case, reading the L:Var AB_AP_ALT_Select will give you the altitude displayed in the "cockpit". The first time the loop is executed this value is written to the offset 0x66C0, it's like "assigning" that offset to the L:Var and sync the "cockpit" with your panel. The rest of the loop will then only read the value from the panel and write that to the L:Var.

Now, in order for this lua script to be executed at all you can assign it to a key press combination as explained by jumpin84, or you can execute it automatically whenever you start a flight with the A320/321. The latter is done by writing another lua script and save it in the Modules folder as Ipcready.lua:

iconCode:
if ipc.readSTR(0x3D00, 10) == "Airbus A32" then
	ipc.runlua("Lua:a320_test")
end


To show the altitude in MobiFlight you assign a display to the offset that you've chosen and to set the altitude you assign an encoder to the same offset.

I hope this make sense?
2016-10-01 13:52
Avatar
N767SG
Posts: 5
Hello to all. A2A aircrafts allowed to use macros in this case if any one don't want have deal with Lua scrips. You just need
1. To make macro file put it in modules folder.
2. Assign key in FSUIPC to that macro.
3. And use that key in Mobiflight.

Example:
1 Make macro file with LVars which you want to use. Make new file in any text editor program and save in flight sim modules folder with yourname.MCRO put a2a lvars inside that file. In my example I have LVars for Cessna 172 and my macro file name is A2A_C172.MCRO
iconphp:
 
[MACROS]
1=L:FSelC172State=SET
2=L:Nav1ObsNeedle=CYCLIC
3=L:VOR1_OBI_INC=CYCLIC
4=L:StaticAir=SET
 

More about LVars and how to make them you can read on a2a forum here: https://a2asimulations.com/forum/viewtopic.php?f=23&t=19751

2.In FSUIPC go to key assignment tab. Assign any combination buttons to LVar macro, which you did in first step. In my case I assign Ctrl+Shift+L to my first line LVar macro L:FSelC172State=SET (that LVAr for Fuel selector switch)


3 And I use that key in Mobiflight and assign for left fuel selector switch


P.S. Sorry for my English I hope it clear and understandable. If you have any question I'll be glad to answer them.
Good Luck.
[Last edited by N767SG, 2016-12-09 20:22]
2016-12-09 20:12
Avatar
joshuadouch@yahoo.co.uk
Posts: 5
iconzenit_swe:

As we say here in Sweden, better late than never! Here comes a little explanation of how I was able to read the AP altitude of my Aerosoft A320, and set it using an encoder. Remember that I'm a total newbie in this particular area and I'm still learning. This step was the first in my project to build some panels for the A320 and that panel is still a work in progress.

The L:Var for that one is AB_AP_ALT_Select. Here is the LUA script I used to "assign" that L:Var to an offset:

iconCode:
first = true

while true do
    if first then
        initialALTVal = ipc.readLvar("L:AB_AP_ALT_Select")
        ipc.writeUD(0x66C0, initialALTVal)
        first = false
    else
        currentALTVal = ipc.readUD(0x66C0)
        ipc.writeLvar("L:AB_AP_ALT_Select", currentALTVal)
    end
end


The file is saved in <FSX root folder>\Modules, I named it a320_test.lua. The offset (0x66C0) is the first in the range that FSUIPC have dedicated for us to use for whatever we like.

One important thing I've learned about L:Vars and offsets is that L:Vars contains the value that is present in the simulator and the offset contains the value that is present on your panel. In this case, reading the L:Var AB_AP_ALT_Select will give you the altitude displayed in the "cockpit". The first time the loop is executed this value is written to the offset 0x66C0, it's like "assigning" that offset to the L:Var and sync the "cockpit" with your panel. The rest of the loop will then only read the value from the panel and write that to the L:Var.

Now, in order for this lua script to be executed at all you can assign it to a key press combination as explained by jumpin84, or you can execute it automatically whenever you start a flight with the A320/321. The latter is done by writing another lua script and save it in the Modules folder as Ipcready.lua:

iconCode:
if ipc.readSTR(0x3D00, 10) == "Airbus A32" then
	ipc.runlua("Lua:a320_test")
end


To show the altitude in MobiFlight you assign a display to the offset that you've chosen and to set the altitude you assign an encoder to the same offset.

I hope this make sense?



If this works I will love you forever...
2017-09-17 09:24
Avatar
tommy1332
Posts: 26
I have written a lua script that makes it really easy to manage the lvar to offset mappings. Maybe it will help someone.
It is fully commented so it should be easy to understand what to do. Essentially you only need to change the lvar_list variable.
Some values are already inserted from the Majestic Dash 8 Q400.

For the people that don't know how to run the script:
Save in FSX/Modules/ as lvar_offsets.lua and enable it in FSUIPC under "Key Presses". There you set "Control sent when keys pressed" to "Lua Lvar_offsets". With the key you set there you can run the script.

iconCode:
local UB = {r=ipc.readUB,w=ipc.writeUB} -- 1 Byte Int
local UW = {r=ipc.readUW,w=ipc.writeUW} -- 2 Byte Int
local UD = {r=ipc.readUD,w=ipc.writeUD} -- 4 Byte Int
local FLT = {r=ipc.readFLT,w=ipc.writeFLT} -- 4 Byte Float
local DBL = {r=ipc.readDBL,w=ipc.writeDBL} -- 8 Byte Float
local STR = {r=ipc.readSTR,w=ipc.writeSTR} -- String

local EN1 = "66C0" -- master offset enable

local R = 0
local W = 1

--[[
	Every entry in lvar_list corresponds to one offset.
	How to build an entry:
	{"offset", mode, {enable_switches}, {lvars}}
	- offset = fsuipc offset (between 0x66C0 and 0x66FF)
	- mode is either R or W. R means only read from lvar
	and W means only write to lvar. (e.g. an LED displaying
	the flaps status is R. A switch that extends the gear
	is W.)
	- enable_switches = list of offsets which all have to
	be set to 1 otherwise the line gets ignored. This is useful
	for shared cockpit so that if you are not in charge of the
	buttons your switches won't override the switches of the 
	other pilot.
	-- lvars = list of lvars that get the same value written to.
	You should only use one lvar when mode=R.
]]
local lvar_list = {
	{"66C3", W, {EN1}, UB, { "OHD_EXT_LIGHTS_L_FLARE_SW", "OHD_EXT_LIGHTS_L_APPR_SW" }},
	{"66C4", W, {EN1}, UB, { "OHD_EXT_LIGHTS_L_TAXI_SW" }},
	{"66C5", R, {}, UB, { "Q400_FLAP_POS" }}
}

-- set this to true if you want to force your own switch positions on start
local initialized = false

while true do
	for _,v in pairs(lvar_list) do
		local offset = v[1]
		local mode = v[2]
		local enable_offsets = v[3]
		local offset_type = v[4]
		local lvars = v[5]
			
		-- check all enable switches are set
		local enabled = true
		for _, enable_offset in pairs(enable_offsets) do
			local val = ipc.readUB(enable_offset)
			if val == 0 then
				enabled = false
			end
		end
		
		if enabled == true then -- skip line if disabled
			if initialized == true and mode == W then -- write mode			
				-- read offset
				local offset_val = offset_type.r(offset)
				
				-- update lvars
				for _, lvar in pairs(lvars) do
					ipc.writeLvar(lvar, offset_val)
				end
			else -- read mode
				-- read lvars
				local lvar_val = ipc.readLvar(lvars[1])
				
				-- update offset
				offset_type.w(offset, lvar_val)
			end
		end
	end
	initialized = true
end


I might update this within the next weeks but it is already working.
[Last edited by tommy1332, 2017-10-04 16:13]
2017-10-04 16:01
Avatar
Jeffrey_Pilot
Posts: 24
Hi guys,

Where I can find the LVARS for the Q400? Is the a file available with the lvars?

Regards
2017-11-08 10:11
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
Hi

Please NOT refresh Sticky Topic Gudies with personal Requests ! :thumbdown:

About question.....
Simply use Google..... Search for "Lvar List Q400"
First hit: http://majesticsoftware.com/forums/discussion/2852/lvar-list-of-dash8-q400/p1
Good Luck !
2017-11-08 12:47
Avatar
Jeffrey_Pilot
Posts: 24
Sorry Pizman! didn't know that!:confused:

But yes, same link I found already! Thanks for your help:thumbup:
2017-11-08 12:55
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
No Prob.... Your welcome !
;)
Good Luck !
2017-11-08 13:05
Go to page 1Go to page 0123Go to page 2Go to page 3