| 1 |
# Copyright 2018 Stuart Buchanan |
| 2 |
# This file is part of FlightGear. |
| 3 |
# |
| 4 |
# FlightGear is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# FlightGear is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with FlightGear. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
# FG Commands to support simple bindings |
| 18 |
io.include("Constants.nas"); |
| 19 |
|
| 20 |
removecommand("FG1000HardKeyPushed"); |
| 21 |
addcommand("FG1000HardKeyPushed", |
| 22 |
func(node) { |
| 23 |
var device = node.getNode("device", 1).getValue(); |
| 24 |
var name = node.getNode("notification",1).getValue(); |
| 25 |
|
| 26 |
# The knob animation stores the value as an offset property. Other animations need to set this |
| 27 |
# explicitly int the animation code. |
| 28 |
var value = node.getNode("offset", 1).getValue(); |
| 29 |
|
| 30 |
if (name == nil) { |
| 31 |
print("FG1000HardKeyPushed: No <name> argument passed to fgcommand"); |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
if (value == nil) { |
| 36 |
print("FG1000HardKeyPushed: No <offset> argument passed to fgcommand"); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
if (device == nil) { |
| 41 |
print("FG1000HardKeyPushed: No <device> argument passed to fgcommand for " ~ name); |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
# Notification may be provided as a number, or a string. |
| 46 |
if (int(name) == nil) { |
| 47 |
# Name is a string, to map it to the correct INT id. |
| 48 |
if (FASCIA[name] != nil) { |
| 49 |
name = FASCIA[name]; |
| 50 |
} else { |
| 51 |
print("Unable to find FASCIA entry for Hard Key " ~ name); |
| 52 |
return; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
var notification = notifications.PFDEventNotification.new( |
| 57 |
"MFD", |
| 58 |
int(device), |
| 59 |
notifications.PFDEventNotification.HardKeyPushed, |
| 60 |
{ Id: name, Value: value } |
| 61 |
); |
| 62 |
emesary.GlobalTransmitter.NotifyAll(notification); |
| 63 |
} |
| 64 |
); |
| 65 |
|
| 66 |
removecommand("FG1000SoftKeyPushed"); |
| 67 |
addcommand("FG1000SoftKeyPushed", |
| 68 |
func(node) { |
| 69 |
var device = int(node.getNode("device", 1).getValue()); |
| 70 |
var value = node.getNode("offset", 1).getValue(); |
| 71 |
|
| 72 |
if (device == nil) { |
| 73 |
print("FG1000SoftKeyPushed: Unknown device" ~ node.getNode("device").getValue()); |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
if (value == nil) { |
| 78 |
print("FG1000SoftKeyPushed: No <offset> value for softkey number"); |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
if (int(value) == nil) { |
| 83 |
print("Unable to convert softkey number to integer " ~ node.getNode("value").getValue()); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
value = int(value); |
| 88 |
|
| 89 |
var notification = notifications.PFDEventNotification.new( |
| 90 |
"MFD", |
| 91 |
device, |
| 92 |
notifications.PFDEventNotification.SoftKeyPushed, |
| 93 |
value |
| 94 |
); |
| 95 |
emesary.GlobalTransmitter.NotifyAll(notification); |
| 96 |
} |
| 97 |
); |
| 98 |
|
| 99 |
# This command is a convenience for multi-key/menu support to make it easier to |
| 100 |
# navigate to particular pages without having to use the FMS knobs. |
| 101 |
removecommand("FG1000SelectPage"); |
| 102 |
addcommand("FG1000SelectPage", |
| 103 |
func(node) { |
| 104 |
var device = node.getNode("device", 1).getValue(); |
| 105 |
var group = node.getNode("group",1).getValue(); |
| 106 |
var page = node.getNode("page",1).getValue(); |
| 107 |
|
| 108 |
if (group == nil) { |
| 109 |
print("FG1000SelectPage: No <group> argument passed to fgcommand"); |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
if (page == nil) { |
| 114 |
print("FG1000SelectPage: No <page> argument passed to fgcommand"); |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
if (device == nil) { |
| 119 |
print("FG1000SelectPage: No <device> argument passed to fgcommand for " ~ name); |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
var notification = notifications.PFDEventNotification.new( |
| 124 |
"MFD", |
| 125 |
int(device), |
| 126 |
notifications.PFDEventNotification.SelectPageById, |
| 127 |
{ Group: group, Page: page } |
| 128 |
); |
| 129 |
emesary.GlobalTransmitter.NotifyAll(notification); |
| 130 |
} |
| 131 |
); |