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
@@ -1,9 +1,14 @@
1
1
  import { EventEmitter } from "events";
2
2
 
3
3
  import { IDeviceInterface } from "../interfaces.js";
4
+ import { PortOutputCommand } from "../portoutputcommand.js";
5
+ import { PortOutputSleep } from "../portoutputsleep.js";
4
6
 
5
7
  import * as Consts from "../consts.js";
6
8
 
9
+ import Debug = require("debug");
10
+ const debug = Debug("device");
11
+
7
12
  /**
8
13
  * @class Device
9
14
  * @extends EventEmitter
@@ -14,8 +19,9 @@ export class Device extends EventEmitter {
14
19
  public values: {[event: string]: any} = {};
15
20
 
16
21
  protected _mode: number | undefined;
17
- protected _busy: boolean = false;
18
- protected _finishedCallbacks: (() => void)[] = [];
22
+ protected _bufferLength: number = 0;
23
+ protected _nextPortOutputCommands: (PortOutputCommand | PortOutputSleep)[] = [];
24
+ protected _transmittedPortOutputCommands: PortOutputCommand[] = [];
19
25
 
20
26
  private _hub: IDeviceInterface;
21
27
  private _portId: number;
@@ -25,7 +31,6 @@ export class Device extends EventEmitter {
25
31
 
26
32
  private _isWeDo2SmartHub: boolean;
27
33
  private _isVirtualPort: boolean = false;
28
- private _eventTimer: NodeJS.Timeout | null = null;
29
34
 
30
35
  constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.UNKNOWN) {
31
36
  super();
@@ -126,11 +131,11 @@ export class Device extends EventEmitter {
126
131
  return this._isVirtualPort;
127
132
  }
128
133
 
129
- public writeDirect (mode: number, data: Buffer) {
134
+ public writeDirect (mode: number, data: Buffer, interrupt: boolean = false) {
130
135
  if (this.isWeDo2SmartHub) {
131
- return this.send(Buffer.concat([Buffer.from([this.portId, 0x01, 0x02]), data]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
136
+ return this.send(Buffer.concat([Buffer.from([this.portId, 0x01, 0x02]), data]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE).then(() => { return Consts.CommandFeedback.FEEDBACK_DISABLED; });
132
137
  } else {
133
- return this.send(Buffer.concat([Buffer.from([0x81, this.portId, 0x11, 0x51, mode]), data]), Consts.BLECharacteristic.LPF2_ALL);
138
+ return this.sendPortOutputCommand(Buffer.concat([Buffer.from([0x51, mode]), data]), interrupt);
134
139
  }
135
140
  }
136
141
 
@@ -142,7 +147,6 @@ export class Device extends EventEmitter {
142
147
  public subscribe (mode: number) {
143
148
  this._ensureConnected();
144
149
  if (mode !== this._mode) {
145
- this._mode = mode;
146
150
  this.hub.subscribe(this.portId, this.type, mode);
147
151
  }
148
152
  }
@@ -167,26 +171,180 @@ export class Device extends EventEmitter {
167
171
  this.send(Buffer.from([0x21, this.portId, 0x00]));
168
172
  }
169
173
 
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();
174
+ public setMode (mode: number) {
175
+ this._mode = mode;
176
+ }
177
+
178
+ protected transmitNextPortOutputCommand() {
179
+ if(!this.connected) {
180
+ this._transmittedPortOutputCommands.forEach(command => command.resolve(Consts.CommandFeedback.FEEDBACK_MISSING));
181
+ this._transmittedPortOutputCommands = [];
182
+ this._nextPortOutputCommands.forEach(command => command.resolve(Consts.CommandFeedback.TRANSMISSION_DISCARDED));
183
+ this._nextPortOutputCommands = [];
184
+ return;
185
+ }
186
+ if(!this._nextPortOutputCommands.length) return;
187
+ const nextCommand = this._nextPortOutputCommands[0];
188
+ if(nextCommand instanceof PortOutputSleep) {
189
+ if(nextCommand.state === Consts.CommandFeedback.EXECUTION_PENDING) {
190
+ nextCommand.state = Consts.CommandFeedback.EXECUTION_BUSY;
191
+ debug("sleep command ", nextCommand.duration);
192
+ setTimeout(() => {
193
+ if(nextCommand.state !== Consts.CommandFeedback.EXECUTION_BUSY) return;
194
+ const command = this._nextPortOutputCommands.shift();
195
+ if(command) command.resolve(Consts.CommandFeedback.EXECUTION_COMPLETED);
196
+ this.transmitNextPortOutputCommand();
197
+ }, nextCommand.duration);
177
198
  }
199
+ return;
200
+ }
201
+ if(this._bufferLength !== this._transmittedPortOutputCommands.length) return;
202
+ if(this._bufferLength < 2 || nextCommand.interrupt) {
203
+ if(nextCommand.state === Consts.CommandFeedback.TRANSMISSION_PENDING) {
204
+ nextCommand.state = Consts.CommandFeedback.TRANSMISSION_BUSY;
205
+ debug("transmit command ", nextCommand.startupAndCompletion, nextCommand.data);
206
+ this.send(Buffer.concat([Buffer.from([0x81, this.portId, nextCommand.startupAndCompletion]), nextCommand.data])).then(() => {
207
+ if(nextCommand.state !== Consts.CommandFeedback.TRANSMISSION_BUSY) return;
208
+ const command = this._nextPortOutputCommands.shift();
209
+ if(command instanceof PortOutputCommand) this._transmittedPortOutputCommands.push(command);
210
+ });
211
+ this.transmitNextPortOutputCommand(); // if the next command is PortOutputSleep this starts sleep timeout
212
+ // one could start a timer here to ensure finish function is called
213
+ }
214
+ }
215
+ }
216
+
217
+ public sendPortOutputCommand(data: Buffer, interrupt: boolean = false) {
218
+ if (this.isWeDo2SmartHub) {
219
+ throw new Error("PortOutputCommands are not available on the WeDo 2.0 Smart Hub");
220
+ return;
221
+ }
222
+ const command = new PortOutputCommand(data, interrupt);
223
+ if(interrupt) {
224
+ this._nextPortOutputCommands.forEach(command => {
225
+ if(command.state !== Consts.CommandFeedback.TRANSMISSION_BUSY) {
226
+ command.resolve(Consts.CommandFeedback.TRANSMISSION_DISCARDED);
227
+ }
228
+ });
229
+ this._nextPortOutputCommands = this._nextPortOutputCommands.filter(command => command.state === Consts.CommandFeedback.TRANSMISSION_BUSY);
178
230
  }
231
+ this._nextPortOutputCommands.push(command);
232
+ process.nextTick(() => this.transmitNextPortOutputCommand());
233
+ return command.promise;
179
234
  }
180
235
 
181
- public setEventTimer (timer: NodeJS.Timeout) {
182
- this._eventTimer = timer;
236
+ public addPortOutputSleep(duration: number) {
237
+ const command = new PortOutputSleep(duration);
238
+ this._nextPortOutputCommands.push(command);
239
+ process.nextTick(() => this.transmitNextPortOutputCommand());
240
+ return command.promise;
183
241
  }
184
242
 
185
- public cancelEventTimer () {
186
- if (this._eventTimer) {
187
- clearTimeout(this._eventTimer);
188
- this._eventTimer = null;
243
+ public finish (message: number) {
244
+ debug("recieved command feedback ", message);
245
+ if((message & 0x08) === 0x08) this._bufferLength = 0;
246
+ else if((message & 0x01) === 0x01) this._bufferLength = 1;
247
+ else if((message & 0x10) === 0x10) this._bufferLength = 2;
248
+ const completed = ((message & 0x02) === 0x02);
249
+ const discarded = ((message & 0x04) === 0x04);
250
+
251
+ switch(this._transmittedPortOutputCommands.length) {
252
+ case 0:
253
+ break;
254
+ case 1:
255
+ if(!this._bufferLength && completed && !discarded) {
256
+ this._complete();
257
+ }
258
+ else if(!this._bufferLength && !completed && discarded) {
259
+ this._discard();
260
+ }
261
+ else if(this._bufferLength && !completed && !discarded) {
262
+ this._busy();
263
+ }
264
+ else {
265
+ this._missing();
266
+ }
267
+ break;
268
+ case 2:
269
+ if(!this._bufferLength && completed && discarded) {
270
+ this._discard();
271
+ this._complete();
272
+ }
273
+ else if(!this._bufferLength && completed && !discarded) {
274
+ this._complete();
275
+ this._complete();
276
+ }
277
+ else if(!this._bufferLength && !completed && discarded) {
278
+ this._discard();
279
+ this._discard();
280
+ }
281
+ else if(this._bufferLength === 1 && completed && !discarded) {
282
+ this._complete();
283
+ this._busy();
284
+ }
285
+ else if(this._bufferLength === 1 && !completed && discarded) {
286
+ this._discard();
287
+ this._busy();
288
+ }
289
+ else if(this._bufferLength === 1 && completed && discarded) {
290
+ this._missing();
291
+ this._busy();
292
+ }
293
+ else if(this._bufferLength === 2 && !completed && !discarded) {
294
+ this._busy();
295
+ this._pending();
296
+ }
297
+ else {
298
+ this._missing();
299
+ this._missing();
300
+ }
301
+ break;
302
+ case 3:
303
+ if(!this._bufferLength && completed && discarded) {
304
+ this._discard();
305
+ this._discard();
306
+ this._complete();
307
+ }
308
+ else if(!this._bufferLength && completed && !discarded) {
309
+ this._complete();
310
+ this._complete();
311
+ this._complete();
312
+ }
313
+ else if(!this._bufferLength && !completed && discarded) {
314
+ this._discard();
315
+ this._discard();
316
+ this._discard();
317
+ }
318
+ else if(this._bufferLength === 1 && completed && discarded) {
319
+ this._discard();
320
+ this._complete();
321
+ this._busy();
322
+ }
323
+ else if(this._bufferLength === 1 && completed && !discarded) {
324
+ this._complete();
325
+ this._complete();
326
+ this._busy();
327
+ }
328
+ else if(this._bufferLength === 1 && !completed && discarded) {
329
+ this._discard();
330
+ this._discard();
331
+ this._busy();
332
+ }
333
+ else if(this._bufferLength === 1 && !completed && !discarded) {
334
+ this._missing();
335
+ this._missing();
336
+ this._busy();
337
+ }
338
+ // third command can only be interrupt, if this._bufferLength === 2 it was queued
339
+ else {
340
+ this._missing();
341
+ this._missing();
342
+ this._missing();
343
+ }
344
+ break;
189
345
  }
346
+
347
+ this.transmitNextPortOutputCommand();
190
348
  }
191
349
 
192
350
  private _ensureConnected () {
@@ -195,4 +353,24 @@ export class Device extends EventEmitter {
195
353
  }
196
354
  }
197
355
 
356
+ private _complete () {
357
+ const command = this._transmittedPortOutputCommands.shift();
358
+ if(command) command.resolve(Consts.CommandFeedback.EXECUTION_COMPLETED);
359
+ }
360
+ private _discard () {
361
+ const command = this._transmittedPortOutputCommands.shift();
362
+ if(command) command.resolve(Consts.CommandFeedback.EXECUTION_DISCARDED);
363
+ }
364
+ private _missing () {
365
+ const command = this._transmittedPortOutputCommands.shift();
366
+ if(command) command.resolve(Consts.CommandFeedback.FEEDBACK_MISSING);
367
+ }
368
+ private _busy () {
369
+ const command = this._transmittedPortOutputCommands[0];
370
+ if(command) command.state = Consts.CommandFeedback.EXECUTION_BUSY;
371
+ }
372
+ private _pending () {
373
+ const command = this._transmittedPortOutputCommands[1];
374
+ if(command) command.state = Consts.CommandFeedback.EXECUTION_PENDING;
375
+ }
198
376
  }
@@ -17,24 +17,21 @@ export class DuploTrainBaseSpeaker extends Device {
17
17
  /**
18
18
  * Play a built-in train sound.
19
19
  * @param {DuploTrainBaseSound} sound
20
- * @returns {Promise} Resolved upon successful issuance of the command.
20
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
21
21
  */
