node-poweredup 10.0.0 → 10.1.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 +0 -1
- package/dist/browser/poweredup.js +6193 -0
- package/dist/browser/poweredup.js.map +7 -0
- package/dist/consts.d.ts +40 -0
- package/dist/consts.d.ts.map +1 -1
- package/dist/consts.js +42 -0
- package/dist/consts.js.map +1 -1
- package/dist/devices/absolutemotor.d.ts +8 -6
- package/dist/devices/absolutemotor.d.ts.map +1 -1
- package/dist/devices/absolutemotor.js +24 -31
- package/dist/devices/absolutemotor.js.map +1 -1
- package/dist/devices/basicmotor.d.ts +11 -10
- package/dist/devices/basicmotor.d.ts.map +1 -1
- package/dist/devices/basicmotor.js +16 -22
- package/dist/devices/basicmotor.js.map +1 -1
- package/dist/devices/colordistancesensor.d.ts +13 -12
- package/dist/devices/colordistancesensor.d.ts.map +1 -1
- package/dist/devices/colordistancesensor.js +25 -31
- package/dist/devices/colordistancesensor.js.map +1 -1
- package/dist/devices/device.d.ts +15 -6
- package/dist/devices/device.d.ts.map +1 -1
- package/dist/devices/device.js +209 -21
- package/dist/devices/device.js.map +1 -1
- package/dist/devices/duplotrainbasespeaker.d.ts +4 -4
- package/dist/devices/duplotrainbasespeaker.d.ts.map +1 -1
- package/dist/devices/duplotrainbasespeaker.js +5 -8
- package/dist/devices/duplotrainbasespeaker.js.map +1 -1
- package/dist/devices/hubled.d.ts +5 -4
- package/dist/devices/hubled.d.ts.map +1 -1
- package/dist/devices/hubled.js +24 -24
- package/dist/devices/hubled.js.map +1 -1
- package/dist/devices/light.d.ts +7 -4
- package/dist/devices/light.d.ts.map +1 -1
- package/dist/devices/light.js +11 -17
- package/dist/devices/light.js.map +1 -1
- package/dist/devices/piezobuzzer.d.ts +3 -2
- package/dist/devices/piezobuzzer.d.ts.map +1 -1
- package/dist/devices/piezobuzzer.js +2 -2
- package/dist/devices/piezobuzzer.js.map +1 -1
- package/dist/devices/tachomotor.d.ts +14 -8
- package/dist/devices/tachomotor.d.ts.map +1 -1
- package/dist/devices/tachomotor.js +50 -56
- package/dist/devices/tachomotor.js.map +1 -1
- package/dist/devices/technic3x3colorlightmatrix.d.ts +3 -2
- package/dist/devices/technic3x3colorlightmatrix.d.ts.map +1 -1
- package/dist/devices/technic3x3colorlightmatrix.js +20 -23
- package/dist/devices/technic3x3colorlightmatrix.js.map +1 -1
- package/dist/devices/techniccolorsensor.d.ts +9 -4
- package/dist/devices/techniccolorsensor.d.ts.map +1 -1
- package/dist/devices/techniccolorsensor.js +99 -8
- package/dist/devices/techniccolorsensor.js.map +1 -1
- package/dist/devices/technicdistancesensor.d.ts +1 -1
- package/dist/devices/technicdistancesensor.js +1 -1
- package/dist/devices/technicmediumhubtiltsensor.d.ts +7 -6
- package/dist/devices/technicmediumhubtiltsensor.d.ts.map +1 -1
- package/dist/devices/technicmediumhubtiltsensor.js +9 -18
- package/dist/devices/technicmediumhubtiltsensor.js.map +1 -1
- package/dist/devices/tiltsensor.d.ts +4 -1
- package/dist/devices/tiltsensor.d.ts.map +1 -1
- package/dist/devices/tiltsensor.js +84 -3
- package/dist/devices/tiltsensor.js.map +1 -1
- package/dist/hubs/basehub.d.ts +1 -0
- package/dist/hubs/basehub.d.ts.map +1 -1
- package/dist/hubs/basehub.js +17 -0
- package/dist/hubs/basehub.js.map +1 -1
- package/dist/hubs/lpf2hub.d.ts +1 -0
- package/dist/hubs/lpf2hub.d.ts.map +1 -1
- package/dist/hubs/lpf2hub.js +11 -0
- package/dist/hubs/lpf2hub.js.map +1 -1
- package/dist/portoutputcommand.d.ts +13 -0
- package/dist/portoutputcommand.d.ts.map +1 -0
- package/dist/portoutputcommand.js +30 -0
- package/dist/portoutputcommand.js.map +1 -0
- package/dist/portoutputsleep.d.ts +6 -0
- package/dist/portoutputsleep.d.ts.map +1 -0
- package/dist/portoutputsleep.js +10 -0
- package/dist/portoutputsleep.js.map +1 -0
- package/dist/utils.d.ts +1 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -19
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/consts.ts +44 -0
- package/src/devices/absolutemotor.ts +24 -31
- package/src/devices/basicmotor.ts +16 -22
- package/src/devices/colordistancesensor.ts +23 -29
- package/src/devices/device.ts +198 -20
- package/src/devices/duplotrainbasespeaker.ts +5 -8
- package/src/devices/hubled.ts +22 -22
- package/src/devices/light.ts +11 -18
- package/src/devices/piezobuzzer.ts +3 -3
- package/src/devices/tachomotor.ts +47 -53
- package/src/devices/technic3x3colorlightmatrix.ts +20 -23
- package/src/devices/techniccolorsensor.ts +102 -10
- package/src/devices/technicdistancesensor.ts +1 -1
- package/src/devices/technicmediumhubtiltsensor.ts +9 -18
- package/src/devices/tiltsensor.ts +85 -5
- package/src/hubs/basehub.ts +18 -0
- package/src/hubs/lpf2hub.ts +12 -5
- package/src/portoutputcommand.ts +37 -0
- package/src/portoutputsleep.ts +11 -0
- package/src/utils.ts +14 -19
- package/tsconfig.tsbuildinfo +1 -1
- package/webpack.config.cjs +35 -0
- package/dist/node/color.d.ts +0 -6
- package/dist/node/color.js +0 -15
- package/dist/node/color.js.map +0 -1
- package/dist/node/commands.d.ts +0 -299
- package/dist/node/commands.js +0 -672
- package/dist/node/commands.js.map +0 -1
- package/dist/node/connection.d.ts +0 -187
- package/dist/node/connection.js +0 -478
- package/dist/node/connection.js.map +0 -1
- package/dist/node/consts.d.ts +0 -644
- package/dist/node/consts.js +0 -675
- package/dist/node/consts.js.map +0 -1
- package/dist/node/devices/absolutemotor.d.ts +0 -43
- package/dist/node/devices/absolutemotor.js +0 -118
- package/dist/node/devices/absolutemotor.js.map +0 -1
- package/dist/node/devices/basicmotor.d.ts +0 -40
- package/dist/node/devices/basicmotor.js +0 -61
- package/dist/node/devices/basicmotor.js.map +0 -1
- package/dist/node/devices/colordistancesensor.d.ts +0 -79
- package/dist/node/devices/colordistancesensor.js +0 -284
- package/dist/node/devices/colordistancesensor.js.map +0 -1
- package/dist/node/devices/currentsensor.d.ts +0 -16
- package/dist/node/devices/currentsensor.js +0 -55
- package/dist/node/devices/currentsensor.js.map +0 -1
- package/dist/node/devices/device.d.ts +0 -71
- package/dist/node/devices/device.js +0 -162
- package/dist/node/devices/device.js.map +0 -1
- package/dist/node/devices/duplotrainbasecolorsensor.d.ts +0 -19
- package/dist/node/devices/duplotrainbasecolorsensor.js +0 -77
- package/dist/node/devices/duplotrainbasecolorsensor.js.map +0 -1
- package/dist/node/devices/duplotrainbasemotor.d.ts +0 -9
- package/dist/node/devices/duplotrainbasemotor.js +0 -12
- package/dist/node/devices/duplotrainbasemotor.js.map +0 -1
- package/dist/node/devices/duplotrainbasespeaker.d.ts +0 -28
- package/dist/node/devices/duplotrainbasespeaker.js +0 -40
- package/dist/node/devices/duplotrainbasespeaker.js.map +0 -1
- package/dist/node/devices/duplotrainbasespeedometer.d.ts +0 -16
- package/dist/node/devices/duplotrainbasespeedometer.js +0 -34
- package/dist/node/devices/duplotrainbasespeedometer.js.map +0 -1
- package/dist/node/devices/hubled.d.ts +0 -29
- package/dist/node/devices/hubled.js +0 -60
- package/dist/node/devices/hubled.js.map +0 -1
- package/dist/node/devices/index.d.ts +0 -14
- package/dist/node/devices/index.js +0 -154
- package/dist/node/devices/index.js.map +0 -1
- package/dist/node/devices/led.d.ts +0 -140
- package/dist/node/devices/led.js +0 -295
- package/dist/node/devices/led.js.map +0 -1
- package/dist/node/devices/light.d.ts +0 -25
- package/dist/node/devices/light.js +0 -46
- package/dist/node/devices/light.js.map +0 -1
- package/dist/node/devices/marioaccelerometer.d.ts +0 -17
- package/dist/node/devices/marioaccelerometer.js +0 -50
- package/dist/node/devices/marioaccelerometer.js.map +0 -1
- package/dist/node/devices/mariobarcodesensor.d.ts +0 -17
- package/dist/node/devices/mariobarcodesensor.js +0 -58
- package/dist/node/devices/mariobarcodesensor.js.map +0 -1
- package/dist/node/devices/mariopantssensor.d.ts +0 -16
- package/dist/node/devices/mariopantssensor.js +0 -34
- package/dist/node/devices/mariopantssensor.js.map +0 -1
- package/dist/node/devices/mediumlinearmotor.d.ts +0 -9
- package/dist/node/devices/mediumlinearmotor.js +0 -12
- package/dist/node/devices/mediumlinearmotor.js.map +0 -1
- package/dist/node/devices/motionsensor.d.ts +0 -16
- package/dist/node/devices/motionsensor.js +0 -38
- package/dist/node/devices/motionsensor.js.map +0 -1
- package/dist/node/devices/motor.d.ts +0 -182
- package/dist/node/devices/motor.js +0 -367
- package/dist/node/devices/motor.js.map +0 -1
- package/dist/node/devices/movehubmediumlinearmotor.d.ts +0 -9
- package/dist/node/devices/movehubmediumlinearmotor.js +0 -12
- package/dist/node/devices/movehubmediumlinearmotor.js.map +0 -1
- package/dist/node/devices/movehubtiltsensor.d.ts +0 -16
- package/dist/node/devices/movehubtiltsensor.js +0 -36
- package/dist/node/devices/movehubtiltsensor.js.map +0 -1
- package/dist/node/devices/piezobuzzer.d.ts +0 -17
- package/dist/node/devices/piezobuzzer.js +0 -28
- package/dist/node/devices/piezobuzzer.js.map +0 -1
- package/dist/node/devices/remotecontrolbutton.d.ts +0 -19
- package/dist/node/devices/remotecontrolbutton.js +0 -40
- package/dist/node/devices/remotecontrolbutton.js.map +0 -1
- package/dist/node/devices/sensor.d.ts +0 -305
- package/dist/node/devices/sensor.js +0 -662
- package/dist/node/devices/sensor.js.map +0 -1
- package/dist/node/devices/simplemediumlinearmotor.d.ts +0 -9
- package/dist/node/devices/simplemediumlinearmotor.js +0 -12
- package/dist/node/devices/simplemediumlinearmotor.js.map +0 -1
- package/dist/node/devices/tachomotor.d.ts +0 -70
- package/dist/node/devices/tachomotor.js +0 -167
- package/dist/node/devices/tachomotor.js.map +0 -1
- package/dist/node/devices/technic3x3colorlightmatrix.d.ts +0 -22
- package/dist/node/devices/technic3x3colorlightmatrix.js +0 -54
- package/dist/node/devices/technic3x3colorlightmatrix.js.map +0 -1
- package/dist/node/devices/techniccolorsensor.d.ts +0 -27
- package/dist/node/devices/techniccolorsensor.js +0 -72
- package/dist/node/devices/techniccolorsensor.js.map +0 -1
- package/dist/node/devices/technicdistancesensor.d.ts +0 -27
- package/dist/node/devices/technicdistancesensor.js +0 -58
- package/dist/node/devices/technicdistancesensor.js.map +0 -1
- package/dist/node/devices/technicforcesensor.d.ts +0 -18
- package/dist/node/devices/technicforcesensor.js +0 -58
- package/dist/node/devices/technicforcesensor.js.map +0 -1
- package/dist/node/devices/techniclargeangularmotor.d.ts +0 -12
- package/dist/node/devices/techniclargeangularmotor.js +0 -12
- package/dist/node/devices/techniclargeangularmotor.js.map +0 -1
- package/dist/node/devices/techniclargelinearmotor.d.ts +0 -9
- package/dist/node/devices/techniclargelinearmotor.js +0 -12
- package/dist/node/devices/techniclargelinearmotor.js.map +0 -1
- package/dist/node/devices/technicmediumangularmotor.d.ts +0 -12
- package/dist/node/devices/technicmediumangularmotor.js +0 -12
- package/dist/node/devices/technicmediumangularmotor.js.map +0 -1
- package/dist/node/devices/technicmediumhubaccelerometersensor.d.ts +0 -16
- package/dist/node/devices/technicmediumhubaccelerometersensor.js +0 -38
- package/dist/node/devices/technicmediumhubaccelerometersensor.js.map +0 -1
- package/dist/node/devices/technicmediumhubgyrosensor.d.ts +0 -16
- package/dist/node/devices/technicmediumhubgyrosensor.js +0 -38
- package/dist/node/devices/technicmediumhubgyrosensor.js.map +0 -1
- package/dist/node/devices/technicmediumhubtiltsensor.d.ts +0 -40
- package/dist/node/devices/technicmediumhubtiltsensor.js +0 -106
- package/dist/node/devices/technicmediumhubtiltsensor.js.map +0 -1
- package/dist/node/devices/technicsmallangularmotor.d.ts +0 -12
- package/dist/node/devices/technicsmallangularmotor.js +0 -12
- package/dist/node/devices/technicsmallangularmotor.js.map +0 -1
- package/dist/node/devices/technicxlargelinearmotor.d.ts +0 -9
- package/dist/node/devices/technicxlargelinearmotor.js +0 -12
- package/dist/node/devices/technicxlargelinearmotor.js.map +0 -1
- package/dist/node/devices/tiltsensor.d.ts +0 -16
- package/dist/node/devices/tiltsensor.js +0 -36
- package/dist/node/devices/tiltsensor.js.map +0 -1
- package/dist/node/devices/trainmotor.d.ts +0 -9
- package/dist/node/devices/trainmotor.js +0 -12
- package/dist/node/devices/trainmotor.js.map +0 -1
- package/dist/node/devices/voltagesensor.d.ts +0 -16
- package/dist/node/devices/voltagesensor.js +0 -59
- package/dist/node/devices/voltagesensor.js.map +0 -1
- package/dist/node/hub.d.ts +0 -291
- package/dist/node/hub.js +0 -778
- package/dist/node/hub.js.map +0 -1
- package/dist/node/hubs/basehub.d.ts +0 -162
- package/dist/node/hubs/basehub.js +0 -392
- package/dist/node/hubs/basehub.js.map +0 -1
- package/dist/node/hubs/duplotrainbase.d.ts +0 -17
- package/dist/node/hubs/duplotrainbase.js +0 -35
- package/dist/node/hubs/duplotrainbase.js.map +0 -1
- package/dist/node/hubs/hub.d.ts +0 -19
- package/dist/node/hubs/hub.js +0 -44
- package/dist/node/hubs/hub.js.map +0 -1
- package/dist/node/hubs/lpf2hub.d.ts +0 -48
- package/dist/node/hubs/lpf2hub.js +0 -314
- package/dist/node/hubs/lpf2hub.js.map +0 -1
- package/dist/node/hubs/mario.d.ts +0 -17
- package/dist/node/hubs/mario.js +0 -31
- package/dist/node/hubs/mario.js.map +0 -1
- package/dist/node/hubs/movehub.d.ts +0 -18
- package/dist/node/hubs/movehub.js +0 -46
- package/dist/node/hubs/movehub.js.map +0 -1
- package/dist/node/hubs/remotecontrol.d.ts +0 -17
- package/dist/node/hubs/remotecontrol.js +0 -37
- package/dist/node/hubs/remotecontrol.js.map +0 -1
- package/dist/node/hubs/technicmediumhub.d.ts +0 -17
- package/dist/node/hubs/technicmediumhub.js +0 -42
- package/dist/node/hubs/technicmediumhub.js.map +0 -1
- package/dist/node/hubs/technicsmallhub.d.ts +0 -18
- package/dist/node/hubs/technicsmallhub.js +0 -41
- package/dist/node/hubs/technicsmallhub.js.map +0 -1
- package/dist/node/hubs/wedo2smarthub.d.ts +0 -40
- package/dist/node/hubs/wedo2smarthub.js +0 -188
- package/dist/node/hubs/wedo2smarthub.js.map +0 -1
- package/dist/node/index-browser.d.ts +0 -1
- package/dist/node/index-browser.js +0 -96
- package/dist/node/index-browser.js.map +0 -1
- package/dist/node/index-node.d.ts +0 -49
- package/dist/node/index-node.js +0 -50
- package/dist/node/index-node.js.map +0 -1
- package/dist/node/index.d.ts +0 -31
- package/dist/node/index.js +0 -93
- package/dist/node/index.js.map +0 -1
- package/dist/node/index.mjs +0 -0
- package/dist/node/interfaces.d.ts +0 -23
- package/dist/node/interfaces.js +0 -2
- package/dist/node/interfaces.js.map +0 -1
- package/dist/node/nobleabstraction.d.ts +0 -26
- package/dist/node/nobleabstraction.js +0 -123
- package/dist/node/nobleabstraction.js.map +0 -1
- package/dist/node/poweredup-browser.d.ts +0 -50
- package/dist/node/poweredup-browser.js +0 -216
- package/dist/node/poweredup-browser.js.map +0 -1
- package/dist/node/poweredup-node.d.ts +0 -54
- package/dist/node/poweredup-node.js +0 -173
- package/dist/node/poweredup-node.js.map +0 -1
- package/dist/node/poweredup.d.ts +0 -83
- package/dist/node/poweredup.js +0 -542
- package/dist/node/poweredup.js.map +0 -1
- package/dist/node/protocol-wedo.d.ts +0 -158
- package/dist/node/protocol-wedo.js +0 -342
- package/dist/node/protocol-wedo.js.map +0 -1
- package/dist/node/protocol.d.ts +0 -340
- package/dist/node/protocol.js +0 -730
- package/dist/node/protocol.js.map +0 -1
- package/dist/node/types.d.ts +0 -408
- package/dist/node/types.js +0 -291
- package/dist/node/types.js.map +0 -1
- package/dist/node/utils.d.ts +0 -12
- package/dist/node/utils.js +0 -90
- package/dist/node/utils.js.map +0 -1
- package/dist/node/webbleabstraction.d.ts +0 -26
- package/dist/node/webbleabstraction.js +0 -104
- package/dist/node/webbleabstraction.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
1
|
// @ts-ignore
|
|
3
2
|
export const isWebBluetooth = !!(typeof navigator !== "undefined" && navigator && navigator.bluetooth);
|
|
4
3
|
export const toHex = (value, length = 2) => {
|
|
@@ -51,35 +50,30 @@ export const roundAngleToNearest90 = (angle) => {
|
|
|
51
50
|
}
|
|
52
51
|
return -180;
|
|
53
52
|
};
|
|
54
|
-
export const calculateRamp = (
|
|
55
|
-
const emitter = new EventEmitter();
|
|
53
|
+
export const calculateRamp = (fromPower, toPower, time) => {
|
|
56
54
|
const steps = Math.abs(toPower - fromPower);
|
|
55
|
+
if (steps === 0 || time <= 0) {
|
|
56
|
+
return [toPower];
|
|
57
|
+
}
|
|
57
58
|
let delay = time / steps;
|
|
58
59
|
let increment = 1;
|
|
59
|
-
if (delay < 50
|
|
60
|
+
if (delay < 50) {
|
|
60
61
|
increment = 50 / delay;
|
|
61
62
|
delay = 50;
|
|
62
63
|
}
|
|
63
64
|
if (fromPower > toPower) {
|
|
64
65
|
increment = -increment;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
power = toPower;
|
|
71
|
-
}
|
|
72
|
-
else if (fromPower > toPower && power < toPower) {
|
|
73
|
-
power = toPower;
|
|
67
|
+
return Array(Math.round(time / delay)).fill(0).map((element, index) => {
|
|
68
|
+
let value = Math.round(fromPower + (index + 1) * increment);
|
|
69
|
+
if (toPower > fromPower && value > toPower) {
|
|
70
|
+
value = toPower;
|
|
74
71
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
clearInterval(interval);
|
|
78
|
-
emitter.emit("finished");
|
|
72
|
+
else if (fromPower > toPower && value < toPower) {
|
|
73
|
+
value = toPower;
|
|
79
74
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return emitter;
|
|
75
|
+
return value;
|
|
76
|
+
});
|
|
83
77
|
};
|
|
84
78
|
export const parseColor = (color) => {
|
|
85
79
|
if (color === 1 || color === 5) {
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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AAC;AACP,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE;IACxC,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAC7B,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAA"}
|
package/package.json
CHANGED
package/src/consts.ts
CHANGED
|
@@ -703,3 +703,47 @@ export enum MarioColor {
|
|
|
703
703
|
BROWN = 0x6a00,
|
|
704
704
|
CYAN = 0x4201,
|
|
705
705
|
}
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* @typedef TiltDirection
|
|
710
|
+
* @param {number} NEUTRAL 0
|
|
711
|
+
* @param {number} BACKWARD 3
|
|
712
|
+
* @param {number} RIGHT 5
|
|
713
|
+
* @param {number} LEFT 7
|
|
714
|
+
* @param {number} FORWARD 9
|
|
715
|
+
* @param {number} UNKNOWN 10
|
|
716
|
+
*/
|
|
717
|
+
export enum TiltDirection {
|
|
718
|
+
NEUTRAL = 0,
|
|
719
|
+
BACKWARD = 3,
|
|
720
|
+
RIGHT = 5,
|
|
721
|
+
LEFT = 7,
|
|
722
|
+
FORWARD = 9,
|
|
723
|
+
UNKNOWN = 10,
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* @typedef CommandFeedback
|
|
729
|
+
* @param {number} TRANSMISSION_PENDING 0x00 waiting for previous commands to complete transmission or execution
|
|
730
|
+
* @param {number} TRANSMISSION_BUSY 0x10 waiting for device to acknowledge reception
|
|
731
|
+
* @param {number} TRANSMISSION_DISCARDED 0x44 interrupt command has been recieved or device disconnected
|
|
732
|
+
* @param {number} EXECUTION_PENDING 0x20 device is waiting for previous command to complete
|
|
733
|
+
* @param {number} EXECUTION_BUSY 0x21 device is executing the command
|
|
734
|
+
* @param {number} EXECUTION_DISCARDED 0x24 device discarded the command e.g. due to interrupt
|
|
735
|
+
* @param {number} EXECUTION_COMPLETED 0x22 device reported successful completion of command
|
|
736
|
+
* @param {number} FEEDBACK_MISSING 0x66 device disconnected or failed to report feedback
|
|
737
|
+
* @param {number} FEEDBACK_DISABLED 0x26 feedback not implemented for this command
|
|
738
|
+
*/
|
|
739
|
+
export enum CommandFeedback {
|
|
740
|
+
TRANSMISSION_PENDING = 0x00,
|
|
741
|
+
TRANSMISSION_BUSY = 0x10,
|
|
742
|
+
TRANSMISSION_DISCARDED = 0x44,
|
|
743
|
+
EXECUTION_PENDING = 0x20,
|
|
744
|
+
EXECUTION_BUSY = 0x21,
|
|
745
|
+
EXECUTION_DISCARDED = 0x24,
|
|
746
|
+
EXECUTION_COMPLETED = 0x22,
|
|
747
|
+
FEEDBACK_MISSING = 0x66,
|
|
748
|
+
FEEDBACK_DISABLED = 0x26,
|
|
749
|
+
}
|
|
@@ -39,34 +39,29 @@ export class AbsoluteMotor extends TachoMotor {
|
|
|
39
39
|
* Rotate a motor by a given angle.
|
|
40
40
|
* @param {number} angle Absolute position the motor should go to (degrees from 0).
|
|
41
41
|
* @param {number} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100.
|
|
42
|
-
* @
|
|
42
|
+
* @param {boolean} [interrupt=false] If true, previous commands are discarded.
|
|
43
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
|
|
43
44
|
*/
|
|
44
|
-
public gotoAngle (angle: [number, number] | number, speed: number = 100) {
|
|
45
|
+
public gotoAngle (angle: [number, number] | number, speed: number = 100, interrupt: boolean = false) {
|
|
45
46
|
if (!this.isVirtualPort && angle instanceof Array) {
|
|
46
47
|
throw new Error("Only virtual ports can accept multiple positions");
|
|
47
48
|
}
|
|
48
49
|
if (this.isWeDo2SmartHub) {
|
|
49
50
|
throw new Error("Absolute positioning is not available on the WeDo 2.0 Smart Hub");
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
this.send(message);
|
|
66
|
-
this._finishedCallbacks.push(() => {
|
|
67
|
-
return resolve();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
52
|
+
if (speed === undefined || speed === null) {
|
|
53
|
+
speed = 100;
|
|
54
|
+
}
|
|
55
|
+
let message;
|
|
56
|
+
if (angle instanceof Array) {
|
|
57
|
+
message = Buffer.from([0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
|
|
58
|
+
message.writeInt32LE(normalizeAngle(angle[0]), 1);
|
|
59
|
+
message.writeInt32LE(normalizeAngle(angle[1]), 5);
|
|
60
|
+
} else {
|
|
61
|
+
message = Buffer.from([0x0d, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
|
|
62
|
+
message.writeInt32LE(normalizeAngle(angle), 1);
|
|
63
|
+
}
|
|
64
|
+
return this.sendPortOutputCommand(message, interrupt);
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
|
|
@@ -75,10 +70,10 @@ export class AbsoluteMotor extends TachoMotor {
|
|
|
75
70
|
*
|
|
76
71
|
* Real zero is marked on Technic angular motors (SPIKE Prime). It is also available on Technic linear motors (Control+) but is unmarked.
|
|
77
72
|
* @param {number} [speed=100] Speed between 1 - 100. Note that this will always take the shortest path to zero.
|
|
78
|
-
* @returns {Promise} Resolved upon
|
|
73
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
|
|
79
74
|
*/
|
|
80
75
|
public gotoRealZero (speed: number = 100) {
|
|
81
|
-
return new Promise<
|
|
76
|
+
return new Promise<Consts.CommandFeedback>((resolve) => {
|
|
82
77
|
const oldMode = this.mode;
|
|
83
78
|
let calibrated = false;
|
|
84
79
|
this.on("absolute", async ({ angle }) => {
|
|
@@ -93,7 +88,7 @@ export class AbsoluteMotor extends TachoMotor {
|
|
|
93
88
|
if (oldMode) {
|
|
94
89
|
this.subscribe(oldMode);
|
|
95
90
|
}
|
|
96
|
-
return resolve();
|
|
91
|
+
return resolve(Consts.CommandFeedback.FEEDBACK_DISABLED);
|
|
97
92
|
}
|
|
98
93
|
});
|
|
99
94
|
this.requestUpdate();
|
|
@@ -103,14 +98,12 @@ export class AbsoluteMotor extends TachoMotor {
|
|
|
103
98
|
|
|
104
99
|
/**
|
|
105
100
|
* Reset zero to current position
|
|
106
|
-
* @
|
|
101
|
+
* @param {boolean} [interrupt=false] If true, previous commands are discarded.
|
|
102
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
|
|
107
103
|
*/
|
|
108
|
-
public resetZero () {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.send(data);
|
|
112
|
-
return resolve();
|
|
113
|
-
});
|
|
104
|
+
public resetZero (interrupt: boolean = false) {
|
|
105
|
+
const data = Buffer.from([0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
|
|
106
|
+
return this.sendPortOutputCommand(data, interrupt);
|
|
114
107
|
}
|
|
115
108
|
|
|
116
109
|
|
|
@@ -21,13 +21,11 @@ export class BasicMotor extends Device {
|
|
|
21
21
|
/**
|
|
22
22
|
* Set the motor power.
|
|
23
23
|
* @param {number} power For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
|
|
24
|
-
* @
|
|
24
|
+
* @param {boolean} [interrupt=false] If true, previous commands are discarded.
|
|
25
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of command.
|
|
25
26
|
*/
|
|
26
|
-
public setPower (power: number, interrupt: boolean =
|
|
27
|
-
|
|
28
|
-
this.cancelEventTimer();
|
|
29
|
-
}
|
|
30
|
-
return this.writeDirect(0x00, Buffer.from([mapSpeed(power)]));
|
|
27
|
+
public setPower (power: number, interrupt: boolean = false) {
|
|
28
|
+
return this.writeDirect(0x00, Buffer.from([mapSpeed(power)]), interrupt);
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
|
|
@@ -36,37 +34,33 @@ export class BasicMotor extends Device {
|
|
|
36
34
|
* @param {number} fromPower For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
|
|
37
35
|
* @param {number} toPower For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
|
|
38
36
|
* @param {number} time How long the ramp should last (in milliseconds).
|
|
39
|
-
* @returns {Promise} Resolved upon
|
|
37
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of command.
|
|
40
38
|
*/
|
|
41
39
|
public rampPower (fromPower: number, toPower: number, time: number) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.
|
|
46
|
-
this.setPower(power, false);
|
|
47
|
-
})
|
|
48
|
-
.on("finished", resolve);
|
|
40
|
+
const powerValues = calculateRamp(fromPower, toPower, time);
|
|
41
|
+
powerValues.forEach(value => {
|
|
42
|
+
this.setPower(value);
|
|
43
|
+
this.addPortOutputSleep(Math.round(time/powerValues.length));
|
|
49
44
|
});
|
|
45
|
+
return this.setPower(toPower);
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
|
|
53
49
|
/**
|
|
54
|
-
* Stop the motor.
|
|
55
|
-
* @returns {Promise} Resolved upon
|
|
50
|
+
* Stop the motor. Previous commands that have not completed are discarded.
|
|
51
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of command.
|
|
56
52
|
*/
|
|
57
53
|
public stop () {
|
|
58
|
-
this.
|
|
59
|
-
return this.setPower(0);
|
|
54
|
+
return this.setPower(0, true);
|
|
60
55
|
}
|
|
61
56
|
|
|
62
57
|
|
|
63
58
|
/**
|
|
64
|
-
* Brake the motor.
|
|
65
|
-
* @returns {Promise} Resolved upon
|
|
59
|
+
* Brake the motor. Previous commands that have not completed are discarded.
|
|
60
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of command.
|
|
66
61
|
*/
|
|
67
62
|
public brake () {
|
|
68
|
-
this.
|
|
69
|
-
return this.setPower(Consts.BrakingStyle.BRAKE);
|
|
63
|
+
return this.setPower(Consts.BrakingStyle.BRAKE, true);
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
|
|
@@ -158,7 +158,7 @@ export class ColorDistanceSensor extends Device {
|
|
|
158
158
|
*
|
|
159
159
|
* NOTE: Calling this with channel 5-8 with switch off extended channel mode for this receiver.
|
|
160
160
|
* @param {number} channel Channel number, between 1-8
|
|
161
|
-
* @returns {Promise} Resolved upon
|
|
161
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
|
|
162
162
|
*/
|
|
163
163
|
public setPFExtendedChannel (channel: number) {
|
|
164
164
|
let address = 0;
|
|
@@ -179,7 +179,7 @@ export class ColorDistanceSensor extends Device {
|
|
|
179
179
|
* @param {number} channel Channel number, between 1-4
|
|
180
180
|
* @param {string} output Outport port, "RED" (A) or "BLUE" (B)
|
|
181
181
|
* @param {number} power -7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.
|
|
182
|
-
* @returns {Promise} Resolved upon
|
|
182
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
|
|
183
183
|
*/
|
|
184
184
|
public setPFPower (channel: number, output: Output, power: number) {
|
|
185
185
|
let address = 0;
|
|
@@ -202,7 +202,7 @@ export class ColorDistanceSensor extends Device {
|
|
|
202
202
|
* @param {number} channel Channel number, between 1-4
|
|
203
203
|
* @param {number} powerBlue -7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.
|
|
204
204
|
* @param {number} powerRed -7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.
|
|
205
|
-
* @returns {Promise} Resolved upon
|
|
205
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
|
|
206
206
|
*/
|
|
207
207
|
public startPFMotors (channel: number, powerBlue: number, powerRed: number) {
|
|
208
208
|
let address = 0;
|
|
@@ -221,7 +221,7 @@ export class ColorDistanceSensor extends Device {
|
|
|
221
221
|
/**
|
|
222
222
|
* Send a raw Power Functions IR command
|
|
223
223
|
* @param {Buffer} message 2 byte payload making up a Power Functions protocol command. NOTE: Only specify nibbles 1-3, nibble 4 should be zeroed.
|
|
224
|
-
* @returns {Promise} Resolved upon
|
|
224
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
|
|
225
225
|
*/
|
|
226
226
|
public sendPFIRMessage (message: Buffer) {
|
|
227
227
|
if (this.isWeDo2SmartHub) {
|
|
@@ -239,40 +239,34 @@ export class ColorDistanceSensor extends Device {
|
|
|
239
239
|
/**
|
|
240
240
|
* Set the color of the LED on the sensor via a color value.
|
|
241
241
|
* @param {Color} color
|
|
242
|
-
* @returns {Promise} Resolved upon
|
|
242
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
|
|
243
243
|
*/
|
|
244
244
|
public setColor (color: number | boolean) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
return resolve();
|
|
256
|
-
});
|
|
245
|
+
if (color === false) {
|
|
246
|
+
color = 0;
|
|
247
|
+
}
|
|
248
|
+
if (this.isWeDo2SmartHub) {
|
|
249
|
+
throw new Error("Setting LED color is not available on the WeDo 2.0 Smart Hub");
|
|
250
|
+
} else {
|
|
251
|
+
this.subscribe(Mode.LED);
|
|
252
|
+
return this.writeDirect(0x05, Buffer.from([color as number]));
|
|
253
|
+
}
|
|
257
254
|
}
|
|
258
255
|
|
|
259
256
|
/**
|
|
260
257
|
* Set the distance count value.
|
|
261
258
|
* @param {number} count distance count between 0 and 2^32
|
|
262
|
-
* @returns {Promise} Resolved upon
|
|
259
|
+
* @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
|
|
263
260
|
*/
|
|
264
261
|
public setDistanceCount (count: number) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
return resolve();
|
|
275
|
-
});
|
|
262
|
+
if (this.isWeDo2SmartHub) {
|
|
263
|
+
throw new Error("Setting distance count is not available on the WeDo 2.0 Smart Hub");
|
|
264
|
+
} else {
|
|
265
|
+
const payload = Buffer.alloc(4);
|
|
266
|
+
payload.writeUInt32LE(count % 2**32);
|
|
267
|
+
// no need to subscribe, can be set in different mode
|
|
268
|
+
return this.writeDirect(0x02, payload);
|
|
269
|
+
}
|
|
276
270
|
}
|
|
277
271
|
|
|
278
272
|
private _pfPowerToPWM (power: number) {
|