node-poweredup 7.1.0 → 8.0.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 +40 -40
- package/dist/browser/poweredup.js +1 -1
- package/dist/browser/poweredup.js.map +1 -1
- package/dist/node/consts.d.ts +41 -24
- package/dist/node/consts.js +41 -24
- package/dist/node/consts.js.map +1 -1
- package/dist/node/devices/colordistancesensor.d.ts +11 -0
- package/dist/node/devices/colordistancesensor.js +93 -1
- package/dist/node/devices/colordistancesensor.js.map +1 -1
- package/dist/node/devices/device.js +2 -0
- package/dist/node/devices/device.js.map +1 -1
- package/dist/node/devices/technicmediumhubtiltsensor.d.ts +25 -1
- package/dist/node/devices/technicmediumhubtiltsensor.js +70 -2
- package/dist/node/devices/technicmediumhubtiltsensor.js.map +1 -1
- package/dist/node/hubs/lpf2hub.js +5 -4
- package/dist/node/hubs/lpf2hub.js.map +1 -1
- package/dist/node/poweredup-node.js +24 -1
- package/dist/node/poweredup-node.js.map +1 -1
- package/docs/AbsoluteMotor.html +1 -1
- package/docs/BaseHub.html +1 -1
- package/docs/BasicMotor.html +1 -1
- package/docs/ColorDistanceSensor.html +841 -53
- package/docs/CurrentSensor.html +1 -1
- package/docs/Device.html +1 -1
- package/docs/DuploTrainBase.html +1 -1
- package/docs/DuploTrainBaseColorSensor.html +1 -1
- package/docs/DuploTrainBaseMotor.html +1 -1
- package/docs/DuploTrainBaseSpeaker.html +1 -1
- package/docs/DuploTraniBaseSpeedometer.html +1 -1
- package/docs/Hub.html +1 -1
- package/docs/HubLED.html +1 -1
- package/docs/LPF2Hub.html +1 -1
- package/docs/Light.html +1 -1
- package/docs/Mario.html +1 -1
- package/docs/MarioAccelerometer.html +1 -1
- package/docs/MarioBarcodeSensor.html +1 -1
- package/docs/MarioPantsSensor.html +1 -1
- package/docs/MediumLinearMotor.html +1 -1
- package/docs/MotionSensor.html +1 -1
- package/docs/MoveHub.html +1 -1
- package/docs/MoveHubMediumLinearMotor.html +1 -1
- package/docs/MoveHubTiltSensor.html +1 -1
- package/docs/PiezoBuzzer.html +1 -1
- package/docs/PoweredUP.html +23 -23
- package/docs/RemoteControl.html +1 -1
- package/docs/RemoteControlButton.html +1 -1
- package/docs/SimpleMediumLinearMotor.html +1 -1
- package/docs/TachoMotor.html +1 -1
- package/docs/Technic3x3ColorLightMatrix.html +1 -1
- package/docs/TechnicColorSensor.html +1 -1
- package/docs/TechnicDistanceSensor.html +1 -1
- package/docs/TechnicForceSensor.html +1 -1
- package/docs/TechnicLargeAngularMotor.html +1 -1
- package/docs/TechnicLargeLinearMotor.html +1 -1
- package/docs/TechnicMediumAngularMotor.html +1 -1
- package/docs/TechnicMediumHub.html +1 -1
- package/docs/TechnicMediumHubAccelerometerSensor.html +1 -1
- package/docs/TechnicMediumHubGyroSensor.html +1 -1
- package/docs/TechnicMediumHubTiltSensor.html +590 -2
- package/docs/TechnicSmallAngularMotor.html +1 -1
- package/docs/TechnicXLargeLinearMotor.html +1 -1
- package/docs/TiltSensor.html +1 -1
- package/docs/TrainMotor.html +1 -1
- package/docs/VoltageSensor.html +1 -1
- package/docs/WeDo2SmartHub.html +1 -1
- package/docs/consts.js.html +42 -25
- package/docs/devices_absolutemotor.js.html +1 -1
- package/docs/devices_basicmotor.js.html +1 -1
- package/docs/devices_colordistancesensor.js.html +94 -2
- package/docs/devices_currentsensor.js.html +1 -1
- package/docs/devices_device.js.html +3 -1
- package/docs/devices_duplotrainbasecolorsensor.js.html +1 -1
- package/docs/devices_duplotrainbasemotor.js.html +1 -1
- package/docs/devices_duplotrainbasespeaker.js.html +1 -1
- package/docs/devices_duplotrainbasespeedometer.js.html +1 -1
- package/docs/devices_hubled.js.html +1 -1
- package/docs/devices_light.js.html +1 -1
- package/docs/devices_marioaccelerometer.js.html +1 -1
- package/docs/devices_mariobarcodesensor.js.html +1 -1
- package/docs/devices_mariopantssensor.js.html +1 -1
- package/docs/devices_mediumlinearmotor.js.html +1 -1
- package/docs/devices_motionsensor.js.html +1 -1
- package/docs/devices_movehubmediumlinearmotor.js.html +1 -1
- package/docs/devices_movehubtiltsensor.js.html +1 -1
- package/docs/devices_piezobuzzer.js.html +1 -1
- package/docs/devices_remotecontrolbutton.js.html +1 -1
- package/docs/devices_simplemediumlinearmotor.js.html +1 -1
- package/docs/devices_tachomotor.js.html +1 -1
- package/docs/devices_technic3x3colorlightmatrix.js.html +1 -1
- package/docs/devices_techniccolorsensor.js.html +1 -1
- package/docs/devices_technicdistancesensor.js.html +1 -1
- package/docs/devices_technicforcesensor.js.html +1 -1
- package/docs/devices_techniclargeangularmotor.js.html +1 -1
- package/docs/devices_techniclargelinearmotor.js.html +1 -1
- package/docs/devices_technicmediumangularmotor.js.html +1 -1
- package/docs/devices_technicmediumhubaccelerometersensor.js.html +1 -1
- package/docs/devices_technicmediumhubgyrosensor.js.html +1 -1
- package/docs/devices_technicmediumhubtiltsensor.js.html +71 -3
- package/docs/devices_technicsmallangularmotor.js.html +1 -1
- package/docs/devices_technicxlargelinearmotor.js.html +1 -1
- package/docs/devices_tiltsensor.js.html +1 -1
- package/docs/devices_trainmotor.js.html +1 -1
- package/docs/devices_voltagesensor.js.html +1 -1
- package/docs/global.html +541 -48
- package/docs/hubs_basehub.js.html +1 -1
- package/docs/hubs_duplotrainbase.js.html +1 -1
- package/docs/hubs_hub.js.html +1 -1
- package/docs/hubs_lpf2hub.js.html +6 -5
- package/docs/hubs_mario.js.html +1 -1
- package/docs/hubs_movehub.js.html +1 -1
- package/docs/hubs_remotecontrol.js.html +1 -1
- package/docs/hubs_technicmediumhub.js.html +1 -1
- package/docs/hubs_technicsmallhub.js.html +1 -1
- package/docs/hubs_wedo2smarthub.js.html +1 -1
- package/docs/index.html +35 -35
- package/docs/poweredup-browser.js.html +1 -1
- package/docs/poweredup-node.js.html +25 -2
- package/package.json +12 -12
- package/src/consts.ts +41 -24
- package/src/devices/colordistancesensor.ts +96 -2
- package/src/devices/device.ts +1 -0
- package/src/devices/technicmediumhubtiltsensor.ts +75 -3
- package/src/hubs/lpf2hub.ts +5 -6
- package/src/poweredup-node.ts +4 -1
|
@@ -38,7 +38,7 @@ export class ColorDistanceSensor extends Device {
|
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
40
|
if (message[4] <= 10) {
|
|
41
|
-
let distance = Math.floor(message[4] * 25.4);
|
|
41
|
+
let distance = Math.floor(message[4] * 25.4) - 20;
|
|
42
42
|
|
|
43
43
|
if (distance < 0) {
|
|
44
44
|
distance = 0;
|
|
@@ -54,6 +54,74 @@ export class ColorDistanceSensor extends Device {
|
|
|
54
54
|
}
|
|
55
55
|
break;
|
|
56
56
|
|
|
57
|
+
case Mode.DISTANCE_COUNT:
|
|
58
|
+
if (this.isWeDo2SmartHub) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (message.length !== 8) {
|
|
62
|
+
// if mode of device has not changed to this._mode yet
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
const count = message.readUInt32LE(4);
|
|
66
|
+
/**
|
|
67
|
+
* Emits when distance is reduced to less than 10 centimeters.
|
|
68
|
+
* @event ColorDistanceSensor#distanceCount
|
|
69
|
+
* @type {object}
|
|
70
|
+
* @param {number} number of distance events.
|
|
71
|
+
*/
|
|
72
|
+
this.notify("distanceCount", { count });
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case Mode.REFLECT:
|
|
76
|
+
if (this.isWeDo2SmartHub) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
const reflect = message[4];
|
|
80
|
+
/**
|
|
81
|
+
* Event measuring reflection change, emits when the sensor is activated.
|
|
82
|
+
* @event ColorDistanceSensor#reflect
|
|
83
|
+
* @type {object}
|
|
84
|
+
* @param {number} percentage from 0 to 100.
|
|
85
|
+
*/
|
|
86
|
+
this.notify("reflect", { reflect });
|
|
87
|
+
break;
|
|
88
|
+
|
|
89
|
+
case Mode.AMBIENT:
|
|
90
|
+
if (this.isWeDo2SmartHub) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
const ambient = message[4];
|
|
94
|
+
/**
|
|
95
|
+
* Event measuring abient light change, emits when the sensor is activated.
|
|
96
|
+
* @event ColorDistanceSensor#ambient
|
|
97
|
+
* @type {object}
|
|
98
|
+
* @param {number} percentage from 0 to 100.
|
|
99
|
+
*/
|
|
100
|
+
this.notify("ambient", { ambient });
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case Mode.RGB_I:
|
|
104
|
+
if (this.isWeDo2SmartHub) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
if (message.length !== 10) {
|
|
108
|
+
// if mode of device has not changed to this._mode yet
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
const red = message.readUInt16LE(4);
|
|
112
|
+
const green = message.readUInt16LE(6);
|
|
113
|
+
const blue = message.readUInt16LE(8);
|
|
114
|
+
/**
|
|
115
|
+
* Emits when a color sensor is activated.
|
|
116
|
+
* @event ColorDistanceSensor#rgbIntensity
|
|
117
|
+
* @type {object}
|
|
118
|
+
* @param {number} red
|
|
119
|
+
* @param {number} green
|
|
120
|
+
* @param {number} blue
|
|
121
|
+
*/
|
|
122
|
+
this.notify("rgbIntensity", { red, green, blue });
|
|
123
|
+
break;
|
|
124
|
+
|
|
57
125
|
case Mode.COLOR_AND_DISTANCE:
|
|
58
126
|
if (this.isWeDo2SmartHub) {
|
|
59
127
|
break;
|
|
@@ -193,18 +261,40 @@ export class ColorDistanceSensor extends Device {
|
|
|
193
261
|
});
|
|
194
262
|
}
|
|
195
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Set the distance count value.
|
|
266
|
+
* @method ColorDistanceSensor#setDistanceCount
|
|
267
|
+
* @param {count} distance count between 0 and 2^32
|
|
268
|
+
* @returns {Promise} Resolved upon successful issuance of the command.
|
|
269
|
+
*/
|
|
270
|
+
public setDistanceCount (count: number) {
|
|
271
|
+
return new Promise<void>((resolve) => {
|
|
272
|
+
if (this.isWeDo2SmartHub) {
|
|
273
|
+
throw new Error("Setting distance count is not available on the WeDo 2.0 Smart Hub");
|
|
274
|
+
} else {
|
|
275
|
+
const payload = Buffer.alloc(4);
|
|
276
|
+
payload.writeUInt32LE(count % 2**32);
|
|
277
|
+
// no need to subscribe, can be set in different mode
|
|
278
|
+
this.writeDirect(0x02, payload);
|
|
279
|
+
}
|
|
280
|
+
return resolve();
|
|
281
|
+
});
|
|
282
|
+
}
|
|
196
283
|
|
|
197
284
|
private _pfPowerToPWM (power: number) {
|
|
198
285
|
return power & 15;
|
|
199
286
|
}
|
|
200
287
|
|
|
201
|
-
|
|
202
288
|
}
|
|
203
289
|
|
|
204
290
|
export enum Mode {
|
|
205
291
|
COLOR = 0x00,
|
|
206
292
|
DISTANCE = 0x01,
|
|
293
|
+
DISTANCE_COUNT = 0x02,
|
|
294
|
+
REFLECT = 0x03,
|
|
295
|
+
AMBIENT = 0x04,
|
|
207
296
|
LED = 0x05,
|
|
297
|
+
RGB_I = 0x06,
|
|
208
298
|
PF_IR = 0x07,
|
|
209
299
|
COLOR_AND_DISTANCE = 0x08
|
|
210
300
|
}
|
|
@@ -212,6 +302,10 @@ export enum Mode {
|
|
|
212
302
|
export const ModeMap: {[event: string]: number} = {
|
|
213
303
|
"color": Mode.COLOR,
|
|
214
304
|
"distance": Mode.DISTANCE,
|
|
305
|
+
"distanceCount": Mode.DISTANCE_COUNT,
|
|
306
|
+
"reflect": Mode.REFLECT,
|
|
307
|
+
"ambient": Mode.AMBIENT,
|
|
308
|
+
"rgbIntensity": Mode.RGB_I,
|
|
215
309
|
"colorAndDistance": Mode.COLOR_AND_DISTANCE
|
|
216
310
|
};
|
|
217
311
|
|
package/src/devices/device.ts
CHANGED
|
@@ -168,6 +168,7 @@ export class Device extends EventEmitter {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
public finish (message: number) {
|
|
171
|
+
if((message & 0x10) === 0x10) return; // "busy/full"
|
|
171
172
|
this._busy = (message & 0x01) === 0x01;
|
|
172
173
|
while(this._finishedCallbacks.length > Number(this._busy)) {
|
|
173
174
|
const callback = this._finishedCallbacks.shift();
|
|
@@ -10,6 +10,9 @@ import * as Consts from "../consts";
|
|
|
10
10
|
*/
|
|
11
11
|
export class TechnicMediumHubTiltSensor extends Device {
|
|
12
12
|
|
|
13
|
+
protected _impactThreshold: number = 10; // guess of default value
|
|
14
|
+
protected _impactHoldoff: number = 10; // guess of default value
|
|
15
|
+
|
|
13
16
|
constructor (hub: IDeviceInterface, portId: number) {
|
|
14
17
|
super(hub, portId, ModeMap, Consts.DeviceType.TECHNIC_MEDIUM_HUB_TILT_SENSOR);
|
|
15
18
|
}
|
|
@@ -21,26 +24,95 @@ export class TechnicMediumHubTiltSensor extends Device {
|
|
|
21
24
|
case Mode.TILT:
|
|
22
25
|
/**
|
|
23
26
|
* Emits when a tilt sensor is activated.
|
|
27
|
+
*
|
|
24
28
|
* @event TechnicMediumHubTiltSensor#tilt
|
|
25
29
|
* @type {object}
|
|
26
30
|
* @param {number} x
|
|
27
31
|
* @param {number} y
|
|
28
32
|
* @param {number} z
|
|
29
33
|
*/
|
|
30
|
-
|
|
34
|
+
let z = -message.readInt16LE(4);
|
|
31
35
|
const y = message.readInt16LE(6);
|
|
32
36
|
const x = message.readInt16LE(8);
|
|
37
|
+
|
|
38
|
+
// workaround for calibration problem or bug in technicMediumHub firmware 1.1.00.0000
|
|
39
|
+
if(y === 90 || y === -90) {
|
|
40
|
+
z = Math.sign(y)*(z + 180);
|
|
41
|
+
if(z > 180) z -= 360;
|
|
42
|
+
if(z < -180) z += 360;
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
this.notify("tilt", { x, y, z });
|
|
34
46
|
break;
|
|
47
|
+
|
|
48
|
+
case Mode.IMPACT_COUNT:
|
|
49
|
+
if (message.length !== 8) {
|
|
50
|
+
// if mode of device has not changed to this._mode yet
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
const count = message.readUInt32LE(4);
|
|
54
|
+
/**
|
|
55
|
+
* Emits when proper acceleration is above threshold (e.g. on impact when being thrown to the ground).
|
|
56
|
+
* @event TechnicMediumHubTiltSensor#impactCount
|
|
57
|
+
* @type {object}
|
|
58
|
+
* @param {number} number of impact events.
|
|
59
|
+
*/
|
|
60
|
+
this.notify("tiltCount", { count });
|
|
61
|
+
break;
|
|
35
62
|
}
|
|
36
63
|
}
|
|
37
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Set the impact count value.
|
|
67
|
+
* @method TechnicMediumHubTiltSensor#setImpactCount
|
|
68
|
+
* @param {count} impact count between 0 and 2^32
|
|
69
|
+
* @returns {Promise} Resolved upon successful issuance of the command.
|
|
70
|
+
*/
|
|
71
|
+
public setImpactCount (count: number) {
|
|
72
|
+
return new Promise<void>((resolve) => {
|
|
73
|
+
const payload = Buffer.alloc(4);
|
|
74
|
+
payload.writeUInt32LE(count % 2**32);
|
|
75
|
+
// no need to subscribe, can be set in different mode
|
|
76
|
+
this.writeDirect(0x01, payload);
|
|
77
|
+
return resolve();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Set the impact threshold.
|
|
83
|
+
* @method TechnicMediumHubTiltSensor#setImpactThreshold
|
|
84
|
+
* @param {threshold} value between 1 and 127
|
|
85
|
+
* @returns {Promise} Resolved upon successful issuance of the command.
|
|
86
|
+
*/
|
|
87
|
+
public setImpactThreshold (threshold: number) {
|
|
88
|
+
this._impactThreshold = threshold;
|
|
89
|
+
return new Promise<void>((resolve) => {
|
|
90
|
+
this.writeDirect(0x02, Buffer.from([this._impactThreshold, this._impactHoldoff]));
|
|
91
|
+
return resolve();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Set the impact holdoff time.
|
|
97
|
+
* @method TechnicMediumHubTiltSensor#setImpactHoldoff
|
|
98
|
+
* @param {holdoff} value between 1 and 127
|
|
99
|
+
* @returns {Promise} Resolved upon successful issuance of the command.
|
|
100
|
+
*/
|
|
101
|
+
public setImpactHoldoff (holdoff: number) {
|
|
102
|
+
this._impactHoldoff = holdoff;
|
|
103
|
+
return new Promise<void>((resolve) => {
|
|
104
|
+
this.writeDirect(0x02, Buffer.from([this._impactThreshold, this._impactHoldoff]));
|
|
105
|
+
return resolve();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
38
108
|
}
|
|
39
109
|
|
|
40
110
|
export enum Mode {
|
|
41
|
-
TILT = 0x00
|
|
111
|
+
TILT = 0x00,
|
|
112
|
+
IMPACT_COUNT = 0x01
|
|
42
113
|
}
|
|
43
114
|
|
|
44
115
|
export const ModeMap: {[event: string]: number} = {
|
|
45
|
-
"tilt": Mode.TILT
|
|
116
|
+
"tilt": Mode.TILT,
|
|
117
|
+
"impactCount": Mode.IMPACT_COUNT
|
|
46
118
|
};
|
package/src/hubs/lpf2hub.ts
CHANGED
|
@@ -348,14 +348,13 @@ export class LPF2Hub extends BaseHub {
|
|
|
348
348
|
|
|
349
349
|
|
|
350
350
|
private _parsePortAction (message: Buffer) {
|
|
351
|
+
for (let offset = 3; offset < message.length; offset += 2) {
|
|
352
|
+
const device = this._getDeviceByPortId(message[offset]);
|
|
351
353
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (device) {
|
|
356
|
-
device.finish(message[4]);
|
|
354
|
+
if (device) {
|
|
355
|
+
device.finish(message[offset+1]);
|
|
356
|
+
}
|
|
357
357
|
}
|
|
358
|
-
|
|
359
358
|
}
|
|
360
359
|
|
|
361
360
|
|
package/src/poweredup-node.ts
CHANGED
|
@@ -25,7 +25,10 @@ let wantScan = false;
|
|
|
25
25
|
let discoveryEventAttached = false;
|
|
26
26
|
|
|
27
27
|
const startScanning = () => {
|
|
28
|
-
noble.startScanning(
|
|
28
|
+
noble.startScanning([
|
|
29
|
+
Consts.BLEService.LPF2_HUB,
|
|
30
|
+
Consts.BLEService.WEDO2_SMART_HUB
|
|
31
|
+
]);
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
noble.on("stateChange", (state: string) => {
|