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!
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.
Code: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")
Code: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
Code:if ipc.readSTR(0x3D00, 10) == "Airbus A32" then ipc.runlua("Lua:a320_test") end
php:[MACROS] 1=L:FSelC172State=SET 2=L:Nav1ObsNeedle=CYCLIC 3=L:VOR1_OBI_INC=CYCLIC 4=L:StaticAir=SET
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:
Code: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:
Code: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?
Code: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