node-poweredup 7.0.0 → 8.0.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.
Files changed (294) hide show
  1. package/.drone.yml +1 -0
  2. package/.gitmodules +3 -0
  3. package/{jsdoc.conf.json → .jsdoc.json} +14 -1
  4. package/README.md +47 -42
  5. package/dist/browser/poweredup.js +1 -1
  6. package/dist/browser/poweredup.js.map +1 -1
  7. package/dist/node/color.d.ts +6 -0
  8. package/dist/node/color.js +38 -0
  9. package/dist/node/color.js.map +1 -0
  10. package/dist/node/consts.d.ts +47 -26
  11. package/dist/node/consts.js +46 -25
  12. package/dist/node/consts.js.map +1 -1
  13. package/dist/node/devices/colordistancesensor.d.ts +11 -0
  14. package/dist/node/devices/colordistancesensor.js +93 -1
  15. package/dist/node/devices/colordistancesensor.js.map +1 -1
  16. package/dist/node/devices/device.js +2 -0
  17. package/dist/node/devices/device.js.map +1 -1
  18. package/dist/node/devices/technic3x3colorlightmatrix.d.ts +22 -0
  19. package/dist/node/devices/technic3x3colorlightmatrix.js +77 -0
  20. package/dist/node/devices/technic3x3colorlightmatrix.js.map +1 -0
  21. package/dist/node/devices/technicmediumhubtiltsensor.d.ts +25 -1
  22. package/dist/node/devices/technicmediumhubtiltsensor.js +70 -2
  23. package/dist/node/devices/technicmediumhubtiltsensor.js.map +1 -1
  24. package/dist/node/devices/technicsmallangularmotor.d.ts +12 -0
  25. package/dist/node/devices/technicsmallangularmotor.js +35 -0
  26. package/dist/node/devices/technicsmallangularmotor.js.map +1 -0
  27. package/dist/node/hubs/basehub.js +4 -0
  28. package/dist/node/hubs/basehub.js.map +1 -1
  29. package/dist/node/hubs/lpf2hub.js +5 -4
  30. package/dist/node/hubs/lpf2hub.js.map +1 -1
  31. package/dist/node/hubs/technicmediumhub.js +1 -1
  32. package/dist/node/hubs/technicmediumhub.js.map +1 -1
  33. package/dist/node/hubs/technicsmallhub.d.ts +18 -0
  34. package/dist/node/hubs/technicsmallhub.js +64 -0
  35. package/dist/node/hubs/technicsmallhub.js.map +1 -0
  36. package/dist/node/index-browser.js +6 -0
  37. package/dist/node/index-browser.js.map +1 -1
  38. package/dist/node/index-node.d.ts +4 -1
  39. package/dist/node/index-node.js +7 -1
  40. package/dist/node/index-node.js.map +1 -1
  41. package/dist/node/nobleabstraction.js +2 -0
  42. package/dist/node/nobleabstraction.js.map +1 -1
  43. package/dist/node/poweredup-browser.js +8 -1
  44. package/dist/node/poweredup-browser.js.map +1 -1
  45. package/dist/node/poweredup-node.js +30 -1
  46. package/dist/node/poweredup-node.js.map +1 -1
  47. package/dist/node/webbleabstraction.js +1 -0
  48. package/dist/node/webbleabstraction.js.map +1 -1
  49. package/docs/AbsoluteMotor.html +1220 -1405
  50. package/docs/BaseHub.html +787 -872
  51. package/docs/BasicMotor.html +923 -1078
  52. package/docs/ColorDistanceSensor.html +2188 -1540
  53. package/docs/CurrentSensor.html +711 -800
  54. package/docs/Device.html +574 -665
  55. package/docs/DuploTrainBase.html +1255 -1375
  56. package/docs/DuploTrainBaseColorSensor.html +1009 -1082
  57. package/docs/DuploTrainBaseMotor.html +958 -1113
  58. package/docs/DuploTrainBaseSpeaker.html +793 -916
  59. package/docs/DuploTraniBaseSpeedometer.html +628 -719
  60. package/docs/Hub.html +5621 -2397
  61. package/docs/HubLED.html +831 -944
  62. package/docs/LPF2Hub.html +1215 -1335
  63. package/docs/Light.html +831 -944
  64. package/docs/Mario.html +1255 -1420
  65. package/docs/MarioAccelerometer.html +834 -911
  66. package/docs/MarioBarcodeSensor.html +834 -911
  67. package/docs/MarioPantsSensor.html +711 -800
  68. package/docs/MediumLinearMotor.html +861 -1000
  69. package/docs/MotionSensor.html +711 -800
  70. package/docs/MoveHub.html +1255 -1420
  71. package/docs/MoveHubMediumLinearMotor.html +861 -1000
  72. package/docs/MoveHubTiltSensor.html +730 -814
  73. package/docs/PiezoBuzzer.html +732 -834
  74. package/docs/PoweredUP.html +4322 -0
  75. package/docs/RemoteControl.html +1255 -1420
  76. package/docs/RemoteControlButton.html +711 -800
  77. package/docs/SimpleMediumLinearMotor.html +628 -719
  78. package/docs/TachoMotor.html +1644 -1835
  79. package/docs/Technic3x3ColorLightMatrix.html +1181 -0
  80. package/docs/TechnicColorSensor.html +1008 -1099
  81. package/docs/TechnicDistanceSensor.html +939 -1027
  82. package/docs/TechnicForceSensor.html +883 -968
  83. package/docs/TechnicLargeAngularMotor.html +1254 -1439
  84. package/docs/TechnicLargeLinearMotor.html +1254 -1439
  85. package/docs/TechnicMediumAngularMotor.html +1254 -1439
  86. package/docs/TechnicMediumHub.html +1255 -1420
  87. package/docs/TechnicMediumHubAccelerometerSensor.html +749 -828
  88. package/docs/TechnicMediumHubGyroSensor.html +749 -828
  89. package/docs/TechnicMediumHubTiltSensor.html +1340 -831
  90. package/docs/TechnicSmallAngularMotor.html +2073 -0
  91. package/docs/TechnicXLargeLinearMotor.html +1254 -1439
  92. package/docs/TiltSensor.html +730 -814
  93. package/docs/TrainMotor.html +958 -1113
  94. package/docs/VoltageSensor.html +711 -800
  95. package/docs/WeDo2SmartHub.html +1112 -1221
  96. package/docs/consts.js.html +791 -0
  97. package/docs/devices_absolutemotor.js.html +89 -191
  98. package/docs/devices_basicmotor.js.html +89 -191
  99. package/docs/devices_colordistancesensor.js.html +182 -192
  100. package/docs/devices_currentsensor.js.html +89 -191
  101. package/docs/devices_device.js.html +91 -191
  102. package/docs/devices_duplotrainbasecolorsensor.js.html +89 -191
  103. package/docs/devices_duplotrainbasemotor.js.html +92 -194
  104. package/docs/devices_duplotrainbasespeaker.js.html +89 -191
  105. package/docs/devices_duplotrainbasespeedometer.js.html +89 -191
  106. package/docs/devices_hubled.js.html +89 -191
  107. package/docs/devices_light.js.html +89 -191
  108. package/docs/devices_marioaccelerometer.js.html +89 -191
  109. package/docs/devices_mariobarcodesensor.js.html +89 -191
  110. package/docs/devices_mariopantssensor.js.html +89 -191
  111. package/docs/devices_mediumlinearmotor.js.html +92 -194
  112. package/docs/devices_motionsensor.js.html +89 -191
  113. package/docs/devices_movehubmediumlinearmotor.js.html +92 -194
  114. package/docs/devices_movehubtiltsensor.js.html +89 -191
  115. package/docs/devices_piezobuzzer.js.html +89 -191
  116. package/docs/devices_remotecontrolbutton.js.html +89 -191
  117. package/docs/devices_simplemediumlinearmotor.js.html +92 -194
  118. package/docs/devices_tachomotor.js.html +89 -191
  119. package/docs/devices_technic3x3colorlightmatrix.js.html +190 -0
  120. package/docs/devices_techniccolorsensor.js.html +89 -191
  121. package/docs/devices_technicdistancesensor.js.html +89 -191
  122. package/docs/devices_technicforcesensor.js.html +89 -191
  123. package/docs/devices_techniclargeangularmotor.js.html +92 -194
  124. package/docs/devices_techniclargelinearmotor.js.html +92 -194
  125. package/docs/devices_technicmediumangularmotor.js.html +92 -194
  126. package/docs/devices_technicmediumhubaccelerometersensor.js.html +89 -191
  127. package/docs/devices_technicmediumhubgyrosensor.js.html +89 -191
  128. package/docs/devices_technicmediumhubtiltsensor.js.html +159 -193
  129. package/docs/devices_technicsmallangularmotor.js.html +148 -0
  130. package/docs/devices_technicxlargelinearmotor.js.html +92 -194
  131. package/docs/devices_tiltsensor.js.html +89 -191
  132. package/docs/devices_trainmotor.js.html +92 -194
  133. package/docs/devices_voltagesensor.js.html +89 -191
  134. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  135. package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
  136. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  137. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  138. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  139. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  140. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  141. package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
  142. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  143. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  144. package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
  145. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  146. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  147. package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  148. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  149. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  150. package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
  151. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  152. package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
  153. package/docs/fonts/OpenSans-Semibold-webfont.svg +1830 -0
  154. package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  155. package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
  156. package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  157. package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
  158. package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  159. package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  160. package/docs/global.html +9829 -0
  161. package/docs/hubs_basehub.js.html +93 -191
  162. package/docs/hubs_duplotrainbase.js.html +89 -191
  163. package/docs/hubs_hub.js.html +89 -191
  164. package/docs/hubs_lpf2hub.js.html +94 -195
  165. package/docs/hubs_mario.js.html +89 -191
  166. package/docs/hubs_movehub.js.html +89 -191
  167. package/docs/hubs_remotecontrol.js.html +89 -191
  168. package/docs/hubs_technicmediumhub.js.html +90 -192
  169. package/docs/hubs_technicsmallhub.js.html +177 -0
  170. package/docs/hubs_wedo2smarthub.js.html +89 -191
  171. package/docs/icons/home.svg +4 -0
  172. package/docs/icons/search.svg +4 -0
  173. package/docs/index.html +143 -236
  174. package/docs/poweredup-browser.js.html +348 -0
  175. package/docs/poweredup-node.js.html +314 -0
  176. package/docs/scripts/linenumber.js +23 -0
  177. package/docs/scripts/pagelocation.js +89 -0
  178. package/docs/styles/collapse.css +27 -0
  179. package/docs/styles/jsdoc-default.css +953 -0
  180. package/docs/styles/prettify-jsdoc.css +111 -0
  181. package/docs/styles/prettify-tomorrow.css +15 -9
  182. package/jsdoc-template/braintree/CHANGELOG.md +31 -0
  183. package/jsdoc-template/braintree/LICENSE +27 -0
  184. package/jsdoc-template/braintree/README.md +90 -0
  185. package/jsdoc-template/braintree/package.json +39 -0
  186. package/jsdoc-template/braintree/publish.js +675 -0
  187. package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.eot +0 -0
  188. package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.svg +1830 -0
  189. package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.woff +0 -0
  190. package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  191. package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  192. package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  193. package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.eot +0 -0
  194. package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.svg +1830 -0
  195. package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.woff +0 -0
  196. package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.eot +0 -0
  197. package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.svg +1831 -0
  198. package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.woff +0 -0
  199. package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  200. package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  201. package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  202. package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.eot +0 -0
  203. package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.svg +1831 -0
  204. package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.woff +0 -0
  205. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.eot +0 -0
  206. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.svg +1830 -0
  207. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  208. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.woff +0 -0
  209. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  210. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
  211. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  212. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  213. package/jsdoc-template/braintree/static/icons/home.svg +4 -0
  214. package/jsdoc-template/braintree/static/icons/search.svg +4 -0
  215. package/jsdoc-template/braintree/static/scripts/linenumber.js +23 -0
  216. package/jsdoc-template/braintree/static/scripts/pagelocation.js +89 -0
  217. package/jsdoc-template/braintree/static/styles/collapse.css +27 -0
  218. package/jsdoc-template/braintree/static/styles/jsdoc-default.css +953 -0
  219. package/jsdoc-template/braintree/static/styles/prettify-jsdoc.css +111 -0
  220. package/jsdoc-template/braintree/static/styles/prettify-tomorrow.css +138 -0
  221. package/jsdoc-template/braintree/tmpl/augments.tmpl +10 -0
  222. package/jsdoc-template/braintree/tmpl/container.tmpl +213 -0
  223. package/jsdoc-template/braintree/tmpl/details.tmpl +223 -0
  224. package/jsdoc-template/braintree/tmpl/example.tmpl +2 -0
  225. package/jsdoc-template/braintree/tmpl/examples.tmpl +14 -0
  226. package/jsdoc-template/braintree/tmpl/exceptions.tmpl +28 -0
  227. package/jsdoc-template/braintree/tmpl/layout.tmpl +150 -0
  228. package/jsdoc-template/braintree/tmpl/mainpage.tmpl +9 -0
  229. package/jsdoc-template/braintree/tmpl/members.tmpl +38 -0
  230. package/jsdoc-template/braintree/tmpl/method.tmpl +128 -0
  231. package/jsdoc-template/braintree/tmpl/params.tmpl +125 -0
  232. package/jsdoc-template/braintree/tmpl/properties.tmpl +111 -0
  233. package/jsdoc-template/braintree/tmpl/returns.tmpl +17 -0
  234. package/jsdoc-template/braintree/tmpl/source.tmpl +9 -0
  235. package/jsdoc-template/braintree/tmpl/tutorial.tmpl +23 -0
  236. package/jsdoc-template/braintree/tmpl/type.tmpl +11 -0
  237. package/package.json +13 -14
  238. package/src/color.ts +20 -0
  239. package/src/consts.ts +46 -25
  240. package/src/devices/colordistancesensor.ts +96 -2
  241. package/src/devices/device.ts +1 -0
  242. package/src/devices/technic3x3colorlightmatrix.ts +64 -0
  243. package/src/devices/technicmediumhubtiltsensor.ts +75 -3
  244. package/src/devices/technicsmallangularmotor.ts +17 -0
  245. package/src/hubs/basehub.ts +4 -0
  246. package/src/hubs/lpf2hub.ts +5 -6
  247. package/src/hubs/technicmediumhub.ts +1 -1
  248. package/src/hubs/technicsmallhub.ts +60 -0
  249. package/src/index-browser.ts +6 -0
  250. package/src/index-node.ts +6 -0
  251. package/src/nobleabstraction.ts +2 -0
  252. package/src/poweredup-browser.ts +8 -1
  253. package/src/poweredup-node.ts +9 -1
  254. package/src/webbleabstraction.ts +1 -0
  255. package/docs/classes.list.html +0 -8798
  256. package/docs/fonts/glyphicons-halflings-regular.eot +0 -0
  257. package/docs/fonts/glyphicons-halflings-regular.svg +0 -288
  258. package/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
  259. package/docs/fonts/glyphicons-halflings-regular.woff +0 -0
  260. package/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
  261. package/docs/img/glyphicons-halflings-white.png +0 -0
  262. package/docs/img/glyphicons-halflings.png +0 -0
  263. package/docs/quicksearch.html +0 -31
  264. package/docs/scripts/docstrap.lib.js +0 -11
  265. package/docs/scripts/fulltext-search-ui.js +0 -89
  266. package/docs/scripts/fulltext-search.js +0 -36
  267. package/docs/scripts/lunr.min.js +0 -6
  268. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  269. package/docs/scripts/prettify/jquery.min.js +0 -6
  270. package/docs/scripts/prettify/lang-css.js +0 -21
  271. package/docs/scripts/prettify/prettify.js +0 -496
  272. package/docs/scripts/sunlight.js +0 -1157
  273. package/docs/scripts/toc.js +0 -203
  274. package/docs/styles/darkstrap.css +0 -960
  275. package/docs/styles/site.cerulean.css +0 -7008
  276. package/docs/styles/site.cosmo.css +0 -7061
  277. package/docs/styles/site.cyborg.css +0 -7048
  278. package/docs/styles/site.darkly.css +0 -7171
  279. package/docs/styles/site.darkstrap.css +0 -5638
  280. package/docs/styles/site.dibs-bootstrap.css +0 -5899
  281. package/docs/styles/site.flatly.css +0 -7147
  282. package/docs/styles/site.journal.css +0 -6973
  283. package/docs/styles/site.lumen.css +0 -7298
  284. package/docs/styles/site.paper.css +0 -7623
  285. package/docs/styles/site.readable.css +0 -6997
  286. package/docs/styles/site.sandstone.css +0 -7035
  287. package/docs/styles/site.simplex.css +0 -7023
  288. package/docs/styles/site.slate.css +0 -7343
  289. package/docs/styles/site.spacelab.css +0 -7055
  290. package/docs/styles/site.superhero.css +0 -7131
  291. package/docs/styles/site.united.css +0 -6895
  292. package/docs/styles/site.yeti.css +0 -7195
  293. package/docs/styles/sunlight.dark.css +0 -345
  294. 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": "7.0.0",
