@sensslen/node-gamepad 1.0.3 → 1.0.5-beta.2
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/IConfig.d.ts +34 -29
- package/IConfig.js +2 -2
- package/IDeviceSpec.d.ts +5 -5
- package/IDeviceSpec.js +2 -2
- package/ILogger.d.ts +4 -4
- package/ILogger.js +2 -2
- package/JoyStickValue.d.ts +4 -4
- package/JoyStickValue.js +2 -2
- package/NodeGamepad.d.ts +38 -34
- package/NodeGamepad.js +231 -209
- package/README.md +92 -92
- package/controllers/logitech/gamepadf310.json +106 -106
- package/controllers/logitech/gamepadf710.json +106 -106
- package/controllers/logitech/rumblepad2.json +106 -106
- package/index.d.ts +6 -6
- package/index.js +5 -5
- package/package.json +3 -3
- package/test.d.ts +0 -1
package/IConfig.d.ts
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
import { IDeviceSpec } from './IDeviceSpec';
|
|
2
|
-
export interface
|
|
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
|
-
|
|
1
|
+
import { IDeviceSpec } from './IDeviceSpec';
|
|
2
|
+
export interface IJoyStickConfig {
|
|
3
|
+
name: string;
|
|
4
|
+
x: {
|
|
5
|
+
pin: number;
|
|
6
|
+
};
|
|
7
|
+
y: {
|
|
8
|
+
pin: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface IButtonConfig {
|
|
12
|
+
value: string;
|
|
13
|
+
pin: number;
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
export interface IStatusConfig {
|
|
17
|
+
name: string;
|
|
18
|
+
pin: number;
|
|
19
|
+
states: IStateMappingConfig[];
|
|
20
|
+
}
|
|
21
|
+
export interface IStateMappingConfig {
|
|
22
|
+
value: number;
|
|
23
|
+
state: string;
|
|
24
|
+
}
|
|
25
|
+
export interface IScaleConfig {
|
|
26
|
+
pin: number;
|
|
27
|
+
name: string;
|
|
28
|
+
}
|
|
29
|
+
export interface IConfig extends IDeviceSpec {
|
|
30
|
+
joysticks?: IJoyStickConfig[];
|
|
31
|
+
buttons?: IButtonConfig[];
|
|
32
|
+
status?: IStatusConfig[];
|
|
33
|
+
scales?: IScaleConfig[];
|
|
34
|
+
}
|
package/IConfig.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=IConfig.js.map
|
package/IDeviceSpec.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export interface IDeviceSpec {
|
|
2
|
-
vendorID: number;
|
|
3
|
-
productID: number;
|
|
4
|
-
serialNumber?: string;
|
|
5
|
-
}
|
|
1
|
+
export interface IDeviceSpec {
|
|
2
|
+
vendorID: number;
|
|
3
|
+
productID: number;
|
|
4
|
+
serialNumber?: string;
|
|
5
|
+
}
|
package/IDeviceSpec.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=IDeviceSpec.js.map
|
package/ILogger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface ILogger {
|
|
2
|
-
debug?: (toLog: string) => void;
|
|
3
|
-
info(toLog: string): void;
|
|
4
|
-
}
|
|
1
|
+
export interface ILogger {
|
|
2
|
+
debug?: (toLog: string) => void;
|
|
3
|
+
info(toLog: string): void;
|
|
4
|
+
}
|
package/ILogger.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=ILogger.js.map
|
package/JoyStickValue.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface JoyStickValue {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
}
|
|
1
|
+
export interface JoyStickValue {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
package/JoyStickValue.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=JoyStickValue.js.map
|
package/NodeGamepad.d.ts
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { HID } from 'node-hid';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ILogger } from './ILogger';
|
|
6
|
-
export declare class NodeGamepad extends EventEmitter {
|
|
7
|
-
private config;
|
|
8
|
-
private logger?;
|
|
9
|
-
protected _usb?: HID;
|
|
10
|
-
private
|
|
11
|
-
private _joystickStates;
|
|
12
|
-
private _buttonStates;
|
|
13
|
-
private _statusStates;
|
|
14
|
-
private _scaleStates;
|
|
15
|
-
private _connectRetryTimeout?;
|
|
16
|
-
private readonly _connectionRetryTimeoutInMs;
|
|
17
|
-
constructor(config: IConfig, logger?: ILogger | undefined);
|
|
18
|
-
start(): void;
|
|
19
|
-
stop(): void;
|
|
20
|
-
rumble(_duration: number): void;
|
|
21
|
-
private logDebug;
|
|
22
|
-
private log;
|
|
23
|
-
private connect;
|
|
24
|
-
private stopConnectionProcess;
|
|
25
|
-
private
|
|
26
|
-
private
|
|
27
|
-
private toIDeviceSpec;
|
|
28
|
-
private onControllerFrame;
|
|
29
|
-
private processJoysticks;
|
|
30
|
-
private
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
private
|
|
34
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { HID } from 'node-hid';
|
|
3
|
+
import { IConfig } from './IConfig';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import { ILogger } from './ILogger';
|
|
6
|
+
export declare class NodeGamepad extends EventEmitter {
|
|
7
|
+
private config;
|
|
8
|
+
private logger?;
|
|
9
|
+
protected _usb?: HID;
|
|
10
|
+
private _running;
|
|
11
|
+
private _joystickStates;
|
|
12
|
+
private _buttonStates;
|
|
13
|
+
private _statusStates;
|
|
14
|
+
private _scaleStates;
|
|
15
|
+
private _connectRetryTimeout?;
|
|
16
|
+
private readonly _connectionRetryTimeoutInMs;
|
|
17
|
+
constructor(config: IConfig, logger?: ILogger | undefined);
|
|
18
|
+
start(): void;
|
|
19
|
+
stop(): void;
|
|
20
|
+
rumble(_intensity: number, _duration: number): void;
|
|
21
|
+
private logDebug;
|
|
22
|
+
private log;
|
|
23
|
+
private connect;
|
|
24
|
+
private stopConnectionProcess;
|
|
25
|
+
private registerProgramExitEvents;
|
|
26
|
+
private closeUsbDevice;
|
|
27
|
+
private toIDeviceSpec;
|
|
28
|
+
private onControllerFrame;
|
|
29
|
+
private processJoysticks;
|
|
30
|
+
private processJoystick;
|
|
31
|
+
private processButtons;
|
|
32
|
+
private processButton;
|
|
33
|
+
private processScales;
|
|
34
|
+
private processScale;
|
|
35
|
+
private processStates;
|
|
36
|
+
private processState;
|
|
37
|
+
private getStateName;
|
|
38
|
+
}
|
package/NodeGamepad.js
CHANGED
|
@@ -1,210 +1,232 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.NodeGamepad = void 0;
|
|
19
|
-
var node_hid_1 = require("node-hid");
|
|
20
|
-
var events_1 = require("events");
|
|
21
|
-
var mathjs_1 = require("mathjs");
|
|
22
|
-
var NodeGamepad = /** @class */ (function (_super) {
|
|
23
|
-
__extends(NodeGamepad, _super);
|
|
24
|
-
function NodeGamepad(config, logger) {
|
|
25
|
-
var _this = _super.call(this) || this;
|
|
26
|
-
_this.config = config;
|
|
27
|
-
_this.logger = logger;
|
|
28
|
-
_this.
|
|
29
|
-
_this.
|
|
30
|
-
_this.
|
|
31
|
-
_this.
|
|
32
|
-
_this.
|
|
33
|
-
_this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
51
|
-
NodeGamepad.prototype.rumble = function (_duration) {
|
|
52
|
-
//
|
|
53
|
-
};
|
|
54
|
-
NodeGamepad.prototype.logDebug = function (toLog) {
|
|
55
|
-
var _a;
|
|
56
|
-
if ((_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
57
|
-
this.logger.debug("NodeGamepad (Debug):"
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
NodeGamepad.prototype.log = function (toLog) {
|
|
61
|
-
if (this.logger) {
|
|
62
|
-
this.logger.info("NodeGamepad:"
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
NodeGamepad.prototype.connect = function () {
|
|
66
|
-
var _this = this;
|
|
67
|
-
if (this.
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
var deviceList = (0, node_hid_1.devices)(this.config.vendorID, this.config.productID);
|
|
71
|
-
if (this.config.serialNumber) {
|
|
72
|
-
deviceList = deviceList.filter(function (d) { return d.serialNumber === _this.config.serialNumber; });
|
|
73
|
-
}
|
|
74
|
-
if (deviceList.length < 1) {
|
|
75
|
-
this.logDebug('Device not found, trying again later');
|
|
76
|
-
this._connectRetryTimeout = setTimeout(function () { return _this.connect(); }, this._connectionRetryTimeoutInMs);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
var deviceToConnectTo = deviceList[0];
|
|
80
|
-
if ((deviceToConnectTo === null || deviceToConnectTo === void 0 ? void 0 : deviceToConnectTo.path) === undefined) {
|
|
81
|
-
this.logDebug('Failed to connect. Checking again later.');
|
|
82
|
-
this._connectRetryTimeout = setTimeout(function () { return _this.connect(); }, this._connectionRetryTimeoutInMs);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
this.logDebug("connecting to:"
|
|
86
|
-
try {
|
|
87
|
-
this._usb = new node_hid_1.HID(deviceToConnectTo.path);
|
|
88
|
-
this.log('connected');
|
|
89
|
-
this.emit('connected');
|
|
90
|
-
this._connectRetryTimeout = undefined;
|
|
91
|
-
this._usb.on('data', function (data) { return _this.onControllerFrame(data); });
|
|
92
|
-
this._usb.on('error', function (error) {
|
|
93
|
-
_this.log("Error occurred:"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
_this.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.log(
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
process.on('
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.
|
|
138
|
-
this.
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
186
|
-
NodeGamepad.prototype.
|
|
187
|
-
var _this = this;
|
|
188
|
-
var _a;
|
|
189
|
-
(_a = this.config.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.NodeGamepad = void 0;
|
|
19
|
+
var node_hid_1 = require("node-hid");
|
|
20
|
+
var events_1 = require("events");
|
|
21
|
+
var mathjs_1 = require("mathjs");
|
|
22
|
+
var NodeGamepad = /** @class */ (function (_super) {
|
|
23
|
+
__extends(NodeGamepad, _super);
|
|
24
|
+
function NodeGamepad(config, logger) {
|
|
25
|
+
var _this = _super.call(this) || this;
|
|
26
|
+
_this.config = config;
|
|
27
|
+
_this.logger = logger;
|
|
28
|
+
_this._usb = undefined;
|
|
29
|
+
_this._running = false;
|
|
30
|
+
_this._joystickStates = {};
|
|
31
|
+
_this._buttonStates = {};
|
|
32
|
+
_this._statusStates = {};
|
|
33
|
+
_this._scaleStates = {};
|
|
34
|
+
_this._connectionRetryTimeoutInMs = 500;
|
|
35
|
+
return _this;
|
|
36
|
+
}
|
|
37
|
+
NodeGamepad.prototype.start = function () {
|
|
38
|
+
if (this._running) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.log("Starting connection procedure to device:".concat(JSON.stringify(this.toIDeviceSpec(this.config))));
|
|
42
|
+
this.registerProgramExitEvents();
|
|
43
|
+
this._running = true;
|
|
44
|
+
this.connect();
|
|
45
|
+
};
|
|
46
|
+
NodeGamepad.prototype.stop = function () {
|
|
47
|
+
this._running = false;
|
|
48
|
+
this.stopConnectionProcess();
|
|
49
|
+
this.closeUsbDevice();
|
|
50
|
+
};
|
|
51
|
+
NodeGamepad.prototype.rumble = function (_intensity, _duration) {
|
|
52
|
+
// todo
|
|
53
|
+
};
|
|
54
|
+
NodeGamepad.prototype.logDebug = function (toLog) {
|
|
55
|
+
var _a;
|
|
56
|
+
if ((_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
57
|
+
this.logger.debug("NodeGamepad (Debug):".concat(toLog));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
NodeGamepad.prototype.log = function (toLog) {
|
|
61
|
+
if (this.logger) {
|
|
62
|
+
this.logger.info("NodeGamepad:".concat(toLog));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
NodeGamepad.prototype.connect = function () {
|
|
66
|
+
var _this = this;
|
|
67
|
+
if (!this._running) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var deviceList = (0, node_hid_1.devices)(this.config.vendorID, this.config.productID);
|
|
71
|
+
if (this.config.serialNumber) {
|
|
72
|
+
deviceList = deviceList.filter(function (d) { return d.serialNumber === _this.config.serialNumber; });
|
|
73
|
+
}
|
|
74
|
+
if (deviceList.length < 1) {
|
|
75
|
+
this.logDebug('Device not found, trying again later');
|
|
76
|
+
this._connectRetryTimeout = setTimeout(function () { return _this.connect(); }, this._connectionRetryTimeoutInMs);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var deviceToConnectTo = deviceList[0];
|
|
80
|
+
if ((deviceToConnectTo === null || deviceToConnectTo === void 0 ? void 0 : deviceToConnectTo.path) === undefined) {
|
|
81
|
+
this.logDebug('Failed to connect. Checking again later.');
|
|
82
|
+
this._connectRetryTimeout = setTimeout(function () { return _this.connect(); }, this._connectionRetryTimeoutInMs);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.logDebug("connecting to:".concat(JSON.stringify(deviceToConnectTo)));
|
|
86
|
+
try {
|
|
87
|
+
this._usb = new node_hid_1.HID(deviceToConnectTo.path);
|
|
88
|
+
this.log('connected');
|
|
89
|
+
this.emit('connected');
|
|
90
|
+
this._connectRetryTimeout = undefined;
|
|
91
|
+
this._usb.on('data', function (data) { return _this.onControllerFrame(data); });
|
|
92
|
+
this._usb.on('error', function (error) {
|
|
93
|
+
_this.log("Error occurred:".concat(JSON.stringify(error)));
|
|
94
|
+
_this.emit('disconnected');
|
|
95
|
+
_this.closeUsbDevice();
|
|
96
|
+
setTimeout(function () {
|
|
97
|
+
_this.log('reconnecting');
|
|
98
|
+
_this.connect();
|
|
99
|
+
}, 0);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
var typedError = error;
|
|
104
|
+
this.log("Connecting failed: ".concat(typedError.message));
|
|
105
|
+
this.log('trying again later.');
|
|
106
|
+
this.closeUsbDevice();
|
|
107
|
+
this._connectRetryTimeout = setTimeout(function () { return _this.connect(); }, this._connectionRetryTimeoutInMs);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
NodeGamepad.prototype.stopConnectionProcess = function () {
|
|
111
|
+
if (this._connectRetryTimeout) {
|
|
112
|
+
clearTimeout(this._connectRetryTimeout);
|
|
113
|
+
this._connectRetryTimeout = undefined;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
NodeGamepad.prototype.registerProgramExitEvents = function () {
|
|
117
|
+
var _this = this;
|
|
118
|
+
process.on('exit', function () {
|
|
119
|
+
_this.logDebug('exit encontered, cleaning up');
|
|
120
|
+
_this.stop();
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
NodeGamepad.prototype.closeUsbDevice = function () {
|
|
124
|
+
if (this._usb) {
|
|
125
|
+
this._usb.close();
|
|
126
|
+
this._usb = undefined;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
NodeGamepad.prototype.toIDeviceSpec = function (spec) {
|
|
130
|
+
return {
|
|
131
|
+
vendorID: spec.vendorID,
|
|
132
|
+
productID: spec.productID,
|
|
133
|
+
serialNumber: spec.serialNumber,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
NodeGamepad.prototype.onControllerFrame = function (data) {
|
|
137
|
+
this.logDebug(JSON.stringify(data));
|
|
138
|
+
this.processJoysticks(data);
|
|
139
|
+
this.processButtons(data);
|
|
140
|
+
this.processStates(data);
|
|
141
|
+
this.processScales(data);
|
|
142
|
+
};
|
|
143
|
+
NodeGamepad.prototype.processJoysticks = function (data) {
|
|
144
|
+
var _this = this;
|
|
145
|
+
var _a;
|
|
146
|
+
(_a = this.config.joysticks) === null || _a === void 0 ? void 0 : _a.forEach(function (joystick) {
|
|
147
|
+
if (data.length > joystick.x.pin || data.length > joystick.y.pin) {
|
|
148
|
+
_this.processJoystick(joystick, data);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
NodeGamepad.prototype.processJoystick = function (joystick, data) {
|
|
153
|
+
var oldState = this._joystickStates[joystick.name];
|
|
154
|
+
var newState = {
|
|
155
|
+
x: data[joystick.x.pin],
|
|
156
|
+
y: data[joystick.y.pin],
|
|
157
|
+
};
|
|
158
|
+
if (oldState === undefined || oldState.x !== newState.x || oldState.y !== newState.y) {
|
|
159
|
+
this.emit(joystick.name + ':move', newState);
|
|
160
|
+
}
|
|
161
|
+
this._joystickStates[joystick.name] = newState;
|
|
162
|
+
};
|
|
163
|
+
NodeGamepad.prototype.processButtons = function (data) {
|
|
164
|
+
var _this = this;
|
|
165
|
+
var _a;
|
|
166
|
+
(_a = this.config.buttons) === null || _a === void 0 ? void 0 : _a.forEach(function (button) {
|
|
167
|
+
if (data.length > button.pin) {
|
|
168
|
+
_this.processButton(data, button);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
NodeGamepad.prototype.processButton = function (data, config) {
|
|
173
|
+
var oldState = this._buttonStates[config.name];
|
|
174
|
+
var newState = (0, mathjs_1.evaluate)(config.value, { value: data[config.pin] });
|
|
175
|
+
if (oldState == undefined) {
|
|
176
|
+
if (newState) {
|
|
177
|
+
this.emit(config.name + ':press');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else if (oldState !== newState) {
|
|
181
|
+
var emitEvent = newState ? "".concat(config.name, ":press") : "".concat(config.name, ":release");
|
|
182
|
+
this.emit(emitEvent);
|
|
183
|
+
}
|
|
184
|
+
this._buttonStates[config.name] = newState;
|
|
185
|
+
};
|
|
186
|
+
NodeGamepad.prototype.processScales = function (data) {
|
|
187
|
+
var _this = this;
|
|
188
|
+
var _a;
|
|
189
|
+
(_a = this.config.scales) === null || _a === void 0 ? void 0 : _a.forEach(function (scale) {
|
|
190
|
+
if (data.length > scale.pin) {
|
|
191
|
+
_this.processScale(scale, data);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
NodeGamepad.prototype.processScale = function (config, data) {
|
|
196
|
+
var oldState = this._scaleStates[config.name];
|
|
197
|
+
var newState = data[config.pin];
|
|
198
|
+
if (oldState !== newState) {
|
|
199
|
+
this.emit(config.name + ':change', newState);
|
|
200
|
+
}
|
|
201
|
+
this._scaleStates[config.name] = newState;
|
|
202
|
+
};
|
|
203
|
+
NodeGamepad.prototype.processStates = function (data) {
|
|
204
|
+
var _this = this;
|
|
205
|
+
var _a;
|
|
206
|
+
(_a = this.config.status) === null || _a === void 0 ? void 0 : _a.forEach(function (status) {
|
|
207
|
+
if (data.length > status.pin) {
|
|
208
|
+
_this.processState(status, data);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
NodeGamepad.prototype.processState = function (config, data) {
|
|
213
|
+
var oldState = this._statusStates[config.name];
|
|
214
|
+
var newState = data[config.pin];
|
|
215
|
+
if (oldState !== newState) {
|
|
216
|
+
this.emit(config.name + ':change', this.getStateName(config.states, newState));
|
|
217
|
+
}
|
|
218
|
+
this._statusStates[config.name] = newState;
|
|
219
|
+
};
|
|
220
|
+
NodeGamepad.prototype.getStateName = function (states, value) {
|
|
221
|
+
for (var _i = 0, states_1 = states; _i < states_1.length; _i++) {
|
|
222
|
+
var state = states_1[_i];
|
|
223
|
+
if (state.value === value) {
|
|
224
|
+
return state.state;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return "unknown state:".concat(value);
|
|
228
|
+
};
|
|
229
|
+
return NodeGamepad;
|
|
230
|
+
}(events_1.EventEmitter));
|
|
231
|
+
exports.NodeGamepad = NodeGamepad;
|
|
210
232
|
//# sourceMappingURL=NodeGamepad.js.map
|