Help with instrument that has multiple display pages

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
erj145sim
Posts: 34
Joined: Mon Feb 10, 2020 1:03 pm

Help with instrument that has multiple display pages

#1 Post by erj145sim »

Hello everyone,

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)



JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Help with instrument that has multiple display pages

#2 Post by JackZ »

Here’s my 10 cents.
In your code, you set the Bleed Air indication visibility to true

Code: Select all

visible(BLEED1_TEMP_NORM_IND, true)
That means that no matter what was the visibility of the group that value is in, it is turned visible. You need a way to set an element to visible or not according to the current group visibility this element is in.

So my suggestion would be to create and have a Boolean status variable for each system page you use, that keeps the state of the specific page, such as

Code: Select all

Bleed_Page_is_Displayed=true — or false

This variable is set once the group is created and every time you turn the Page (read: the group) visibility ON or OFF, you also set this value to true or false.

You can then use this status value in your code whenever you want to address a particular element in the group.
The element will then be displayed ONLY when the visibility status of the page (here Bleed_Page_is_Displayed) is true.
For example the previous line becomes :

Code: Select all

visible(BLEED1_TEMP_NORM_IND, Bleed_Page_is_Displayed
 )
This logic also applies to all the individual elements you turn visible by the way, such as for example here

Code: Select all

visible(OXY_PRESS_NORM_IND, true)
Side note: There is no way to prevent the dataref to be updated, once it is subscribed to (automatic Air Manager process), but since you control the visibility of the displayed value, this is not really an issue.

It is NOT a good practice to place the dataref_subscribe() into a function, as this is a “single action” line and that means it should be called only once. Here you call the subscribe every time you enter the function.

Hope this helps.
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

erj145sim
Posts: 34
Joined: Mon Feb 10, 2020 1:03 pm

Re: Help with instrument that has multiple display pages

#3 Post by erj145sim »

Hi Jacques,

Thanks so much for your reply and insight! I will try make the suggested changes and report back.

Marco

erj145sim
Posts: 34
Joined: Mon Feb 10, 2020 1:03 pm

Re: Help with instrument that has multiple display pages

#4 Post by erj145sim »

Hi again Jacques,

Wanted to circle back and thank you again for your guidance with my issue. It took a few trials and adjustments (and some optimization(I use the term loosely here)) on my code, but I finally got it working! It’s perfect now!
Thanks again for the help!

Marco

Post Reply