3
+ "version": "8.0.2",
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 -d docs -c jsdoc.conf.json -t ./node_modules/ink-docstrap/template -R README.md dist/node/**/*.js",
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-14",
22
- "compare-versions": "^3.6.0",
23
- "debug": "^4.3.2"
21
+ "@abandonware/noble": "1.9.2-15",
22
+ "compare-versions": "^4.1.3",
23
+ "debug": "^4.3.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/debug": "4.1.7",
27
- "@types/node": "^16.7.6",
28
- "@types/web-bluetooth": "0.0.11",
27
+ "@types/node": "^17.0.10",
28
+ "@types/web-bluetooth": "0.0.12",
29
29
  "buffer": "^6.0.3",
30
- "ink-docstrap": "^1.3.2",
31
- "jsdoc": "^3.6.7",
32
- "jsdoc-to-markdown": "^7.0.1",
33
- "ts-loader": "^9.2.5",
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.4.2",
36
- "webpack": "^5.51.1",
37
- "webpack-cli": "^4.8.0"
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} POWERED_UP_HUB 3
7
- * @property {number} POWERED_UP_REMOTE 4
8
- * @property {number} DUPLO_TRAIN_HUB 5
9
- * @property {number} CONTROL_PLUS_HUB 6
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} LED_LIGHTS 8
34
- * @property {number} VOLTAGE 20
35
- * @property {number} CURRENT 21
36
- * @property {number} PIEZO_TONE 22
37
- * @property {number} RGB_LIGHT 23
38
- * @property {number} WEDO2_TILT 34
39
- * @property {number} WEDO2_DISTANCE 35
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} BOOST_TILT 40
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} DUPLO_TRAIN_BASE_COLOR 43
48
+ * @property {number} DUPLO_TRAIN_BASE_COLOR_SENSOR 43
47
49
  * @property {number} DUPLO_TRAIN_BASE_SPEEDOMETER 44
