1
0
Fork 0

Create a Listener-based property publisher.

Use it for NavCom, and include the Nav IDs in the display.
This commit is contained in:
Stuart Buchanan 2018-01-10 23:11:38 +00:00
parent a25c66850a
commit b45ae04c15
7 changed files with 122 additions and 51 deletions

View file

@ -23,9 +23,9 @@
borderopacity="0" borderopacity="0"
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="7.9999999" inkscape:zoom="1.4142135"
inkscape:cx="803.96414" inkscape:cx="208.90255"
inkscape:cy="710.97882" inkscape:cy="491.35422"
inkscape:document-units="px" inkscape:document-units="px"
inkscape:current-layer="SurroundGroup" inkscape:current-layer="SurroundGroup"
showgrid="true" showgrid="true"
@ -279,7 +279,7 @@
<text <text
sodipodi:linespacing="125%" sodipodi:linespacing="125%"
inkscape:label="nav1-id" inkscape:label="nav1-id"
id="nav1-id" id="SurroundNav1ID"
y="21.999998" y="21.999998"
x="219.32292" x="219.32292"
style="display:inline;font-style:normal;font-weight:normal;font-size:18.66666603px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" style="display:inline;font-style:normal;font-weight:normal;font-size:18.66666603px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
@ -292,7 +292,7 @@
<text <text
sodipodi:linespacing="125%" sodipodi:linespacing="125%"
inkscape:label="nav2-id" inkscape:label="nav2-id"
id="nav2-id" id="SurroundNav2ID"
y="47.054035" y="47.054035"
x="219.32292" x="219.32292"
style="display:inline;font-style:normal;font-weight:normal;font-size:18.66666603px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" style="display:inline;font-style:normal;font-weight:normal;font-size:18.66666603px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

View file

@ -2,9 +2,12 @@
var GenericEISPublisher = var GenericEISPublisher =
{ {
new : func (frequency=0.25, transmitter = nil) { new : func (frequency=0.25) {
var obj = { var obj = {
parents : [ GenericEISPublisher, PropertyPublisher.new(frequency, transmitter) ], parents : [
GenericEISPublisher,
PeriodicPropertyPublisher.new(notifications.PFDEventNotification.EngineData, frequency)
],
}; };
# Hack to handle most aircraft not having proper engine hours # Hack to handle most aircraft not having proper engine hours
@ -25,6 +28,9 @@ var GenericEISPublisher =
return obj; return obj;
}, },
# Custom publish method as we package the values into an array of engines,
# in this case, only one!
publish : func() { publish : func() {
var engineData0 = {}; var engineData0 = {};
@ -36,6 +42,12 @@ var GenericEISPublisher =
var engineData = []; var engineData = [];
append(engineData, engineData0); append(engineData, engineData0);
me.notify(notifications.PFDEventNotification.EngineData, engineData); var notification = notifications.PFDEventNotification.new(
"MFD",
1,
notifications.PFDEventNotification.EngineData,
engineData);
me._transmitter.NotifyAll(notification);
}, },
}; };

View file

