node-poweredup 10.0.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/README.md +0 -1
  2. package/dist/browser/poweredup.js +6193 -0
  3. package/dist/browser/poweredup.js.map +7 -0
  4. package/dist/consts.d.ts +40 -0
  5. package/dist/consts.d.ts.map +1 -1
  6. package/dist/consts.js +42 -0
  7. package/dist/consts.js.map +1 -1
  8. package/dist/devices/absolutemotor.d.ts +8 -6
  9. package/dist/devices/absolutemotor.d.ts.map +1 -1
  10. package/dist/devices/absolutemotor.js +24 -31
  11. package/dist/devices/absolutemotor.js.map +1 -1
  12. package/dist/devices/basicmotor.d.ts +11 -10
  13. package/dist/devices/basicmotor.d.ts.map +1 -1
  14. package/dist/devices/basicmotor.js +16 -22
  15. package/dist/devices/basicmotor.js.map +1 -1
  16. package/dist/devices/colordistancesensor.d.ts +13 -12
  17. package/dist/devices/colordistancesensor.d.ts.map +1 -1
  18. package/dist/devices/colordistancesensor.js +25 -31
  19. package/dist/devices/colordistancesensor.js.map +1 -1
  20. package/dist/devices/device.d.ts +15 -6
  21. package/dist/devices/device.d.ts.map +1 -1
  22. package/dist/devices/device.js +209 -21
  23. package/dist/devices/device.js.map +1 -1
  24. package/dist/devices/duplotrainbasespeaker.d.ts +4 -4
  25. package/dist/devices/duplotrainbasespeaker.d.ts.map +1 -1
  26. package/dist/devices/duplotrainbasespeaker.js +5 -8
  27. package/dist/devices/duplotrainbasespeaker.js.map +1 -1
  28. package/dist/devices/hubled.d.ts +5 -4
  29. package/dist/devices/hubled.d.ts.map +1 -1
  30. package/dist/devices/hubled.js +24 -24
  31. package/dist/devices/hubled.js.map +1 -1
  32. package/dist/devices/light.d.ts +7 -4
  33. package/dist/devices/light.d.ts.map +1 -1
  34. package/dist/devices/light.js +11 -17
  35. package/dist/devices/light.js.map +1 -1
  36. package/dist/devices/piezobuzzer.d.ts +3 -2
  37. package/dist/devices/piezobuzzer.d.ts.map +1 -1
  38. package/dist/devices/piezobuzzer.js +2 -2
  39. package/dist/devices/piezobuzzer.js.map +1 -1
  40. package/dist/devices/tachomotor.d.ts +14 -8
  41. package/dist/devices/tachomotor.d.ts.map +1 -1
  42. package/dist/devices/tachomotor.js +50 -56
  43. package/dist/devices/tachomotor.js.map +1 -1
  44. package/dist/devices/technic3x3colorlightmatrix.d.ts +3 -2
  45. package/dist/devices/technic3x3colorlightmatrix.d.ts.map +1 -1
  46. package/dist/devices/technic3x3colorlightmatrix.js +20 -23
  47. package/dist/devices/technic3x3colorlightmatrix.js.map +1 -1
  48. package/dist/devices/techniccolorsensor.d.ts +9 -4
  49. package/dist/devices/techniccolorsensor.d.ts.map +1 -1
  50. package/dist/devices/techniccolorsensor.js +99 -8
  51. package/dist/devices/techniccolorsensor.js.map +1 -1
  52. package/dist/devices/technicdistancesensor.d.ts +1 -1
  53. package/dist/devices/technicdistancesensor.js +1 -1
  54. package/dist/devices/technicmediumhubtiltsensor.d.ts +7 -6
  55. package/dist/devices/technicmediumhubtiltsensor.d.ts.map +1 -1
  56. package/dist/devices/technicmediumhubtiltsensor.js +9 -18
  57. package/dist/devices/technicmediumhubtiltsensor.js.map +1 -1
  58. package/dist/devices/tiltsensor.d.ts +4 -1
  59. package/dist/devices/tiltsensor.d.ts.map +1 -1
  60. package/dist/devices/tiltsensor.js +84 -3
  61. package/dist/devices/tiltsensor.js.map +1 -1
  62. package/dist/hubs/basehub.d.ts +1 -0
  63. package/dist/hubs/basehub.d.ts.map +1 -1
  64. package/dist/hubs/basehub.js +17 -0
  65. package/dist/hubs/basehub.js.map +1 -1
  66. package/dist/hubs/lpf2hub.d.ts +1 -0
  67. package/dist/hubs/lpf2hub.d.ts.map +1 -1
  68. package/dist/hubs/lpf2hub.js +11 -0
  69. package/dist/hubs/lpf2hub.js.map +1 -1
  70. package/dist/portoutputcommand.d.ts +13 -0
  71. package/dist/portoutputcommand.d.ts.map +1 -0
  72. package/dist/portoutputcommand.js +30 -0
  73. package/dist/portoutputcommand.js.map +1 -0
  74. package/dist/portoutputsleep.d.ts +6 -0
  75. package/dist/portoutputsleep.d.ts.map +1 -0
  76. package/dist/portoutputsleep.js +10 -0
  77. package/dist/portoutputsleep.js.map +1 -0
  78. package/dist/utils.d.ts +1 -3
  79. package/dist/utils.d.ts.map +1 -1
  80. package/dist/utils.js +13 -19
  81. package/dist/utils.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/consts.ts +44 -0
  84. package/src/devices/absolutemotor.ts +24 -31
  85. package/src/devices/basicmotor.ts +16 -22
  86. package/src/devices/colordistancesensor.ts +23 -29
  87. package/src/devices/device.ts +198 -20
  88. package/src/devices/duplotrainbasespeaker.ts +5 -8
  89. package/src/devices/hubled.ts +22 -22
  90. package/src/devices/light.ts +11 -18
  91. package/src/devices/piezobuzzer.ts +3 -3
  92. package/src/devices/tachomotor.ts +47 -53
  93. package/src/devices/technic3x3colorlightmatrix.ts +20 -23
  94. package/src/devices/techniccolorsensor.ts +102 -10
  95. package/src/devices/technicdistancesensor.ts +1 -1
  96. package/src/devices/technicmediumhubtiltsensor.ts +9 -18
  97. package/src/devices/tiltsensor.ts +85 -5
  98. package/src/hubs/basehub.ts +18 -0
  99. package/src/hubs/lpf2hub.ts +12 -5
  100. package/src/portoutputcommand.ts +37 -0
  101. package/src/portoutputsleep.ts +11 -0
  102. package/src/utils.ts +14 -19
  103. package/tsconfig.tsbuildinfo +1 -1
  104. package/webpack.config.cjs +35 -0
  105. package/dist/node/color.d.ts +0 -6
  106. package/dist/node/color.js +0 -15
  107. package/dist/node/color.js.map +0 -1
  108. package/dist/node/commands.d.ts +0 -299
  109. package/dist/node/commands.js +0 -672
  110. package/dist/node/commands.js.map +0 -1
  111. package/dist/node/connection.d.ts +0 -187
  112. package/dist/node/connection.js +0 -478
  113. package/dist/node/connection.js.map +0 -1
  114. package/dist/node/consts.d.ts +0 -644
  115. package/dist/node/consts.js +0 -675
  116. package/dist/node/consts.js.map +0 -1
  117. package/dist/node/devices/absolutemotor.d.ts +0 -43
  118. package/dist/node/devices/absolutemotor.js +0 -118
  119. package/dist/node/devices/absolutemotor.js.map +0 -1
  120. package/dist/node/devices/basicmotor.d.ts +0 -40
  121. package/dist/node/devices/basicmotor.js +0 -61
  122. package/dist/node/devices/basicmotor.js.map +0 -1
  123. package/dist/node/devices/colordistancesensor.d.ts +0 -79
  124. package/dist/node/devices/colordistancesensor.js +0 -284
  125. package/dist/node/devices/colordistancesensor.js.map +0 -1
  126. package/dist/node/devices/currentsensor.d.ts +0 -16
  127. package/dist/node/devices/currentsensor.js +0 -55
  128. package/dist/node/devices/currentsensor.js.map +0 -1
  129. package/dist/node/devices/device.d.ts +0 -71
  130. package/dist/node/devices/device.js +0 -162
  131. package/dist/node/devices/device.js.map +0 -1
  132. package/dist/node/devices/duplotrainbasecolorsensor.d.ts +0 -19
  133. package/dist/node/devices/duplotrainbasecolorsensor.js +0 -77
  134. package/dist/node/devices/duplotrainbasecolorsensor.js.map +0 -1
  135. package/dist/node/devices/duplotrainbasemotor.d.ts +0 -9
  136. package/dist/node/devices/duplotrainbasemotor.js +0 -12
  137. package/dist/node/devices/duplotrainbasemotor.js.map +0 -1
  138. package/dist/node/devices/duplotrainbasespeaker.d.ts +0 -28
  139. package/dist/node/devices/duplotrainbasespeaker.js +0 -40
  140. package/dist/node/devices/duplotrainbasespeaker.js.map +0 -1
  141. package/dist/node/devices/duplotrainbasespeedometer.d.ts +0 -16
  142. package/dist/node/devices/duplotrainbasespeedometer.js +0 -34
  143. package/dist/node/devices/duplotrainbasespeedometer.js.map +0 -1
  144. package/dist/node/devices/hubled.d.ts +0 -29
  145. package/dist/node/devices/hubled.js +0 -60
  146. package/dist/node/devices/hubled.js.map +0 -1
  147. package/dist/node/devices/index.d.ts +0 -14
  148. package/dist/node/devices/index.js +0 -154
  149. package/dist/node/devices/index.js.map +0 -1
  150. package/dist/node/devices/led.d.ts +0 -140
  151. package/dist/node/devices/led.js +0 -295
  152. package/dist/node/devices/led.js.map +0 -1
  153. package/dist/node/devices/light.d.ts +0 -25
  154. package/dist/node/devices/light.js +0 -46
  155. package/dist/node/devices/light.js.map +0 -1
  156. package/dist/node/devices/marioaccelerometer.d.ts +0 -17
  157. package/dist/node/devices/marioaccelerometer.js +0 -50
  158. package/dist/node/devices/marioaccelerometer.js.map +0 -1
  159. package/dist/node/devices/mariobarcodesensor.d.ts +0 -17
  160. package/dist/node/devices/mariobarcodesensor.js +0 -58
  161. package/dist/node/devices/mariobarcodesensor.js.map +0 -1
  162. package/dist/node/devices/mariopantssensor.d.ts +0 -16
  163. package/dist/node/devices/mariopantssensor.js +0 -34
  164. package/dist/node/devices/mariopantssensor.js.map +0 -1
  165. package/dist/node/devices/mediumlinearmotor.d.ts +0 -9
  166. package/dist/node/devices/mediumlinearmotor.js +0 -12
  167. package/dist/node/devices/mediumlinearmotor.js.map +0 -1
  168. package/dist/node/devices/motionsensor.d.ts +0 -16
  169. package/dist/node/devices/motionsensor.js +0 -38
  170. package/dist/node/devices/motionsensor.js.map +0 -1
  171. package/dist/node/devices/motor.d.ts +0 -182
  172. package/dist/node/devices/motor.js +0 -367
  173. package/dist/node/devices/motor.js.map +0 -1
  174. package/dist/node/devices/movehubmediumlinearmotor.d.ts +0 -9
  175. package/dist/node/devices/movehubmediumlinearmotor.js +0 -12
  176. package/dist/node/devices/movehubmediumlinearmotor.js.map +0 -1
  177. package/dist/node/devices/movehubtiltsensor.d.ts +0 -16
  178. package/dist/node/devices/movehubtiltsensor.js +0 -36
  179. package/dist/node/devices/movehubtiltsensor.js.map +0 -1
  180. package/dist/node/devices/piezobuzzer.d.ts +0 -17
  181. package/dist/node/devices/piezobuzzer.js +0 -28
  182. package/dist/node/devices/piezobuzzer.js.map +0 -1
  183. package/dist/node/devices/remotecontrolbutton.d.ts +0 -19
  184. package/dist/node/devices/remotecontrolbutton.js +0 -40
  185. package/dist/node/devices/remotecontrolbutton.js.map +0 -1
  186. package/dist/node/devices/sensor.d.ts +0 -305
  187. package/dist/node/devices/sensor.js +0 -662
  188. package/dist/node/devices/sensor.js.map +0 -1
  189. package/dist/node/devices/simplemediumlinearmotor.d.ts +0 -9
  190. package/dist/node/devices/simplemediumlinearmotor.js +0 -12
  191. package/dist/node/devices/simplemediumlinearmotor.js.map +0 -1
  192. package/dist/node/devices/tachomotor.d.ts +0 -70
  193. package/dist/node/devices/tachomotor.js +0 -167
  194. package/dist/node/devices/tachomotor.js.map +0 -1
  195. package/dist/node/devices/technic3x3colorlightmatrix.d.ts +0 -22
  196. package/dist/node/devices/technic3x3colorlightmatrix.js +0 -54
  197. package/dist/node/devices/technic3x3colorlightmatrix.js.map +0 -1
  198. package/dist/node/devices/techniccolorsensor.d.ts +0 -27
  199. package/dist/node/devices/techniccolorsensor.js +0 -72
  200. package/dist/node/devices/techniccolorsensor.js.map +0 -1
  201. package/dist/node/devices/technicdistancesensor.d.ts +0 -27
  202. package/dist/node/devices/technicdistancesensor.js +0 -58
  203. package/dist/node/devices/technicdistancesensor.js.map +0 -1
  204. package/dist/node/devices/technicforcesensor.d.ts +0 -18
  205. package/dist/node/devices/technicforcesensor.js +0 -58
  206. package/dist/node/devices/technicforcesensor.js.map +0 -1
  207. package/dist/node/devices/techniclargeangularmotor.d.ts +0 -12
  208. package/dist/node/devices/techniclargeangularmotor.js +0 -12
  209. package/dist/node/devices/techniclargeangularmotor.js.map +0 -1
  210. package/dist/node/devices/techniclargelinearmotor.d.ts +0 -9
  211. package/dist/node/devices/techniclargelinearmotor.js +0 -12
  212. package/dist/node/devices/techniclargelinearmotor.js.map +0 -1
  213. package/dist/node/devices/technicmediumangularmotor.d.ts +0 -12
  214. package/dist/node/devices/technicmediumangularmotor.js +0 -12
  215. package/dist/node/devices/technicmediumangularmotor.js.map +0 -1
  216. package/dist/node/devices/technicmediumhubaccelerometersensor.d.ts +0 -16
  217. package/dist/node/devices/technicmediumhubaccelerometersensor.js +0 -38
  218. package/dist/node/devices/technicmediumhubaccelerometersensor.js.map +0 -1
  219. package/dist/node/devices/technicmediumhubgyrosensor.d.ts +0 -16
  220. package/dist/node/devices/technicmediumhubgyrosensor.js +0 -38
  221. package/dist/node/devices/technicmediumhubgyrosensor.js.map +0 -1
  222. package/dist/node/devices/technicmediumhubtiltsensor.d.ts +0 -40
  223. package/dist/node/devices/technicmediumhubtiltsensor.js +0 -106
  224. package/dist/node/devices/technicmediumhubtiltsensor.js.map +0 -1
  225. package/dist/node/devices/technicsmallangularmotor.d.ts +0 -12
  226. package/dist/node/devices/technicsmallangularmotor.js +0 -12
  227. package/dist/node/devices/technicsmallangularmotor.js.map +0 -1
  228. package/dist/node/devices/technicxlargelinearmotor.d.ts +0 -9
  229. package/dist/node/devices/technicxlargelinearmotor.js +0 -12
  230. package/dist/node/devices/technicxlargelinearmotor.js.map +0 -1
  231. package/dist/node/devices/tiltsensor.d.ts +0 -16
  232. package/dist/node/devices/tiltsensor.js +0 -36
  233. package/dist/node/devices/tiltsensor.js.map +0 -1
  234. package/dist/node/devices/trainmotor.d.ts +0 -9
  235. package/dist/node/devices/trainmotor.js +0 -12
  236. package/dist/node/devices/trainmotor.js.map +0 -1
  237. package/dist/node/devices/voltagesensor.d.ts +0 -16
  238. package/dist/node/devices/voltagesensor.js +0 -59
  239. package/dist/node/devices/voltagesensor.js.map +0 -1
  240. package/dist/node/hub.d.ts +0 -291
  241. package/dist/node/hub.js +0 -778
  242. package/dist/node/hub.js.map +0 -1
  243. package/dist/node/hubs/basehub.d.ts +0 -162
  244. package/dist/node/hubs/basehub.js +0 -392
  245. package/dist/node/hubs/basehub.js.map +0 -1
  246. package/dist/node/hubs/duplotrainbase.d.ts +0 -17
  247. package/dist/node/hubs/duplotrainbase.js +0 -35
  248. package/dist/node/hubs/duplotrainbase.js.map +0 -1
  249. package/dist/node/hubs/hub.d.ts +0 -19
  250. package/dist/node/hubs/hub.js +0 -44
  251. package/dist/node/hubs/hub.js.map +0 -1
  252. package/dist/node/hubs/lpf2hub.d.ts +0 -48
  253. package/dist/node/hubs/lpf2hub.js +0 -314
  254. package/dist/node/hubs/lpf2hub.js.map +0 -1
  255. package/dist/node/hubs/mario.d.ts +0 -17
  256. package/dist/node/hubs/mario.js +0 -31
  257. package/dist/node/hubs/mario.js.map +0 -1
  258. package/dist/node/hubs/movehub.d.ts +0 -18
  259. package/dist/node/hubs/movehub.js +0 -46
  260. package/dist/node/hubs/movehub.js.map +0 -1
  261. package/dist/node/hubs/remotecontrol.d.ts +0 -17
  262. package/dist/node/hubs/remotecontrol.js +0 -37
  263. package/dist/node/hubs/remotecontrol.js.map +0 -1
  264. package/dist/node/hubs/technicmediumhub.d.ts +0 -17
  265. package/dist/node/hubs/technicmediumhub.js +0 -42
  266. package/dist/node/hubs/technicmediumhub.js.map +0 -1
  267. package/dist/node/hubs/technicsmallhub.d.ts +0 -18
  268. package/dist/node/hubs/technicsmallhub.js +0 -41
  269. package/dist/node/hubs/technicsmallhub.js.map +0 -1
  270. package/dist/node/hubs/wedo2smarthub.d.ts +0 -40
  271. package/dist/node/hubs/wedo2smarthub.js +0 -188
  272. package/dist/node/hubs/wedo2smarthub.js.map +0 -1
  273. package/dist/node/index-browser.d.ts +0 -1
  274. package/dist/node/index-browser.js +0 -96
  275. package/dist/node/index-browser.js.map +0 -1
  276. package/dist/node/index-node.d.ts +0 -49
  277. package/dist/node/index-node.js +0 -50
  278. package/dist/node/index-node.js.map +0 -1
  279. package/dist/node/index.d.ts +0 -31
  280. package/dist/node/index.js +0 -93
  281. package/dist/node/index.js.map +0 -1
  282. package/dist/node/index.mjs +0 -0
  283. package/dist/node/interfaces.d.ts +0 -23
  284. package/dist/node/interfaces.js +0 -2
  285. package/dist/node/interfaces.js.map +0 -1
  286. package/dist/node/nobleabstraction.d.ts +0 -26
  287. package/dist/node/nobleabstraction.js +0 -123
  288. package/dist/node/nobleabstraction.js.map +0 -1
  289. package/dist/node/poweredup-browser.d.ts +0 -50
  290. package/dist/node/poweredup-browser.js +0 -216
  291. package/dist/node/poweredup-browser.js.map +0 -1
  292. package/dist/node/poweredup-node.d.ts +0 -54
  293. package/dist/node/poweredup-node.js +0 -173
  294. package/dist/node/poweredup-node.js.map +0 -1
  295. package/dist/node/poweredup.d.ts +0 -83
  296. package/dist/node/poweredup.js +0 -542
  297. package/dist/node/poweredup.js.map +0 -1
  298. package/dist/node/protocol-wedo.d.ts +0 -158
  299. package/dist/node/protocol-wedo.js +0 -342
  300. package/dist/node/protocol-wedo.js.map +0 -1
  301. package/dist/node/protocol.d.ts +0 -340
  302. package/dist/node/protocol.js +0 -730
  303. package/dist/node/protocol.js.map +0 -1
  304. package/dist/node/types.d.ts +0 -408
  305. package/dist/node/types.js +0 -291
  306. package/dist/node/types.js.map +0 -1
  307. package/dist/node/utils.d.ts +0 -12
  308. package/dist/node/utils.js +0 -90
  309. package/dist/node/utils.js.map +0 -1
  310. package/dist/node/webbleabstraction.d.ts +0 -26
  311. package/dist/node/webbleabstraction.js +0 -104
  312. package/dist/node/webbleabstraction.js.map +0 -1
  313. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -17,9 +17,17 @@ export class TechnicColorSensor extends Device {
17
17
 
18
18
  public receive (message: Buffer) {
19
19
  const mode = this._mode;
20
+ let hue;
21
+ let saturation;
22
+ let value;
23
+ let intensity;
20
24
 
21
25
  switch (mode) {
22
26
  case Mode.COLOR:
27
+ if (message.length !== 5) {
28
+ // if mode of device has not changed to this._mode yet
29
+ break;
30
+ }
23
31
  if (message[4] <= 10) {
24
32
  const color = parseColor(message[4]);
25
33
 
@@ -33,9 +41,12 @@ export class TechnicColorSensor extends Device {
33
41
  }
34
42
  break;
35
43
 
36
- case Mode.REFLECTIVITY:
44
+ case Mode.REFLECT:
45
+ if (message.length !== 5) {
46
+ // if mode of device has not changed to this._mode yet
47
+ break;
48
+ }
37
49
  const reflect = message[4];
38
-
39
50
  /**
40
51
  * Emits when the light reflectivity changes.
41
52
  * @event TechnicColorSensor#reflect
@@ -45,9 +56,12 @@ export class TechnicColorSensor extends Device {
45
56
  this.notify("reflect", { reflect });
46
57
  break;
47
58
 
48
- case Mode.AMBIENT_LIGHT:
59
+ case Mode.AMBIENT:
60
+ if (message.length !== 5) {
61
+ // if mode of device has not changed to this._mode yet
62
+ break;
63
+ }
49
64
  const ambient = message[4];
50
-
51
65
  /**
52
66
  * Emits when the ambient light changes.
53
67
  * @event TechnicColorSensor#ambient
@@ -56,6 +70,76 @@ export class TechnicColorSensor extends Device {
56
70
  */
57
71
  this.notify("ambient", { ambient });
58
72
  break;
73
+
74
+ case Mode.RGB_I:
75
+ if (this.isWeDo2SmartHub) {
76
+ break;
77
+ }
78
+ if (message.length !== 12) {
79
+ // if mode of device has not changed to this._mode yet
80
+ break;
81
+ }
82
+ const red = message.readUInt16LE(4);
83
+ const green = message.readUInt16LE(6);
84
+ const blue = message.readUInt16LE(8);
85
+ intensity = message.readUInt16LE(10);
86
+ /**
87
+ * Emits when a color sensor is activated. Measured with light on.
88
+ * @event TechnicColorSensor#rgbIntensity
89
+ * @type {object}
90
+ * @param {number} red
91
+ * @param {number} green
92
+ * @param {number} blue
93
+ * @param {number} intensity
94
+ */
95
+ this.notify("rgbIntensity", { red, green, blue, intensity });
96
+ break;
97
+
98
+ case Mode.HSV:
99
+ if (this.isWeDo2SmartHub) {
100
+ break;
101
+ }
102
+ if (message.length !== 10) {
103
+ // if mode of device has not changed to this._mode yet
104
+ break;
105
+ }
106
+ hue = message.readUInt16LE(4);
107
+ saturation = message.readUInt16LE(6);
108
+ value = message.readUInt16LE(8);
109
+ /**
110
+ * Emits when a color sensor is activated. Measured with light on.
111
+ * @event TechnicColorSensor#hsvIntensity
112
+ * @type {object}
113
+ * @param {number} hue
114
+ * @param {number} saturation
115
+ * @param {number} value
116
+ */
117
+ this.notify("hsvIntensity", { hue, saturation, value });
118
+ break;
119
+
120
+ case Mode.SHSV:
121
+ if (this.isWeDo2SmartHub) {
122
+ break;
123
+ }
124
+ if (message.length !== 12) {
125
+ // if mode of device has not changed to this._mode yet
126
+ break;
127
+ }
128
+ hue = message.readUInt16LE(4);
129
+ saturation = message.readUInt16LE(6);
130
+ value = message.readUInt16LE(8);
131
+ intensity = message.readUInt16LE(10);
132
+ /**
133
+ * Emits when a color sensor is activated. Measured with light off.
134
+ * @event TechnicColorSensor#hsvAmbient
135
+ * @type {object}
136
+ * @param {number} hue
137
+ * @param {number} saturation
138
+ * @param {number} value
139
+ * @param {number} intensity
140
+ */
141
+ this.notify("hsvAmbient", { hue, saturation, value, intensity });
142
+ break;
59
143
  }
60
144
  }
61
145
 
@@ -64,22 +148,30 @@ export class TechnicColorSensor extends Device {
64
148
  * @param {number} firstSegment First light segment. 0-100 brightness.
65
149
  * @param {number} secondSegment Second light segment. 0-100 brightness.
66
150
  * @param {number} thirdSegment Third light segment. 0-100 brightness.
67
- * @returns {Promise} Resolved upon successful issuance of the command.
151
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
68
152
  */
69
153
  public setBrightness (firstSegment: number, secondSegment: number, thirdSegment: number) {
70
- this.writeDirect(0x03, Buffer.from([firstSegment, secondSegment, thirdSegment]));
154
+ this.subscribe(Mode.LIGHT); // other modes use different light setting
155
+ return this.writeDirect(Mode.LIGHT, Buffer.from([firstSegment, secondSegment, thirdSegment]));
71
156
  }
72
157
 
73
158
  }
74
159
 
75
160
  export enum Mode {
76
161
  COLOR = 0x00,
77
- REFLECTIVITY = 0x01,
78
- AMBIENT_LIGHT = 0x02
162
+ REFLECT = 0x01,
163
+ AMBIENT = 0x02,
164
+ LIGHT = 0x03,
165
+ RGB_I = 0x05,
166
+ HSV = 0x06,
167
+ SHSV = 0x07
79
168
  }
80
169
 
81
170
  export const ModeMap: {[event: string]: number} = {
82
171
  "color": Mode.COLOR,
83
- "reflect": Mode.REFLECTIVITY,
84
- "ambient": Mode.AMBIENT_LIGHT
172
+ "reflect": Mode.REFLECT,
173
+ "ambient": Mode.AMBIENT,
174
+ "rgbIntensity": Mode.RGB_I,
175
+ "hsvIntensity": Mode.HSV,
176
+ "hsvAmbient": Mode.SHSV
85
177
  };
@@ -50,7 +50,7 @@ export class TechnicDistanceSensor extends Device {
50
50
  * @param {number} bottomLeft Bottom left quadrant (below left eye). 0-100 brightness.
51
51
  * @param {number} topRight Top right quadrant (above right eye). 0-100 brightness.
52
52
  * @param {number} bottomRight Bottom right quadrant (below right eye). 0-100 brightness.
53
- * @returns {Promise} Resolved upon successful issuance of the command.
53
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
54
54
  */
55
55
  public setBrightness (topLeft: number, bottomLeft: number, topRight: number, bottomRight: number) {
56
56
  this.writeDirect(0x05, Buffer.from([topLeft, topRight, bottomLeft, bottomRight]));
@@ -65,42 +65,33 @@ export class TechnicMediumHubTiltSensor extends Device {
65
65
  /**
66
66
  * Set the impact count value.
67
67
  * @param {number} count impact count between 0 and 2^32
68
- * @returns {Promise} Resolved upon successful issuance of the command.
68
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
69
69
  */
70
70
  public setImpactCount (count: number) {
71
- return new Promise<void>((resolve) => {
72
- const payload = Buffer.alloc(4);
73
- payload.writeUInt32LE(count % 2**32);
74
- // no need to subscribe, can be set in different mode
75
- this.writeDirect(0x01, payload);
76
- return resolve();
77
- });
71
+ const payload = Buffer.alloc(4);
72
+ payload.writeUInt32LE(count % 2**32);
73
+ // no need to subscribe, can be set in different mode
74
+ return this.writeDirect(0x01, payload);
78
75
  }
79
76
 
80
77
  /**
81
78
  * Set the impact threshold.
82
79
  * @param {number} threshold value between 1 and 127
83
- * @returns {Promise} Resolved upon successful issuance of the command.
80
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
84
81
  */
85
82
  public setImpactThreshold (threshold: number) {
86
83
  this._impactThreshold = threshold;
87
- return new Promise<void>((resolve) => {
88
- this.writeDirect(0x02, Buffer.from([this._impactThreshold, this._impactHoldoff]));
89
- return resolve();
90
- });
84
+ return this.writeDirect(0x02, Buffer.from([this._impactThreshold, this._impactHoldoff]));
91
85
  }
92
86
 
93
87
  /**
94
88
  * Set the impact holdoff time.
95
89
  * @param {number} holdoff value between 1 and 127
96
- * @returns {Promise} Resolved upon successful issuance of the command.
90
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
97
91
  */
98
92
  public setImpactHoldoff (holdoff: number) {
99
93
  this._impactHoldoff = holdoff;
100
- return new Promise<void>((resolve) => {
101
- this.writeDirect(0x02, Buffer.from([this._impactThreshold, this._impactHoldoff]));
102
- return resolve();
103
- });
94
+ return this.writeDirect(0x02, Buffer.from([this._impactThreshold, this._impactHoldoff]));
104
95
  }
105
96
  }
106
97
 
@@ -16,11 +16,18 @@ export class TiltSensor extends Device {
16
16
 
17
17
  public receive (message: Buffer) {
18
18
  const mode = this._mode;
19
+ let x = 0;
20
+ let y = 0;
21
+ let z = 0;
19
22
 
20
23
  switch (mode) {
21
24
  case Mode.TILT:
22
- const x = message.readInt8(this.isWeDo2SmartHub ? 2 : 4);
23
- const y = message.readInt8(this.isWeDo2SmartHub ? 3 : 5);
25
+ if (message.length !== (this.isWeDo2SmartHub ? 4 : 6)) {
26
+ // if mode of device has not changed to this._mode yet
27
+ break;
28
+ }
29
+ x = message.readInt8(this.isWeDo2SmartHub ? 2 : 4);
30
+ y = message.readInt8(this.isWeDo2SmartHub ? 3 : 5);
24
31
  /**
25
32
  * Emits when a tilt sensor is activated.
26
33
  * @event TiltSensor#tilt
@@ -30,15 +37,88 @@ export class TiltSensor extends Device {
30
37
  */
31
38
  this.notify("tilt", { x, y });
32
39
  break;
40
+ case Mode.DIRECTION:
41
+ const dir = message.readInt8(this.isWeDo2SmartHub ? 2 : 4);
42
+ /**
43
+ * Emits when the tilt sensor direction changes.
44
+ * @event TiltSensor#direction
45
+ * @type {object}
46
+ * @param {TiltDirection} dir
47
+ */
48
+ this.notify("direction", { dir });
49
+ break;
50
+ case Mode.CRASH:
51
+ if (message.length !== (this.isWeDo2SmartHub ? 5 : 7)) {
52
+ // if mode of device has not changed to this._mode yet
53
+ break;
54
+ }
55
+ x = message.readUInt8(this.isWeDo2SmartHub ? 2 : 4);
56
+ y = message.readUInt8(this.isWeDo2SmartHub ? 3 : 5);
57
+ z = message.readUInt8(this.isWeDo2SmartHub ? 4 : 6);
58
+ /**
59
+ * Emits when proper acceleration is above threshold (e.g. on impact when being thrown to the ground).
60
+ * @event TiltSensor#impactCount
61
+ * @type {object}
62
+ * @param {number} x
63
+ * @param {number} y
64
+ * @param {number} z
65
+ */
66
+ this.notify("impactCount", { x, y, z });
67
+ break;
68
+ case Mode.CAL:
69
+ if (message.length !== (this.isWeDo2SmartHub ? 5 : 7)) {
70
+ // if mode of device has not changed to this._mode yet
71
+ break;
72
+ }
73
+ const ax = message.readInt8(this.isWeDo2SmartHub ? 2 : 4);
74
+ const ay = message.readInt8(this.isWeDo2SmartHub ? 3 : 5);
75
+ const az = message.readInt8(this.isWeDo2SmartHub ? 4 : 6);
76
+ const con = 1000/(45*Math.sqrt(2)); // convert to mG
77
+ x = con*ax;
78
+ y = con*ay;
79
+ z = con*az;
80
+ if(ax === 45) {
81
+ x = con*Math.sqrt(2*45**2 - ay**2 - az**2);
82
+ }
83
+ else if(ax === -45) {
84
+ x = -con*Math.sqrt(2*45**2 - ay**2 - az**2);
85
+ }
86
+ if(ay === 45) {
87
+ y = con*Math.sqrt(2*45**2 - ax**2 - az**2);
88
+ }
89
+ else if(ay === -45) {
90
+ y = -con*Math.sqrt(2*45**2 - ax**2 - az**2);
91
+ }
92
+ if(az === 45) {
93
+ z = con*Math.sqrt(2*45**2 - ax**2 - ay**2);
94
+ }
95
+ else if(az === -45) {
96
+ z = -con*Math.sqrt(2*45**2 - ax**2 - ay**2);
97
+ }
98
+ /**
99
+ * Emits when tilt sensor detects acceleration. Measured in mG.
100
+ * @event TiltSensor#accel
101
+ * @type {object}
102
+ * @param {number} x
103
+ * @param {number} y
104
+ * @param {number} z
105
+ */
106
+ this.notify("accel", { x, y, z });
107
+ break;
33
108
  }
34
109
  }
35
-
36
110
  }
37
111
 
38
112
  export enum Mode {
39
- TILT = 0x00
113
+ TILT = 0x00,
114
+ DIRECTION = 0x01,
115
+ CRASH = 0x02,
116
+ CAL = 0x03
40
117
  }
41
118
 
42
119
  export const ModeMap: {[event: string]: number} = {
43
- "tilt": Mode.TILT
120
+ "tilt": Mode.TILT,
121
+ "direction": Mode.DIRECTION,
122
+ "impactCount": Mode.CRASH,
123
+ "accel": Mode.CAL
44
124
  };
@@ -361,6 +361,24 @@ export class BaseHub extends EventEmitter {
361
361
  }
362
362
  }
363
363
 
364
+ public manuallyDetachDevice(portId: number) {
365
+ const device = this._attachedDevices[portId];
366
+ if (!device) {
367
+ debug(`No device attached to portId ${portId}, nothing to detach`);
368
+ return;
369
+ }
370
+ debug(`Detaching device type ${device.type} from portId ${portId}`);
371
+ this._detachDevice(device);
372
+ if (this.isPortVirtual(portId)) {
373
+ const portName = this.getPortNameForPortId(portId);
374
+ if (portName) {
375
+ delete this._portMap[portName];
376
+ }
377
+ this._virtualPorts = this._virtualPorts.filter((virtualPortId) => virtualPortId !== portId);
378
+ }
379
+ return device;
380
+ }
381
+
364
382
 
365
383
  protected _attachDevice (device: Device) {
366
384
  if (this._attachedDevices[device.portId] && this._attachedDevices[device.portId].type === device.type) {
@@ -156,10 +156,14 @@ export class LPF2Hub extends BaseHub {
156
156
  this._parseSensorMessage(message);
157
157
  break;
158
158
  }
159
+ case Consts.MessageType.PORT_INPUT_FORMAT_SINGLE: {
160
+ this._parsePortInputFormatMessage(message);
161
+ break;
162
+ }
159
163
  case Consts.MessageType.PORT_OUTPUT_COMMAND_FEEDBACK: {
160
164
  this._parsePortAction(message);
161
165
  break;
162
- }
166
+ }
163
167
  }
164
168
 
165
169
  if (this._messageBuffer.length > 0) {
@@ -343,7 +347,6 @@ export class LPF2Hub extends BaseHub {
343
347
  }
344
348
  }
345
349
 
346
-
347
350
  private _parsePortAction (message: Buffer) {
348
351
  for (let offset = 3; offset < message.length; offset += 2) {
349
352
  const device = this._getDeviceByPortId(message[offset]);
@@ -354,17 +357,21 @@ export class LPF2Hub extends BaseHub {
354
357
  }
355
358
  }
356
359
 
357
-
358
360
  private _parseSensorMessage (message: Buffer) {
359
-
360
361
  const portId = message[3];
361
362
  const device = this._getDeviceByPortId(portId);
362
363
 
363
364
  if (device) {
364
365
  device.receive(message);
365
366
  }
366
-
367
367
  }
368
368
 
369
+ private _parsePortInputFormatMessage (message: Buffer) {
370
+ const portId = message[3];
371
+ const device = this._getDeviceByPortId(portId);
369
372
 
373
+ if (device) {
374
+ device.setMode(message[4]);
375
+ }
376
+ }
370
377
  }
@@ -0,0 +1,37 @@
1
+ import { CommandFeedback } from "./consts.js";
2
+ import Debug = require("debug");
3
+ const debug = Debug("device");
4
+
5
+ export class PortOutputCommand {
6
+
7
+ public data: Buffer;
8
+ public interrupt: boolean;
9
+ public state: CommandFeedback;
10
+ private _promise: Promise<CommandFeedback>;
11
+ private _resolveCallback: any;
12
+
13
+ constructor (data: Buffer, interrupt: boolean) {
14
+ this.data = data;
15
+ this.interrupt = interrupt;
16
+ this.state = CommandFeedback.TRANSMISSION_PENDING;
17
+ this._promise = new Promise<CommandFeedback>((resolve) => {
18
+ this._resolveCallback = () => resolve(this.state);
19
+ });
20
+ }
21
+
22
+ public get startupAndCompletion () {
23
+ let val = 0x01; // request feedback
24
+ if(this.interrupt) val |= 0x10;
25
+ return val;
26
+ }
27
+
28
+ public get promise () {
29
+ return this._promise;
30
+ }
31
+
32
+ public resolve(feedback: CommandFeedback) {
33
+ debug("complete command ", this.startupAndCompletion, this.data, " result: ", feedback);
34
+ this.state = feedback;
35
+ this._resolveCallback();
36
+ }
37
+ }
@@ -0,0 +1,11 @@
1
+ import { CommandFeedback } from "./consts.js";
2
+ import { PortOutputCommand } from "./portoutputcommand.js";
3
+
4
+ export class PortOutputSleep extends PortOutputCommand {
5
+ public duration: number;
6
+ constructor (duration: number) {
7
+ super(Buffer.alloc(0), false);
8
+ this.duration = duration;
9
+ this.state = CommandFeedback.EXECUTION_PENDING;
10
+ }
11
+ }
package/src/utils.ts CHANGED
@@ -59,34 +59,29 @@ export const roundAngleToNearest90 = (angle: number) => {
59
59
  return -180;
60
60
  };
61
61
 
62
- export const calculateRamp = (device: Device, fromPower: number, toPower: number, time: number) => {
63
- const emitter = new EventEmitter();
62
+ export const calculateRamp = (fromPower: number, toPower: number, time: number) => {
64
63
  const steps = Math.abs(toPower - fromPower);
64
+ if (steps === 0 || time <= 0) {
65
+ return [toPower];
66
+ }
65
67
  let delay = time / steps;
66
68
  let increment = 1;
67
- if (delay < 50 && steps > 0) {
69
+ if (delay < 50) {
68
70
  increment = 50 / delay;
69
71
  delay = 50;
70
72
  }
71
73
  if (fromPower > toPower) {
72
74
  increment = -increment;
73
75
  }
74
- let i = 0;
75
- const interval = setInterval(() => {
76
- let power = Math.round(fromPower + (++i * increment));
77
- if (toPower > fromPower && power > toPower) {
78
- power = toPower;
79
- } else if (fromPower > toPower && power < toPower) {
80
- power = toPower;
81
- }
82
- emitter.emit("changePower", power);
83
- if (power === toPower) {
84
- clearInterval(interval);
85
- emitter.emit("finished");
76
+ return Array(Math.round(time / delay)).fill(0).map((element, index) => {
77
+ let value = Math.round(fromPower + (index + 1) * increment);
78
+ if (toPower > fromPower && value > toPower) {
79
+ value = toPower;
80
+ } else if (fromPower > toPower && value < toPower) {
81
+ value = toPower;
86
82
  }
87
- }, delay);
88
- device.setEventTimer(interval);
89
- return emitter;
83
+ return value;
84
+ });
90
85
  };
91
86
 
92
87
  export const parseColor = (color: number) => {
@@ -94,4 +89,4 @@ export const parseColor = (color: number) => {
94
89
  color = color + 1;
95
90
  }
96
91
  return color;
97
- }
92
+ }
@@ -1 +1 @@
1
- {"root":["./src/color.ts","./src/consts.ts","./src/index-browser.ts","./src/index-node.ts","./src/interfaces.ts","./src/nobleabstraction.ts","./src/poweredup-browser.ts","./src/poweredup-node.ts","./src/utils.ts","./src/webbleabstraction.ts","./src/devices/absolutemotor.ts","./src/devices/basicmotor.ts","./src/devices/colordistancesensor.ts","./src/devices/currentsensor.ts","./src/devices/device.ts","./src/devices/duplotrainbasecolorsensor.ts","./src/devices/duplotrainbasemotor.ts","./src/devices/duplotrainbasespeaker.ts","./src/devices/duplotrainbasespeedometer.ts","./src/devices/hubled.ts","./src/devices/light.ts","./src/devices/marioaccelerometer.ts","./src/devices/mariobarcodesensor.ts","./src/devices/mariopantssensor.ts","./src/devices/mediumlinearmotor.ts","./src/devices/motionsensor.ts","./src/devices/movehubmediumlinearmotor.ts","./src/devices/movehubtiltsensor.ts","./src/devices/piezobuzzer.ts","./src/devices/remotecontrolbutton.ts","./src/devices/simplemediumlinearmotor.ts","./src/devices/tachomotor.ts","./src/devices/technic3x3colorlightmatrix.ts","./src/devices/techniccolorsensor.ts","./src/devices/technicdistancesensor.ts","./src/devices/technicforcesensor.ts","./src/devices/techniclargeangularmotor.ts","./src/devices/techniclargelinearmotor.ts","./src/devices/technicmediumangularmotor.ts","./src/devices/technicmediumhubaccelerometersensor.ts","./src/devices/technicmediumhubgyrosensor.ts","./src/devices/technicmediumhubtiltsensor.ts","./src/devices/technicsmallangularmotor.ts","./src/devices/technicxlargelinearmotor.ts","./src/devices/tiltsensor.ts","./src/devices/trainmotor.ts","./src/devices/voltagesensor.ts","./src/hubs/basehub.ts","./src/hubs/duplotrainbase.ts","./src/hubs/hub.ts","./src/hubs/lpf2hub.ts","./src/hubs/mario.ts","./src/hubs/movehub.ts","./src/hubs/remotecontrol.ts","./src/hubs/technicmediumhub.ts","./src/hubs/technicsmallhub.ts","./src/hubs/wedo2smarthub.ts"],"version":"5.9.3"}
1
+ {"root":["./src/color.ts","./src/consts.ts","./src/index-browser.ts","./src/index-node.ts","./src/interfaces.ts","./src/nobleabstraction.ts","./src/portoutputcommand.ts","./src/portoutputsleep.ts","./src/poweredup-browser.ts","./src/poweredup-node.ts","./src/utils.ts","./src/webbleabstraction.ts","./src/devices/absolutemotor.ts","./src/devices/basicmotor.ts","./src/devices/colordistancesensor.ts","./src/devices/currentsensor.ts","./src/devices/device.ts","./src/devices/duplotrainbasecolorsensor.ts","./src/devices/duplotrainbasemotor.ts","./src/devices/duplotrainbasespeaker.ts","./src/devices/duplotrainbasespeedometer.ts","./src/devices/hubled.ts","./src/devices/light.ts","./src/devices/marioaccelerometer.ts","./src/devices/mariobarcodesensor.ts","./src/devices/mariopantssensor.ts","./src/devices/mediumlinearmotor.ts","./src/devices/motionsensor.ts","./src/devices/movehubmediumlinearmotor.ts","./src/devices/movehubtiltsensor.ts","./src/devices/piezobuzzer.ts","./src/devices/remotecontrolbutton.ts","./src/devices/simplemediumlinearmotor.ts","./src/devices/tachomotor.ts","./src/devices/technic3x3colorlightmatrix.ts","./src/devices/techniccolorsensor.ts","./src/devices/technicdistancesensor.ts","./src/devices/technicforcesensor.ts","./src/devices/techniclargeangularmotor.ts","./src/devices/techniclargelinearmotor.ts","./src/devices/technicmediumangularmotor.ts","./src/devices/technicmediumhubaccelerometersensor.ts","./src/devices/technicmediumhubgyrosensor.ts","./src/devices/technicmediumhubtiltsensor.ts","./src/devices/technicsmallangularmotor.ts","./src/devices/technicxlargelinearmotor.ts","./src/devices/tiltsensor.ts","./src/devices/trainmotor.ts","./src/devices/voltagesensor.ts","./src/hubs/basehub.ts","./src/hubs/duplotrainbase.ts","./src/hubs/hub.ts","./src/hubs/lpf2hub.ts","./src/hubs/mario.ts","./src/hubs/movehub.ts","./src/hubs/remotecontrol.ts","./src/hubs/technicmediumhub.ts","./src/hubs/technicsmallhub.ts","./src/hubs/wedo2smarthub.ts"],"version":"5.9.3"}
@@ -0,0 +1,35 @@
1
+ const webpack = require('webpack');
2
+ const path = require("path");
3
+
4
+ module.exports = {
5
+ entry: "./src/index-browser.ts",
6
+ devtool: "source-map",
7
+ plugins: [
8
+ new webpack.ProvidePlugin({
9
+ Buffer: ['buffer', 'Buffer'],
10
+ })
11
+ ],
12
+ module: {
13
+ rules: [
14
+ {
15
+ test: /\.ts?$/,
16
+ use: "ts-loader",
17
+ exclude: /node_modules/
18
+ }
19
+ ],
20
+ },
21
+ externals: {
22
+ "noble": "noble",
23
+ "noble-mac": "noble-mac"
24
+ },
25
+ resolve: {
26
+ alias: {
27
+ buffer: 'buffer'
28
+ },
29
+ extensions: [".ts", ".js"]
30
+ },
31
+ output: {
32
+ filename: "poweredup.js",
33
+ path: path.resolve(__dirname, "dist", "browser")
34
+ }
35
+ };
@@ -1,6 +0,0 @@
1
- export declare class Color {
2
- private _color;
3
- private _brightness;
4
- constructor(color: number, brightness?: number);
5
- toValue(): number;
6
- }
@@ -1,15 +0,0 @@
1
- import * as Consts from "./consts";
2
- export class Color {
3
- constructor(color, brightness) {
4
- this._brightness = 100;
5
- this._color = color;
6
- this._brightness = brightness || 100;
7
- }
8
- toValue() {
9
- if (this._color === Consts.Color.NONE) {
10
- return this._color;
11
- }
12
- return this._color + (Math.round(this._brightness / 10) << 4);
13
- }
14
- }
15
- //# sourceMappingURL=color.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"color.js","sourceRoot":"","sources":["../../src/color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAEnC,MAAM,OAAO,KAAK;IAKd,YAAa,KAAa,EAAE,UAAmB;QAFvC,gBAAW,GAAW,GAAG,CAAC;QAG9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,UAAU,IAAI,GAAG,CAAC;IACzC,CAAC;IAEM,OAAO;QACV,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC,MAAM,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAClE,CAAC;CAEJ"}