48
- * @property {number} CONTROL_PLUS_LARGE_MOTOR 46
49
- * @property {number} CONTROL_PLUS_XLARGE_MOTOR 47
50
- * @property {number} POWERED_UP_REMOTE_BUTTON 55
51
- * @property {number} RSSI 56
52
- * @property {number} CONTROL_PLUS_ACCELEROMETER 58
53
- * @property {number} CONTROL_PLUS_TILT 59
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 0
138
- * @property {number} RELEASED 1
139
- * @property {number} UP 2
140
- * @property {number} DOWN 3
141
- * @property {number} STOP 4
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
- TECHNIC_MEDIUM_HUB = 128
207
+ TECHNIC_MEDIUM_HUB_ID = 128,
208
+ TECHNIC_SMALL_HUB_ID = 131
188
209
  }
189
210
 
190
211
 
@@ -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
 
@@ -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();
@@ -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
+ }
@@ -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
- const z = -message.readInt16LE(4);
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
+ }
@@ -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];
@@ -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
- const portId = message[3];
353
- const device = this._getDeviceByPortId(portId);
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
 
@@ -26,7 +26,7 @@ export class TechnicMediumHub extends LPF2Hub {
26
26
  peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
27
27
  peripheral.advertisement.manufacturerData &&
28
28
  peripheral.advertisement.manufacturerData.length > 3 &&
29
- peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.TECHNIC_MEDIUM_HUB
29
+ peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.TECHNIC_MEDIUM_HUB_ID
30
30
  );