22
22
  public playSound (sound: Consts.DuploTrainBaseSound) {
23
- return new Promise<void>((resolve) => {
24
- this.subscribe(Mode.SOUND);
25
- this.writeDirect(0x01, Buffer.from([sound]));
26
- return resolve();
27
- });
23
+ this.subscribe(Mode.SOUND);
24
+ return this.writeDirect(0x01, Buffer.from([sound]));
28
25
  }
29
26
 
30
27
  /**
31
28
  * Play a built-in system tone.
32
29
  * @param {number} tone
33
- * @returns {Promise} Resolved upon successful issuance of the command.
30
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
34
31
  */
35
32
  public playTone (tone: number) {
36
33
  this.subscribe(Mode.TONE);
37
- this.writeDirect(0x02, Buffer.from([tone]));
34
+ return this.writeDirect(0x02, Buffer.from([tone]));
38
35
  }
39
36
 
40
37
  }
@@ -19,22 +19,22 @@ export class HubLED extends Device {
19
19
  /**
20
20
  * Set the color of the LED on the Hub via a color value.
21
21
  * @param {Color} color
22
- * @returns {Promise} Resolved upon successful issuance of the command.
22
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
23
23
  */
24
24
  public setColor (color: number | boolean) {
25
- return new Promise<void>((resolve) => {
26
- if (typeof color === "boolean") {
27
- color = 0;
28
- }
29
- if (this.isWeDo2SmartHub) {
25
+ if (typeof color === "boolean") {
26
+ color = 0;
27
+ }
28
+ if (this.isWeDo2SmartHub) {
29
+ return new Promise<Consts.CommandFeedback>((resolve) => {
30
30
  this.send(Buffer.from([0x06, 0x17, 0x01, 0x01]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
31
- this.send(Buffer.from([0x06, 0x04, 0x01, color]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
32
- } else {
33
- this.subscribe(Mode.COLOR);
34
- this.writeDirect(0x00, Buffer.from([color]));
35
- }
36
- return resolve();
37
- });
31
+ this.send(Buffer.from([0x06, 0x04, 0x01, Number(color)]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
32
+ return resolve(Consts.CommandFeedback.FEEDBACK_DISABLED);
33
+ })
34
+ } else {
35
+ this.subscribe(Mode.COLOR);
36
+ return this.writeDirect(0x00, Buffer.from([color]));
37
+ }
38
38
  }
39
39
 
40
40
 
@@ -43,19 +43,19 @@ export class HubLED extends Device {
43
43
  * @param {number} red
44
44
  * @param {number} green
45
45
  * @param {number} blue
46
- * @returns {Promise} Resolved upon successful issuance of the command.
46
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
47
47
  */
48
48
  public setRGB (red: number, green: number, blue: number) {
49
- return new Promise<void>((resolve) => {
50
- if (this.isWeDo2SmartHub) {
49
+ if (this.isWeDo2SmartHub) {
50
+ return new Promise<Consts.CommandFeedback>((resolve) => {
51
51
  this.send(Buffer.from([0x06, 0x17, 0x01, 0x02]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
52
52
  this.send(Buffer.from([0x06, 0x04, 0x03, red, green, blue]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
53
- } else {
54
- this.subscribe(Mode.RGB);
55
- this.writeDirect(0x01, Buffer.from([red, green, blue]));
56
- }
57
- return resolve();
58
- });
53
+ resolve(Consts.CommandFeedback.FEEDBACK_DISABLED);
54
+ });
55
+ } else {
56
+ this.subscribe(Mode.RGB);
57
+ return this.writeDirect(0x01, Buffer.from([red, green, blue]));
58
+ }
59
59
  }
60
60
 
61
61
 
@@ -20,16 +20,12 @@ export class Light extends Device {
20
20
  /**
21
21
  * Set the light brightness.
22
22
  * @param {number} brightness Brightness value between 0-100 (0 is off)
23
- * @returns {Promise} Resolved upon successful completion of command.
23
+ * @param {number} brightness Brightness value between 0-100 (0 is off)
24
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
25
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
24
26
  */
25
- public setBrightness (brightness: number, interrupt: boolean = true) {
26
- if (interrupt) {
27
- this.cancelEventTimer();
28
- }
29
- return new Promise<void>((resolve) => {
30
- this.writeDirect(0x00, Buffer.from([brightness]));
31
- return resolve();
32
- });
27
+ public setBrightness (brightness: number, interrupt: boolean = false) {
28
+ return this.writeDirect(0x00, Buffer.from([brightness]), interrupt);
33
29
  }
34
30
 
35
31
 
@@ -38,18 +34,15 @@ export class Light extends Device {
38
34
  * @param {number} fromBrightness Brightness value between 0-100 (0 is off)
39
35
  * @param {number} toBrightness Brightness value between 0-100 (0 is off)
40
36
  * @param {number} time How long the ramp should last (in milliseconds).
41
- * @returns {Promise} Resolved upon successful completion of command.
37
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
42
38
  */
43
39
  public rampBrightness (fromBrightness: number, toBrightness: number, time: number) {
44
- this.cancelEventTimer();
45
- return new Promise((resolve) => {
46
- calculateRamp(this, fromBrightness, toBrightness, time)
47
- .on("changePower", (power) => {
48
- this.setBrightness(power, false);
49
- })
50
- .on("finished", resolve);
40
+ const powerValues = calculateRamp(fromBrightness, toBrightness, time);
41
+ powerValues.forEach(value => {
42
+ this.setBrightness(value);
43
+ this.addPortOutputSleep(Math.round(time/powerValues.length));
51
44
  });
45
+ return this.setBrightness(toBrightness);
52
46
  }
53
47
 
54
-
55
48
  }
@@ -20,15 +20,15 @@ export class PiezoBuzzer extends Device {
20
20
  * Play a tone on the Hub's in-built buzzer
21
21
  * @param {number} frequency
22
22
  * @param {number} time How long the tone should play for (in milliseconds).
23
- * @returns {Promise} Resolved upon successful completion of command (ie. once the tone has finished playing).
23
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the tone has finished playing).
24
24
  */
25
25
  public playTone (frequency: number, time: number) {
26
- return new Promise((resolve) => {
26
+ return new Promise<Consts.CommandFeedback>((resolve) => {
27
27
  const data = Buffer.from([0x05, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00]);
28
28
  data.writeUInt16LE(frequency, 3);
29
29
  data.writeUInt16LE(time, 5);
30
30
  this.send(data, Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
31
- global.setTimeout(resolve, time);
31
+ global.setTimeout(() => {return resolve(Consts.CommandFeedback.FEEDBACK_DISABLED)}, time);
32
32
  });
33
33
  }
34
34
 
@@ -63,24 +63,28 @@ export class TachoMotor extends BasicMotor {
63
63
  /**
64
64
  * Set the global acceleration time
65
65
  * @param {number} time How long acceleration should last (in milliseconds).
66
- * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
66
+ * @param {number} profile 0 by default
67
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
68
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
67
69
  */
68
- public setAccelerationTime (time: number, profile: number = 0x00) {
69
- const message = Buffer.from([0x81, this.portId, 0x11, 0x05, 0x00, 0x00, profile]);
70
- message.writeUInt16LE(time, 4);
71
- this.send(message);
70
+ public setAccelerationTime (time: number, profile: number = 0x00, interrupt: boolean = false) {
71
+ const message = Buffer.from([0x05, 0x00, 0x00, profile]);
72
+ message.writeUInt16LE(time, 1);
73
+ return this.sendPortOutputCommand(message, interrupt);
72
74
  }
73
75
 
74
76
 
75
77
  /**
76
78
  * Set the global deceleration time
77
79
  * @param {number} time How long deceleration should last (in milliseconds).
78
- * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
80
+ * @param {number} profile 0 by default
81
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
82
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
79
83
  */
80
- public setDecelerationTime (time: number, profile: number = 0x00) {
81
- const message = Buffer.from([0x81, this.portId, 0x11, 0x06, 0x00, 0x00, profile]);
82
- message.writeUInt16LE(time, 4);
83
- this.send(message);
84
+ public setDecelerationTime (time: number, profile: number = 0x00, interrupt: boolean = true) {
85
+ const message = Buffer.from([0x06, 0x00, 0x00, profile]);
86
+ message.writeUInt16LE(time, 1);
87
+ return this.sendPortOutputCommand(message, interrupt);
84
88
  }
85
89
 
86
90
 
@@ -88,72 +92,62 @@ export class TachoMotor extends BasicMotor {
88
92
  * Set the motor speed.
89
93
  * @param {number} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
90
94
  * @param {number} time How long the motor should run for (in milliseconds).
91
- * @returns {Promise} Resolved upon successful issuance of the command.
95
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
96
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
92
97
  */
93
- public setSpeed (speed: [number, number] | number, time: number | undefined) {
98
+ public setSpeed (speed: [number, number] | number, time: number | undefined, interrupt: boolean = false) {
94
99
  if (!this.isVirtualPort && speed instanceof Array) {
95
100
  throw new Error("Only virtual ports can accept multiple speeds");
96
101
  }
97
102
  if (this.isWeDo2SmartHub) {
98
103
  throw new Error("Motor speed is not available on the WeDo 2.0 Smart Hub");
99
104
  }
100
- this.cancelEventTimer();
101
- return new Promise<void>((resolve) => {
102
- if (speed === undefined || speed === null) {
103
- speed = 100;
105
+ if (speed === undefined || speed === null) {
106
+ speed = 100;
107
+ }
108
+ let message;
109
+ if (time !== undefined) {
110
+ if (speed instanceof Array) {
111
+ message = Buffer.from([0x0a, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), this._maxPower, this._brakeStyle, this.useProfile()]);
112
+ } else {
113
+ message = Buffer.from([0x09, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
104
114
  }
105
- let message;
106
- if (time !== undefined) {
107
- if (speed instanceof Array) {
108
- message = Buffer.from([0x81, this.portId, 0x11, 0x0a, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), this._maxPower, this._brakeStyle, this.useProfile()]);
109
- } else {
110
- message = Buffer.from([0x81, this.portId, 0x11, 0x09, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
111
- }
112
- message.writeUInt16LE(time, 4);
115
+ message.writeUInt16LE(time, 1);
116
+ } else {
117
+ if (speed instanceof Array) {
118
+ message = Buffer.from([0x08, mapSpeed(speed[0]), mapSpeed(speed[1]), this._maxPower, this.useProfile()]);
113
119
  } else {
114
- if (speed instanceof Array) {
115
- message = Buffer.from([0x81, this.portId, 0x11, 0x08, mapSpeed(speed[0]), mapSpeed(speed[1]), this._maxPower, this.useProfile()]);
116
- } else {
117
- message = Buffer.from([0x81, this.portId, 0x11, 0x07, mapSpeed(speed), this._maxPower, this.useProfile()]);
118
- }
120
+ message = Buffer.from([0x07, mapSpeed(speed), this._maxPower, this.useProfile()]);
119
121
  }
120
- this.send(message);
121
- this._finishedCallbacks.push(() => {
122
- return resolve();
123
- });
124
- });
122
+ }
123
+ return this.sendPortOutputCommand(message, interrupt);
125
124
  }
126
125
 
127
126
  /**
128
127
  * Rotate a motor by a given amount of degrees.
129
128
  * @param {number} degrees How much the motor should be rotated (in degrees).
130
129
  * @param {number} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100.
131
- * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
130
+ * @param {boolean} [interrupt=false] If true, previous commands are discarded.
131
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command (i.e. once the motor is finished).
132
132
  */
133
- public rotateByDegrees (degrees: number, speed: [number, number] | number) {
133
+ public rotateByDegrees (degrees: number, speed: [number, number] | number, interrupt: boolean = false) {
134
134
  if (!this.isVirtualPort && speed instanceof Array) {
135
135
  throw new Error("Only virtual ports can accept multiple speeds");
136
136
  }
137
137
  if (this.isWeDo2SmartHub) {
138
138
  throw new Error("Rotation is not available on the WeDo 2.0 Smart Hub");
139
139
  }
140
- this.cancelEventTimer();
141
- return new Promise<void>((resolve) => {
142
- if (speed === undefined || speed === null) {
143
- speed = 100;
144
- }
145
- let message;
146
- if (speed instanceof Array) {
147
- message = Buffer.from([0x81, this.portId, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), this._maxPower, this._brakeStyle, this.useProfile()]);
148
- } else {
149
- message = Buffer.from([0x81, this.portId, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
150
- }
151
- message.writeUInt32LE(degrees, 4);
152
- this.send(message);
153
- this._finishedCallbacks.push(() => {
154
- return resolve();
155
- });
156
- });
140
+ if (speed === undefined || speed === null) {
141
+ speed = 100;
142
+ }
143
+ let message;
144
+ if (speed instanceof Array) {
145
+ message = Buffer.from([0x0c, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), this._maxPower, this._brakeStyle, this.useProfile()]);
146
+ } else {
147
+ message = Buffer.from([0x0b, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), this._maxPower, this._brakeStyle, this.useProfile()]);
148
+ }
149
+ message.writeUInt32LE(degrees, 1);
150
+ return this.sendPortOutputCommand(message, interrupt);
157
151
  }
158
152
 
159
153
 
@@ -21,35 +21,32 @@ export class Technic3x3ColorLightMatrix extends Device {
21
21
  /**
22
22
  * Set the LED matrix, one color per LED
23
23
  * @param {Color[] | Color} colors Array of 9 colors, 9 Color objects, or a single color
24
- * @returns {Promise} Resolved upon successful issuance of the command.
24
+ * @returns {Promise<CommandFeedback>} Resolved upon completion of command.
25
25
  */
26
26
  public setMatrix (colors: number[] | number) {
27
- return new Promise<void>((resolve) => {
28
- this.subscribe(Mode.PIX_0);
29
- const colorArray = new Array(9);
30
- for (let i = 0; i < colorArray.length; i++) {
31
- if (typeof colors === 'number') {
32
- // @ts-ignore
33
- colorArray[i] = colors + (10 << 4);
34
- }
27
+ this.subscribe(Mode.PIX_0);
28
+ const colorArray = new Array(9);
29
+ for (let i = 0; i < colorArray.length; i++) {
30
+ if (typeof colors === 'number') {
35
31
  // @ts-ignore
36
- if (colors[i] instanceof Color) {
37
- // @ts-ignore
38
- colorArray[i] = colors[i].toValue();
39
- }
32
+ colorArray[i] = colors + (10 << 4);
33
+ }
34
+ // @ts-ignore
35
+ if (colors[i] instanceof Color) {
40
36
  // @ts-ignore
41
- if (colors[i] === Consts.Color.NONE) {
42
- colorArray[i] = Consts.Color.NONE;
43
- }
37
+ colorArray[i] = colors[i].toValue();
38
+ }
39
+ // @ts-ignore
40
+ if (colors[i] === Consts.Color.NONE) {
41
+ colorArray[i] = Consts.Color.NONE;
42
+ }
43
+ // @ts-ignore
44
+ if (colors[i] <= 10) {
44
45
  // @ts-ignore
45
- if (colors[i] <= 10) {
46
- // @ts-ignore
47
- colorArray[i] = colors[i] + (10 << 4); // If a raw color value, set it to max brightness (10)
48
- }
46
+ colorArray[i] = colors[i] + (10 << 4); // If a raw color value, set it to max brightness (10)
49
47
  }
50
- this.writeDirect(Mode.PIX_0, Buffer.from(colorArray));
51
- return resolve();
52
- });
48
+ }
49
+ return this.writeDirect(Mode.PIX_0, Buffer.from(colorArray));
53
50
  }
54
51
 
55
52