-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsimulationVariablesWrite.ts
54 lines (45 loc) · 1.35 KB
/
simulationVariablesWrite.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
open,
Protocol,
SimConnectConstants,
SimConnectDataType,
SimConnectPeriod,
RawBuffer,
} from '../../dist';
const enum DefinitionID {
LIGHTS,
}
open('Flick lights', Protocol.FSX_SP2)
.then(({ recvOpen, handle }) => {
console.log('Connected:', recvOpen);
const lights = ['LIGHT LANDING', 'LIGHT LOGO', 'LIGHT TAXI', 'LIGHT WING', 'LIGHT NAV'];
lights.forEach(lightName => {
handle.addToDataDefinition(
DefinitionID.LIGHTS,
lightName,
'Bool',
SimConnectDataType.INT32
);
});
let lightsOn = false;
const dataToSet = new RawBuffer(100);
// Toggle all lights on/off every second
setInterval(() => {
lightsOn = !lightsOn;
dataToSet.clear();
lights.forEach(() => {
dataToSet.writeInt32(lightsOn ? 1 : 0);
});
handle.setDataOnSimObject(DefinitionID.LIGHTS, SimConnectConstants.OBJECT_ID_USER, {
buffer: dataToSet,
arrayCount: 0,
tagged: false,
});
}, 1000);
handle.on('exception', recvException => {
console.log(recvException);
});
})
.catch(error => {
console.log('Failed to connect', error);
});