@ -1,9 +1,12 @@
# NavCom Interface using Emesary for a simple dual Nav/Com system using standard properties # NavCom Interface using Emesary for a simple dual Nav/Com system using standard properties
var GenericNavComPublisher = var GenericNavComPublisher =
{ {
new : func (frequency=0.25, transmitter = nil) { new : func () {
var obj = { var obj = {
parents : [ GenericNavComPublisher, PropertyPublisher.new(frequency, transmitter) ], parents : [
GenericNavComPublisher,
TriggeredPropertyPublisher.new(notifications.PFDEventNotification.NavComData)
],
}; };
# Hack to handle cases where there is no selected COMM or NAV frequency # Hack to handle cases where there is no selected COMM or NAV frequency
@ -11,7 +14,7 @@ var GenericNavComPublisher =
if (getprop("/instrumentation/nav-selected") == nil) setprop("/instrumentation/nav-selected", 1); if (getprop("/instrumentation/nav-selected") == nil) setprop("/instrumentation/nav-selected", 1);
obj.addPropMap("Comm1SelectedFreq", "/instrumentation/comm/frequencies/selected-mhz"); obj.addPropMap("Comm1SelectedFreq", "/instrumentation/comm/frequencies/selected-mhz");
obj.addPropMap("Comm1StandbyFreq", "/instrumentation/comm/frequencies/selected-mhz"); obj.addPropMap("Comm1StandbyFreq", "/instrumentation/comm/frequencies/standby-mhz");
obj.addPropMap("Comm1AirportID", "/instrumentation/comm/airport-id"); obj.addPropMap("Comm1AirportID", "/instrumentation/comm/airport-id");
obj.addPropMap("Comm1StationName", "/instrumentation/comm/station-name"); obj.addPropMap("Comm1StationName", "/instrumentation/comm/station-name");
obj.addPropMap("Comm1StationType", "/instrumentation/comm/station-type"); obj.addPropMap("Comm1StationType", "/instrumentation/comm/station-type");
@ -19,7 +22,7 @@ var GenericNavComPublisher =
obj.addPropMap("Comm1Serviceable", "/instrumentation/comm/serviceable"); obj.addPropMap("Comm1Serviceable", "/instrumentation/comm/serviceable");
obj.addPropMap("Comm2SelectedFreq", "/instrumentation/comm[1]/frequencies/selected-mhz"); obj.addPropMap("Comm2SelectedFreq", "/instrumentation/comm[1]/frequencies/selected-mhz");
obj.addPropMap("Comm2StandbyFreq", "/instrumentation/comm[1]/frequencies/selected-mhz"); obj.addPropMap("Comm2StandbyFreq", "/instrumentation/comm[1]/frequencies/standby-mhz");
obj.addPropMap("Comm2AirportID", "/instrumentation/comm[1]/airport-id"); obj.addPropMap("Comm2AirportID", "/instrumentation/comm[1]/airport-id");
obj.addPropMap("Comm2StationName", "/instrumentation/comm[1]/station-name"); obj.addPropMap("Comm2StationName", "/instrumentation/comm[1]/station-name");
obj.addPropMap("Comm2StationType", "/instrumentation/comm[1]/station-type"); obj.addPropMap("Comm2StationType", "/instrumentation/comm[1]/station-type");
@ -29,12 +32,12 @@ var GenericNavComPublisher =
obj.addPropMap("CommSelected", "/instrumentation/com-selected"); obj.addPropMap("CommSelected", "/instrumentation/com-selected");
obj.addPropMap("Nav1SelectedFreq", "/instrumentation/nav/frequencies/selected-mhz"); obj.addPropMap("Nav1SelectedFreq", "/instrumentation/nav/frequencies/selected-mhz");
obj.addPropMap("Nav1StandbyFreq", "/instrumentation/nav/frequencies/selected-mhz"); obj.addPropMap("Nav1StandbyFreq", "/instrumentation/nav/frequencies/standby-mhz");
obj.addPropMap("Nav1ID", "/instrumentation/nav/nav-id"); obj.addPropMap("Nav1ID", "/instrumentation/nav/nav-id");
obj.addPropMap("Nav1Serviceable", "/instrumentation/nav/serviceable"); obj.addPropMap("Nav1Serviceable", "/instrumentation/nav/serviceable");
obj.addPropMap("Nav2SelectedFreq", "/instrumentation/nav[1]/frequencies/selected-mhz"); obj.addPropMap("Nav2SelectedFreq", "/instrumentation/nav[1]/frequencies/selected-mhz");
obj.addPropMap("Nav2StandbyFreq", "/instrumentation/nav[1]/frequencies/selected-mhz"); obj.addPropMap("Nav2StandbyFreq", "/instrumentation/nav[1]/frequencies/standby-mhz");
obj.addPropMap("Nav2ID", "/instrumentation/nav[1]/nav-id"); obj.addPropMap("Nav2ID", "/instrumentation/nav[1]/nav-id");
obj.addPropMap("Nav2Serviceable", "/instrumentation/nav[1]/serviceable"); obj.addPropMap("Nav2Serviceable", "/instrumentation/nav[1]/serviceable");
@ -43,15 +46,4 @@ var GenericNavComPublisher =
return obj; return obj;
}, },
publish : func() {
var data = {};
foreach (var propmap; me._propmaps) {
var name = propmap.getName();
data[name] = propmap.getValue();
}
me.notify(notifications.PFDEventNotification.NavComData, data);
},
}; };

View file

