node-poweredup 6.11.0 → 8.0.1
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/.drone.yml +1 -0
- package/.gitmodules +3 -0
- package/{jsdoc.conf.json → .jsdoc.json} +14 -1
- package/README.md +47 -42
- package/dist/browser/poweredup.js +1 -1
- package/dist/browser/poweredup.js.map +1 -1
- package/dist/node/color.d.ts +6 -0
- package/dist/node/color.js +38 -0
- package/dist/node/color.js.map +1 -0
- package/dist/node/consts.d.ts +48 -27
- package/dist/node/consts.js +53 -31
- package/dist/node/consts.js.map +1 -1
- package/dist/node/devices/absolutemotor.js +6 -6
- package/dist/node/devices/absolutemotor.js.map +1 -1
- package/dist/node/devices/basicmotor.js +2 -2
- package/dist/node/devices/basicmotor.js.map +1 -1
- package/dist/node/devices/colordistancesensor.d.ts +11 -0
- package/dist/node/devices/colordistancesensor.js +95 -2
- 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/duplotrainbasecolorsensor.d.ts +2 -1
- package/dist/node/devices/duplotrainbasecolorsensor.js +15 -2
- package/dist/node/devices/duplotrainbasecolorsensor.js.map +1 -1
- package/dist/node/devices/light.js +1 -1
- package/dist/node/devices/light.js.map +1 -1
- package/dist/node/devices/tachomotor.js +6 -6
- package/dist/node/devices/tachomotor.js.map +1 -1
- package/dist/node/devices/technic3x3colorlightmatrix.d.ts +22 -0
- package/dist/node/devices/technic3x3colorlightmatrix.js +77 -0
- package/dist/node/devices/technic3x3colorlightmatrix.js.map +1 -0
- package/dist/node/devices/techniccolorsensor.js +2 -1
- package/dist/node/devices/techniccolorsensor.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/devices/technicsmallangularmotor.d.ts +12 -0
- package/dist/node/devices/technicsmallangularmotor.js +35 -0
- package/dist/node/devices/technicsmallangularmotor.js.map +1 -0
- package/dist/node/hubs/basehub.js +4 -0
- package/dist/node/hubs/basehub.js.map +1 -1
- package/dist/node/hubs/hub.js +1 -1
- package/dist/node/hubs/hub.js.map +1 -1
- package/dist/node/hubs/lpf2hub.js +20 -19
- package/dist/node/hubs/lpf2hub.js.map +1 -1
- package/dist/node/hubs/movehub.js +1 -1
- package/dist/node/hubs/movehub.js.map +1 -1
- package/dist/node/hubs/technicmediumhub.js +1 -1
- package/dist/node/hubs/technicmediumhub.js.map +1 -1
- package/dist/node/hubs/technicsmallhub.d.ts +18 -0
- package/dist/node/hubs/technicsmallhub.js +64 -0
- package/dist/node/hubs/technicsmallhub.js.map +1 -0
- package/dist/node/index-browser.js +6 -0
- package/dist/node/index-browser.js.map +1 -1
- package/dist/node/index-node.d.ts +4 -1
- package/dist/node/index-node.js +7 -1
- package/dist/node/index-node.js.map +1 -1
- package/dist/node/poweredup-browser.js +8 -1
- package/dist/node/poweredup-browser.js.map +1 -1
- package/dist/node/poweredup-node.js +30 -1
- package/dist/node/poweredup-node.js.map +1 -1
- package/dist/node/utils.d.ts +1 -1
- package/dist/node/utils.js +10 -3
- package/dist/node/utils.js.map +1 -1
- package/docs/AbsoluteMotor.html +1220 -1405
- package/docs/BaseHub.html +787 -872
- package/docs/BasicMotor.html +923 -1078
- package/docs/ColorDistanceSensor.html +2188 -1540
- package/docs/CurrentSensor.html +711 -800
- package/docs/Device.html +574 -665
- package/docs/DuploTrainBase.html +1255 -1375
- package/docs/DuploTrainBaseColorSensor.html +1049 -978
- package/docs/DuploTrainBaseMotor.html +958 -1113
- package/docs/DuploTrainBaseSpeaker.html +793 -916
- package/docs/DuploTraniBaseSpeedometer.html +628 -719
- package/docs/Hub.html +5621 -2397
- package/docs/HubLED.html +831 -944
- package/docs/LPF2Hub.html +1215 -1335
- package/docs/Light.html +831 -944
- package/docs/Mario.html +1255 -1420
- package/docs/MarioAccelerometer.html +834 -911
- package/docs/MarioBarcodeSensor.html +834 -911
- package/docs/MarioPantsSensor.html +711 -800
- package/docs/MediumLinearMotor.html +861 -1000
- package/docs/MotionSensor.html +711 -800
- package/docs/MoveHub.html +1255 -1420
- package/docs/MoveHubMediumLinearMotor.html +861 -1000
- package/docs/MoveHubTiltSensor.html +730 -814
- package/docs/PiezoBuzzer.html +732 -834
- package/docs/PoweredUP.html +4322 -0
- package/docs/RemoteControl.html +1255 -1420
- package/docs/RemoteControlButton.html +711 -800
- package/docs/SimpleMediumLinearMotor.html +628 -719
- package/docs/TachoMotor.html +1644 -1835
- package/docs/Technic3x3ColorLightMatrix.html +1181 -0
- package/docs/TechnicColorSensor.html +1008 -1099
- package/docs/TechnicDistanceSensor.html +939 -1027
- package/docs/TechnicForceSensor.html +883 -968
- package/docs/TechnicLargeAngularMotor.html +1254 -1439
- package/docs/TechnicLargeLinearMotor.html +1254 -1439
- package/docs/TechnicMediumAngularMotor.html +1254 -1439
- package/docs/TechnicMediumHub.html +1255 -1420
- package/docs/TechnicMediumHubAccelerometerSensor.html +749 -828
- package/docs/TechnicMediumHubGyroSensor.html +749 -828
- package/docs/TechnicMediumHubTiltSensor.html +1340 -831
- package/docs/TechnicSmallAngularMotor.html +2073 -0
- package/docs/TechnicXLargeLinearMotor.html +1254 -1439
- package/docs/TiltSensor.html +730 -814
- package/docs/TrainMotor.html +958 -1113
- package/docs/VoltageSensor.html +711 -800
- package/docs/WeDo2SmartHub.html +1112 -1221
- package/docs/consts.js.html +791 -0
- package/docs/devices_absolutemotor.js.html +95 -197
- package/docs/devices_basicmotor.js.html +91 -193
- package/docs/devices_colordistancesensor.js.html +184 -193
- package/docs/devices_currentsensor.js.html +89 -191
- package/docs/devices_device.js.html +91 -191
- package/docs/devices_duplotrainbasecolorsensor.js.html +104 -193
- package/docs/devices_duplotrainbasemotor.js.html +92 -194
- package/docs/devices_duplotrainbasespeaker.js.html +89 -191
- package/docs/devices_duplotrainbasespeedometer.js.html +89 -191
- package/docs/devices_hubled.js.html +89 -191
- package/docs/devices_light.js.html +90 -192
- package/docs/devices_marioaccelerometer.js.html +89 -191
- package/docs/devices_mariobarcodesensor.js.html +89 -191
- package/docs/devices_mariopantssensor.js.html +89 -191
- package/docs/devices_mediumlinearmotor.js.html +92 -194
- package/docs/devices_motionsensor.js.html +89 -191
- package/docs/devices_movehubmediumlinearmotor.js.html +92 -194
- package/docs/devices_movehubtiltsensor.js.html +89 -191
- package/docs/devices_piezobuzzer.js.html +89 -191
- package/docs/devices_remotecontrolbutton.js.html +89 -191
- package/docs/devices_simplemediumlinearmotor.js.html +92 -194
- package/docs/devices_tachomotor.js.html +95 -197
- package/docs/devices_technic3x3colorlightmatrix.js.html +190 -0
- package/docs/devices_techniccolorsensor.js.html +91 -192
- package/docs/devices_technicdistancesensor.js.html +89 -191
- package/docs/devices_technicforcesensor.js.html +89 -191
- package/docs/devices_techniclargeangularmotor.js.html +92 -194
- package/docs/devices_techniclargelinearmotor.js.html +92 -194
- package/docs/devices_technicmediumangularmotor.js.html +92 -194
- package/docs/devices_technicmediumhubaccelerometersensor.js.html +89 -191
- package/docs/devices_technicmediumhubgyrosensor.js.html +89 -191
- package/docs/devices_technicmediumhubtiltsensor.js.html +159 -193
- package/docs/devices_technicsmallangularmotor.js.html +148 -0
- package/docs/devices_technicxlargelinearmotor.js.html +92 -194
- package/docs/devices_tiltsensor.js.html +89 -191
- package/docs/devices_trainmotor.js.html +92 -194
- package/docs/devices_voltagesensor.js.html +89 -191
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/docs/global.html +9829 -0
- package/docs/hubs_basehub.js.html +93 -191
- package/docs/hubs_duplotrainbase.js.html +89 -191
- package/docs/hubs_hub.js.html +90 -192
- package/docs/hubs_lpf2hub.js.html +109 -210
- package/docs/hubs_mario.js.html +89 -191
- package/docs/hubs_movehub.js.html +90 -192
- package/docs/hubs_remotecontrol.js.html +89 -191
- package/docs/hubs_technicmediumhub.js.html +90 -192
- package/docs/hubs_technicsmallhub.js.html +177 -0
- package/docs/hubs_wedo2smarthub.js.html +89 -191
- package/docs/icons/home.svg +4 -0
- package/docs/icons/search.svg +4 -0
- package/docs/index.html +143 -236
- package/docs/poweredup-browser.js.html +348 -0
- package/docs/poweredup-node.js.html +314 -0
- package/docs/scripts/linenumber.js +23 -0
- package/docs/scripts/pagelocation.js +89 -0
- package/docs/styles/collapse.css +27 -0
- package/docs/styles/jsdoc-default.css +953 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +15 -9
- package/jsdoc-template/braintree/CHANGELOG.md +31 -0
- package/jsdoc-template/braintree/LICENSE +27 -0
- package/jsdoc-template/braintree/README.md +90 -0
- package/jsdoc-template/braintree/package.json +39 -0
- package/jsdoc-template/braintree/publish.js +675 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.svg +1830 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/jsdoc-template/braintree/static/icons/home.svg +4 -0
- package/jsdoc-template/braintree/static/icons/search.svg +4 -0
- package/jsdoc-template/braintree/static/scripts/linenumber.js +23 -0
- package/jsdoc-template/braintree/static/scripts/pagelocation.js +89 -0
- package/jsdoc-template/braintree/static/styles/collapse.css +27 -0
- package/jsdoc-template/braintree/static/styles/jsdoc-default.css +953 -0
- package/jsdoc-template/braintree/static/styles/prettify-jsdoc.css +111 -0
- package/jsdoc-template/braintree/static/styles/prettify-tomorrow.css +138 -0
- package/jsdoc-template/braintree/tmpl/augments.tmpl +10 -0
- package/jsdoc-template/braintree/tmpl/container.tmpl +213 -0
- package/jsdoc-template/braintree/tmpl/details.tmpl +223 -0
- package/jsdoc-template/braintree/tmpl/example.tmpl +2 -0
- package/jsdoc-template/braintree/tmpl/examples.tmpl +14 -0
- package/jsdoc-template/braintree/tmpl/exceptions.tmpl +28 -0
- package/jsdoc-template/braintree/tmpl/layout.tmpl +150 -0
- package/jsdoc-template/braintree/tmpl/mainpage.tmpl +9 -0
- package/jsdoc-template/braintree/tmpl/members.tmpl +38 -0
- package/jsdoc-template/braintree/tmpl/method.tmpl +128 -0
- package/jsdoc-template/braintree/tmpl/params.tmpl +125 -0
- package/jsdoc-template/braintree/tmpl/properties.tmpl +111 -0
- package/jsdoc-template/braintree/tmpl/returns.tmpl +17 -0
- package/jsdoc-template/braintree/tmpl/source.tmpl +9 -0
- package/jsdoc-template/braintree/tmpl/tutorial.tmpl +23 -0
- package/jsdoc-template/braintree/tmpl/type.tmpl +11 -0
- package/package.json +14 -15
- package/src/color.ts +20 -0
- package/src/consts.ts +47 -26
- package/src/devices/colordistancesensor.ts +98 -3
- package/src/devices/device.ts +1 -0
- package/src/devices/duplotrainbasecolorsensor.ts +17 -2
- package/src/devices/technic3x3colorlightmatrix.ts +64 -0
- package/src/devices/techniccolorsensor.ts +2 -1
- package/src/devices/technicmediumhubtiltsensor.ts +75 -3
- package/src/devices/technicsmallangularmotor.ts +17 -0
- package/src/hubs/basehub.ts +4 -0
- package/src/hubs/lpf2hub.ts +8 -9
- package/src/hubs/technicmediumhub.ts +1 -1
- package/src/hubs/technicsmallhub.ts +60 -0
- package/src/index-browser.ts +6 -0
- package/src/index-node.ts +6 -0
- package/src/poweredup-browser.ts +8 -1
- package/src/poweredup-node.ts +9 -1
- package/src/utils.ts +7 -0
- package/docs/classes.list.html +0 -8654
- package/docs/fonts/glyphicons-halflings-regular.eot +0 -0
- package/docs/fonts/glyphicons-halflings-regular.svg +0 -288
- package/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/docs/fonts/glyphicons-halflings-regular.woff +0 -0
- package/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/docs/img/glyphicons-halflings-white.png +0 -0
- package/docs/img/glyphicons-halflings.png +0 -0
- package/docs/quicksearch.html +0 -31
- package/docs/scripts/docstrap.lib.js +0 -11
- package/docs/scripts/fulltext-search-ui.js +0 -89
- package/docs/scripts/fulltext-search.js +0 -36
- package/docs/scripts/lunr.min.js +0 -6
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docs/scripts/prettify/jquery.min.js +0 -6
- package/docs/scripts/prettify/lang-css.js +0 -21
- package/docs/scripts/prettify/prettify.js +0 -496
- package/docs/scripts/sunlight.js +0 -1157
- package/docs/scripts/toc.js +0 -203
- package/docs/styles/darkstrap.css +0 -960
- package/docs/styles/site.cerulean.css +0 -7008
- package/docs/styles/site.cosmo.css +0 -7061
- package/docs/styles/site.cyborg.css +0 -7048
- package/docs/styles/site.darkly.css +0 -7171
- package/docs/styles/site.darkstrap.css +0 -5638
- package/docs/styles/site.dibs-bootstrap.css +0 -5899
- package/docs/styles/site.flatly.css +0 -7147
- package/docs/styles/site.journal.css +0 -6973
- package/docs/styles/site.lumen.css +0 -7298
- package/docs/styles/site.paper.css +0 -7623
- package/docs/styles/site.readable.css +0 -6997
- package/docs/styles/site.sandstone.css +0 -7035
- package/docs/styles/site.simplex.css +0 -7023
- package/docs/styles/site.slate.css +0 -7343
- package/docs/styles/site.spacelab.css +0 -7055
- package/docs/styles/site.superhero.css +0 -7131
- package/docs/styles/site.united.css +0 -6895
- package/docs/styles/site.yeti.css +0 -7195
- package/docs/styles/sunlight.dark.css +0 -345
- package/docs/styles/sunlight.default.css +0 -344
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-poweredup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "A Javascript module to interface with LEGO Powered Up components.",
|
|
5
5
|
"homepage": "https://github.com/nathankellenicki/node-poweredup/",
|
|
6
6
|
"main": "dist/node/index-node.js",
|
|
@@ -11,29 +11,28 @@
|
|
|
11
11
|
"build:all": "npm run build:node && npm run build:browser",
|
|
12
12
|
"lint": "tslint -c tslint.json \"./src/**/*.ts\"",
|
|
13
13
|
"build": "npm run lint && npm run build:all",
|
|
14
|
-
"docs": "jsdoc -
|
|
14
|
+
"docs": "jsdoc -c .jsdoc.json",
|
|
15
15
|
"all": "npm run build && npm run docs",
|
|
16
16
|
"prepublishOnly": "npm run lint && npm run build:node"
|
|
17
17
|
},
|
|
18
18
|
"author": "Nathan Kellenicki <nathan@kellenicki.com>",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abandonware/noble": "1.9.2-
|
|
22
|
-
"compare-versions": "^
|
|
23
|
-
"debug": "^4.3.
|
|
21
|
+
"@abandonware/noble": "1.9.2-15",
|
|
22
|
+
"compare-versions": "^4.1.3",
|
|
23
|
+
"debug": "^4.3.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/debug": "4.1.
|
|
27
|
-
"@types/node": "^
|
|
28
|
-
"@types/web-bluetooth": "0.0.
|
|
26
|
+
"@types/debug": "4.1.7",
|
|
27
|
+
"@types/node": "^17.0.10",
|
|
28
|
+
"@types/web-bluetooth": "0.0.12",
|
|
29
29
|
"buffer": "^6.0.3",
|
|
30
|
-
"
|
|
31
|
-
"jsdoc": "^
|
|
32
|
-
"
|
|
33
|
-
"ts-loader": "^8.1.0",
|
|
30
|
+
"jsdoc": "^3.5.5",
|
|
31
|
+
"jsdoc-to-markdown": "^7.1.0",
|
|
32
|
+
"ts-loader": "^9.2.6",
|
|
34
33
|
"tslint": "^6.1.3",
|
|
35
|
-
"typescript": "^4.
|
|
36
|
-
"webpack": "^5.
|
|
37
|
-
"webpack-cli": "^4.
|
|
34
|
+
"typescript": "^4.5.4",
|
|
35
|
+
"webpack": "^5.66.0",
|
|
36
|
+
"webpack-cli": "^4.9.1"
|
|
38
37
|
}
|
|
39
38
|
}
|
package/src/color.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as Consts from "./consts";
|
|
2
|
+
|
|
3
|
+
export class Color {
|
|
4
|
+
|
|
5
|
+
private _color: number;
|
|
6
|
+
private _brightness: number = 100;
|
|
7
|
+
|
|
8
|
+
constructor (color: number, brightness?: number) {
|
|
9
|
+
this._color = color;
|
|
10
|
+
this._brightness = brightness || 100;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public toValue () {
|
|
14
|
+
if (this._color === Consts.Color.NONE) {
|
|
15
|
+
return this._color;
|
|
16
|
+
}
|
|
17
|
+
return this._color + (Math.round(this._brightness / 10) << 4);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
package/src/consts.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* @property {number} UNKNOWN 0
|
|
4
4
|
* @property {number} WEDO2_SMART_HUB 1
|
|
5
5
|
* @property {number} MOVE_HUB 2
|
|
6
|
-
* @property {number}
|
|
7
|
-
* @property {number}
|
|
8
|
-
* @property {number}
|
|
9
|
-
* @property {number}
|
|
6
|
+
* @property {number} HUB 3
|
|
7
|
+
* @property {number} REMOTE_CONTROL 4
|
|
8
|
+
* @property {number} DUPLO_TRAIN_BASE 5
|
|
9
|
+
* @property {number} TECHNIC_MEDIUM_HUB 6
|
|
10
10
|
* @property {number} MARIO 7
|
|
11
|
+
* @property {number} TECHNIC_SMALL_HUB 8
|
|
11
12
|
*/
|
|
12
13
|
export enum HubType {
|
|
13
14
|
UNKNOWN = 0,
|
|
@@ -18,6 +19,7 @@ export enum HubType {
|
|
|
18
19
|
DUPLO_TRAIN_BASE = 5,
|
|
19
20
|
TECHNIC_MEDIUM_HUB = 6,
|
|
20
21
|
MARIO = 7,
|
|
22
|
+
TECHNIC_SMALL_HUB = 8,
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
|
|
@@ -30,27 +32,42 @@ export const HubTypeNames = HubType;
|
|
|
30
32
|
* @property {number} UNKNOWN 0
|
|
31
33
|
* @property {number} SIMPLE_MEDIUM_LINEAR_MOTOR 1
|
|
32
34
|
* @property {number} TRAIN_MOTOR 2
|
|
33
|
-
* @property {number}
|
|
34
|
-
* @property {number}
|
|
35
|
-
* @property {number}
|
|
36
|
-
* @property {number}
|
|
37
|
-
* @property {number}
|
|
38
|
-
* @property {number}
|
|
39
|
-
* @property {number}
|
|
35
|
+
* @property {number} LIGHT 8
|
|
36
|
+
* @property {number} VOLTAGE_SENSOR 20
|
|
37
|
+
* @property {number} CURRENT_SENSOR 21
|
|
38
|
+
* @property {number} PIEZO_BUZZER 22
|
|
39
|
+
* @property {number} HUB_LED 23
|
|
40
|
+
* @property {number} TILT_SENSOR 34
|
|
41
|
+
* @property {number} MOTION_SENSOR 35
|
|
40
42
|
* @property {number} COLOR_DISTANCE_SENSOR 37
|
|
41
43
|
* @property {number} MEDIUM_LINEAR_MOTOR 38
|
|
42
44
|
* @property {number} MOVE_HUB_MEDIUM_LINEAR_MOTOR 39
|
|
43
|
-
* @property {number}
|
|
45
|
+
* @property {number} MOVE_HUB_TILT_SENSOR 40
|
|
44
46
|
* @property {number} DUPLO_TRAIN_BASE_MOTOR 41
|
|
45
47
|
* @property {number} DUPLO_TRAIN_BASE_SPEAKER 42
|
|
46
|
-
* @property {number}
|
|
48
|
+
* @property {number} DUPLO_TRAIN_BASE_COLOR_SENSOR 43
|
|
47
49
|
* @property {number} DUPLO_TRAIN_BASE_SPEEDOMETER 44
|
|
48
|
-
* @property {number}
|
|
49
|
-
* @property {number}
|
|
50
|
-
* @property {number}
|
|
51
|
-
* @property {number}
|
|
52
|
-
* @property {number}
|
|
53
|
-
* @property {number}
|
|
50
|
+
* @property {number} TECHNIC_LARGE_LINEAR_MOTOR 46
|
|
51
|
+
* @property {number} TECHNIC_XLARGE_LINEAR_MOTOR 47
|
|
52
|
+
* @property {number} TECHNIC_MEDIUM_ANGULAR_MOTOR 48
|
|
53
|
+
* @property {number} TECHNIC_LARGE_ANGULAR_MOTOR 49
|
|
54
|
+
* @property {number} TECHNIC_MEDIUM_HUB_GEST_SENSOR 54
|
|
55
|
+
* @property {number} REMOTE_CONTROL_BUTTON 55
|
|
56
|
+
* @property {number} REMOTE_CONTROL_RSSI 56
|
|
57
|
+
* @property {number} TECHNIC_MEDIUM_HUB_ACCELEROMETER 57
|
|
58
|
+
* @property {number} TECHNIC_MEDIUM_HUB_GYRO_SENSOR 58
|
|
59
|
+
* @property {number} TECHNIC_MEDIUM_HUB_TILT_SENSOR 59
|
|
60
|
+
* @property {number} TECHNIC_MEDIUM_HUB_TEMPERATURE_SENSOR 60
|
|
61
|
+
* @property {number} TECHNIC_COLOR_SENSOR 61
|
|
62
|
+
* @property {number} TECHNIC_DISTANCE_SENSOR 62
|
|
63
|
+
* @property {number} TECHNIC_FORCE_SENSOR 63
|
|
64
|
+
* @property {number} TECHNIC_3X3_COLOR_LIGHT_MATRIX 64
|
|
65
|
+
* @property {number} TECHNIC_SMALL_ANGULAR_MOTOR 65
|
|
66
|
+
* @property {number} MARIO_ACCELEROMETER 71
|
|
67
|
+
* @property {number} MARIO_BARCODE_SENSOR 73
|
|
68
|
+
* @property {number} MARIO_PANTS_SENSOR 74
|
|
69
|
+
* @property {number} TECHNIC_MEDIUM_ANGULAR_MOTOR_GREY 75
|
|
70
|
+
* @property {number} TECHNIC_LARGE_ANGULAR_MOTOR_GREY 76
|
|
54
71
|
*/
|
|
55
72
|
export enum DeviceType {
|
|
56
73
|
UNKNOWN = 0,
|
|
@@ -85,6 +102,8 @@ export enum DeviceType {
|
|
|
85
102
|
TECHNIC_COLOR_SENSOR = 61, // Spike Prime
|
|
86
103
|
TECHNIC_DISTANCE_SENSOR = 62, // Spike Prime
|
|
87
104
|
TECHNIC_FORCE_SENSOR = 63, // Spike Prime
|
|
105
|
+
TECHNIC_3X3_COLOR_LIGHT_MATRIX = 64, // Spike Essential
|
|
106
|
+
TECHNIC_SMALL_ANGULAR_MOTOR = 65, // Spike Essential
|
|
88
107
|
MARIO_ACCELEROMETER = 71,
|
|
89
108
|
MARIO_BARCODE_SENSOR = 73,
|
|
90
109
|
MARIO_PANTS_SENSOR = 74,
|
|
@@ -134,11 +153,11 @@ export const ColorNames = Color;
|
|
|
134
153
|
|
|
135
154
|
/**
|
|
136
155
|
* @typedef ButtonState
|
|
137
|
-
* @property {number} PRESSED
|
|
138
|
-
* @property {number} RELEASED
|
|
139
|
-
* @property {number} UP
|
|
140
|
-
* @property {number} DOWN
|
|
141
|
-
* @property {number} STOP
|
|
156
|
+
* @property {number} PRESSED 2
|
|
157
|
+
* @property {number} RELEASED 0
|
|
158
|
+
* @property {number} UP 1
|
|
159
|
+
* @property {number} DOWN 255
|
|
160
|
+
* @property {number} STOP 127
|
|
142
161
|
*/
|
|
143
162
|
export enum ButtonState {
|
|
144
163
|
PRESSED = 2,
|
|
@@ -151,6 +170,7 @@ export enum ButtonState {
|
|
|
151
170
|
|
|
152
171
|
/**
|
|
153
172
|
* @typedef BrakingStyle
|
|
173
|
+
* @property {number} FLOAT 0
|
|
154
174
|
* @property {number} HOLD 127
|
|
155
175
|
* @property {number} BRAKE 128
|
|
156
176
|
*/
|
|
@@ -184,7 +204,8 @@ export enum BLEManufacturerData {
|
|
|
184
204
|
HUB_ID = 65,
|
|
185
205
|
REMOTE_CONTROL_ID = 66,
|
|
186
206
|
MARIO_ID = 67,
|
|
187
|
-
|
|
207
|
+
TECHNIC_MEDIUM_HUB_ID = 128,
|
|
208
|
+
TECHNIC_SMALL_HUB_ID = 131
|
|
188
209
|
}
|
|
189
210
|
|
|
190
211
|
|
|
@@ -445,7 +466,7 @@ export enum AlertPayload {
|
|
|
445
466
|
* @param {number} ATTACHED_VIRTUAL_IO 0x02
|
|
446
467
|
* @description https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#event
|
|
447
468
|
*/
|
|
448
|
-
export enum
|
|
469
|
+
export enum Event {
|
|
449
470
|
DETACHED_IO = 0x00,
|
|
450
471
|
ATTACHED_IO = 0x01,
|
|
451
472
|
ATTACHED_VIRTUAL_IO = 0x02,
|
|
@@ -3,6 +3,7 @@ import { Device } from "./device";
|
|
|
3
3
|
import { IDeviceInterface } from "../interfaces";
|
|
4
4
|
|
|
5
5
|
import * as Consts from "../consts";
|
|
6
|
+
import { parseColor } from "../utils";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @class ColorDistanceSensor
|
|
@@ -20,7 +21,7 @@ export class ColorDistanceSensor extends Device {
|
|
|
20
21
|
switch (mode) {
|
|
21
22
|
case Mode.COLOR:
|
|
22
23
|
if (message[this.isWeDo2SmartHub ? 2 : 4] <= 10) {
|
|
23
|
-
const color = message[this.isWeDo2SmartHub ? 2 : 4];
|
|
24
|
+
const color = parseColor(message[this.isWeDo2SmartHub ? 2 : 4]);
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Emits when a color sensor is activated.
|
|
@@ -37,7 +38,7 @@ export class ColorDistanceSensor extends Device {
|
|
|
37
38
|
break;
|
|
38
39
|
}
|
|
39
40
|
if (message[4] <= 10) {
|
|
40
|
-
let distance = Math.floor(message[4] * 25.4);
|
|
41
|
+
let distance = Math.floor(message[4] * 25.4) - 20;
|
|
41
42
|
|
|
42
43
|
if (distance < 0) {
|
|
43
44
|
distance = 0;
|
|
@@ -53,6 +54,74 @@ export class ColorDistanceSensor extends Device {
|
|
|
53
54
|
}
|
|
54
55
|
break;
|
|
55
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
|
+
|
|
56
125
|
case Mode.COLOR_AND_DISTANCE:
|
|
57
126
|
if (this.isWeDo2SmartHub) {
|
|
58
127
|
break;
|
|
@@ -192,18 +261,40 @@ export class ColorDistanceSensor extends Device {
|
|
|
192
261
|
});
|
|
193
262
|
}
|
|
194
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
|
+
}
|
|
195
283
|
|
|
196
284
|
private _pfPowerToPWM (power: number) {
|
|
197
285
|
return power & 15;
|
|
198
286
|
}
|
|
199
287
|
|
|
200
|
-
|
|
201
288
|
}
|
|
202
289
|
|
|
203
290
|
export enum Mode {
|
|
204
291
|
COLOR = 0x00,
|
|
205
292
|
DISTANCE = 0x01,
|
|
293
|
+
DISTANCE_COUNT = 0x02,
|
|
294
|
+
REFLECT = 0x03,
|
|
295
|
+
AMBIENT = 0x04,
|
|
206
296
|
LED = 0x05,
|
|
297
|
+
RGB_I = 0x06,
|
|
207
298
|
PF_IR = 0x07,
|
|
208
299
|
COLOR_AND_DISTANCE = 0x08
|
|
209
300
|
}
|
|
@@ -211,6 +302,10 @@ export enum Mode {
|
|
|
211
302
|
export const ModeMap: {[event: string]: number} = {
|
|
212
303
|
"color": Mode.COLOR,
|
|
213
304
|
"distance": Mode.DISTANCE,
|
|
305
|
+
"distanceCount": Mode.DISTANCE_COUNT,
|
|
306
|
+
"reflect": Mode.REFLECT,
|
|
307
|
+
"ambient": Mode.AMBIENT,
|
|
308
|
+
"rgbIntensity": Mode.RGB_I,
|
|
214
309
|
"colorAndDistance": Mode.COLOR_AND_DISTANCE
|
|
215
310
|
};
|
|
216
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();
|
|
@@ -3,6 +3,7 @@ import { Device } from "./device";
|
|
|
3
3
|
import { IDeviceInterface } from "../interfaces";
|
|
4
4
|
|
|
5
5
|
import * as Consts from "../consts";
|
|
6
|
+
import { parseColor } from "../utils";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @class DuploTrainBaseColorSensor
|
|
@@ -18,9 +19,21 @@ export class DuploTrainBaseColorSensor extends Device {
|
|
|
18
19
|
const mode = this._mode;
|
|
19
20
|
|
|
20
21
|
switch (mode) {
|
|
22
|
+
case Mode.INTENSITY:
|
|
23
|
+
const intensity = message[4];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Emits when intensity of the color/light changes.
|
|
27
|
+
* @event DuploTrainBaseColorSensor#intensity
|
|
28
|
+
* @type {object}
|
|
29
|
+
* @param {number} intensity
|
|
30
|
+
*/
|
|
31
|
+
this.notify("intensity", { intensity });
|
|
32
|
+
break;
|
|
33
|
+
|
|
21
34
|
case Mode.COLOR:
|
|
22
35
|
if (message[4] <= 10) {
|
|
23
|
-
const color = message[4];
|
|
36
|
+
const color = parseColor(message[4]);
|
|
24
37
|
|
|
25
38
|
/**
|
|
26
39
|
* Emits when a color sensor is activated.
|
|
@@ -66,12 +79,14 @@ export class DuploTrainBaseColorSensor extends Device {
|
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
export enum Mode {
|
|
69
|
-
|
|
82
|
+
INTENSITY = 0x00,
|
|
83
|
+
COLOR = 0x01,
|
|
70
84
|
REFLECTIVITY = 0x02,
|
|
71
85
|
RGB = 0x03
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
export const ModeMap: {[event: string]: number} = {
|
|
89
|
+
"intensity": Mode.INTENSITY,
|
|
75
90
|
"color": Mode.COLOR,
|
|
76
91
|
"reflect": Mode.REFLECTIVITY,
|
|
77
92
|
"rgb": Mode.RGB
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Color } from "../color";
|
|
2
|
+
|
|
3
|
+
import { Device } from "./device";
|
|
4
|
+
|
|
5
|
+
import { IDeviceInterface } from "../interfaces";
|
|
6
|
+
|
|
7
|
+
import * as Consts from "../consts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class Technic3x3ColorLightMatrix
|
|
11
|
+
* @extends Device
|
|
12
|
+
*/
|
|
13
|
+
export class Technic3x3ColorLightMatrix extends Device {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
constructor (hub: IDeviceInterface, portId: number) {
|
|
17
|
+
super(hub, portId, {}, Consts.DeviceType.TECHNIC_3X3_COLOR_LIGHT_MATRIX);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Set the LED matrix, one color per LED
|
|
23
|
+
* @method Technic3x3ColorLightMatrix#setMatrix
|
|
24
|
+
* @param {Color[] | Color} colors Array of 9 colors, 9 Color objects, or a single color
|
|
25
|
+
* @returns {Promise} Resolved upon successful issuance of the command.
|
|
26
|
+
*/
|
|
27
|
+
public setMatrix (colors: number[] | number) {
|
|
28
|
+
return new Promise<void>((resolve) => {
|
|
29
|
+
this.subscribe(Mode.PIX_0);
|
|
30
|
+
const colorArray = new Array(9);
|
|
31
|
+
for (let i = 0; i < colorArray.length; i++) {
|
|
32
|
+
if (typeof colors === 'number') {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
colorArray[i] = colors + (10 << 4);
|
|
35
|
+
}
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
if (colors[i] instanceof Color) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
colorArray[i] = colors[i].toValue();
|
|
40
|
+
}
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
if (colors[i] === Consts.Color.NONE) {
|
|
43
|
+
colorArray[i] = Consts.Color.NONE;
|
|
44
|
+
}
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
if (colors[i] <= 10) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
colorArray[i] = colors[i] + (10 << 4); // If a raw color value, set it to max brightness (10)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.writeDirect(Mode.PIX_0, Buffer.from(colorArray));
|
|
52
|
+
return resolve();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export enum Mode {
|
|
60
|
+
LEV_0 = 0x00,
|
|
61
|
+
COL_0 = 0x01,
|
|
62
|
+
PIX_0 = 0x02,
|
|
63
|
+
TRANS = 0x03
|
|
64
|
+
}
|
|
@@ -3,6 +3,7 @@ import { Device } from "./device";
|
|
|
3
3
|
import { IDeviceInterface } from "../interfaces";
|
|
4
4
|
|
|
5
5
|
import * as Consts from "../consts";
|
|
6
|
+
import { parseColor } from "../utils";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @class TechnicColorSensor
|
|
@@ -20,7 +21,7 @@ export class TechnicColorSensor extends Device {
|
|
|
20
21
|
switch (mode) {
|
|
21
22
|
case Mode.COLOR:
|
|
22
23
|
if (message[4] <= 10) {
|
|
23
|
-
const color = message[4];
|
|
24
|
+
const color = parseColor(message[4]);
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Emits when a color sensor is activated.
|
|
@@ -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
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AbsoluteMotor } from "./absolutemotor";
|
|
2
|
+
|
|
3
|
+
import { IDeviceInterface } from "../interfaces";
|
|
4
|
+
|
|
5
|
+
import * as Consts from "../consts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @class TechnicSmallAngularMotor
|
|
9
|
+
* @extends AbsoluteMotor
|
|
10
|
+
*/
|
|
11
|
+
export class TechnicSmallAngularMotor extends AbsoluteMotor {
|
|
12
|
+
|
|
13
|
+
constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.TECHNIC_SMALL_ANGULAR_MOTOR) {
|
|
14
|
+
super(hub, portId, {}, type);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
}
|
package/src/hubs/basehub.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { TechnicDistanceSensor } from "../devices/technicdistancesensor";
|
|
|
28
28
|
import { TechnicForceSensor } from "../devices/technicforcesensor";
|
|
29
29
|
import { TechnicLargeAngularMotor } from "../devices/techniclargeangularmotor";
|
|
30
30
|
import { TechnicLargeLinearMotor } from "../devices/techniclargelinearmotor";
|
|
31
|
+
import { TechnicSmallAngularMotor } from "../devices/technicsmallangularmotor";
|
|
31
32
|
import { TechnicMediumAngularMotor } from "../devices/technicmediumangularmotor";
|
|
32
33
|
import { TechnicMediumHubAccelerometerSensor } from "../devices/technicmediumhubaccelerometersensor";
|
|
33
34
|
import { TechnicMediumHubGyroSensor } from "../devices/technicmediumhubgyrosensor";
|
|
@@ -40,6 +41,7 @@ import { VoltageSensor } from "../devices/voltagesensor";
|
|
|
40
41
|
import * as Consts from "../consts";
|
|
41
42
|
|
|
42
43
|
import Debug = require("debug");
|
|
44
|
+
import { Technic3x3ColorLightMatrix } from "../devices/technic3x3colorlightmatrix";
|
|
43
45
|
const debug = Debug("basehub");
|
|
44
46
|
|
|
45
47
|
|
|
@@ -407,6 +409,7 @@ export class BaseHub extends EventEmitter {
|
|
|
407
409
|
[Consts.DeviceType.TECHNIC_MEDIUM_HUB_GYRO_SENSOR]: TechnicMediumHubGyroSensor,
|
|
408
410
|
[Consts.DeviceType.TECHNIC_MEDIUM_HUB_ACCELEROMETER]: TechnicMediumHubAccelerometerSensor,
|
|
409
411
|
[Consts.DeviceType.MEDIUM_LINEAR_MOTOR]: MediumLinearMotor,
|
|
412
|
+
[Consts.DeviceType.TECHNIC_SMALL_ANGULAR_MOTOR]: TechnicSmallAngularMotor,
|
|
410
413
|
[Consts.DeviceType.TECHNIC_MEDIUM_ANGULAR_MOTOR]: TechnicMediumAngularMotor,
|
|
411
414
|
[Consts.DeviceType.TECHNIC_LARGE_ANGULAR_MOTOR]: TechnicLargeAngularMotor,
|
|
412
415
|
[Consts.DeviceType.TECHNIC_LARGE_LINEAR_MOTOR]: TechnicLargeLinearMotor,
|
|
@@ -425,6 +428,7 @@ export class BaseHub extends EventEmitter {
|
|
|
425
428
|
[Consts.DeviceType.MARIO_PANTS_SENSOR]: MarioPantsSensor,
|
|
426
429
|
[Consts.DeviceType.TECHNIC_MEDIUM_ANGULAR_MOTOR_GREY]: TechnicMediumAngularMotor,
|
|
427
430
|
[Consts.DeviceType.TECHNIC_LARGE_ANGULAR_MOTOR_GREY]: TechnicLargeAngularMotor,
|
|
431
|
+
[Consts.DeviceType.TECHNIC_3X3_COLOR_LIGHT_MATRIX]: Technic3x3ColorLightMatrix,
|
|
428
432
|
};
|
|
429
433
|
|
|
430
434
|
constructor = deviceConstructors[deviceType as Consts.DeviceType];
|