Canvas EFIS Framework

From FlightGear wiki
Revision as of 11:32, 8 February 2020 by Jsb (Talk | contribs)

Jump to: navigation, search
This article is a stub. You can help the wiki by expanding it.


The canvas EFIS framework (created by jsb) is by-product of the EFIS development done for the CRJ700 family, which uses Rockwell Collins Proline. It is published as a separate framework in the hope that it is useful for other aircraft as well, however some features may be rather specific. The biggest motivation and primary design goal was to support "near optimal" performance but that does not come automatically of course.

For the bigger picture see also Howto:Add an EFIS to your aircraft.

Introduction and Overview

An EFIS usually comprises multiple display units (DU for short; CRT or LCD screens) to show all the information relevant to the pilot (e.g. 2x PFD, 2x MFD, 2x EICAS in the CRJ700). Some displays like an EICAS / ECAM may show different pages for the systems of the aircraft, they can be select by the pilot via a corresponding control panel. Furthermore, displays can be swapped in case of a DU fault. In the CRJ700 the pilot can select display sources by turning the corresponding knobs.

The EFIS framework provides Nasal classes to handle the following:

Display unit

  • reference to a 3D object in the cockpit ("display unit") on which the canvas texture shall be displayed
  • power switch property
  • image source (canvas reference)

Note: Dimming of display can be done by defining an animation in the XML going with the 3D model of the DU. See example below.

Image source (EFISCanvas)

  • base class for EFIS/EICAS pages handling some SVG stuff
  • can load a SVG file and create clipping from <name>_clip elements
  • allows to register multiple update functions with individual update intervals
  • update functions can be en-/disabled by a single property that should reflect the visibility of the canvas (e.g. do not waste CPU with updating pages that are not currently displayed)
  • several listener factories for common animations like show/hide, translation, rotation

Display selectors / routing

  • Handle input events from cockpit knobs to switch displays / pages

EICAS Message system

  • Handle EICAS messages efficiently without eating up to much frame rate
  • Message queue: decouple canvas updates from message arrival

Thoughts on implementation

Design goal: EFIS framework should support best performance by offering different update methods and update rates for efficency.

Update rates

The EFIS/EICAS basically monitors the whole aircraft so it will have to read lots of properties. For efficiency the properties must be grouped into different classes already in the design phase, that is, the aircraft developer shall carefully think about how often a property changes. Some props are written to at frame rate by property rules but that does not mean the value changes every time. Furthermore, not every change has the same relevance, not everything needs to be displayed real time (= frame rate).

update rate Interval comment
2 0.500s low performance needs
10 0.100s low to med. performance but no fluent animation
20 0.050s
30 0.033s smooth canvas animation but possibly high performance need
60 0.017s

Some examples:

  • PFD contains many "real-time" elements like attitude indicator, speed, altitude etc. They should be updated probably at frame rate (min. 25 Hz) Other elements like radio frequency may be ok to update after 100ms or even 0.5s
  • An EICAS page displaying the door status maybe just fine with one update per second as doors move slowly and you won't see the door from outside and EICAS display inside the cockpit at the same time so a delay of one second does not matter

Update methods

  • Simple approach is to write an update loop that reads all relevant props, calculates the needed updates and updates the canvas elements (which in the end means writing properties) -> tends to be inefficient.
  • Property read/write is somehow "expensive" and can cost you a lot of frame rate. So the next better idea could be to limit the rate at which the update function is called - usually by a timer with some sensible interval.
  • If an animation is triggered only by one property and that property is unlikely to change often, remove the prop / animation from the update loop and use a listener instead. The listener may read other props as needed. A listener does not consume any CPU unless the property it listens to has changed, in which case the listener function is run.

Framework documentation

This section documents the framework classes and their methods.

Class EFIS

This is the top level class which ties together the different parts like display units, sources and cockpit controls.


new(display_names, object_names, canvas_settings=nil);

Returns a new EFIS object

Vector of display names
Vector of 3D object names for canvas placement.
Optional config hash for canvas that is merged with default settings of EFIS class



Creates listener for property path. Power on will start all display update functions, power of will stop them.

Property path to EFIS power property (bool).



Sets default size for canvas windows

Vector [size_x, size_y]


setDUPowerProps(power_props, minimum_power=0);

Sets default size for canvas windows

Vector of property paths, must be of same size as display_names given to new().
Passed to DisplayUnit.setPowerSource()



Adds a EFISCanvas as display source, returns source ID to be used in mappings.

A EFISCanvas instance created with


addDisplaySwapControl(ctrl, mappings, callback=nil);

Adds a listener for "ctrl", activates new source-display-mapping on change. Use this to implement a display swap knob in the cockpit.

optional function that will be called with current ctrl value


addSourceSelector(selected, target, sources=nil);

