node-poweredup 6.10.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) 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 +48 -27
  11. package/dist/node/consts.js +53 -31
  12. package/dist/node/consts.js.map +1 -1
  13. package/dist/node/devices/absolutemotor.js +8 -9
  14. package/dist/node/devices/absolutemotor.js.map +1 -1
  15. package/dist/node/devices/basicmotor.js +2 -2
  16. package/dist/node/devices/basicmotor.js.map +1 -1
  17. package/dist/node/devices/colordistancesensor.d.ts +11 -0
  18. package/dist/node/devices/colordistancesensor.js +95 -2
  19. package/dist/node/devices/colordistancesensor.js.map +1 -1
  20. package/dist/node/devices/device.d.ts +2 -2
  21. package/dist/node/devices/device.js +10 -5
  22. package/dist/node/devices/device.js.map +1 -1
  23. package/dist/node/devices/duplotrainbasecolorsensor.d.ts +2 -1
  24. package/dist/node/devices/duplotrainbasecolorsensor.js +15 -2
  25. package/dist/node/devices/duplotrainbasecolorsensor.js.map +1 -1
  26. package/dist/node/devices/light.js +1 -1
  27. package/dist/node/devices/light.js.map +1 -1
  28. package/dist/node/devices/tachomotor.js +10 -12
  29. package/dist/node/devices/tachomotor.js.map +1 -1
  30. package/dist/node/devices/technic3x3colorlightmatrix.d.ts +22 -0
  31. package/dist/node/devices/technic3x3colorlightmatrix.js +77 -0
  32. package/dist/node/devices/technic3x3colorlightmatrix.js.map +1 -0
  33. package/dist/node/devices/techniccolorsensor.js +2 -1
  34. package/dist/node/devices/techniccolorsensor.js.map +1 -1
  35. package/dist/node/devices/technicmediumhubtiltsensor.d.ts +25 -1
  36. package/dist/node/devices/technicmediumhubtiltsensor.js +70 -2
  37. package/dist/node/devices/technicmediumhubtiltsensor.js.map +1 -1
  38. package/dist/node/devices/technicsmallangularmotor.d.ts +12 -0
  39. package/dist/node/devices/technicsmallangularmotor.js +35 -0
  40. package/dist/node/devices/technicsmallangularmotor.js.map +1 -0
  41. package/dist/node/hubs/basehub.js +4 -0
  42. package/dist/node/hubs/basehub.js.map +1 -1
  43. package/dist/node/hubs/hub.js +1 -1
  44. package/dist/node/hubs/hub.js.map +1 -1
  45. package/dist/node/hubs/lpf2hub.js +19 -21
  46. package/dist/node/hubs/lpf2hub.js.map +1 -1
  47. package/dist/node/hubs/movehub.js +1 -1
  48. package/dist/node/hubs/movehub.js.map +1 -1
  49. package/dist/node/hubs/technicmediumhub.js +1 -1
  50. package/dist/node/hubs/technicmediumhub.js.map +1 -1
  51. package/dist/node/hubs/technicsmallhub.d.ts +18 -0
  52. package/dist/node/hubs/technicsmallhub.js +64 -0
  53. package/dist/node/hubs/technicsmallhub.js.map +1 -0
  54. package/dist/node/index-browser.js +6 -0
  55. package/dist/node/index-browser.js.map +1 -1
  56. package/dist/node/index-node.d.ts +4 -1
  57. package/dist/node/index-node.js +7 -1
  58. package/dist/node/index-node.js.map +1 -1
  59. package/dist/node/poweredup-browser.js +8 -1
  60. package/dist/node/poweredup-browser.js.map +1 -1
  61. package/dist/node/poweredup-node.js +28 -1
  62. package/dist/node/poweredup-node.js.map +1 -1
  63. package/dist/node/utils.d.ts +1 -1
  64. package/dist/node/utils.js +10 -3
  65. package/dist/node/utils.js.map +1 -1
  66. package/docs/AbsoluteMotor.html +1220 -1405
  67. package/docs/BaseHub.html +787 -872
  68. package/docs/BasicMotor.html +923 -1078
  69. package/docs/ColorDistanceSensor.html +2188 -1540
  70. package/docs/CurrentSensor.html +711 -800
  71. package/docs/Device.html +574 -665
  72. package/docs/DuploTrainBase.html +1255 -1375
  73. package/docs/DuploTrainBaseColorSensor.html +1049 -978
  74. package/docs/DuploTrainBaseMotor.html +958 -1113
  75. package/docs/DuploTrainBaseSpeaker.html +793 -916
  76. package/docs/DuploTraniBaseSpeedometer.html +628 -719
  77. package/docs/Hub.html +5621 -2397
  78. package/docs/HubLED.html +831 -944
  79. package/docs/LPF2Hub.html +1215 -1335
  80. package/docs/Light.html +831 -944
  81. package/docs/Mario.html +1255 -1420
  82. package/docs/MarioAccelerometer.html +834 -911
  83. package/docs/MarioBarcodeSensor.html +834 -911
  84. package/docs/MarioPantsSensor.html +711 -800
  85. package/docs/MediumLinearMotor.html +861 -1000
  86. package/docs/MotionSensor.html +711 -800
  87. package/docs/MoveHub.html +1255 -1420
  88. package/docs/MoveHubMediumLinearMotor.html +861 -1000
  89. package/docs/MoveHubTiltSensor.html +730 -814
  90. package/docs/PiezoBuzzer.html +732 -834
  91. package/docs/PoweredUP.html +4322 -0
  92. package/docs/RemoteControl.html +1255 -1420
  93. package/docs/RemoteControlButton.html +711 -800
  94. package/docs/SimpleMediumLinearMotor.html +628 -719
  95. package/docs/TachoMotor.html +1644 -1835
  96. package/docs/Technic3x3ColorLightMatrix.html +1181 -0
  97. package/docs/TechnicColorSensor.html +1008 -1099
  98. package/docs/TechnicDistanceSensor.html +939 -1027
  99. package/docs/TechnicForceSensor.html +883 -968
  100. package/docs/TechnicLargeAngularMotor.html +1254 -1439
  101. package/docs/TechnicLargeLinearMotor.html +1254 -1439
  102. package/docs/TechnicMediumAngularMotor.html +1254 -1439
  103. package/docs/TechnicMediumHub.html +1255 -1420
  104. package/docs/TechnicMediumHubAccelerometerSensor.html +749 -828
  105. package/docs/TechnicMediumHubGyroSensor.html +749 -828
  106. package/docs/TechnicMediumHubTiltSensor.html +1340 -831
  107. package/docs/TechnicSmallAngularMotor.html +2073 -0
  108. package/docs/TechnicXLargeLinearMotor.html +1254 -1439
  109. package/docs/TiltSensor.html +730 -814
  110. package/docs/TrainMotor.html +958 -1113
  111. package/docs/VoltageSensor.html +711 -800
  112. package/docs/WeDo2SmartHub.html +1112 -1221
  113. package/docs/consts.js.html +791 -0
  114. package/docs/devices_absolutemotor.js.html +97 -200
  115. package/docs/devices_basicmotor.js.html +91 -193
  116. package/docs/devices_colordistancesensor.js.html +184 -193
  117. package/docs/devices_currentsensor.js.html +89 -191
  118. package/docs/devices_device.js.html +99 -196
  119. package/docs/devices_duplotrainbasecolorsensor.js.html +104 -193
  120. package/docs/devices_duplotrainbasemotor.js.html +92 -194
  121. package/docs/devices_duplotrainbasespeaker.js.html +89 -191
  122. package/docs/devices_duplotrainbasespeedometer.js.html +89 -191
  123. package/docs/devices_hubled.js.html +89 -191
  124. package/docs/devices_light.js.html +90 -192
  125. package/docs/devices_marioaccelerometer.js.html +89 -191
  126. package/docs/devices_mariobarcodesensor.js.html +89 -191
  127. package/docs/devices_mariopantssensor.js.html +89 -191
  128. package/docs/devices_mediumlinearmotor.js.html +92 -194
  129. package/docs/devices_motionsensor.js.html +89 -191
  130. package/docs/devices_movehubmediumlinearmotor.js.html +92 -194
  131. package/docs/devices_movehubtiltsensor.js.html +89 -191
  132. package/docs/devices_piezobuzzer.js.html +89 -191
  133. package/docs/devices_remotecontrolbutton.js.html +89 -191
  134. package/docs/devices_simplemediumlinearmotor.js.html +92 -194
  135. package/docs/devices_tachomotor.js.html +99 -203
  136. package/docs/devices_technic3x3colorlightmatrix.js.html +190 -0
  137. package/docs/devices_techniccolorsensor.js.html +91 -192
  138. package/docs/devices_technicdistancesensor.js.html +89 -191
  139. package/docs/devices_technicforcesensor.js.html +89 -191
  140. package/docs/devices_techniclargeangularmotor.js.html +92 -194
  141. package/docs/devices_techniclargelinearmotor.js.html +92 -194
  142. package/docs/devices_technicmediumangularmotor.js.html +92 -194
  143. package/docs/devices_technicmediumhubaccelerometersensor.js.html +89 -191
  144. package/docs/devices_technicmediumhubgyrosensor.js.html +89 -191
  145. package/docs/devices_technicmediumhubtiltsensor.js.html +159 -193
  146. package/docs/devices_technicsmallangularmotor.js.html +148 -0
  147. package/docs/devices_technicxlargelinearmotor.js.html +92 -194
  148. package/docs/devices_tiltsensor.js.html +89 -191
  149. package/docs/devices_trainmotor.js.html +92 -194
  150. package/docs/devices_voltagesensor.js.html +89 -191
  151. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  152. package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
  153. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  154. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  155. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  156. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  157. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  158. package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
  159. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  160. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  161. package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
  162. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  163. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  164. package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  165. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  166. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  167. package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
  168. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  169. package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
  170. package/docs/fonts/OpenSans-Semibold-webfont.svg +1830 -0
  171. package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  172. package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
  173. package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  174. package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
  175. package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  176. package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  177. package/docs/global.html +9829 -0
  178. package/docs/hubs_basehub.js.html +93 -191
  179. package/docs/hubs_duplotrainbase.js.html +89 -191
  180. package/docs/hubs_hub.js.html +90 -192
  181. package/docs/hubs_lpf2hub.js.html +108 -212
  182. package/docs/hubs_mario.js.html +89 -191
  183. package/docs/hubs_movehub.js.html +90 -192
  184. package/docs/hubs_remotecontrol.js.html +89 -191
  185. package/docs/hubs_technicmediumhub.js.html +90 -192
  186. package/docs/hubs_technicsmallhub.js.html +177 -0
  187. package/docs/hubs_wedo2smarthub.js.html +89 -191
  188. package/docs/icons/home.svg +4 -0
  189. package/docs/icons/search.svg +4 -0
  190. package/docs/index.html +143 -236
  191. package/docs/poweredup-browser.js.html +348 -0
  192. package/docs/poweredup-node.js.html +312 -0
  193. package/docs/scripts/linenumber.js +23 -0
  194. package/docs/scripts/pagelocation.js +89 -0
  195. package/docs/styles/collapse.css +27 -0
  196. package/docs/styles/jsdoc-default.css +953 -0
  197. package/docs/styles/prettify-jsdoc.css +111 -0
  198. package/docs/styles/prettify-tomorrow.css +15 -9
  199. package/jsdoc-template/braintree/CHANGELOG.md +31 -0
  200. package/jsdoc-template/braintree/LICENSE +27 -0
  201. package/jsdoc-template/braintree/README.md +90 -0
  202. package/jsdoc-template/braintree/package.json +39 -0
  203. package/jsdoc-template/braintree/publish.js +675 -0
  204. package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.eot +0 -0
  205. package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.svg +1830 -0
  206. package/jsdoc-template/braintree/static/fonts/OpenSans-Bold-webfont.woff +0 -0
  207. package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  208. package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  209. package/jsdoc-template/braintree/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  210. package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.eot +0 -0
  211. package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.svg +1830 -0
  212. package/jsdoc-template/braintree/static/fonts/OpenSans-Italic-webfont.woff +0 -0
  213. package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.eot +0 -0
  214. package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.svg +1831 -0
  215. package/jsdoc-template/braintree/static/fonts/OpenSans-Light-webfont.woff +0 -0
  216. package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  217. package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  218. package/jsdoc-template/braintree/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  219. package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.eot +0 -0
  220. package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.svg +1831 -0
  221. package/jsdoc-template/braintree/static/fonts/OpenSans-Regular-webfont.woff +0 -0
  222. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.eot +0 -0
  223. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.svg +1830 -0
  224. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  225. package/jsdoc-template/braintree/static/fonts/OpenSans-Semibold-webfont.woff +0 -0
  226. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  227. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
  228. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  229. package/jsdoc-template/braintree/static/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  230. package/jsdoc-template/braintree/static/icons/home.svg +4 -0
  231. package/jsdoc-template/braintree/static/icons/search.svg +4 -0
  232. package/jsdoc-template/braintree/static/scripts/linenumber.js +23 -0
  233. package/jsdoc-template/braintree/static/scripts/pagelocation.js +89 -0
  234. package/jsdoc-template/braintree/static/styles/collapse.css +27 -0
  235. package/jsdoc-template/braintree/static/styles/jsdoc-default.css +953 -0
  236. package/jsdoc-template/braintree/static/styles/prettify-jsdoc.css +111 -0
  237. package/jsdoc-template/braintree/static/styles/prettify-tomorrow.css +138 -0
  238. package/jsdoc-template/braintree/tmpl/augments.tmpl +10 -0
  239. package/jsdoc-template/braintree/tmpl/container.tmpl +213 -0
  240. package/jsdoc-template/braintree/tmpl/details.tmpl +223 -0
  241. package/jsdoc-template/braintree/tmpl/example.tmpl +2 -0
  242. package/jsdoc-template/braintree/tmpl/examples.tmpl +14 -0
  243. package/jsdoc-template/braintree/tmpl/exceptions.tmpl +28 -0
  244. package/jsdoc-template/braintree/tmpl/layout.tmpl +150 -0
  245. package/jsdoc-template/braintree/tmpl/mainpage.tmpl +9 -0
  246. package/jsdoc-template/braintree/tmpl/members.tmpl +38 -0
  247. package/jsdoc-template/braintree/tmpl/method.tmpl +128 -0
  248. package/jsdoc-template/braintree/tmpl/params.tmpl +125 -0
  249. package/jsdoc-template/braintree/tmpl/properties.tmpl +111 -0
  250. package/jsdoc-template/braintree/tmpl/returns.tmpl +17 -0
  251. package/jsdoc-template/braintree/tmpl/source.tmpl +9 -0
  252. package/jsdoc-template/braintree/tmpl/tutorial.tmpl +23 -0
  253. package/jsdoc-template/braintree/tmpl/type.tmpl +11 -0
  254. package/package.json +14 -15
  255. package/src/color.ts +20 -0
  256. package/src/consts.ts +47 -26
  257. package/src/devices/absolutemotor.ts +2 -3
  258. package/src/devices/colordistancesensor.ts +98 -3
  259. package/src/devices/device.ts +9 -6
  260. package/src/devices/duplotrainbasecolorsensor.ts +17 -2
  261. package/src/devices/tachomotor.ts +4 -6
  262. package/src/devices/technic3x3colorlightmatrix.ts +64 -0
  263. package/src/devices/techniccolorsensor.ts +2 -1
  264. package/src/devices/technicmediumhubtiltsensor.ts +75 -3
  265. package/src/devices/technicsmallangularmotor.ts +17 -0
  266. package/src/hubs/basehub.ts +4 -0
  267. package/src/hubs/lpf2hub.ts +7 -11
  268. package/src/hubs/technicmediumhub.ts +1 -1
  269. package/src/hubs/technicsmallhub.ts +60 -0
  270. package/src/index-browser.ts +6 -0
  271. package/src/index-node.ts +6 -0
  272. package/src/poweredup-browser.ts +8 -1
  273. package/src/poweredup-node.ts +7 -1
  274. package/src/utils.ts +7 -0
  275. package/docs/classes.list.html +0 -8654
  276. package/docs/fonts/glyphicons-halflings-regular.eot +0 -0
  277. package/docs/fonts/glyphicons-halflings-regular.svg +0 -288
  278. package/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
  279. package/docs/fonts/glyphicons-halflings-regular.woff +0 -0
  280. package/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
  281. package/docs/img/glyphicons-halflings-white.png +0 -0
  282. package/docs/img/glyphicons-halflings.png +0 -0
  283. package/docs/quicksearch.html +0 -31
  284. package/docs/scripts/docstrap.lib.js +0 -11
  285. package/docs/scripts/fulltext-search-ui.js +0 -89
  286. package/docs/scripts/fulltext-search.js +0 -36
  287. package/docs/scripts/lunr.min.js +0 -6
  288. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  289. package/docs/scripts/prettify/jquery.min.js +0 -6
  290. package/docs/scripts/prettify/lang-css.js +0 -21
  291. package/docs/scripts/prettify/prettify.js +0 -496
  292. package/docs/scripts/sunlight.js +0 -1157
  293. package/docs/scripts/toc.js +0 -203
  294. package/docs/styles/darkstrap.css +0 -960
  295. package/docs/styles/site.cerulean.css +0 -7008
  296. package/docs/styles/site.cosmo.css +0 -7061
  297. package/docs/styles/site.cyborg.css +0 -7048
  298. package/docs/styles/site.darkly.css +0 -7171
  299. package/docs/styles/site.darkstrap.css +0 -5638
  300. package/docs/styles/site.dibs-bootstrap.css +0 -5899
  301. package/docs/styles/site.flatly.css +0 -7147
  302. package/docs/styles/site.journal.css +0 -6973
  303. package/docs/styles/site.lumen.css +0 -7298
  304. package/docs/styles/site.paper.css +0 -7623
  305. package/docs/styles/site.readable.css +0 -6997
  306. package/docs/styles/site.sandstone.css +0 -7035
  307. package/docs/styles/site.simplex.css +0 -7023
  308. package/docs/styles/site.slate.css +0 -7343
  309. package/docs/styles/site.spacelab.css +0 -7055
  310. package/docs/styles/site.superhero.css +0 -7131
  311. package/docs/styles/site.united.css +0 -6895
  312. package/docs/styles/site.yeti.css +0 -7195
  313. package/docs/styles/sunlight.dark.css +0 -345
  314. 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": "6.10.0",
