xp-command 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -16
- package/bin/index.js +9 -6
- package/package.json +1 -1
- package/src/api.js +30 -1
- package/src/config.js +1 -1
- package/src/config.yml +45 -14
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Quick cockpit commands for X-Plane 12** - set your radios, altimeter, autopilot, and more from the terminal while flying.
|
|
4
4
|
|
|
5
|
-
|  |  |
|
|
6
6
|
| ----------------- | ---------------- |
|
|
7
7
|
|
|
8
8
|
|
|
@@ -89,23 +89,30 @@ All pre-configured commands work well with most aircraft I currently fly, but yo
|
|
|
89
89
|
|
|
90
90
|
### Barometric pressure
|
|
91
91
|
|
|
92
|
-
| Command
|
|
93
|
-
|
|
94
|
-
| `q`
|
|
95
|
-
| `l`
|
|
96
|
-
| `q####`
|
|
97
|
-
| `l####`
|
|
92
|
+
| Command | Action | Example |
|
|
93
|
+
|----------|-----------------------------------------|--------------|
|
|
94
|
+
| `q` | Get QNH in hPa/mb (copied to clipboard) | `q` → `1013` |
|
|
95
|
+
| `l` | Get QNH in inHg (copied to clipboard) | `l` → `2992` |
|
|
96
|
+
| `q####` | Set QNH in hPa/mb | `q1013` |
|
|
97
|
+
| `l####` | Set QNH in inHg | `l2992` |
|
|
98
|
+
| `m###` | Set BARO minimum in feet | `m200` |
|
|
99
|
+
| `mra###` | Set RA minimum in feet | `mra1451` |
|
|
100
|
+
|
|
101
|
+
**Minimums format:** Minimums take one to four digits and can range from 0 to 5000.
|
|
98
102
|
|
|
99
103
|
### Autopilot
|
|
100
104
|
|
|
101
|
-
| Command | Action
|
|
102
|
-
|
|
103
|
-
| `h###` | Set heading
|
|
104
|
-
| `a###` | Set altitude (flight level)
|
|
105
|
-
| `a#####` | Set altitude (exact feet)
|
|
106
|
-
| `s###` | Set speed in KIAS
|
|
107
|
-
| `s##` | Set speed in Mach
|
|
108
|
-
| `v####` | Set vertical speed
|
|
105
|
+
| Command | Action | Example |
|
|
106
|
+
|----------|-----------------------------------------|---------------------------|
|
|
107
|
+
| `h###` | Set heading | `h090` → 090° |
|
|
108
|
+
| `a###` | Set altitude (flight level) | `a250` → FL250 (25000 ft) |
|
|
109
|
+
| `a#####` | Set altitude (exact feet) | `a03500` → 3500 ft |
|
|
110
|
+
| `s###` | Set speed in KIAS | `s180` → 180 knots |
|
|
111
|
+
| `s##` | Set speed in Mach | `s78` → Mach 0.78 |
|
|
112
|
+
| `v####` | Set vertical speed | `v1500` → 1500 ft/min |
|
|
113
|
+
| `fms` | Copy current FMS CDU1 text to clipboard | |
|
|
114
|
+
|
|
115
|
+
**The `fms` command:** This command can be very helpful, if you want to quickly paste the FMS screen content into a prompt. Note that only the first line will be shortly displayed in xp-command cli while the full text will be copied to clipboard.
|
|
109
116
|
|
|
110
117
|
### Radios
|
|
111
118
|
|
|
@@ -155,7 +162,7 @@ You can edit these YAML files to add aircraft-specific commands or modify existi
|
|
|
155
162
|
|
|
156
163
|
**Key components:**
|
|
157
164
|
- `pattern`: Regular expression matching your command (`hdg18`)
|
|
158
|
-
- `type`: Either `get` (read value) or `set` (write value)
|
|
165
|
+
- `type`: Either `get` (read value and copy to clipboard) or `set` (write value)
|
|
159
166
|
- `dataref`: X-Plane dataref path (find these in X-Plane's DataRef Editor)
|
|
160
167
|
- `transform`: Optional value conversions (multiply, divide, round, etc.)
|
|
161
168
|
|
|
@@ -172,6 +179,19 @@ Many X-Plane datarefs are arrays (e.g., for multiple engines, generators, radios
|
|
|
172
179
|
dataref: sim/cockpit/electrical/generator_on[1]
|
|
173
180
|
```
|
|
174
181
|
|
|
182
|
+
Here is an example of a custom set command which sets multiple datarefs at once (all datarefs receive the same value):
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
# toggle door and chocks
|
|
186
|
+
- pattern: "^d(0|1)$"
|
|
187
|
+
type: set
|
|
188
|
+
dataref:
|
|
189
|
+
- sim/cockpit2/switches/door_open[0]
|
|
190
|
+
- sim/flightmodel2/gear/is_chocked[0]
|
|
191
|
+
- sim/flightmodel2/gear/is_chocked[1]
|
|
192
|
+
- sim/flightmodel2/gear/is_chocked[2]
|
|
193
|
+
```
|
|
194
|
+
|
|
175
195
|
## 🔄 Resetting Aircraft Profiles
|
|
176
196
|
|
|
177
197
|
If you've edited an aircraft configuration and xp-command crashes or stops working, you can reset to default settings by deleting the config files.
|
package/bin/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import chalk from "chalk";
|
|
|
12
12
|
import { program } from "commander";
|
|
13
13
|
import ora from "ora";
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { getDatarefValues, initAPI, setDatarefValues } from "../src/api.js";
|
|
16
16
|
import { copyToClipboard } from "../src/clipboard.js";
|
|
17
17
|
import { getConfig } from "../src/config.js";
|
|
18
18
|
import { clearLine, hideCursor, showCursor } from "../src/console.js";
|
|
@@ -81,12 +81,15 @@ const processCommand = async (command) => {
|
|
|
81
81
|
return [
|
|
82
82
|
new RegExp(c.pattern),
|
|
83
83
|
async () => {
|
|
84
|
-
let value = await
|
|
84
|
+
let value = await getDatarefValues(c.dataref);
|
|
85
85
|
c.transform?.forEach((t) => {
|
|
86
86
|
value = getTransformedValue(value, t);
|
|
87
87
|
});
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
const asString = String(value)
|
|
89
|
+
await copyToClipboard(asString);
|
|
90
|
+
const lines = asString.split('\n')
|
|
91
|
+
const firstLine = lines[0]
|
|
92
|
+
spinner.succeed(chalk.green(`${PREFIX} ${lines.length > 1 ? firstLine + '...' : firstLine}`));
|
|
90
93
|
hideCursor();
|
|
91
94
|
await sleep(1500);
|
|
92
95
|
clearLine();
|
|
@@ -100,12 +103,12 @@ const processCommand = async (command) => {
|
|
|
100
103
|
|
|
101
104
|
if (isNaN(Number(value))) {
|
|
102
105
|
const base64 = Buffer.from(value, 'utf-8').toString('base64');
|
|
103
|
-
await
|
|
106
|
+
await setDatarefValues(c.dataref, base64);
|
|
104
107
|
} else {
|
|
105
108
|
c.transform?.forEach((t) => {
|
|
106
109
|
value = String(getTransformedValue(value, t));
|
|
107
110
|
});
|
|
108
|
-
await
|
|
111
|
+
await setDatarefValues(c.dataref, Number(value));
|
|
109
112
|
}
|
|
110
113
|
spinner.succeed(chalk.green(`${PREFIX} ${command}`));
|
|
111
114
|
hideCursor();
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -67,7 +67,7 @@ export const initAPI = (options) => {
|
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* @param {string} datarefNameWithOptionalIndex
|
|
70
|
-
* @return {Promise<number|
|
|
70
|
+
* @return {Promise<number|string>}
|
|
71
71
|
*/
|
|
72
72
|
export const getDatarefValue = async (datarefNameWithOptionalIndex) => {
|
|
73
73
|
const [datarefName, index] = parseDataref(datarefNameWithOptionalIndex);
|
|
@@ -106,6 +106,20 @@ export const getDatarefValue = async (datarefNameWithOptionalIndex) => {
|
|
|
106
106
|
return JSON.stringify(json.data);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* @param {string|Array<string>} datarefNamesWithOptionalIndex
|
|
111
|
+
* @return {Promise<number|string>}
|
|
112
|
+
*/
|
|
113
|
+
export const getDatarefValues = async (datarefNamesWithOptionalIndex) => {
|
|
114
|
+
if (Array.isArray(datarefNamesWithOptionalIndex)) {
|
|
115
|
+
return Promise.all(datarefNamesWithOptionalIndex.map(dataref => getDatarefValue(dataref))).then(results => {
|
|
116
|
+
return results.map(v => String(v)).join('\n').trim()
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return getDatarefValue(datarefNamesWithOptionalIndex)
|
|
121
|
+
}
|
|
122
|
+
|
|
109
123
|
/**
|
|
110
124
|
* @param {string} datarefNameWithOptionalIndex
|
|
111
125
|
* @param {number|string} value
|
|
@@ -136,3 +150,18 @@ export const setDatarefValue = async (datarefNameWithOptionalIndex, value) => {
|
|
|
136
150
|
|
|
137
151
|
return json;
|
|
138
152
|
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {string|Array<string>} datarefNamesWithOptionalIndex
|
|
156
|
+
* @param {number|string} value
|
|
157
|
+
* @return {Promise<number|string>}
|
|
158
|
+
*/
|
|
159
|
+
export const setDatarefValues = async (datarefNamesWithOptionalIndex, value) => {
|
|
160
|
+
if (Array.isArray(datarefNamesWithOptionalIndex)) {
|
|
161
|
+
return Promise.all(datarefNamesWithOptionalIndex.map(dataref => setDatarefValue(dataref, value))).then(results => {
|
|
162
|
+
return results[0]
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return setDatarefValue(datarefNamesWithOptionalIndex, value)
|
|
167
|
+
}
|
package/src/config.js
CHANGED
|
@@ -20,7 +20,7 @@ const __dirname = dirname(__filename);
|
|
|
20
20
|
* @typedef {Object} Command
|
|
21
21
|
* @property {RegExp} pattern - Regular expression pattern to match commands
|
|
22
22
|
* @property {'get' | 'set'} type - Operation type
|
|
23
|
-
* @property {string} dataref - X-Plane dataref path
|
|
23
|
+
* @property {string|Array<string>} dataref - X-Plane dataref path(s)
|
|
24
24
|
* @property {Transform[]} transform - Array of transformation operations to apply
|
|
25
25
|
*/
|
|
26
26
|
|
package/src/config.yml
CHANGED
|
@@ -72,7 +72,7 @@ commands:
|
|
|
72
72
|
- mult100
|
|
73
73
|
- round
|
|
74
74
|
|
|
75
|
-
# set
|
|
75
|
+
# set COM1 frequency
|
|
76
76
|
- pattern: "^c1(\\d{6})$"
|
|
77
77
|
type: set
|
|
78
78
|
dataref: sim/cockpit2/radios/actuators/com1_frequency_hz_833
|
|
@@ -83,7 +83,7 @@ commands:
|
|
|
83
83
|
- mult10
|
|
84
84
|
- round
|
|
85
85
|
|
|
86
|
-
# set
|
|
86
|
+
# set COM1 standby frequency
|
|
87
87
|
- pattern: "^cs1(\\d{6})$"
|
|
88
88
|
type: set
|
|
89
89
|
dataref: sim/cockpit2/radios/actuators/com1_standby_frequency_hz_833
|
|
@@ -94,7 +94,7 @@ commands:
|
|
|
94
94
|
- mult10
|
|
95
95
|
- round
|
|
96
96
|
|
|
97
|
-
# set
|
|
97
|
+
# set COM2 frequency
|
|
98
98
|
- pattern: "^c2(\\d{6})$"
|
|
99
99
|
type: set
|
|
100
100
|
dataref: sim/cockpit2/radios/actuators/com2_frequency_hz_833
|
|
@@ -105,7 +105,7 @@ commands:
|
|
|
105
105
|
- mult10
|
|
106
106
|
- round
|
|
107
107
|
|
|
108
|
-
# set
|
|
108
|
+
# set COM2 standby frequency
|
|
109
109
|
- pattern: "^cs2(\\d{6})$"
|
|
110
110
|
type: set
|
|
111
111
|
dataref: sim/cockpit2/radios/actuators/com2_standby_frequency_hz_833
|
|
@@ -116,32 +116,63 @@ commands:
|
|
|
116
116
|
- mult10
|
|
117
117
|
- round
|
|
118
118
|
|
|
119
|
-
# set
|
|
119
|
+
# set NAV1 frequency
|
|
120
120
|
- pattern: "^n1(\\d{5})$"
|
|
121
121
|
type: set
|
|
122
122
|
dataref: sim/cockpit/radios/nav1_freq_hz
|
|
123
123
|
|
|
124
|
-
# set
|
|
124
|
+
# set NAV1 standby frequency
|
|
125
125
|
- pattern: "^ns1(\\d{5})$"
|
|
126
126
|
type: set
|
|
127
127
|
dataref: sim/cockpit/radios/nav1_stdby_freq_hz
|
|
128
128
|
|
|
129
|
-
# set
|
|
129
|
+
# set NAV2 frequency
|
|
130
130
|
- pattern: "^n2(\\d{5})$"
|
|
131
131
|
type: set
|
|
132
132
|
dataref: sim/cockpit/radios/nav2_freq_hz
|
|
133
133
|
|
|
134
|
-
# set
|
|
134
|
+
# set NAV2 standby frequency
|
|
135
135
|
- pattern: "^ns2(\\d{5})$"
|
|
136
136
|
type: set
|
|
137
137
|
dataref: sim/cockpit/radios/nav2_stdby_freq_hz
|
|
138
|
-
|
|
139
|
-
# set
|
|
140
|
-
- pattern: "^adf1(
|
|
138
|
+
|
|
139
|
+
# set ADF1
|
|
140
|
+
- pattern: "^adf1(\\d{3})$"
|
|
141
141
|
type: set
|
|
142
142
|
dataref: sim/cockpit/radios/adf1_freq_hz
|
|
143
|
-
|
|
144
|
-
# set
|
|
145
|
-
- pattern: "^adf2(
|
|
143
|
+
|
|
144
|
+
# set ADF2
|
|
145
|
+
- pattern: "^adf2(\\d{3})$"
|
|
146
146
|
type: set
|
|
147
147
|
dataref: sim/cockpit/radios/adf2_freq_hz
|
|
148
|
+
|
|
149
|
+
# set BARO minimum
|
|
150
|
+
- pattern: "^m(\\d\\d?\\d?|[0-4]\\d\\d\\d|5000)$"
|
|
151
|
+
type: set
|
|
152
|
+
dataref: sim/cockpit2/gauges/actuators/baro_altimeter_bug_ft_pilot
|
|
153
|
+
|
|
154
|
+
# set RA minimum
|
|
155
|
+
- pattern: "^mra(\\d\\d?\\d?|[0-4]\\d\\d\\d|5000)$"
|
|
156
|
+
type: set
|
|
157
|
+
dataref: sim/cockpit/misc/radio_altimeter_minimum
|
|
158
|
+
|
|
159
|
+
# copy FMS to clipboard
|
|
160
|
+
- pattern: "^fm(s|c)$"
|
|
161
|
+
type: get
|
|
162
|
+
dataref:
|
|
163
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line0
|
|
164
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line1
|
|
165
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line2
|
|
166
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line3
|
|
167
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line4
|
|
168
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line5
|
|
169
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line6
|
|
170
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line7
|
|
171
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line8
|
|
172
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line9
|
|
173
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line10
|
|
174
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line11
|
|
175
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line12
|
|
176
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line13
|
|
177
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line14
|
|
178
|
+
- sim/cockpit2/radios/indicators/fms_cdu1_text_line15
|