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
package/dist/utils.js CHANGED
@@ -1,4 +1,3 @@
1
- import { EventEmitter } from "events";
2
1
  // @ts-ignore
3
2
  export const isWebBluetooth = !!(typeof navigator !== "undefined" && navigator && navigator.bluetooth);
4
3
  export const toHex = (value, length = 2) => {
@@ -51,35 +50,30 @@ export const roundAngleToNearest90 = (angle) => {
51
50
  }
52
51
  return -180;
53
52
  };
54
- export const calculateRamp = (device, fromPower, toPower, time) => {
55
- const emitter = new EventEmitter();
53
+ export const calculateRamp = (fromPower, toPower, time) => {
56
54
  const steps = Math.abs(toPower - fromPower);
55
+ if (steps === 0 || time <= 0) {
56
+ return [toPower];
57
+ }
57
58
  let delay = time / steps;
58
59
  let increment = 1;
59
- if (delay < 50 && steps > 0) {
60
+ if (delay < 50) {
60
61
  increment = 50 / delay;
61
62
  delay = 50;
62
63
  }
63
64
  if (fromPower > toPower) {
64
65
  increment = -increment;
65
66
  }
66
- let i = 0;
67
- const interval = setInterval(() => {
68
- let power = Math.round(fromPower + (++i * increment));
69
- if (toPower > fromPower && power > toPower) {
70
- power = toPower;
71
- }
72
- else if (fromPower > toPower && power < toPower) {
73
- power = toPower;
67
+ return Array(Math.round(time / delay)).fill(0).map((element, index) => {
68
+ let value = Math.round(fromPower + (index + 1) * increment);
69
+ if (toPower > fromPower && value > toPower) {
70
+ value = toPower;
74
71
  }
75
- emitter.emit("changePower", power);
76
- if (power === toPower) {
77
- clearInterval(interval);
78
- emitter.emit("finished");
72
+ else if (fromPower > toPower && value < toPower) {
73
+ value = toPower;
79
74
  }
80
- }, delay);
81
- device.setEventTimer(interval);
82
- return emitter;
75
+ return value;
76
+ });
83
77
  };
84
78
  export const parseColor = (color) => {
85
79
  if (color === 1 || color === 5) {
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,aAAa;AACb,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;AAEvG,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,SAAiB,CAAC,EAAE,EAAE;IACvD,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,SAAiB,CAAC,EAAE,EAAE;IACvD,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,EAAE;IACtC,IAAI,KAAK,KAAK,G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IACD,IAAI,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;IACzB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QACb,SAAS,GAAG,EAAE,GAAG,KAAK,CAAC;QACvB,KAAK,GAAG,EAAE,CAAC;IACf,CAAC;IACD,IAAI,SAAS,GAAG,OAAO,EAAE,CAAC;QACtB,SAAS,GAAG,CAAC,SAAS,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QAClE,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;QAC5D,IAAI,OAAO,GAAG,SAAS,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;YACzC,KAAK,GAAG,OAAO,CAAC;QACpB,CAAC;aAAM,IAAI,SAAS,GAAG,OAAO,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;YAChD,KAAK,GAAG,OAAO,CAAC;QACpB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE;IACxC,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAC7B,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-poweredup",
3
- "version": "10.0.0",
3
+ "version": "10.1.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
  "type": "module",
package/src/consts.ts CHANGED
@@ -703,3 +703,47 @@ export enum MarioColor {
703
703
  BROWN = 0x6a00,
704
704
  CYAN = 0x4201,
705
705
  }
706
+
707
+
708
+ /**
709
+ * @typedef TiltDirection
710
+ * @param {number} NEUTRAL 0
711
+ * @param {number} BACKWARD 3
712
+ * @param {number} RIGHT 5
713
+ * @param {number} LEFT 7
714
+ * @param {number} FORWARD 9
715
+ * @param {number} UNKNOWN 10
716
+ */
717
+ export enum TiltDirection {
718
+ NEUTRAL = 0,
719
+ BACKWARD = 3,
720
+ RIGHT = 5,
721
+ LEFT = 7,
722
+ FORWARD = 9,
723
+ UNKNOWN = 10,
724
+ }
725
+
726
+
727
+ /**
728
+ * @typedef CommandFeedback
729
+ * @param {number} TRANSMISSION_PENDING 0x00 waiting for previous commands to complete transmission or execution
730
+ * @param {number} TRANSMISSION_BUSY 0x10 waiting for device to acknowledge reception
731
+ * @param {number} TRANSMISSION_DISCARDED 0x44 interrupt command has been recieved or device disconnected
732
+ * @param {number} EXECUTION_PENDING 0x20 device is waiting for previous command to complete
733
+ * @param {number} EXECUTION_BUSY 0x21 device is executing the command
734
+ * @param {number} EXECUTION_DISCARDED 0x24 device discarded the command e.g. due to interrupt
735
+ * @param {number} EXECUTION_COMPLETED 0x22 device reported successful completion of command
736
+ * @param {number} FEEDBACK_MISSING 0x66 device disconnected or failed to report feedback
737
+ * @param {number} FEEDBACK_DISABLED 0x26 feedback not implemented for this command
738
+ */
739
+ export enum CommandFeedback {
740
+ TRANSMISSION_PENDING = 0x00,
741
+ TRANSMISSION_BUSY = 0x10,
742
+ TRANSMISSION_DISCARDED = 0x44,
743
+ EXECUTION_PENDING = 0x20,
744
+ EXECUTION_BUSY = 0x21,
745
+ EXECUTION_DISCARDED = 0x24,
746
+ EXECUTION_COMPLETED = 0x22,
747
+ FEEDBACK_MISSING = 0x66,
748
+ FEEDBACK_DISABLED = 0x26,
749
+ }
@@ -39,34 +39,29 @@ export class AbsoluteMotor extends TachoMotor {
39
39
  * Rotate a motor by a given angle.
40
40
  * @param {number} angle Absolute position the motor should go to (degrees from 0).
41
41
  * @param {number} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100.
42
- * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
42
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
43
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
43
44
  */
44
- public gotoAngle (angle: [number, number] | number, speed: number = 100) {
45
+ public gotoAngle (angle: [number, number] | number, speed: number = 100, interrupt: boolean = false) {
45
46
  if (!this.isVirtualPort && angle instanceof Array) {
46
47
  throw new Error("Only virtual ports can accept multiple positions");
47
48
  }
48
49
  if (this.isWeDo2SmartHub) {
49
50
  throw new Error("Absolute positioning is not available on the WeDo 2.0 Smart Hub");
50
51
  }
51
- this.cancelEventTimer();
52
- return new Promise<void>((resolve) => {
53
- if (speed === undefined || speed === null) {
54
- speed = 100;
55
- }
56
- let message;
57
- if (angle instanceof Array) {
58
- message = Buffer.from([0x81, this.portId, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
59
- message.writeInt32LE(normalizeAngle(angle[0]), 4);
60
- message.writeInt32LE(normalizeAngle(angle[1]), 8);
61
- } else {
62
- message = Buffer.from([0x81, this.portId, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
63
- message.writeInt32LE(normalizeAngle(angle), 4);
64
- }
65
- this.send(message);
66
- this._finishedCallbacks.push(() => {
67
- return resolve();
68
- });
69
- });
52
+ if (speed === undefined || speed === null) {
53
+ speed = 100;
54
+ }
55
+ let message;
56
+ if (angle instanceof Array) {
57
+ message = Buffer.from([0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
58
+ message.writeInt32LE(normalizeAngle(angle[0]), 1);
59
+ message.writeInt32LE(normalizeAngle(angle[1]), 5);
60
+ } else {
61
+ message = Buffer.from([0x0d, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
62
+ message.writeInt32LE(normalizeAngle(angle), 1);
63
+ }
64
+ return this.sendPortOutputCommand(message, interrupt);
70
65
  }
71
66
 
72
67
 
@@ -75,10 +70,10 @@ export class AbsoluteMotor extends TachoMotor {
75
70
  *
76
71
  * Real zero is marked on Technic angular motors (SPIKE Prime). It is also available on Technic linear motors (Control+) but is unmarked.
77
72
  * @param {number} [speed=100] Speed between 1 - 100. Note that this will always take the shortest path to zero.
78
- * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
73
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
79
74
  */
80
75
  public gotoRealZero (speed: number = 100) {
81
- return new Promise<void>((resolve) => {
76
+ return new Promise<Consts.CommandFeedback>((resolve) => {
82
77
  const oldMode = this.mode;
83
78
  let calibrated = false;
84
79
  this.on("absolute", async ({ angle }) => {
@@ -93,7 +88,7 @@ export class AbsoluteMotor extends TachoMotor {
93
88
  if (oldMode) {
94
89
  this.subscribe(oldMode);
95
90
  }
96
- return resolve();
91
+ return resolve(Consts.CommandFeedback.FEEDBACK_DISABLED);
97
92
  }
98
93
  });
99
94
  this.requestUpdate();
@@ -103,14 +98,12 @@ export class AbsoluteMotor extends TachoMotor {
103
98
 
104
99
  /**
105
100
  * Reset zero to current position
106
- * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
101
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
102
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
107
103
  */
108
- public resetZero () {
109
- return new Promise<void>((resolve) => {
110
- const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
111
- this.send(data);
112
- return resolve();
113
- });
104
+ public resetZero (interrupt: boolean = false) {
105
+ const data = Buffer.from([0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
106
+ return this.sendPortOutputCommand(data, interrupt);
114
107
  }
115
108
 
116
109
 
@@ -21,13 +21,11 @@ export class BasicMotor extends Device {
21
21
  /**
22
22
  * Set the motor power.
23
23
  * @param {number} power For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
24
- * @returns {Promise} Resolved upon successful issuance of the command.
24
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
25
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
25
26
  */
26
- public setPower (power: number, interrupt: boolean = true) {
27
- if (interrupt) {
28
- this.cancelEventTimer();
29
- }
30
- return this.writeDirect(0x00, Buffer.from([mapSpeed(power)]));
27
+ public setPower (power: number, interrupt: boolean = false) {
28
+ return this.writeDirect(0x00, Buffer.from([mapSpeed(power)]), interrupt);
31
29
  }
32
30
 
33
31
 
@@ -36,37 +34,33 @@ export class BasicMotor extends Device {
36
34
  * @param {number} fromPower For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
37
35
  * @param {number} toPower For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
38
36
  * @param {number} time How long the ramp should last (in milliseconds).
39
- * @returns {Promise} Resolved upon successful completion of command.
37
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
40
38
  */
41
39
  public rampPower (fromPower: number, toPower: number, time: number) {
42
- this.cancelEventTimer();
43
- return new Promise((resolve) => {
44
- calculateRamp(this, fromPower, toPower, time)
45
- .on("changePower", (power) => {
46
- this.setPower(power, false);
47
- })
48
- .on("finished", resolve);
40
+ const powerValues = calculateRamp(fromPower, toPower, time);
41
+ powerValues.forEach(value => {
42
+ this.setPower(value);
43
+ this.addPortOutputSleep(Math.round(time/powerValues.length));
49
44
  });
45
+ return this.setPower(toPower);
50
46
  }
51
47
 
52
48
 
53
49
  /**
54
- * Stop the motor.
55
- * @returns {Promise} Resolved upon successful issuance of the command.
50
+ * Stop the motor. Previous commands that have not completed are discarded.
51
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
56
52
  */
57
53
  public stop () {
58
- this.cancelEventTimer();
59
- return this.setPower(0);
54
+ return this.setPower(0, true);
60
55
  }
61
56
 
62
57
 
63
58
  /**
64
- * Brake the motor.
65
- * @returns {Promise} Resolved upon successful issuance of the command.
59
+ * Brake the motor. Previous commands that have not completed are discarded.
60
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
66
61
  */
67
62
  public brake () {
68
- this.cancelEventTimer();
69
- return this.setPower(Consts.BrakingStyle.BRAKE);
63
+ return this.setPower(Consts.BrakingStyle.BRAKE, true);
70
64
  }
71
65
 
72
66
 
@@ -158,7 +158,7 @@ export class ColorDistanceSensor extends Device {
158
158
  *
159
159
  * NOTE: Calling this with channel 5-8 with switch off extended channel mode for this receiver.
160
160
  * @param {number} channel Channel number, between 1-8
161
- * @returns {Promise} Resolved upon successful issuance of the command.
161
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
162
162
  */
163
163
  public setPFExtendedChannel (channel: number) {
164
164
  let address = 0;
@@ -179,7 +179,7 @@ export class ColorDistanceSensor extends Device {
179
179
  * @param {number} channel Channel number, between 1-4
180
180
  * @param {string} output Outport port, "RED" (A) or "BLUE" (B)
181
181
  * @param {number} power -7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.
182
- * @returns {Promise} Resolved upon successful issuance of the command.
182
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
183
183
  */
184
184
  public setPFPower (channel: number, output: Output, power: number) {
185
185
  let address = 0;
@@ -202,7 +202,7 @@ export class ColorDistanceSensor extends Device {
202
202
  * @param {number} channel Channel number, between 1-4
203
203
  * @param {number} powerBlue -7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.
204
204
  * @param {number} powerRed -7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.
205
- * @returns {Promise} Resolved upon successful issuance of the command.
205
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
206
206
  */
207
207
  public startPFMotors (channel: number, powerBlue: number, powerRed: number) {
208
208
  let address = 0;
@@ -221,7 +221,7 @@ export class ColorDistanceSensor extends Device {
221
221
  /**
222
222
  * Send a raw Power Functions IR command
223
223
  * @param {Buffer} message 2 byte payload making up a Power Functions protocol command. NOTE: Only specify nibbles 1-3, nibble 4 should be zeroed.
224
- * @returns {Promise} Resolved upon successful issuance of the command.
224
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
225
225
  */
226
226
  public sendPFIRMessage (message: Buffer) {
227
227
  if (this.isWeDo2SmartHub) {
@@ -239,40 +239,34 @@ export class ColorDistanceSensor extends Device {
239
239
  /**
240
240
  * Set the color of the LED on the sensor via a color value.
241
241
  * @param {Color} color
242
- * @returns {Promise} Resolved upon successful issuance of the command.
242
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
243
243
  */
244
244
  public setColor (color: number | boolean) {
245
- return new Promise<void>((resolve) => {
246
- if (color === false) {
247
- color = 0;
248
- }
249
- if (this.isWeDo2SmartHub) {
250
- throw new Error("Setting LED color is not available on the WeDo 2.0 Smart Hub");
251
- } else {
252
- this.subscribe(Mode.LED);
253
- this.writeDirect(0x05, Buffer.from([color as number]));
254
- }
255
- return resolve();
256
- });
245
+ if (color === false) {
246
+ color = 0;
247
+ }
248
+ if (this.isWeDo2SmartHub) {
249
+ throw new Error("Setting LED color is not available on the WeDo 2.0 Smart Hub");
250
+ } else {
251
+ this.subscribe(Mode.LED);
252
+ return this.writeDirect(0x05, Buffer.from([color as number]));
253
+ }
257
254
  }
258
255
 
259
256
  /**
260
257
  * Set the distance count value.
261
258
  * @param {number} count distance count between 0 and 2^32
262
- * @returns {Promise} Resolved upon successful issuance of the command.
259
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of the command.
263
260
  */
264
261
  public setDistanceCount (count: number) {
265
- return new Promise<void>((resolve) => {
266
- if (this.isWeDo2SmartHub) {
267
- throw new Error("Setting distance count is not available on the WeDo 2.0 Smart Hub");
268
- } else {
269
- const payload = Buffer.alloc(4);
270
- payload.writeUInt32LE(count % 2**32);
271
- // no need to subscribe, can be set in different mode
272
- this.writeDirect(0x02, payload);
273
- }
274
- return resolve();
275
- });
262
+ if (this.isWeDo2SmartHub) {
263
+ throw new Error("Setting distance count is not available on the WeDo 2.0 Smart Hub");
264
+ } else {
265
+ const payload = Buffer.alloc(4);
266
+ payload.writeUInt32LE(count % 2**32);
267
+ // no need to subscribe, can be set in different mode
268
+ return this.writeDirect(0x02, payload);
269
+ }
276
270
  }
277
271
 
278
272
  private _pfPowerToPWM (power: number) {