3
+ "version": "8.0.0",
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-13",
22
- "compare-versions": "^3.6.0",
23
- "debug": "^4.3.1"
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.5",
27
- "@types/node": "^14.14.37",
28
- "@types/web-bluetooth": "0.0.9",
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
- "ink-docstrap": "^1.3.2",
31
- "jsdoc": "^3.6.6",
32
- "jsdoc-to-markdown": "^7.0.1",
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.2.3",
36
- "webpack": "^5.30.0",
37
- "webpack-cli": "^4.6.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
 
@@ -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 AlertPayload {
469
+ export enum Event {
449
470
  DETACHED_IO = 0x00,
450
471
  ATTACHED_IO = 0x01,
451
472
  ATTACHED_VIRTUAL_IO = 0x02,
@@ -51,7 +51,6 @@ export class AbsoluteMotor extends TachoMotor {
51
51
  }
52
52
  this.cancelEventTimer();
53
53
  return new Promise<void>((resolve) => {
54
- this._busy = true;
55
54
  if (speed === undefined || speed === null) {
56
55
  speed = 100;
57
56
  }
@@ -65,9 +64,9 @@ export class AbsoluteMotor extends TachoMotor {
65
64
  message.writeInt32LE(normalizeAngle(angle), 4);
66
65
  }
67
66
  this.send(message);
68
- this._finished = () => {
67
+ this._finishedCallbacks.push(() => {
69
68
  return resolve();
70
- };
69
+ });
71
70
  });
72
71
  }
73
72
 
@@ -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
 
@@ -15,7 +15,7 @@ export class Device extends EventEmitter {
15
15
 
16
16
  protected _mode: number | undefined;
17
17
  protected _busy: boolean = false;
18
- protected _finished: (() => void) | undefined;
18
+ protected _finishedCallbacks: (() => void)[] = [];
19
19
 
20
20
  private _hub: IDeviceInterface;
21
21
  private _portId: number;
@@ -167,11 +167,14 @@ export class Device extends EventEmitter {
167
167
  this.send(Buffer.from([0x21, this.portId, 0x00]));
168
168
  }
169
169
 
170
- public finish () {
171
- this._busy = false;
172
- if (this._finished) {
173
- this._finished();
174
- this._finished = undefined;
170
+ public finish (message: number) {
171
+ if((message & 0x10) === 0x10) return; // "busy/full"
172
+ this._busy = (message & 0x01) === 0x01;
173
+ while(this._finishedCallbacks.length > Number(this._busy)) {
174
+ const callback = this._finishedCallbacks.shift();
175
+ if(callback) {
176
+ callback();
177
+ }
175
178
  }
176
179
  }
177
180
 
@@ -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
- COLOR = 0x00,
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
@@ -104,7 +104,6 @@ export class TachoMotor extends BasicMotor {
104
104
  }
105
105
  this.cancelEventTimer();
106
106
  return new Promise<void>((resolve) => {
107
- this._busy = true;
108
107
  if (speed === undefined || speed === null) {
109
108
  speed = 100;
110
109
  }
@@ -124,9 +123,9 @@ export class TachoMotor extends BasicMotor {
124
123
  }
125
124
  }
126
125
  this.send(message);
127
- this._finished = () => {
126
+ this._finishedCallbacks.push(() => {
128
127
  return resolve();
129
- };
128
+ });
130
129
  });
131
130
  }
132
131
 
@@ -146,7 +145,6 @@ export class TachoMotor extends BasicMotor {
146
145
  }
147
146
  this.cancelEventTimer();
148
147
  return new Promise<void>((resolve) => {
149
- this._busy = true;
150
148
  if (speed === undefined || speed === null) {
151
149
  speed = 100;
152
150
  }
@@ -158,9 +156,9 @@ export class TachoMotor extends BasicMotor {
158
156
  }
159
157
  message.writeUInt32LE(degrees, 4);
160
158
  this.send(message);
161
- this._finished = () => {
159
+ this._finishedCallbacks.push(() => {
162
160
  return resolve();
163
- };
161
+ });
164
162
  });
165
163
  }
166
164
 
@@ -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
- 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
  };