1
0
Fork 0

Support fgcommand, multiple MFD instances

- Add fgcommands FG1000HardKeyPushed, FG1000SoftKeyPushed, to
simplify bindings from model XML.  See FG1000/Nasal/commands.nas

- Use Device ID to ensure commands affect only the device to which
they belong.  Navigation data, FMS, EIS and ADC information is shared
across all devices.
This commit is contained in:
Stuart Buchanan 2018-02-04 21:40:37 +00:00
parent deba08f840
commit 857e983524
15 changed files with 185 additions and 119 deletions

View file

@ -196,9 +196,9 @@ var AirportInfoController =
# Use Emesary to get the airport
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NearestAirports", Value: id});
{Id: "NearestAirports", Value: nil});
var response = me._transmitter.NotifyAll(notification);
var retval = notification.EventParameter.Value;
@ -217,7 +217,7 @@ var AirportInfoController =
# Use Emesary to get the airport
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "AirportByID", Value: id});

View file

@ -167,7 +167,7 @@ var DirectToController =
# type and value;
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: type, Value: value});
@ -185,7 +185,7 @@ var DirectToController =
# type and value;
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: type, Value: value});
@ -333,7 +333,7 @@ var DirectToController =
# Use Emesary to get the destination
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NavDataByID", Value: id});

View file

@ -52,13 +52,11 @@ var EISController =
var controller = me;
me._recipient.Receive = func(notification)
{
if (notification.Device_Id == pfd_obj.device_id
and notification.NotificationType == notifications.PFDEventNotification.DefaultType) {
if (notification.Event_Id == notifications.PFDEventNotification.EngineData
and notification.EventParameter != nil)
{
return controller.handleEngineData(notification.EventParameter);
}
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
notification.Event_Id == notifications.PFDEventNotification.EngineData and
notification.EventParameter != nil)
{
return controller.handleEngineData(notification.EventParameter);
}
return emesary.Transmitter.ReceiptStatus_NotProcessed;
};

View file