@ -1,49 +1,62 @@
# Generic PropertyPublisher class for the FG1000 MFD using Emesary # Generic PropertyPublisher classes for the FG1000 MFD using Emesary
# Publishes property values to Emesary for consumption by the MFD # Publishes property values to Emesary for consumption by the MFD
#
# Two variants:
# - TriggeredPropertyPublisher which publishes based on listening to properties
# - PeriodicPropertyPublisher which publishes on a periodic basis
#
#
#
var PropertyPublisher = var PropMap = {
{
PropMap : {
new : func(name, property) new : func(name, property)
{ {
var obj = { parents : [ PropertyPublisher.PropMap ] }; var obj = { parents : [ PropMap ] };
obj._name = name; obj._name = name;
obj._prop = globals.props.getNode(property, 1); obj._prop = globals.props.getNode(property, 1);
return obj; return obj;
}, },
getName : func() { return me._name; }, getName : func() { return me._name; },
getPropPath : func() { return me._prop.getPath(); },
getValue : func() { return me._prop.getValue(); }, getValue : func() { return me._prop.getValue(); },
}, getProp: func() { return me._prop; },
new : func (frequency=0.25, transmitter = nil) {
var obj = {
parents : [ PropertyPublisher ],
_transmitter : transmitter,
_frequency : frequency,
_propmaps : [],
}; };
if (obj._transmitter == nil) obj._transmitter = emesary.GlobalTransmitter; var PeriodicPropertyPublisher =
{
new : func (notification, frequency=0.25) {
var obj = {
parents : [ PeriodicPropertyPublisher ],
_notification : notification,
_frequency : frequency,
_propmaps : [],
_timer: nil,
};
obj._transmitter = emesary.GlobalTransmitter;
obj._publishTimer = nil; obj._publishTimer = nil;
return obj; return obj;
}, },
addPropMap : func(name, prop) { addPropMap : func(name, prop) {
append(me._propmaps, PropertyPublisher.PropMap.new(name, prop)); append(me._propmaps, PropMap.new(name, prop));
}, },
publish : func() { publish : func() {
}, var data = {};
foreach (var propmap; me._propmaps) {
var name = propmap.getName();
data[name] = propmap.getValue();
}
notify : func(notification, data) {
var notification = notifications.PFDEventNotification.new( var notification = notifications.PFDEventNotification.new(
"MFD", "MFD",
1, 1,
notification, me._notification,
data); data);
me._transmitter.NotifyAll(notification); me._transmitter.NotifyAll(notification);
@ -58,3 +71,53 @@ var PropertyPublisher =
me._timer = nil; me._timer = nil;
}, },
}; };
var TriggeredPropertyPublisher =
{
new : func (notification) {
var obj = {
parents : [ TriggeredPropertyPublisher ],
_notification : notification,
_propmaps : {},
_listeners : [],
};
obj._transmitter = emesary.GlobalTransmitter;
return obj;
},
addPropMap : func(name, prop) {
me._propmaps[prop] = name;
},
publish : func(propNode) {
var data = {};
var name = me._propmaps[propNode.getPath()];
assert(name != nil, "Unable to find property map for " ~ name);
data[name] = propNode.getValue();
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me._notification,
data);
me._transmitter.NotifyAll(notification);
},
start : func() {
foreach (var prop; keys(me._propmaps)) {
# Set up a listener triggering on create (to ensure all values are set at
# start of day) and only on changed values. These are the last two
# arguments to the setlistener call.
var listener = setlistener(prop, func(p) { me.publish(p); }, 1, 0);
append(me._listeners, listener);
}
},
stop : func() {
foreach (var l; me._listeners)
removelistener(l);
},
};

View file

@ -57,7 +57,7 @@ var PropertyUpdater =
RegisterWithEmesary : func(){ RegisterWithEmesary : func(){
if (me._recipient == nil){ if (me._recipient == nil){
me._recipient = emesary.Recipient.new("AirportInfoController_" ~ me._page.device.designation); me._recipient = emesary.Recipient.new("PropertyUpdater_" ~ me._page.device.designation);
var pfd_obj = me._device; var pfd_obj = me._device;
var controller = me; var controller = me;
me._recipient.Receive = func(notification) me._recipient.Receive = func(notification)

View file

@ -52,6 +52,7 @@ var Surround =
"Comm2StandbyFreq", "Comm2SelectedFreq", "Comm2StandbyFreq", "Comm2SelectedFreq",
"Nav1StandbyFreq", "Nav1SelectedFreq", "Nav1StandbyFreq", "Nav1SelectedFreq",
"Nav2StandbyFreq", "Nav2SelectedFreq", "Nav2StandbyFreq", "Nav2SelectedFreq",
"Nav1ID", "Nav2ID"
]; ];
obj.addTextElements(textElements); obj.addTextElements(textElements);
@ -169,6 +170,10 @@ var Surround =
me._nav2selected.highlightElement(); me._nav2selected.highlightElement();
} }
} }
if (name == "Nav1ID") me.setTextElement("Nav1ID", val);
if (name == "Nav2ID") me.setTextElement("Nav2ID", val);
} }
}, },

View file

@ -519,7 +519,6 @@
append(listeners, softkey_listener); append(listeners, softkey_listener);
]]></load></nasal> ]]></load></nasal>
</canvas> </canvas>
<layout>hbox</layout> <layout>hbox</layout>