Adds a listener for "selected" which will read the target DU from "target" and sets its source according to "selected". Use this e.g. for a EICAS / ECAM page select panel.

optional vector; selected -> source ID (as returned by addSource), defaults to all registered sources



Sets and activates a default mapping of sources to display units.

Vector [source_id1, source_id2, ...] or hash {DisplayName: source_id}



Opens display unit as canvas window.

Index of display

Class EFISCanvas

EFISCanvas manages a single canvas for you. It offers a bunch of little helpers to make the live of an aircraft developer easier. These helpers mostly do animation and update stuff on canvas elements in an efficient way.


new(name, svgfile);

Returns a new EFISCanvas

Used e.g. in window title (see below)
Filename of a SVG to load. (see also: loadsvg)


returns path of canvas


returns canvas instance


returns root group of the canvas



set a node that is checked in all registered update functions, they will only be run, if the value of this node is true

props.node object



Parses the given SVG file into the root group of the EFISCanvas. Clipping is setup for elements that have a corresponding element with the same name extended by "_clip".

filepath passed to canvas.parsesvg


addUpdateFunction(f, interval);

Creates a timer with given interval that runs the given function if the value of the update node is true.

Nasal function to run
Interval in seconds


Start all update timers.


Stop all update timers.


When updating EFIS displays, there is a need to access properties under /instrumentation very often. To avoid the rather expensive append operator ("~") and property path lookups, you should use this little helper. It creates node objects (only once) to access properties like "/instrumentation/"~sys~"["~id~"]/"~prop,

getInstr(sys, prop, default=0, id=nil);

Helper to quickly access instrumentation properties with this name schema: "/instrumentation/"~sys~"["~id~"]/"~prop

the system name under /instrumentation
Optional default value to return, if getValue() returns nil
Optional override the id of the current EFISCanvas obj (


updateTextElement(svgkey, text, color=nil);

Updates a single text element and optionally sets its color.

Name of the text element to update.
new text, passed to setText()
Vector [r,g,b] or valid color name from EFISCanvas.colors


private function that sets clipping for an element, if there is another element with the same name extended by "_clip".

Listener factories


The following listener factories will return a function. The general usage is setlistener("/some/property/name", _makeListener_xxx(parameters), 1, 0);

As usual, the listened-to node is passed into the listener function as first argument and the function will getValue() and do something meaningful with the value.

The first argument to the listener factory functions is always svgkey which can be either a string naming one canvas element or a vector of such strings.

_makeListener_showHide(svgkey, value=nil);

Returns listener to show/hide element(s).

String or vector; the element(s) to update.
optional value to trigger show(); otherwise node.value will be implicitly treated as bool.
_makeListener_rotate(svgkey, factors=nil);

Returns listener to rotate one or more canvas element(s) by property value. If svgkey is a vector, factors must be a hash having each elemnent in svgkey as a key and the corresponding factor.

String or vector; the element(s) to update.
Factor for setRotation(value * factor); defaults to 1 if not given
_makeListener_translate(svgkey, fx, fy);

Returns listener to translate one or more canvas element(s) by property value. If svgkey is a vector, fx and fy must be hashes having each elemnent in svgkey as a key and the corresponding factor for translation.

String or vector; the element(s) to update.
Factor for translation in x direction
Factor for translation in y direction
_makeListener_setColor(svgkey, color_true, color_false);

Returns generic listener to change element color. Both color arguments can be either a vector [r,g,b] or a valid name (hash key) for EFISCanvas.colors;

String or vector; element(s) on which to call setColor().
Color to use, if getValue() is true.
Color to use, if getValue() is false.
_makeListener_updateText(svgkey, format="%s", default="");

Returns listener to update a canvas text element from property value.

The element to update.
A valid format string for printf()
Value to use, if getValue() returns nil or false.

Methods of class DisplayUnit

This class is used by the EFIS class. DisplayUnit creates and places a canvas to a 3D object specified in new().


new(name, canvas_settings, screen_obj, parent_obj = nil);

Configure the nasal file to load.

Used e.g. in window title (see below)
passed to
used for canvas placement
used for canvas placement



Select a canvas to show on the display unit.

A valid canvas path as returned by the canvas.getPath() method.


display_unit.setPowerSource(prop, min);

Sets a listener to prop. Display will show only if property value >= min

Path to property that represents display power supply.
Minimum value of property to show display.


var my_display_unit ="PFD1");
# display turns on when DC power is >= 24 volts
my_display_unit.setPowerSource("/systems/DC/outputs/pfd1", 24);



Opens the display in a canvas window.

Vector [size_x, size_y]; passed to

EICAS / ECAM message system

to be written

Format for message definitions

Class Pager

Class MessageClass

Class MessageSystem

HOWTO and Examples

to be written