@ -113,7 +113,7 @@ getNavAidById : func (params)
var id = params.id;
var type = "all";
if (params.type != nil) type = params.type;
var navdata = findNavaidsByID(id, type);
if ((size(navdata) > 0) and (! me._recentWaypoints.contains(id))) {
me._recentWaypoints.insert(0, id);
@ -223,67 +223,69 @@ RegisterWithEmesary : func()
me._recipient = emesary.Recipient.new("DataInterface");
var pfd_obj = me._device;
var controller = me;
# Note that unlike the various keys, this data isn't specific to a particular
# Device - it's shared by all. Hence we don't check for the notificaiton
# Device_Id.
me._recipient.Receive = func(notification)
{
if (notification.Device_Id == pfd_obj.device_id
and notification.NotificationType == notifications.PFDEventNotification.DefaultType) {
if (notification.Event_Id == notifications.PFDEventNotification.NavData
and notification.EventParameter != nil)
{
var id = notification.EventParameter.Id;
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
notification.Event_Id == notifications.PFDEventNotification.NavData and
notification.EventParameter != nil)
{
var id = notification.EventParameter.Id;
if (id == "NearestAirports") {
notification.EventParameter.Value = controller.getNearestAirports();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "AirportByID") {
notification.EventParameter.Value = controller.getAirportById(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "NavDataByID") {
notification.EventParameter.Value = controller.getNavDataById(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "NavAidByID") {
notification.EventParameter.Value = controller.getNavAidById(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "NavDataWithinRange") {
notification.EventParameter.Value = controller.getNavDataWithinRange(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "Flightplan") {
notification.EventParameter.Value = controller.getFlightplan();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "RecentWaypoints") {
notification.EventParameter.Value = controller.getRecentWaypoints();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "AddRecentWaypoint") {
controller.addRecentWaypoint(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "AirwayWaypoints") {
notification.EventParameter.Value = controller.getAirwayWaypoints();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "UserWaypoints") {
notification.EventParameter.Value = controller.getUserWaypoints();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "CurrentDTO") {
notification.EventParameter.Value = controller.getCurrentDTO();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "SetDirectTo") {
controller.setDirectTo(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "SetDefaultDTO") {
controller.setDefaultDTO(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "NearestAirports") {
notification.EventParameter.Value = controller.getNearestAirports();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "AirportByID") {
notification.EventParameter.Value = controller.getAirportById(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "NavDataByID") {
notification.EventParameter.Value = controller.getNavDataById(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "NavAidByID") {
notification.EventParameter.Value = controller.getNavAidById(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "NavDataWithinRange") {
notification.EventParameter.Value = controller.getNavDataWithinRange(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "Flightplan") {
notification.EventParameter.Value = controller.getFlightplan();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "RecentWaypoints") {
notification.EventParameter.Value = controller.getRecentWaypoints();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "AddRecentWaypoint") {
controller.addRecentWaypoint(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "AirwayWaypoints") {
notification.EventParameter.Value = controller.getAirwayWaypoints();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "UserWaypoints") {
notification.EventParameter.Value = controller.getUserWaypoints();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "CurrentDTO") {
notification.EventParameter.Value = controller.getCurrentDTO();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "SetDirectTo") {
controller.setDirectTo(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "SetDefaultDTO") {
controller.setDefaultDTO(notification.EventParameter.Value);
return emesary.Transmitter.ReceiptStatus_Finished;
}
}
return emesary.Transmitter.ReceiptStatus_NotProcessed;

View file

@ -70,15 +70,14 @@ var PropertyUpdater =
var notificationtype = me._notificationType;
var eventID = me._eventID;
var controller = me;
# Note that we don't care about the device we receive the update from.
me._recipient.Receive = func(notification)
{
if (notification.Device_Id == pfd_obj.device_id
and notification.NotificationType == notificationtype) {
if (notification.Event_Id == eventID
and notification.EventParameter != nil)
{
if (notification.NotificationType == notificationtype and
notification.Event_Id == eventID and
notification.EventParameter != nil)
{
return controller.handleNotificationEvent(notification.EventParameter);
}
}
return emesary.Transmitter.ReceiptStatus_NotProcessed;
};

View file

@ -5,6 +5,7 @@ print("# FG1000 MFD #");
print("##############\n");
io.include("constants.nas");
io.include("commands.nas");
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/";
@ -65,14 +66,14 @@ foreach (var page; MFDPages) {
var MFD =
{
new : func (myCanvas)
new : func (myCanvas, device_id=1)
{
var obj = {
parents : [ MFD ],
EIS : nil,
NavigationMap: nil,
Surround : nil,
_pageList : {}
_pageList : {},
};
obj.ConfigStore = fg1000.ConfigStore.new();
@ -103,6 +104,7 @@ var MFD =
{'font-mapper': fontmapper});
obj._MFDDevice = canvas.PFD_Device.new(obj._svg, 12, "SoftKey", myCanvas, "MFD");
obj._MFDDevice.device_id = device_id;
obj._MFDDevice.RegisterWithEmesary();
# Surround dynamic elements
@ -163,4 +165,8 @@ var MFD =
{
return me._pageList[name];
},
getDeviceID : func() {
return me._MFDDevice.device_id;
},
};

View file

@ -180,7 +180,7 @@ setDefaultDTOWayPoint : func(id)
# Use Emesary to set the default DTO waypoint
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "SetDefaultDTO", Value: id});
@ -188,5 +188,9 @@ setDefaultDTOWayPoint : func(id)
if (me._transmitter.IsFailed(response)) print("Failed to set Default DTO waypoint");
},
getDeviceID : func() {
return me.page.mfd.getDeviceID();
},
};

View file

@ -137,7 +137,6 @@ var NearestAirportsController =
}
if (me._currentGroup == NearestAirportsController.UIGROUP.FREQ) {
# TODO Select the current COM frequency.
var freq = me.page.getSelectedFreq();
if (freq != nil) {
me.page.mfd.SurroundController.setStandbyNavComFreq(freq);
@ -178,7 +177,7 @@ var NearestAirportsController =
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NearestAirports", Value: nil});
@ -195,7 +194,7 @@ var NearestAirportsController =
# Use Emesary to get the airport
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "AirportByID", Value: id});

View file

@ -81,7 +81,7 @@ var NearestIntersectionsController =
getNearestNavData : func(type) {
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NavDataWithinRange", Value: type});
@ -98,7 +98,7 @@ var NearestIntersectionsController =
# Use Emesary to get the Fix
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NavAidByID", Value: { id: id, type: "fix"} });

View file

@ -81,7 +81,7 @@ var NearestNDBController =
getNearestNavData : func(type) {
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NavDataWithinRange", Value: type});
@ -98,7 +98,7 @@ var NearestNDBController =
# Use Emesary to get the Navigation data
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NavAidByID", Value: { id: id, type: "ndb"} });

View file

@ -122,7 +122,7 @@ var NearestVORController =
getNearestNavData : func(type) {
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NavDataWithinRange", Value: type});
@ -139,7 +139,7 @@ var NearestVORController =
# Use Emesary to get the Navigation data
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me.getDeviceID(),
notifications.PFDEventNotification.NavData,
{Id: "NavAidByID", Value: { id: id, type: "vor"} });

View file

@ -31,7 +31,7 @@ var SurroundController =
sendNavComDataNotification : func(data) {
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
me._page.mfd.getDeviceID(),
notifications.PFDEventNotification.NavComData,
data);
@ -352,8 +352,8 @@ var SurroundController =
var controller = me;
me._recipient.Receive = func(notification)
{
if (notification.Device_Id == pfd_obj.device_id
and notification.NotificationType == notifications.PFDEventNotification.DefaultType) {
# Note that we don't care about the device that the data comes from.
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType) {
if (notification.Event_Id == notifications.PFDEventNotification.NavComData
and notification.EventParameter != nil)

View file

@ -0,0 +1,60 @@
# FG Commands to support simple bindings
removecommand("FG1000HardKeyPushed");
addcommand("FG1000HardKeyPushed",
func(node) {
var device = int(node.getNode("device").getValue());
var name = node.getNode("notification").getValue();
var value = node.getNode("value").getValue();
if (device == nil) {
print("FG1000HardKeyPushed: Unknown device" ~ node.getNode("device").getValue());
return;
}
# Notification may be provided as a number, or a string.
if (int(name) == nil) {
# Name is a string, to map it to the correct INT id.
if (defined(fg1000.FASCIA[name])) {
name = fg1000.FASCIA[name];
} else {
print("Unable to find FASCIA entry for Hard Key " ~ name);
return;
}
}
var notification = notifications.PFDEventNotification.new(
"MFD",
device,
notifications.PFDEventNotification.HardKeyPushed,
{ Id: name, Value: value }
);
emesary.GlobalTransmitter.NotifyAll(notification);
}
);
removecommand("FG1000SoftKeyPushed");
addcommand("FG1000SoftKeyPushed",
func(node) {
var device = int(node.getNode("device").getValue());
var value = int(node.getNode("value").getValue());
if (device == nil) {
print("FG1000SoftKeyPushed: Unknown device" ~ node.getNode("device").getValue());
return;
}
if (value == nil) {
print("Unable to convert softkey number to integer " ~ node.getNode("value").getValue());
return;
}
var notification = notifications.PFDEventNotification.new(
"MFD",
device,
notifications.PFDEventNotification.SoftKeyPushed,
value
);
emesary.GlobalTransmitter.NotifyAll(notification);
}
);

View file

@ -69,8 +69,6 @@ var NAV_SPACING = [
var MIN_NAV_FREQ = 108.000;
var MAX_NAV_FREQ = 118.000;
# When the CRSR is selecting fields, this is the period for changing the
# cursor color between normal and highlight (defined below)
# Constants for the hard-buttons on the fascia
var FASCIA = {
NAV_VOL : 0,

View file

@ -1,9 +1,10 @@
io.include("constants.nas");
var MFDGUI =
{
# List of UI hotspots and their mapping to Emesary bridge notifications
WHEEL_HOT_SPOTS : [
{ notification: fg1000.FASCIA.NAV_VOL, shift: 0, top_left: [65, 45], bottom_right: [112, 90] },
@ -89,6 +90,13 @@ var MFDGUI =
scale : 1.0,
};
# Increment the device count, so we get an uniqueish device id.
obj.device_id = getprop("/instrument/fg1000/device-count");
if (obj.device_id == nil) obj.device_id = 0;
setprop("/instrument/fg1000/device-count", obj.device_id + 1);
print("Device count: " ~ getprop("/instrument/fg1000/device-count"));
print("Device ID: " ~ obj.device_id);
obj.scale = getprop("/sim/gui/mfd-scale") or 1.0;
obj.window = canvas.Window.new([obj.scale*obj.width,obj.scale*obj.height],"dialog").set('title',"FG1000 MFD");
@ -120,7 +128,7 @@ var MFDGUI =
if (obj.scale > 0.999) {
# If we're at full scale, then create it directly in this Canvas as that
# produces sharper results and perhaps better performance
obj.mfd = fg1000.MFD.new(obj.myCanvas);
obj.mfd = fg1000.MFD.new(obj.myCanvas, obj.device_id);
obj.mfd._svg.setTranslation(186,45);
#obj.mfd._svg.set("z-index", 150);
} else {
@ -132,7 +140,7 @@ var MFDGUI =
"view" : [1024, 768],
"mipmapping": 0,
});
obj.mfd = fg1000.MFD.new(obj.mfd_canvas);
obj.mfd = fg1000.MFD.new(obj.mfd_canvas, obj.device_id);
var mfd_child = obj.root.createChild("image")
.setFile(obj.mfd_canvas.getPath())
@ -176,13 +184,11 @@ var MFDGUI =
(e.shiftKey == hotspot.shift))
{
# We've found the hotspot, so send a notification to deal with it
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
notifications.PFDEventNotification.HardKeyPushed,
{ Id: hotspot.notification, Value: e.deltaY }
);
emesary.GlobalTransmitter.NotifyAll(notification);
var args = {'device': obj.device_id,
'notification': hotspot.notification,
'value' : e.deltaY};
fgcommand("FG1000HardKeyPushed", props.Node.new(args));
break;
}
}
@ -197,13 +203,11 @@ var MFDGUI =
(e.shiftKey == hotspot.shift))
{
# We've found the hotspot, so send a notification to deal with it
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
notifications.PFDEventNotification.HardKeyPushed,
{ Id: hotspot.notification, Value: hotspot.value }
);
emesary.GlobalTransmitter.NotifyAll(notification);
var args = {'device': obj.device_id,
'notification': hotspot.notification,
'value' : hotspot.value};
fgcommand("FG1000HardKeyPushed", props.Node.new(args));
break;
}
}
@ -213,13 +217,9 @@ var MFDGUI =
(e.localY > obj.scale*hotspot.top_left[1]) and (e.localY < obj.scale*hotspot.bottom_right[1]))
{
# We've found the hotspot, so send a notification to deal with it
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
notifications.PFDEventNotification.SoftKeyPushed,
hotspot.Id
);
emesary.GlobalTransmitter.NotifyAll(notification);
var args = {'device': obj.device_id,
'value' : hotspot.Id};
fgcommand("FG1000SoftKeyPushed", props.Node.new(args));
break;
}
}