I've been developing the MFD for my ERJ cockpit, and I've come pretty far for being a newbie at programming. And now I hit a wall I am hoping someone can help me with.
The MFD has several pages - T/O, ECS/ Pressurization, Fuel, Hydraulic, Electric. Each page is displayed when the systems menu is selected and the proper bezel button is pressed. The way I wrote my logic, when a menu is displayed I set a variable. Then, when I press a button, the code checks that variable and displays the page that corresponds to the menu item above the button. It works pretty well overall, but I have one issue and one concern/ change I would like to make (if it is worth it; I don't know, so looking for advice here too).
THE ISSUE is related to the ECS page. It has two graphical indicators - one for each engine BLEED TEMP. Their positions are controlled by a dataref subscribe. I wrote the code so that each MFD page is a group, set to NOT visible by default; and when a page is selected, I set a variable that represents which page I selected, and then I call a function that sets the respective group to visible==true. I need that MFD_PAGE variable so that I can compare the page displayed with the menu displayed and then map the correct action I need to happen when I press a given button in the MFD bezel. This works ok for all pages except that once the ECS page is displayed once, selecting a different page will hide the ECS page EXCEPT for the BLEED TEMP indicators. I put a couple of prints in the code, and it looks like once the ECS page is displayed the first time (i.e. once the ECS Page function is called), the datarefs are always feeding the BLEED TEMP indicators and causing them to display even in other pages. I can't figure out how to fix that. I thought I'd written the code in a way that when I pressed the MFD button it would call a function that would set the respective page group to visible== true, and setting all other groups to visible== false. With that, I expected all components of the ECS page to be invisible when another page is selected and displayed, but apparently that is not the case - or it's not giving me the expected behavior.
THE CHANGE I would like to make would be for each page to not be displayed (which already works except for the issue above) but also for the datarefs to not be updated in the background when a page that subscribes to those datarefs is not being displayed. I figure that would save unnecessary use of resources (no sense in getting updated dataref values for something not being used/ displayed, in my mind...)
I hope this all make sense. Below is the portion of the code that I wrote for the ECS page and the corresponding hardware code as well. Please let me know if any additional info would be helpful. Thanks in advance for any insight you may provide!
Marco
Code: Select all
-- ECS/AI PAGE --
-- ECS/AI PAGE OBJECTS
-----------------------
MFD_ECS_PAGE = img_add("MFD_ECS_PAGE.png", 0, 0, nil, nil)
CAB_TEMP_VALUE = txt_add("22", "font:arial.ttf; size:23; color: cyan; halign: right; background_color: black", 204, 607, 50, 27)
CKPT_TEMP_VALUE = txt_add("23", "font:arial.ttf; size:23; color: cyan; halign: right", 204, 667, 50, 27)
OXY_PRESS_READOUT = txt_add("9999", "font:arial.ttf; size:23; color: #00FF3A; halign: right; background_color: black", 315, 701, 71, 27)
OXY_PRESS_NORM_IND = img_add("RH_NORM_ARROW.png", 384, 630, nil, nil, "visible: false")
OXY_PRESS_CAUT_IND = img_add("RH_CAUT_ARROW.png", 384, 676, nil, nil, "visible: false")
OXY_PRESS_WARN_IND = img_add("RH_WARN_ARROW.png", 384, 688, nil, nil, "visible: false")
BLEED1_TEMP_NORM_IND = img_add("LH_NORM_ARROW.png", 507, 633, nil, nil, "visible: false")
BLEED1_TEMP_CAUT_IND = img_add("LH_CAUT_ARROW.png", 507, 686, nil, nil, "visible: false")
BLEED2_TEMP_NORM_IND = img_add("RH_NORM_ARROW.png", 523, 633, nil, nil, "visible: false")
BLEED2_TEMP_CAUT_IND = img_add("RH_CAUT_ARROW.png", 523, 680, nil, nil, "visible: false")
MFD_ECS_PAGE_GROUP = group_add
(MFD_ECS_PAGE
, CAB_TEMP_VALUE
, CKPT_TEMP_VALUE
, OXY_PRESS_READOUT
, OXY_PRESS_NORM_IND
, OXY_PRESS_CAUT_IND
, OXY_PRESS_WARN_IND
, BLEED1_TEMP_NORM_IND
, BLEED1_TEMP_CAUT_IND
, BLEED2_TEMP_NORM_IND
, BLEED2_TEMP_CAUT_IND)
visible(MFD_ECS_PAGE_GROUP, false)
-- ECS/AI PAGE DISPLAY LOGIC
-------------------------
function MFD_ECS_PAGE_DISPLAY()
-- MFD_PAGE == "ECS_Page"
visible(MFD_MAIN_MENU, false)
visible(MFD_SYS_MENU, true)
visible(MFD_TO_PAGE_GROUP, false)
visible(MFD_ECS_PAGE_GROUP, true)
visible(MFD_FUEL_PAGE_GROUP, false)
visible(MFD_ELEC_PAGE_GROUP, false)
visible(MFD_TO_PAGE_MENU_BOX, false)
visible(MFD_ECS_PAGE_MENU_BOX, true)
visible(MFD_FUEL_PAGE_MENU_BOX, false)
visible(MFD_HYD_PAGE_MENU_BOX, false)
visible(MFD_ELEC_PAGE_MENU_BOX, false)
print(MFD_PAGE .. " displayed")
print(MFD_MENU .. " displayed")
-- Oxygen Pressure Indication
function O2_pressure(OXY_PRESS)
txt_set(OXY_PRESS_READOUT, string.format("%.0f", OXY_PRESS))
if OXY_PRESS < 250 then
visible(OXY_PRESS_WARN_IND, true)
visible(OXY_PRESS_CAUT_IND, false)
visible(OXY_PRESS_NORM_IND, false)
txt_style(OXY_PRESS_READOUT, "color: red")
end
if OXY_PRESS >= 250 and OXY_PRESS <= 410 then
visible(OXY_PRESS_WARN_IND, false)
visible(OXY_PRESS_CAUT_IND, true)
visible(OXY_PRESS_NORM_IND, false)
txt_style(OXY_PRESS_READOUT, "color: yellow")
end
if OXY_PRESS > 410 then
visible(OXY_PRESS_WARN_IND, false)
visible(OXY_PRESS_CAUT_IND, false)
visible(OXY_PRESS_NORM_IND, true)
txt_style(OXY_PRESS_READOUT, "color: #00FF3A")
end
end
xpl_dataref_subscribe(" sim/cockpit2/oxygen/indicators/o2_bottle_pressure_psi", "FLOAT", O2_pressure)
-- Bleed Air Temperature Indication
function Bleed_temp(BLEED_TEMP)
if BLEED_TEMP[1] <= 260 then
visible(BLEED1_TEMP_CAUT_IND, true)
print("bleed1 temp CAUT ind ON for low temp")
visible(BLEED1_TEMP_NORM_IND, false)
print("bleed1 temp NORM ind OFF for low temp")
end
if BLEED_TEMP[1] > 260 and BLEED_TEMP[1] <=304 then
visible(BLEED1_TEMP_CAUT_IND, false)
print("bleed1 temp CAUT ind OFF for REG temp")
visible(BLEED1_TEMP_NORM_IND, true)
print("bleed1 temp NORM ind ON for REG temp")
end
if BLEED_TEMP[1] > 304 then
visible(BLEED1_TEMP_CAUT_IND, true)
print("bleed1 temp CAUT ind ON for HIGH temp")
visible(BLEED1_TEMP_NORM_IND, false)
print("bleed1 temp NORM ind OFF for HIGH temp")
end
if BLEED_TEMP[2] <= 260 then
visible(BLEED2_TEMP_CAUT_IND, true)
print("bleed2 temp CAUT ind ON for low temp")
visible(BLEED2_TEMP_NORM_IND, false)
print("bleed2 temp NORM ind OFF for low temp")
end
if BLEED_TEMP[2] > 260 and BLEED_TEMP[2] <=304 then
visible(BLEED2_TEMP_CAUT_IND, false)
print("bleed2 temp CAUT ind OFF for REG temp")
visible(BLEED2_TEMP_NORM_IND, true)
print("bleed2 temp NORM ind ON for REG temp")
end
if BLEED_TEMP[2] > 304 then
visible(BLEED2_TEMP_CAUT_IND, true)
print("bleed2 temp CAUT ind ON for HIGH temp")
visible(BLEED2_TEMP_NORM_IND, false)
print("bleed2 temp NORM ind OFF for HIGH temp")
end
end
xpl_dataref_subscribe("sim/flightmodel/engine/ENGN_ITT", "FLOAT[8]", Bleed_temp)
end
-- END ECS/AI PAGE
-- MFD BUTTON 3
------------------------------------------
-- Callback function which is called when Button 3 is pressed on the FO-side MFD Bezel
function FO_MFD_BTN_3_pressed()
print("FO MFD Button 3 pressed")
if MFD_MENU == "Main_Menu" then
visible(MFD_MAIN_MENU, false)
visible(MFD_SYS_MENU, false)
visible(MFD_MFD_MENU, true)
-- visible(MFD_TO_PAGE_MENU_BOX, true)
MFD_MENU = "MFD_Menu"
end
MFD_MENU_DISPLAY()
print(MFD_MENU .. " displayed")
--print(MFD_PAGE .. " displayed")
if MFD_MENU == "SYS_Menu" then
MFD_PAGE = "ECS_Page"
MFD_ECS_PAGE_DISPLAY()
end
end
-- Callback function which is called when Button 3 is released on the FO-side PFD Bezel
function FO_MFD_BTN_3_released()
print("FO MFD Button 3 released")
end
-- Create the hardware for Button 3 on the FO-side MFD. The actual pin used can be configured in Air Manager.
hw_button_add("FO MFD BTN 3", FO_MFD_BTN_3_pressed, FO_MFD_BTN_3_released)