I am in the process of putting together some "magic" buttons and instruments whose appearance and behaviours vary dependent upon the aircraft loaded in the sim.
Creating a subscription with a callback routine to update a variable with the ICAO reference does seem to work but there is always the risk that the rest of the code will run before the variable has been populated. I have tried including all of the setup code in the callback and also using coroutines to prevent this from happening but Air Manager -not unreasonably- only allows setup to happen in mainline code.
As always, there is probably a really simple answer staring me in the face but I cannot see it.
Any ideas?
Thanks in advance.
Colin
Change instrument and hardware behaviour based upon "sim/aircraft/view/acf_ICAO"
-
- Posts: 8
- Joined: Thu Nov 17, 2022 4:00 pm
-
- Posts: 5340
- Joined: Thu Jul 27, 2017 12:22 am
Re: Change instrument and hardware behaviour based upon "sim/aircraft/view/acf_ICAO"
This should be applied at a panel level, which has to manage the arbitration
See my sample here, specifically in the logic.lua of the panel itself "AutoPanels - PA-28 & Other AIRCRAFTS - Panels Loader" and in the AutoConfig instrument "AutoPanels (SP) - TOOLS - AIRCRAFT AUTO CONFIG" :
https://forums.x-plane.org/index.php?/f ... novations/
See my sample here, specifically in the logic.lua of the panel itself "AutoPanels - PA-28 & Other AIRCRAFTS - Panels Loader" and in the AutoConfig instrument "AutoPanels (SP) - TOOLS - AIRCRAFT AUTO CONFIG" :
https://forums.x-plane.org/index.php?/f ... novations/
-
- Posts: 8
- Joined: Thu Nov 17, 2022 4:00 pm
Re: Change instrument and hardware behaviour based upon "sim/aircraft/view/acf_ICAO"
Thanks for your help. Looks like I have just scratched the surface of what is possible.
Colin
Colin
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Change instrument and hardware behaviour based upon "sim/aircraft/view/acf_ICAO"
Hi,
I have another method which works for me.
Using library's and (tables/static_data) I load only the necessary data.
Keith
I have another method which works for me.
Using library's and (tables/static_data) I load only the necessary data.
Code: Select all
xpl_dataref_subscribe("sim/aircraft/view/acf_ICAO","STRING",function(icao)
--- if icao == table 1 then load (table 1 or static _data set 1)
--- if icao == table 2 then load (table 2 or static _data set 2)
end)
--Now you can load your library's
--I use library's for each airframe and tables to do different variants.
--data sets will not load until told to, but will be available. In other words not out side of initial load.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Change instrument and hardware behaviour based upon "sim/aircraft/view/acf_ICAO"
Hi,
I quickly pulled out a instrument I worked on some time back. It will give you the gist of what I said before.
You will have to create the necessary .json and librarys to make it work but you can get the idea.
You could also add a sim check using the connected functions
So the possibilities are vast.
Keith
I quickly pulled out a instrument I worked on some time back. It will give you the gist of what I said before.
You will have to create the necessary .json and librarys to make it work but you can get the idea.
You could also add a sim check using the connected functions
So the possibilities are vast.
Code: Select all
if xpl_connected() then
print("Wowsers, we are connected to X-Plane!")
end
if fs2020_connected() then
print("Good heavens, we are connected to FS2020!")
end
Code: Select all
---- TEST for loading AirFrames and instrument placement.
--- This Instrument comes with 5 supported AirFrames.
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
--Your Rotary encoder pins
mv50_dial_a = "ARDUINO_MEGA2560_A_A11"
mv50_dial_b = "ARDUINO_MEGA2560_A_A12"
--Your pushbutton pins
mv50_select_a = "ARDUINO_MEGA2560_A_A6"
mv50_exit_a = "ARDUINO_MEGA2560_A_A3"
mv50_screens_a = "ARDUINO_MEGA2560_A_A4"
mv50_menu_a = "ARDUINO_MEGA2560_A_A5"
--- vars for checking supported AirFrames
af_id_check1 = ""
af_id_check2 = ""
af_id_check3 = ""
--- vars for switching
af_data_loaded = 0 -- We use a (1 0) switching logic to draw canvas or not
af_type = ""
---Table for all the AirFrame parameters
af_data = nil -- This value is set to nil because a {} returns a valid table
bits_and_bobs_init() -- This is all styles and canvas adds needs to be top of the tree.
hardware_action_init()
---Function to check if AirFrame is supported
xpl_dataref_subscribe("sim/aircraft/view/acf_ICAO","STRING[40]",
"sim/aircraft/view/acf_descrip","STRING[260]",
"sim/aircraft/view/acf_author","STRING[260]",function(icao_acf,description,author)
af_id_check1 = icao_acf
af_id_check2 = author
af_id_check3 = description
end)
---The parameters above are used to find a match for supported AirFrames
---Load the supported AirFrames .json
static_data_load("af_suoprted.json", function(af_supported)
for key,value in pairs(af_supported["data"]) do
if value["airframe"]["icao"] == af_id_check1 and value["airframe"]["author"] == af_id_check2 and value["airframe"]["description"] == af_id_check3 then
print("We are going to use this airframe "..value["airframe"]["load json"])
af_data = static_data_load(value["airframe"]["load json"])
end
end
---Check if the AirFrame is supported
if af_data ~= nil then
print("Data Loaded")
---If the AirFrame is supported then initialize the "init" functions. If AirFrame is not supported display MSG
af_data_loaded = 1
af_type = af_data["DATA"]["ENGINE"][3]
visible(startup_msg ,false)
main_table[1] = 2
eng_P4_instruments_init()
eng_P6t_instruments_init()
eng_turbo_instruments_init()
menus_and_markers_init()
data_functions_init()
visibility_init()
else
print(af_id_check1.." By Author "..af_id_check2.." With Description "..af_id_check3.." Is not supported")
canvas_draw(startup_msg, function()
_rect(0 ,0, 487, 370)
_fill("#1c1c1c")
_txt("This Airframe "..af_id_check1,incCB_26grnCC,243,50)
_txt("By Author",incCB_26grnCC,243,100)
_txt(af_id_check2,incCB_26grnCC,243,150)
_txt("With Description",incCB_26grnCC,243,200)
_txt(af_id_check3,incCB_26grnCC,243,250)
_txt("Is not supported",incCB_26grnCC,243,300)
end)
visible(startup_msg ,true)
end
end)
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card