31
31
  }
32
32
 
@@ -0,0 +1,60 @@
1
+ import { Peripheral } from "@abandonware/noble";
2
+ import compareVersion from "compare-versions";
3
+
4
+ import { IBLEAbstraction } from "../interfaces";
5
+
6
+ import { LPF2Hub } from "./lpf2hub";
7
+
8
+ import * as Consts from "../consts";
9
+
10
+ import Debug = require("debug");
11
+ const debug = Debug("hub");
12
+
13
+
14
+ /**
15
+ * The TechnicSmallHub is emitted if the discovered device is a Technic Small Hub.
16
+ * @class Hub
17
+ * @extends LPF2Hub
18
+ * @extends BaseHub
19
+ */
20
+ export class TechnicSmallHub extends LPF2Hub {
21
+
22
+
23
+ public static IsTechnicSmallHub (peripheral: Peripheral) {
24
+ return (
25
+ peripheral.advertisement &&
26
+ peripheral.advertisement.serviceUuids &&
27
+ peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
28
+ peripheral.advertisement.manufacturerData &&
29
+ peripheral.advertisement.manufacturerData.length > 3 &&
30
+ peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.TECHNIC_SMALL_HUB_ID
31
+ );
32
+ }
33
+
34
+ protected _currentPort = 0x3b;
35
+
36
+ constructor (device: IBLEAbstraction) {
37
+ super(device, PortMap, Consts.HubType.TECHNIC_SMALL_HUB);
38
+ debug("Discovered Spike Essential Hub");
39
+ }
40
+
41
+
42
+ public async connect () {
43
+ debug("Connecting to Spike Essential Hub");
44
+ await super.connect();
45
+ debug("Connect completed");
46
+ }
47
+
48
+
49
+ }
50
+
51
+ export const PortMap: {[portName: string]: number} = {
52
+ "A": 0,
53
+ "B": 1,
54
+ "HUB_LED": 49,
55
+ "CURRENT_SENSOR": 59,
56
+ "VOLTAGE_SENSOR": 60,
57
+ "ACCELEROMETER": 97,
58
+ "GYRO_SENSOR": 98,
59
+ "TILT_SENSOR": 99
60
+ };