lego-front-web-sdk 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index.js +1475 -1712
  2. package/package.json +2 -2
  3. package/dist/constants.d.ts +0 -46
  4. package/dist/constants.d.ts.map +0 -1
  5. package/dist/devices/base.d.ts +0 -63
  6. package/dist/devices/base.d.ts.map +0 -1
  7. package/dist/devices/color-sensor.d.ts +0 -23
  8. package/dist/devices/color-sensor.d.ts.map +0 -1
  9. package/dist/devices/controller.d.ts +0 -20
  10. package/dist/devices/controller.d.ts.map +0 -1
  11. package/dist/devices/double-motor.d.ts +0 -131
  12. package/dist/devices/double-motor.d.ts.map +0 -1
  13. package/dist/devices/index.d.ts +0 -11
  14. package/dist/devices/index.d.ts.map +0 -1
  15. package/dist/devices/single-motor.d.ts +0 -73
  16. package/dist/devices/single-motor.d.ts.map +0 -1
  17. package/dist/index.d.ts +0 -11
  18. package/dist/index.d.ts.map +0 -1
  19. package/dist/index.js.map +0 -1
  20. package/dist/protocol/codec.d.ts +0 -54
  21. package/dist/protocol/codec.d.ts.map +0 -1
  22. package/dist/protocol/colors.d.ts +0 -20
  23. package/dist/protocol/colors.d.ts.map +0 -1
  24. package/dist/protocol/frames.d.ts +0 -6
  25. package/dist/protocol/frames.d.ts.map +0 -1
  26. package/dist/protocol/index.d.ts +0 -7
  27. package/dist/protocol/index.d.ts.map +0 -1
  28. package/dist/protocol/notifications.d.ts +0 -58
  29. package/dist/protocol/notifications.d.ts.map +0 -1
  30. package/dist/protocol/opcodes.d.ts +0 -78
  31. package/dist/protocol/opcodes.d.ts.map +0 -1
  32. package/dist/protocol/uuids.d.ts +0 -18
  33. package/dist/protocol/uuids.d.ts.map +0 -1
  34. package/dist/transport/index.d.ts +0 -7
  35. package/dist/transport/index.d.ts.map +0 -1
  36. package/dist/transport/mock.d.ts +0 -41
  37. package/dist/transport/mock.d.ts.map +0 -1
  38. package/dist/transport/types.d.ts +0 -55
  39. package/dist/transport/types.d.ts.map +0 -1
  40. package/dist/transport/web-bluetooth.d.ts +0 -47
  41. package/dist/transport/web-bluetooth.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,1781 +1,1544 @@
1
- //#region src/protocol/colors.ts
2
- /**
3
- * App-aligned LEGO colors (match Python public API / Coding Canvas).
4
- * Wire frames use firmware numbers via appColorToFirmware().
5
- */
6
- /** App-aligned (what callers pass to lightColor / filters). */
7
- var LEGO_COLOR_NOCOLOR = 0;
8
- var LEGO_COLOR_NONE = 0;
9
- var LEGO_COLOR_RED = 1;
10
- var LEGO_COLOR_YELLOW = 2;
11
- var LEGO_COLOR_BLUE = 3;
12
- var LEGO_COLOR_TEAL = 4;
13
- var LEGO_COLOR_GREEN = 5;
14
- var LEGO_COLOR_PURPLE = 6;
15
- var LEGO_COLOR_WHITE = 7;
16
- var LEGO_COLOR_MAGENTA = 8;
17
- var LEGO_COLOR_ORANGE = 9;
18
- var LEGO_COLOR_AZURE = 10;
19
- /** Firmware wire values (rpc_message). */
20
- var FW_NONE = -1;
21
- var FW_BLACK = 0;
22
- var FW_MAGENTA = 1;
23
- var FW_PURPLE = 2;
24
- var FW_BLUE = 3;
25
- var FW_AZURE = 4;
26
- var FW_TURQUOISE = 5;
27
- var FW_GREEN = 6;
28
- var FW_YELLOW = 7;
29
- var FW_ORANGE = 8;
30
- var FW_RED = 9;
31
- var FW_WHITE = 10;
32
- var APP_TO_FW = {
33
- [0]: FW_NONE,
34
- [1]: FW_RED,
35
- [2]: FW_YELLOW,
36
- [3]: FW_BLUE,
37
- [4]: FW_TURQUOISE,
38
- [5]: FW_GREEN,
39
- [6]: FW_PURPLE,
40
- [7]: FW_WHITE,
41
- [8]: FW_MAGENTA,
42
- [9]: FW_ORANGE,
43
- [10]: FW_AZURE
1
+ var Oo = 0, To = 0, fo = 1, po = 2, bo = 3, Mo = 4, wo = 5, No = 6, Ro = 7, Co = 8, So = 9, Ao = 10, Q = -1, pt = 0, nt = 1, rt = 2, it = 3, st = 4, at = 5, ct = 6, lt = 7, ut = 8, dt = 9, _t = 10, bt = {
2
+ 0: Q,
3
+ 1: dt,
4
+ 2: lt,
5
+ 3: it,
6
+ 4: at,
7
+ 5: ct,
8
+ 6: rt,
9
+ 7: _t,
10
+ 8: nt,
11
+ 9: ut,
12
+ 10: st
13
+ }, Mt = {
14
+ [Q]: 0,
15
+ [pt]: 0,
16
+ [nt]: 8,
17
+ [rt]: 6,
18
+ [it]: 3,
19
+ [st]: 10,
20
+ [at]: 4,
21
+ [ct]: 5,
22
+ [lt]: 2,
23
+ [ut]: 9,
24
+ [dt]: 1,
25
+ [_t]: 7
44
26
  };
45
- var FW_TO_APP = {
46
- [FW_NONE]: 0,
47
- [FW_BLACK]: 0,
48
- [FW_MAGENTA]: 8,
49
- [FW_PURPLE]: 6,
50
- [FW_BLUE]: 3,
51
- [FW_AZURE]: 10,
52
- [FW_TURQUOISE]: 4,
53
- [FW_GREEN]: 5,
54
- [FW_YELLOW]: 2,
55
- [FW_ORANGE]: 9,
56
- [FW_RED]: 1,
57
- [FW_WHITE]: 7
58
- };
59
- function appColorToFirmware(appColor) {
60
- var _APP_TO_FW$appColor;
61
- return (_APP_TO_FW$appColor = APP_TO_FW[appColor]) !== null && _APP_TO_FW$appColor !== void 0 ? _APP_TO_FW$appColor : FW_NONE;
27
+ function wt(o) {
28
+ var t;
29
+ return (t = bt[o]) !== null && t !== void 0 ? t : Q;
62
30
  }
63
- function firmwareColorToApp(firmwareColor) {
64
- var _FW_TO_APP$firmwareCo;
65
- return (_FW_TO_APP$firmwareCo = FW_TO_APP[firmwareColor]) !== null && _FW_TO_APP$firmwareCo !== void 0 ? _FW_TO_APP$firmwareCo : 0;
31
+ function et(o) {
32
+ var t;
33
+ return (t = Mt[o]) !== null && t !== void 0 ? t : 0;
66
34
  }
67
- //#endregion
68
- //#region src/constants.ts
69
- /** Constants aligned with the LEGO Education Python public API. */
70
- var UNCHANGED = -1;
71
- var DEFAULT_MOTOR = 0;
72
- var DEFAULT_DEVICE_NOTIFICATION_DELAY = 100;
73
- var MOTOR_END_STATE_DEFAULT = -1;
74
- var MOTOR_END_STATE_COAST = 0;
75
- var MOTOR_END_STATE_BRAKE = 1;
76
- var MOTOR_END_STATE_HOLD = 2;
77
- var MOTOR_END_STATE_CONTINUE = 3;
78
- var MOTOR_END_STATE_SMART_COAST = 4;
79
- var MOTOR_END_STATE_SMART_BRAKE = 5;
80
- var MOTOR_MOVE_DIRECTION_CLOCKWISE = 0;
81
- var MOTOR_MOVE_DIRECTION_COUNTERCLOCKWISE = 1;
82
- var MOTOR_MOVE_DIRECTION_SHORTEST = 2;
83
- var MOTOR_MOVE_DIRECTION_LONGEST = 3;
84
- var MOTOR_LEFT = 0;
85
- var MOTOR_RIGHT = 1;
86
- var MOTOR_BOTH = 2;
87
- var MOVEMENT_DIRECTION_FORWARD = 0;
88
- var MOVEMENT_DIRECTION_BACKWARD = 1;
89
- var MOVEMENT_DIRECTION_LEFT = 2;
90
- var MOVEMENT_DIRECTION_RIGHT = 3;
91
- var MOVEMENT_MOVE_DIRECTION_FORWARD = 0;
92
- var MOVEMENT_MOVE_DIRECTION_BACKWARD = 1;
93
- var MOVEMENT_TURN_DIRECTION_LEFT = 2;
94
- var MOVEMENT_TURN_DIRECTION_RIGHT = 3;
95
- var DEVICE_FACE_TOP = 0;
96
- var DEVICE_FACE_FRONT = 1;
97
- var DEVICE_FACE_RIGHT = 2;
98
- var DEVICE_FACE_BOTTOM = 3;
99
- var DEVICE_FACE_BACK = 4;
100
- var DEVICE_FACE_LEFT = 5;
101
- var SOUND_PATTERN_BEEP_SINGLE = 0;
102
- var SOUND_PATTERN_BEEP_DOUBLE = 1;
103
- var SOUND_PATTERN_BEEP_TRIPLE = 2;
104
- var SOUND_PATTERN_BEEP_UP_MIDDLE_DOWN = 3;
105
- var LIGHT_PATTERN_SOLID = 0;
106
- var LIGHT_PATTERN_BREATHE = 1;
107
- var LIGHT_PATTERN_PULSE = 2;
108
- var LIGHT_PATTERN_SHORT_BLINK = 3;
109
- var LIGHT_PATTERN_LONG_BLINK = 4;
110
- var LIGHT_PATTERN_DOUBLE_BLINK = 5;
111
- var PROGRAM_ACTION_START = 0;
112
- var PROGRAM_ACTION_STOP = 1;
113
- //#endregion
114
- //#region src/protocol/uuids.ts
115
- /** GATT UUIDs — aligned with legoeducation `basic_ble.py` / Coral fd02 docs. */
116
- var SERVICE_UUID = "0000fd02-0000-1000-8000-00805f9b34fb";
117
- var WRITE_UUID = "0000fd02-0001-1000-8000-00805f9b34fb";
118
- var NOTIFY_UUID = "0000fd02-0002-1000-8000-00805f9b34fb";
119
- /** LEGO Bluetooth company identifier (manufacturer data). */
120
- var LEGO_COMPANY_ID = 919;
121
- /** productGroupDevice values from legoeducation rpc_message. */
122
- var PRODUCT_GROUP_DEVICE_SINGLE_MOTOR = 512;
123
- var PRODUCT_GROUP_DEVICE_DOUBLE_MOTOR = 513;
124
- var PRODUCT_GROUP_DEVICE_COLOR_SENSOR = 514;
125
- var PRODUCT_GROUP_DEVICE_CONTROLLER = 515;
126
- /** Client RPC version expected by legoeducation 1.0.6. */
127
- var RPC_VERSION = {
128
- major: 1,
129
- minor: 0,
130
- build: 73
131
- };
132
- //#endregion
133
- //#region src/protocol/opcodes.ts
134
- /** Message type IDs — legoeducation 1.0.6 `rpc_message.py`. */
135
- var INFO_REQUEST = 0;
136
- var INFO_RESPONSE = 1;
137
- var PROGRAM_FLOW_NOTIFICATION = 32;
138
- var DEVICE_NOTIFICATION_REQUEST = 40;
139
- var DEVICE_NOTIFICATION_RESPONSE = 41;
140
- var DEVICE_NOTIFICATION = 60;
141
- var LIGHT_COLOR_COMMAND = 110;
142
- var LIGHT_COLOR_RESULT = 111;
143
- var PLAY_BEEP_COMMAND = 112;
144
- var PLAY_BEEP_RESULT = 113;
145
- var STOP_SOUND_COMMAND = 114;
146
- var STOP_SOUND_RESULT = 115;
147
- var MOTOR_RESET_RELATIVE_POSITION_COMMAND = 120;
148
- var MOTOR_RESET_RELATIVE_POSITION_RESULT = 121;
149
- var MOTOR_RUN_COMMAND = 122;
150
- var MOTOR_RUN_RESULT = 123;
151
- var MOTOR_RUN_FOR_DEGREES_COMMAND = 124;
152
- var MOTOR_RUN_FOR_DEGREES_RESULT = 125;
153
- var MOTOR_RUN_FOR_TIME_COMMAND = 126;
154
- var MOTOR_RUN_FOR_TIME_RESULT = 127;
155
- var MOTOR_RUN_TO_ABSOLUTE_POSITION_COMMAND = 128;
156
- var MOTOR_RUN_TO_ABSOLUTE_POSITION_RESULT = 129;
157
- var MOTOR_RUN_TO_RELATIVE_POSITION_COMMAND = 130;
158
- var MOTOR_RUN_TO_RELATIVE_POSITION_RESULT = 131;
159
- var MOTOR_SET_DUTY_CYCLE_COMMAND = 132;
160
- var MOTOR_SET_DUTY_CYCLE_RESULT = 133;
161
- var MOTOR_STOP_COMMAND = 138;
162
- var MOTOR_STOP_RESULT = 139;
163
- var MOTOR_SET_SPEED_COMMAND = 140;
164
- var MOTOR_SET_SPEED_RESULT = 141;
165
- var MOTOR_SET_END_STATE_COMMAND = 142;
166
- var MOTOR_SET_END_STATE_RESULT = 143;
167
- var MOTOR_SET_ACCELERATION_COMMAND = 144;
168
- var MOTOR_SET_ACCELERATION_RESULT = 145;
169
- var MOVEMENT_MOVE_COMMAND = 150;
170
- var MOVEMENT_MOVE_RESULT = 151;
171
- var MOVEMENT_MOVE_FOR_TIME_COMMAND = 152;
172
- var MOVEMENT_MOVE_FOR_TIME_RESULT = 153;
173
- var MOVEMENT_MOVE_FOR_DEGREES_COMMAND = 154;
174
- var MOVEMENT_MOVE_FOR_DEGREES_RESULT = 155;
175
- var MOVEMENT_MOVE_TANK_COMMAND = 156;
176
- var MOVEMENT_MOVE_TANK_RESULT = 157;
177
- var MOVEMENT_MOVE_TANK_FOR_DEGREES_COMMAND = 158;
178
- var MOVEMENT_MOVE_TANK_FOR_DEGREES_RESULT = 159;
179
- var MOVEMENT_TURN_FOR_DEGREES_COMMAND = 160;
180
- var MOVEMENT_TURN_FOR_DEGREES_RESULT = 161;
181
- var MOVEMENT_STOP_COMMAND = 168;
182
- var MOVEMENT_STOP_RESULT = 169;
183
- var MOVEMENT_SET_SPEED_COMMAND = 170;
184
- var MOVEMENT_SET_SPEED_RESULT = 171;
185
- var MOVEMENT_SET_END_STATE_COMMAND = 172;
186
- var MOVEMENT_SET_END_STATE_RESULT = 173;
187
- var MOVEMENT_SET_ACCELERATION_COMMAND = 174;
188
- var MOVEMENT_SET_ACCELERATION_RESULT = 175;
189
- var MOVEMENT_SET_TURN_STEERING_COMMAND = 176;
190
- var MOVEMENT_SET_TURN_STEERING_RESULT = 177;
191
- var IMU_SET_YAW_FACE_COMMAND = 190;
192
- var IMU_SET_YAW_FACE_RESULT = 191;
193
- var IMU_RESET_YAW_AXIS_COMMAND = 192;
194
- var IMU_RESET_YAW_AXIS_RESULT = 193;
195
- /** Nested types inside DEVICE_NOTIFICATION deviceData. */
196
- var INFO_DEVICE_NOTIFICATION = 0;
197
- var IMU_DEVICE_NOTIFICATION = 1;
198
- var CARD_NOTIFICATION = 3;
199
- var BUTTON_STATE_NOTIFICATION = 4;
200
- var MOTOR_NOTIFICATION = 10;
201
- var COLOR_SENSOR_NOTIFICATION = 12;
202
- var CONTROLLER_NOTIFICATION = 15;
203
- var IMU_GESTURE_NOTIFICATION = 16;
204
- var MOTOR_BITS_LEFT = 1;
205
- var MOTOR_BITS_RIGHT = 2;
206
- var MOTOR_BITS_BOTH = 3;
207
- /** Body sizes (without nested type byte). */
208
- var NESTED_NOTIFICATION_SIZES = {
209
- [0]: 2,
210
- [1]: 20,
211
- [3]: 3,
212
- [4]: 1,
213
- [10]: 12,
214
- [12]: 12,
215
- [15]: 6,
216
- [16]: 1
35
+ var Io = -1, ko = 0, yo = 100, go = -1, Uo = 0, Do = 1, Lo = 2, Po = 3, Fo = 4, Vo = 5, Bo = 0, Go = 1, $o = 2, Wo = 3, Ho = 0, Yo = 1, xo = 2, jo = 0, qo = 1, Ko = 2, Zo = 3, Xo = 0, zo = 1, Jo = 2, Qo = 3, te = 0, oe = 1, ee = 2, ne = 3, re = 4, ie = 5, se = 0, ae = 1, ce = 2, le = 3, ue = 0, de = 1, _e = 2, ve = 3, me = 4, Ee = 5, he = 0, Oe = 1, J = "0000fd02-0000-1000-8000-00805f9b34fb", Nt = "0000fd02-0001-1000-8000-00805f9b34fb", Rt = "0000fd02-0002-1000-8000-00805f9b34fb", Te = 919, fe = 512, pe = 513, be = 514, Me = 515, N = {
36
+ major: 1,
37
+ minor: 0,
38
+ build: 73
39
+ }, we = 0, Ne = 1, Re = 32, Ce = 40, Se = 41, Ae = 60, Ie = 110, ke = 111, ye = 112, ge = 113, Ue = 114, De = 115, Le = 120, Pe = 121, Fe = 122, Ve = 123, Be = 124, Ge = 125, $e = 126, We = 127, He = 128, Ye = 129, xe = 130, je = 131, qe = 132, Ke = 133, Ze = 138, Xe = 139, ze = 140, Je = 141, Qe = 142, tn = 143, on = 144, en = 145, nn = 150, rn = 151, sn = 152, an = 153, cn = 154, ln = 155, un = 156, dn = 157, _n = 158, vn = 159, mn = 160, En = 161, hn = 168, On = 169, Tn = 170, fn = 171, pn = 172, bn = 173, Mn = 174, wn = 175, Nn = 176, Rn = 177, Cn = 190, Sn = 191, An = 192, In = 193, kn = 0, yn = 1, gn = 3, Un = 4, Dn = 10, Ln = 12, Pn = 15, Fn = 16, Vn = 1, Bn = 2, Gn = 3, Ct = {
40
+ 0: 2,
41
+ 1: 20,
42
+ 3: 3,
43
+ 4: 1,
44
+ 10: 12,
45
+ 12: 12,
46
+ 15: 6,
47
+ 16: 1
217
48
  };
218
- function motorIndexToBitMask(motorIndex) {
219
- if (motorIndex === 2) return 3;
220
- return 1 << motorIndex;
49
+ function St(o) {
50
+ return o === 2 ? 3 : 1 << o;
221
51
  }
222
- function resultOpcodeForMethod(method) {
223
- return {
224
- info_request: 1,
225
- device_notification_request: 41,
226
- light_color: 111,
227
- beep: 113,
228
- stop_beep: 115,
229
- motor_reset_relative_position: 121,
230
- motor_run: 123,
231
- motor_run_for_degrees: 125,
232
- motor_run_for_time: 127,
233
- motor_run_to_absolute_position: 129,
234
- motor_run_to_relative_position: 131,
235
- motor_set_duty_cycle: 133,
236
- motor_stop: 139,
237
- motor_set_speed: 141,
238
- motor_set_end_state: 143,
239
- motor_set_acceleration: 145,
240
- movement_move: 151,
241
- movement_move_for_time: 153,
242
- movement_move_for_degrees: 155,
243
- movement_move_tank: 157,
244
- movement_move_tank_for_degrees: 159,
245
- movement_turn_for_degrees: 161,
246
- movement_stop: 169,
247
- movement_set_speed: 171,
248
- movement_set_end_state: 173,
249
- movement_set_acceleration: 175,
250
- movement_set_turn_steering: 177,
251
- imu_set_yaw_face: 191,
252
- imu_reset_yaw_axis: 193
253
- }[method];
52
+ function At(o) {
53
+ return {
54
+ info_request: 1,
55
+ device_notification_request: 41,
56
+ light_color: 111,
57
+ beep: 113,
58
+ stop_beep: 115,
59
+ motor_reset_relative_position: 121,
60
+ motor_run: 123,
61
+ motor_run_for_degrees: 125,
62
+ motor_run_for_time: 127,
63
+ motor_run_to_absolute_position: 129,
64
+ motor_run_to_relative_position: 131,
65
+ motor_set_duty_cycle: 133,
66
+ motor_stop: 139,
67
+ motor_set_speed: 141,
68
+ motor_set_end_state: 143,
69
+ motor_set_acceleration: 145,
70
+ movement_move: 151,
71
+ movement_move_for_time: 153,
72
+ movement_move_for_degrees: 155,
73
+ movement_move_tank: 157,
74
+ movement_move_tank_for_degrees: 159,
75
+ movement_turn_for_degrees: 161,
76
+ movement_stop: 169,
77
+ movement_set_speed: 171,
78
+ movement_set_end_state: 173,
79
+ movement_set_acceleration: 175,
80
+ movement_set_turn_steering: 177,
81
+ imu_set_yaw_face: 191,
82
+ imu_reset_yaw_axis: 193
83
+ }[o];
254
84
  }
255
- //#endregion
256
- //#region src/protocol/frames.ts
257
- /**
258
- * Split concatenated RPC notify buffers into individual frames.
259
- * Web Bluetooth sometimes delivers DEVICE_NOTIFICATION + result in one packet.
260
- */
261
- /** Total frame size including opcode byte (fixed-layout replies). */
262
- var FIXED_FRAME_SIZE = {
263
- [1]: 17,
264
- [41]: 2,
265
- [111]: 2,
266
- [113]: 2,
267
- [115]: 2,
268
- [121]: 3,
269
- [123]: 3,
270
- [125]: 3,
271
- [127]: 3,
272
- [129]: 3,
273
- [131]: 3,
274
- [133]: 3,
275
- [139]: 3,
276
- [141]: 3,
277
- [143]: 3,
278
- [145]: 3,
279
- [151]: 2,
280
- [153]: 2,
281
- [155]: 2,
282
- [157]: 2,
283
- [159]: 2,
284
- [161]: 2,
285
- [169]: 2,
286
- [171]: 2,
287
- [173]: 2,
288
- [175]: 2,
289
- [177]: 2,
290
- [191]: 2,
291
- [193]: 2
85
+ var It = {
86
+ 1: 17,
87
+ 41: 2,
88
+ 111: 2,
89
+ 113: 2,
90
+ 115: 2,
91
+ 121: 3,
92
+ 123: 3,
93
+ 125: 3,
94
+ 127: 3,
95
+ 129: 3,
96
+ 131: 3,
97
+ 133: 3,
98
+ 139: 3,
99
+ 141: 3,
100
+ 143: 3,
101
+ 145: 3,
102
+ 151: 2,
103
+ 153: 2,
104
+ 155: 2,
105
+ 157: 2,
106
+ 159: 2,
107
+ 161: 2,
108
+ 169: 2,
109
+ 171: 2,
110
+ 173: 2,
111
+ 175: 2,
112
+ 177: 2,
113
+ 191: 2,
114
+ 193: 2
292
115
  };
293
- function splitNotifyFrames(buffer) {
294
- if (buffer.length === 0) return [];
295
- const frames = [];
296
- let o = 0;
297
- while (o < buffer.length) {
298
- const opcode = buffer[o];
299
- let size;
300
- if (opcode === 60 && o + 3 <= buffer.length) size = 3 + (buffer[o + 1] | buffer[o + 2] << 8);
301
- else size = FIXED_FRAME_SIZE[opcode];
302
- if (size == null || o + size > buffer.length) {
303
- frames.push(buffer.subarray(o));
304
- break;
305
- }
306
- frames.push(buffer.subarray(o, o + size));
307
- o += size;
308
- }
309
- return frames;
116
+ function kt(o) {
117
+ if (o.length === 0) return [];
118
+ const t = [];
119
+ let e = 0;
120
+ for (; e < o.length; ) {
121
+ const n = o[e];
122
+ let r;
123
+ if (n === 60 && e + 3 <= o.length ? r = 3 + (o[e + 1] | o[e + 2] << 8) : r = It[n], r == null || e + r > o.length) {
124
+ t.push(o.subarray(e));
125
+ break;
126
+ }
127
+ t.push(o.subarray(e, e + r)), e += r;
128
+ }
129
+ return t;
310
130
  }
311
- //#endregion
312
- //#region src/protocol/notifications.ts
313
- /**
314
- * Parse DEVICE_NOTIFICATION (opcode 60) nested payloads.
315
- */
316
- function decodeMotor(body) {
317
- const v = new DataView(body.buffer, body.byteOffset, body.byteLength);
318
- let o = 0;
319
- const motorBitMask = v.getUint8(o++);
320
- const motorState = v.getUint8(o++);
321
- const absolutePosition = v.getUint16(o, true);
322
- o += 2;
323
- const power = v.getInt16(o, true);
324
- o += 2;
325
- const speed = v.getInt8(o++);
326
- const position = v.getInt32(o, true);
327
- o += 4;
328
- return {
329
- motorBitMask,
330
- motorState,
331
- absolutePosition,
332
- power,
333
- speed,
334
- position,
335
- gesture: v.getInt8(o)
336
- };
131
+ function yt(o) {
132
+ const t = new DataView(o.buffer, o.byteOffset, o.byteLength);
133
+ let e = 0;
134
+ const n = t.getUint8(e++), r = t.getUint8(e++), i = t.getUint16(e, !0);
135
+ e += 2;
136
+ const s = t.getInt16(e, !0);
137
+ e += 2;
138
+ const c = t.getInt8(e++), a = t.getInt32(e, !0);
139
+ return e += 4, {
140
+ motorBitMask: n,
141
+ motorState: r,
142
+ absolutePosition: i,
143
+ power: s,
144
+ speed: c,
145
+ position: a,
146
+ gesture: t.getInt8(e)
147
+ };
337
148
  }
338
- function decodeColor(body) {
339
- const v = new DataView(body.buffer, body.byteOffset, body.byteLength);
340
- let o = 0;
341
- const color = v.getInt8(o++);
342
- const reflection = v.getUint8(o++);
343
- const rawRed = v.getUint16(o, true);
344
- o += 2;
345
- const rawGreen = v.getUint16(o, true);
346
- o += 2;
347
- const rawBlue = v.getUint16(o, true);
348
- o += 2;
349
- const hue = v.getUint16(o, true);
350
- o += 2;
351
- return {
352
- color,
353
- reflection,
354
- rawRed,
355
- rawGreen,
356
- rawBlue,
357
- hue,
358
- saturation: v.getUint8(o++),
359
- value: v.getUint8(o)
360
- };
149
+ function gt(o) {
150
+ const t = new DataView(o.buffer, o.byteOffset, o.byteLength);
151
+ let e = 0;
152
+ const n = t.getInt8(e++), r = t.getUint8(e++), i = t.getUint16(e, !0);
153
+ e += 2;
154
+ const s = t.getUint16(e, !0);
155
+ e += 2;
156
+ const c = t.getUint16(e, !0);
157
+ e += 2;
158
+ const a = t.getUint16(e, !0);
159
+ return e += 2, {
160
+ color: n,
161
+ reflection: r,
162
+ rawRed: i,
163
+ rawGreen: s,
164
+ rawBlue: c,
165
+ hue: a,
166
+ saturation: t.getUint8(e++),
167
+ value: t.getUint8(e)
168
+ };
361
169
  }
362
- function decodeController(body) {
363
- const v = new DataView(body.buffer, body.byteOffset, body.byteLength);
364
- return {
365
- leftPercent: v.getInt8(0),
366
- rightPercent: v.getInt8(1),
367
- leftAngle: v.getInt16(2, true),
368
- rightAngle: v.getInt16(4, true)
369
- };
170
+ function Ut(o) {
171
+ const t = new DataView(o.buffer, o.byteOffset, o.byteLength);
172
+ return {
173
+ leftPercent: t.getInt8(0),
174
+ rightPercent: t.getInt8(1),
175
+ leftAngle: t.getInt16(2, !0),
176
+ rightAngle: t.getInt16(4, !0)
177
+ };
370
178
  }
371
- function decodeImu(body) {
372
- const v = new DataView(body.buffer, body.byteOffset, body.byteLength);
373
- let o = 0;
374
- const orientation = v.getUint8(o++);
375
- const yawFace = v.getUint8(o++);
376
- const yaw = v.getInt16(o, true);
377
- o += 2;
378
- const pitch = v.getInt16(o, true);
379
- o += 2;
380
- const roll = v.getInt16(o, true);
381
- o += 2;
382
- const accelerometerX = v.getInt16(o, true);
383
- o += 2;
384
- const accelerometerY = v.getInt16(o, true);
385
- o += 2;
386
- const accelerometerZ = v.getInt16(o, true);
387
- o += 2;
388
- const gyroscopeX = v.getInt16(o, true);
389
- o += 2;
390
- const gyroscopeY = v.getInt16(o, true);
391
- o += 2;
392
- return {
393
- orientation,
394
- yawFace,
395
- yaw,
396
- pitch,
397
- roll,
398
- accelerometerX,
399
- accelerometerY,
400
- accelerometerZ,
401
- gyroscopeX,
402
- gyroscopeY,
403
- gyroscopeZ: v.getInt16(o, true)
404
- };
179
+ function Dt(o) {
180
+ const t = new DataView(o.buffer, o.byteOffset, o.byteLength);
181
+ let e = 0;
182
+ const n = t.getUint8(e++), r = t.getUint8(e++), i = t.getInt16(e, !0);
183
+ e += 2;
184
+ const s = t.getInt16(e, !0);
185
+ e += 2;
186
+ const c = t.getInt16(e, !0);
187
+ e += 2;
188
+ const a = t.getInt16(e, !0);
189
+ e += 2;
190
+ const d = t.getInt16(e, !0);
191
+ e += 2;
192
+ const v = t.getInt16(e, !0);
193
+ e += 2;
194
+ const m = t.getInt16(e, !0);
195
+ e += 2;
196
+ const E = t.getInt16(e, !0);
197
+ return e += 2, {
198
+ orientation: n,
199
+ yawFace: r,
200
+ yaw: i,
201
+ pitch: s,
202
+ roll: c,
203
+ accelerometerX: a,
204
+ accelerometerY: d,
205
+ accelerometerZ: v,
206
+ gyroscopeX: m,
207
+ gyroscopeY: E,
208
+ gyroscopeZ: t.getInt16(e, !0)
209
+ };
405
210
  }
406
- /** Extract typed readings from a raw notify frame. */
407
- function parseDeviceNotifications(payload) {
408
- let deviceData;
409
- if (payload.length >= 1 && payload[0] === 60) {
410
- if (payload.length < 3) return { motors: [] };
411
- const len = new DataView(payload.buffer, payload.byteOffset + 1, 2).getUint16(0, true);
412
- deviceData = payload.subarray(3, 3 + len);
413
- } else deviceData = payload;
414
- const out = { motors: [] };
415
- let offset = 0;
416
- while (offset < deviceData.length) {
417
- const type = deviceData[offset];
418
- offset += 1;
419
- const size = NESTED_NOTIFICATION_SIZES[type];
420
- if (size == null || offset + size > deviceData.length) break;
421
- const body = deviceData.subarray(offset, offset + size);
422
- offset += size;
423
- switch (type) {
424
- case 10:
425
- out.motors.push(decodeMotor(body));
426
- break;
427
- case 12: {
428
- const c = decodeColor(body);
429
- c.color = firmwareColorToApp(c.color);
430
- out.color = c;
431
- break;
432
- }
433
- case 15:
434
- out.controller = decodeController(body);
435
- break;
436
- case 1:
437
- out.imu = decodeImu(body);
438
- break;
439
- case 16:
440
- out.imuGesture = body[0];
441
- break;
442
- case 3: {
443
- const v = new DataView(body.buffer, body.byteOffset, body.byteLength);
444
- out.card = {
445
- color: firmwareColorToApp(v.getInt8(0)),
446
- serial: v.getUint16(1, true)
447
- };
448
- break;
449
- }
450
- case 4: out.buttonState = body[0];
451
- }
452
- }
453
- return out;
211
+ function k(o) {
212
+ let t;
213
+ if (o.length >= 1 && o[0] === 60) {
214
+ if (o.length < 3) return { motors: [] };
215
+ const r = new DataView(o.buffer, o.byteOffset + 1, 2).getUint16(0, !0);
216
+ t = o.subarray(3, 3 + r);
217
+ } else t = o;
218
+ const e = { motors: [] };
219
+ let n = 0;
220
+ for (; n < t.length; ) {
221
+ const r = t[n];
222
+ n += 1;
223
+ const i = Ct[r];
224
+ if (i == null || n + i > t.length) break;
225
+ const s = t.subarray(n, n + i);
226
+ switch (n += i, r) {
227
+ case 10:
228
+ e.motors.push(yt(s));
229
+ break;
230
+ case 12: {
231
+ const c = gt(s);
232
+ c.color = et(c.color), e.color = c;
233
+ break;
234
+ }
235
+ case 15:
236
+ e.controller = Ut(s);
237
+ break;
238
+ case 1:
239
+ e.imu = Dt(s);
240
+ break;
241
+ case 16:
242
+ e.imuGesture = s[0];
243
+ break;
244
+ case 3: {
245
+ const c = new DataView(s.buffer, s.byteOffset, s.byteLength);
246
+ e.card = {
247
+ color: et(c.getInt8(0)),
248
+ serial: c.getUint16(1, !0)
249
+ };
250
+ break;
251
+ }
252
+ case 4:
253
+ e.buttonState = s[0];
254
+ break;
255
+ case 0:
256
+ }
257
+ }
258
+ return e;
454
259
  }
455
- /** Convenience: motor readings only (back-compat). */
456
- function parseMotorNotifications(payload) {
457
- return parseDeviceNotifications(payload).motors;
260
+ function $n(o) {
261
+ return k(o).motors;
458
262
  }
459
- //#endregion
460
- //#region src/protocol/codec.ts
461
- /**
462
- * RPC codec for CS&AI hubs (fd02).
463
- * Layouts follow legoeducation 1.0.6 `rpc_message.py`.
464
- */
465
- function u8(n) {
466
- return n & 255;
263
+ function l(o) {
264
+ return o & 255;
467
265
  }
468
- function i8(n) {
469
- return n << 24 >> 24;
266
+ function b(o) {
267
+ return o << 24 >> 24;
470
268
  }
471
- function packI16LE(value) {
472
- const b = /* @__PURE__ */ new ArrayBuffer(2);
473
- new DataView(b).setInt16(0, value, true);
474
- return new Uint8Array(b);
269
+ function vt(o) {
270
+ const t = /* @__PURE__ */ new ArrayBuffer(2);
271
+ return new DataView(t).setInt16(0, o, !0), new Uint8Array(t);
475
272
  }
476
- function packU16LE(value) {
477
- const b = /* @__PURE__ */ new ArrayBuffer(2);
478
- new DataView(b).setUint16(0, value, true);
479
- return new Uint8Array(b);
273
+ function tt(o) {
274
+ const t = /* @__PURE__ */ new ArrayBuffer(2);
275
+ return new DataView(t).setUint16(0, o, !0), new Uint8Array(t);
480
276
  }
481
- function packI32LE(value) {
482
- const b = /* @__PURE__ */ new ArrayBuffer(4);
483
- new DataView(b).setInt32(0, value, true);
484
- return new Uint8Array(b);
277
+ function R(o) {
278
+ const t = /* @__PURE__ */ new ArrayBuffer(4);
279
+ return new DataView(t).setInt32(0, o, !0), new Uint8Array(t);
485
280
  }
486
- function packU32LE(value) {
487
- const b = /* @__PURE__ */ new ArrayBuffer(4);
488
- new DataView(b).setUint32(0, value, true);
489
- return new Uint8Array(b);
281
+ function mt(o) {
282
+ const t = /* @__PURE__ */ new ArrayBuffer(4);
283
+ return new DataView(t).setUint32(0, o, !0), new Uint8Array(t);
490
284
  }
491
- function concat(...parts) {
492
- const total = parts.reduce((n, p) => n + p.length, 0);
493
- const out = new Uint8Array(total);
494
- let o = 0;
495
- for (const p of parts) {
496
- out.set(p, o);
497
- o += p.length;
498
- }
499
- return out;
285
+ function _(...o) {
286
+ const t = o.reduce((r, i) => r + i.length, 0), e = new Uint8Array(t);
287
+ let n = 0;
288
+ for (const r of o)
289
+ e.set(r, n), n += r.length;
290
+ return e;
500
291
  }
501
- function bitMask(motor) {
502
- return motorIndexToBitMask(motor !== null && motor !== void 0 ? motor : 0) || 1;
292
+ function h(o) {
293
+ return St(o != null ? o : 0) || 1;
503
294
  }
504
- function encodeInfoRequest() {
505
- return new Uint8Array([0]);
295
+ function Et() {
296
+ return new Uint8Array([0]);
506
297
  }
507
- function encodeProgramFlow(action) {
508
- return new Uint8Array([32, u8(action)]);
298
+ function Lt(o) {
299
+ return new Uint8Array([32, l(o)]);
509
300
  }
510
- function encodeDeviceNotificationRequest(delayMs) {
511
- return concat(new Uint8Array([40]), packU16LE(delayMs));
301
+ function ht(o) {
302
+ return _(new Uint8Array([40]), tt(o));
512
303
  }
513
- function encodeLightColor(color, pattern = 0, intensity = 100) {
514
- const fwColor = appColorToFirmware(color);
515
- const clampedIntensity = Math.max(0, Math.min(100, Math.round(intensity)));
516
- return new Uint8Array([
517
- 110,
518
- i8(fwColor),
519
- u8(pattern),
520
- u8(clampedIntensity)
521
- ]);
304
+ function Pt(o, t = 0, e = 100) {
305
+ const n = wt(o), r = Math.max(0, Math.min(100, Math.round(e)));
306
+ return new Uint8Array([
307
+ 110,
308
+ b(n),
309
+ l(t),
310
+ l(r)
311
+ ]);
522
312
  }
523
- function encodeBeep(pattern = 0, frequency = 440, count = 1) {
524
- const repetitions = Math.max(0, Math.min(255, Math.round(count) - 1));
525
- const hz = Math.max(0, Math.min(2700, Math.round(frequency)));
526
- return concat(new Uint8Array([112, u8(pattern)]), packU16LE(hz), new Uint8Array([u8(repetitions)]));
313
+ function Ft(o = 0, t = 440, e = 1) {
314
+ const n = Math.max(0, Math.min(255, Math.round(e) - 1)), r = Math.max(0, Math.min(2700, Math.round(t)));
315
+ return _(new Uint8Array([112, l(o)]), tt(r), new Uint8Array([l(n)]));
527
316
  }
528
- function encodeStopBeep() {
529
- return new Uint8Array([114]);
317
+ function Vt() {
318
+ return new Uint8Array([114]);
530
319
  }
531
- function encodeMotorSetSpeed(speed, motor) {
532
- return new Uint8Array([
533
- 140,
534
- u8(bitMask(motor)),
535
- i8(speed)
536
- ]);
320
+ function Ot(o, t) {
321
+ return new Uint8Array([
322
+ 140,
323
+ l(h(t)),
324
+ b(o)
325
+ ]);
537
326
  }
538
- function encodeMotorRun(direction = 0, motor) {
539
- return new Uint8Array([
540
- 122,
541
- u8(bitMask(motor)),
542
- u8(direction)
543
- ]);
327
+ function Bt(o = 0, t) {
328
+ return new Uint8Array([
329
+ 122,
330
+ l(h(t)),
331
+ l(o)
332
+ ]);
544
333
  }
545
- function encodeMotorStop(motor) {
546
- return new Uint8Array([138, u8(bitMask(motor))]);
334
+ function Gt(o) {
335
+ return new Uint8Array([138, l(h(o))]);
547
336
  }
548
- function encodeMotorRunForDegrees(degrees, direction = 0, motor) {
549
- return concat(new Uint8Array([124, u8(bitMask(motor))]), packI32LE(degrees), new Uint8Array([u8(direction)]));
337
+ function $t(o, t = 0, e) {
338
+ return _(new Uint8Array([124, l(h(e))]), R(o), new Uint8Array([l(t)]));
550
339
  }
551
- function encodeMotorRunForTime(timeMs, direction = 0, motor) {
552
- return concat(new Uint8Array([126, u8(bitMask(motor))]), packU32LE(timeMs), new Uint8Array([u8(direction)]));
340
+ function Wt(o, t = 0, e) {
341
+ return _(new Uint8Array([126, l(h(e))]), mt(o), new Uint8Array([l(t)]));
553
342
  }
554
- function encodeMotorResetRelativePosition(position = 0, motor) {
555
- return concat(new Uint8Array([120, u8(bitMask(motor))]), packI32LE(position));
343
+ function Ht(o = 0, t) {
344
+ return _(new Uint8Array([120, l(h(t))]), R(o));
556
345
  }
557
- function encodeMotorRunToRelativePosition(position, motor) {
558
- return concat(new Uint8Array([130, u8(bitMask(motor))]), packI32LE(position));
346
+ function Yt(o, t) {
347
+ return _(new Uint8Array([130, l(h(t))]), R(o));
559
348
  }
560
- function encodeMotorRunToAbsolutePosition(position, direction = 2, motor) {
561
- return concat(new Uint8Array([128, u8(bitMask(motor))]), packU16LE(position), new Uint8Array([u8(direction)]));
349
+ function xt(o, t = 2, e) {
350
+ return _(new Uint8Array([128, l(h(e))]), tt(o), new Uint8Array([l(t)]));
562
351
  }
563
- function encodeMotorSetDutyCycle(dutyCycle, motor) {
564
- return concat(new Uint8Array([132, u8(bitMask(motor))]), packI16LE(100 * dutyCycle));
352
+ function jt(o, t) {
353
+ return _(new Uint8Array([132, l(h(t))]), vt(100 * o));
565
354
  }
566
- function encodeMotorSetEndState(endState, motor) {
567
- return new Uint8Array([
568
- 142,
569
- u8(bitMask(motor)),
570
- i8(endState)
571
- ]);
355
+ function qt(o, t) {
356
+ return new Uint8Array([
357
+ 142,
358
+ l(h(t)),
359
+ b(o)
360
+ ]);
572
361
  }
573
- function encodeMotorSetAcceleration(acceleration, deceleration, motor) {
574
- return new Uint8Array([
575
- 144,
576
- u8(bitMask(motor)),
577
- u8(acceleration),
578
- u8(deceleration)
579
- ]);
362
+ function Kt(o, t, e) {
363
+ return new Uint8Array([
364
+ 144,
365
+ l(h(e)),
366
+ l(o),
367
+ l(t)
368
+ ]);
580
369
  }
581
- function encodeMovementSetSpeed(speed) {
582
- return new Uint8Array([170, i8(speed)]);
370
+ function Tt(o) {
371
+ return new Uint8Array([170, b(o)]);
583
372
  }
584
- function encodeMovementMove(direction = 0) {
585
- return new Uint8Array([150, u8(direction)]);
373
+ function Zt(o = 0) {
374
+ return new Uint8Array([150, l(o)]);
586
375
  }
587
- function encodeMovementMoveForTime(timeMs, direction = 0) {
588
- return concat(new Uint8Array([152]), packU32LE(timeMs), new Uint8Array([u8(direction)]));
376
+ function Xt(o, t = 0) {
377
+ return _(new Uint8Array([152]), mt(o), new Uint8Array([l(t)]));
589
378
  }
590
- function encodeMovementMoveForDegrees(degrees, direction = 0) {
591
- return concat(new Uint8Array([154]), packI32LE(degrees), new Uint8Array([u8(direction)]));
379
+ function zt(o, t = 0) {
380
+ return _(new Uint8Array([154]), R(o), new Uint8Array([l(t)]));
592
381
  }
593
- function encodeMovementMoveTank(speedLeft, speedRight) {
594
- return new Uint8Array([
595
- 156,
596
- i8(speedLeft),
597
- i8(speedRight)
598
- ]);
382
+ function Jt(o, t) {
383
+ return new Uint8Array([
384
+ 156,
385
+ b(o),
386
+ b(t)
387
+ ]);
599
388
  }
600
- function encodeMovementMoveTankForDegrees(degrees, speedLeft = 50, speedRight = 50) {
601
- return concat(new Uint8Array([158]), packI32LE(degrees), new Uint8Array([i8(speedLeft), i8(speedRight)]));
389
+ function Qt(o, t = 50, e = 50) {
390
+ return _(new Uint8Array([158]), R(o), new Uint8Array([b(t), b(e)]));
602
391
  }
603
- function encodeMovementTurnForDegrees(degrees, direction = 2) {
604
- return concat(new Uint8Array([160]), packI32LE(degrees), new Uint8Array([u8(direction)]));
392
+ function to(o, t = 2) {
393
+ return _(new Uint8Array([160]), R(o), new Uint8Array([l(t)]));
605
394
  }
606
- function encodeMovementStop() {
607
- return new Uint8Array([168]);
395
+ function oo() {
396
+ return new Uint8Array([168]);
608
397
  }
609
- function encodeMovementSetEndState(endState) {
610
- return new Uint8Array([172, i8(endState)]);
398
+ function eo(o) {
399
+ return new Uint8Array([172, b(o)]);
611
400
  }
612
- function encodeMovementSetAcceleration(acceleration, deceleration) {
613
- return new Uint8Array([
614
- 174,
615
- u8(acceleration),
616
- u8(deceleration)
617
- ]);
401
+ function no(o, t) {
402
+ return new Uint8Array([
403
+ 174,
404
+ l(o),
405
+ l(t)
406
+ ]);
618
407
  }
619
- function encodeMovementSetTurnSteering(steering) {
620
- return new Uint8Array([176, u8(steering)]);
408
+ function ro(o) {
409
+ return new Uint8Array([176, l(o)]);
621
410
  }
622
- function encodeImuSetYawFace(yawFace) {
623
- return new Uint8Array([190, u8(yawFace)]);
411
+ function io(o) {
412
+ return new Uint8Array([190, l(o)]);
624
413
  }
625
- function encodeImuResetYawAxis(value = 0) {
626
- return concat(new Uint8Array([192]), packI16LE(value));
414
+ function so(o = 0) {
415
+ return _(new Uint8Array([192]), vt(o));
627
416
  }
628
- function withMotorSpeed(speed, motor, command) {
629
- if (speed === void 0 || speed === -1) return command;
630
- return concat(encodeMotorSetSpeed(speed, motor), command);
417
+ function A(o, t, e) {
418
+ return o === void 0 || o === -1 ? e : _(Ot(o, t), e);
631
419
  }
632
- function withMovementSpeed(speed, command) {
633
- if (speed === void 0 || speed === -1) return command;
634
- return concat(encodeMovementSetSpeed(speed), command);
420
+ function y(o, t) {
421
+ return o === void 0 || o === -1 ? t : _(Tt(o), t);
635
422
  }
636
- function decodeInfoResponse(payload) {
637
- const body = payload.length >= 1 && payload[0] === 1 ? payload.subarray(1) : payload;
638
- if (body.length < 16) throw new Error(`INFO_RESPONSE too short: got ${payload.length} wire bytes (need 17)`);
639
- const view = new DataView(body.buffer, body.byteOffset, body.byteLength);
640
- let o = 0;
641
- const rpcMajor = view.getUint8(o++);
642
- const rpcMinor = view.getUint8(o++);
643
- const rpcBuild = view.getUint16(o, true);
644
- o += 2;
645
- const firmwareMajor = view.getUint8(o++);
646
- const firmwareMinor = view.getUint8(o++);
647
- const firmwareBuild = view.getUint16(o, true);
648
- o += 2;
649
- const bootloaderMajor = view.getUint8(o++);
650
- const bootloaderMinor = view.getUint8(o++);
651
- const bootloaderBuild = view.getUint16(o, true);
652
- o += 2;
653
- const maxPacketSize = view.getUint16(o, true);
654
- o += 2;
655
- return {
656
- rpcMajor,
657
- rpcMinor,
658
- rpcBuild,
659
- firmwareMajor,
660
- firmwareMinor,
661
- firmwareBuild,
662
- bootloaderMajor,
663
- bootloaderMinor,
664
- bootloaderBuild,
665
- maxPacketSize,
666
- productGroupDevice: view.getUint16(o, true)
667
- };
423
+ function ao(o) {
424
+ const t = o.length >= 1 && o[0] === 1 ? o.subarray(1) : o;
425
+ if (t.length < 16) throw new Error(`INFO_RESPONSE too short: got ${o.length} wire bytes (need 17)`);
426
+ const e = new DataView(t.buffer, t.byteOffset, t.byteLength);
427
+ let n = 0;
428
+ const r = e.getUint8(n++), i = e.getUint8(n++), s = e.getUint16(n, !0);
429
+ n += 2;
430
+ const c = e.getUint8(n++), a = e.getUint8(n++), d = e.getUint16(n, !0);
431
+ n += 2;
432
+ const v = e.getUint8(n++), m = e.getUint8(n++), E = e.getUint16(n, !0);
433
+ n += 2;
434
+ const O = e.getUint16(n, !0);
435
+ return n += 2, {
436
+ rpcMajor: r,
437
+ rpcMinor: i,
438
+ rpcBuild: s,
439
+ firmwareMajor: c,
440
+ firmwareMinor: a,
441
+ firmwareBuild: d,
442
+ bootloaderMajor: v,
443
+ bootloaderMinor: m,
444
+ bootloaderBuild: E,
445
+ maxPacketSize: O,
446
+ productGroupDevice: e.getUint16(n, !0)
447
+ };
668
448
  }
669
- function encodeRpcCommand(method, args = {}) {
670
- var _args$motor, _args$direction;
671
- const motor = Number((_args$motor = args.motor) !== null && _args$motor !== void 0 ? _args$motor : 0);
672
- const direction = Number((_args$direction = args.direction) !== null && _args$direction !== void 0 ? _args$direction : 0);
673
- const speed = args.speed !== void 0 ? Number(args.speed) : -1;
674
- switch (method) {
675
- case "info_request": return encodeInfoRequest();
676
- case "program_flow_notification":
677
- var _args$action;
678
- return encodeProgramFlow(Number((_args$action = args.action) !== null && _args$action !== void 0 ? _args$action : 0));
679
- case "device_notification_request":
680
- var _args$delay_ms;
681
- return encodeDeviceNotificationRequest(Number((_args$delay_ms = args.delay_ms) !== null && _args$delay_ms !== void 0 ? _args$delay_ms : 100));
682
- case "light_color":
683
- var _args$color, _args$pattern, _args$intensity;
684
- return encodeLightColor(Number((_args$color = args.color) !== null && _args$color !== void 0 ? _args$color : 0), Number((_args$pattern = args.pattern) !== null && _args$pattern !== void 0 ? _args$pattern : 0), Number((_args$intensity = args.intensity) !== null && _args$intensity !== void 0 ? _args$intensity : 100));
685
- case "beep":
686
- var _args$pattern2, _args$frequency, _args$count;
687
- return encodeBeep(Number((_args$pattern2 = args.pattern) !== null && _args$pattern2 !== void 0 ? _args$pattern2 : 0), Number((_args$frequency = args.frequency) !== null && _args$frequency !== void 0 ? _args$frequency : 440), Number((_args$count = args.count) !== null && _args$count !== void 0 ? _args$count : 1));
688
- case "stop_beep": return encodeStopBeep();
689
- case "motor_set_speed":
690
- var _args$speed;
691
- return encodeMotorSetSpeed(Number((_args$speed = args.speed) !== null && _args$speed !== void 0 ? _args$speed : 0), motor);
692
- case "motor_run": return withMotorSpeed(speed, motor, encodeMotorRun(direction, motor));
693
- case "motor_stop": return encodeMotorStop(motor);
694
- case "motor_run_for_degrees":
695
- var _args$degrees;
696
- return withMotorSpeed(speed, motor, encodeMotorRunForDegrees(Number((_args$degrees = args.degrees) !== null && _args$degrees !== void 0 ? _args$degrees : 0), direction, motor));
697
- case "motor_run_for_time":
698
- var _args$time_ms;
699
- return withMotorSpeed(speed, motor, encodeMotorRunForTime(Number((_args$time_ms = args.time_ms) !== null && _args$time_ms !== void 0 ? _args$time_ms : 0), direction, motor));
700
- case "motor_reset_relative_position":
701
- var _args$position;
702
- return encodeMotorResetRelativePosition(Number((_args$position = args.position) !== null && _args$position !== void 0 ? _args$position : 0), motor);
703
- case "motor_run_to_relative_position":
704
- var _args$position2;
705
- return withMotorSpeed(speed, motor, encodeMotorRunToRelativePosition(Number((_args$position2 = args.position) !== null && _args$position2 !== void 0 ? _args$position2 : 0), motor));
706
- case "motor_run_to_absolute_position":
707
- var _args$position3;
708
- return withMotorSpeed(speed, motor, encodeMotorRunToAbsolutePosition(Number((_args$position3 = args.position) !== null && _args$position3 !== void 0 ? _args$position3 : 0), direction || 2, motor));
709
- case "motor_set_duty_cycle":
710
- var _args$duty_cycle;
711
- return encodeMotorSetDutyCycle(Number((_args$duty_cycle = args.duty_cycle) !== null && _args$duty_cycle !== void 0 ? _args$duty_cycle : 0), motor);
712
- case "motor_set_end_state":
713
- var _args$end_state;
714
- return encodeMotorSetEndState(Number((_args$end_state = args.end_state) !== null && _args$end_state !== void 0 ? _args$end_state : 0), motor);
715
- case "motor_set_acceleration":
716
- var _args$acceleration, _args$deceleration;
717
- return encodeMotorSetAcceleration(Number((_args$acceleration = args.acceleration) !== null && _args$acceleration !== void 0 ? _args$acceleration : 0), Number((_args$deceleration = args.deceleration) !== null && _args$deceleration !== void 0 ? _args$deceleration : 0), motor);
718
- case "movement_set_speed":
719
- var _args$speed2;
720
- return encodeMovementSetSpeed(Number((_args$speed2 = args.speed) !== null && _args$speed2 !== void 0 ? _args$speed2 : 0));
721
- case "movement_move": return withMovementSpeed(speed, encodeMovementMove(direction));
722
- case "movement_move_for_time":
723
- var _args$time_ms2;
724
- return withMovementSpeed(speed, encodeMovementMoveForTime(Number((_args$time_ms2 = args.time_ms) !== null && _args$time_ms2 !== void 0 ? _args$time_ms2 : 0), direction));
725
- case "movement_move_for_degrees":
726
- var _args$degrees2;
727
- return withMovementSpeed(speed, encodeMovementMoveForDegrees(Number((_args$degrees2 = args.degrees) !== null && _args$degrees2 !== void 0 ? _args$degrees2 : 0), direction));
728
- case "movement_move_tank":
729
- var _args$speed_left, _args$speed_right;
730
- return encodeMovementMoveTank(Number((_args$speed_left = args.speed_left) !== null && _args$speed_left !== void 0 ? _args$speed_left : 0), Number((_args$speed_right = args.speed_right) !== null && _args$speed_right !== void 0 ? _args$speed_right : 0));
731
- case "movement_move_tank_for_degrees":
732
- var _args$degrees3, _args$speed_left2, _args$speed_right2;
733
- return encodeMovementMoveTankForDegrees(Number((_args$degrees3 = args.degrees) !== null && _args$degrees3 !== void 0 ? _args$degrees3 : 0), Number((_args$speed_left2 = args.speed_left) !== null && _args$speed_left2 !== void 0 ? _args$speed_left2 : 50), Number((_args$speed_right2 = args.speed_right) !== null && _args$speed_right2 !== void 0 ? _args$speed_right2 : 50));
734
- case "movement_turn_for_degrees":
735
- var _args$degrees4;
736
- return withMovementSpeed(speed, encodeMovementTurnForDegrees(Number((_args$degrees4 = args.degrees) !== null && _args$degrees4 !== void 0 ? _args$degrees4 : 0), direction || 2));
737
- case "movement_stop": return encodeMovementStop();
738
- case "movement_set_end_state":
739
- var _args$end_state2;
740
- return encodeMovementSetEndState(Number((_args$end_state2 = args.end_state) !== null && _args$end_state2 !== void 0 ? _args$end_state2 : 0));
741
- case "movement_set_acceleration":
742
- var _args$acceleration2, _args$deceleration2;
743
- return encodeMovementSetAcceleration(Number((_args$acceleration2 = args.acceleration) !== null && _args$acceleration2 !== void 0 ? _args$acceleration2 : 0), Number((_args$deceleration2 = args.deceleration) !== null && _args$deceleration2 !== void 0 ? _args$deceleration2 : 0));
744
- case "movement_set_turn_steering":
745
- var _args$steering;
746
- return encodeMovementSetTurnSteering(Number((_args$steering = args.steering) !== null && _args$steering !== void 0 ? _args$steering : 0));
747
- case "imu_set_yaw_face":
748
- var _args$yaw_face;
749
- return encodeImuSetYawFace(Number((_args$yaw_face = args.yaw_face) !== null && _args$yaw_face !== void 0 ? _args$yaw_face : 0));
750
- case "imu_reset_yaw_axis":
751
- var _args$value;
752
- return encodeImuResetYawAxis(Number((_args$value = args.value) !== null && _args$value !== void 0 ? _args$value : 0));
753
- default: throw new Error(`RpcCodec: unsupported method "${method}"`);
754
- }
449
+ function co(o, t = {}) {
450
+ var e, n;
451
+ const r = Number((e = t.motor) !== null && e !== void 0 ? e : 0), i = Number((n = t.direction) !== null && n !== void 0 ? n : 0), s = t.speed !== void 0 ? Number(t.speed) : -1;
452
+ switch (o) {
453
+ case "info_request":
454
+ return Et();
455
+ case "program_flow_notification":
456
+ var c;
457
+ return Lt(Number((c = t.action) !== null && c !== void 0 ? c : 0));
458
+ case "device_notification_request":
459
+ var a;
460
+ return ht(Number((a = t.delay_ms) !== null && a !== void 0 ? a : 100));
461
+ case "light_color":
462
+ var d, v, m;
463
+ return Pt(Number((d = t.color) !== null && d !== void 0 ? d : 0), Number((v = t.pattern) !== null && v !== void 0 ? v : 0), Number((m = t.intensity) !== null && m !== void 0 ? m : 100));
464
+ case "beep":
465
+ var E, O, T;
466
+ return Ft(Number((E = t.pattern) !== null && E !== void 0 ? E : 0), Number((O = t.frequency) !== null && O !== void 0 ? O : 440), Number((T = t.count) !== null && T !== void 0 ? T : 1));
467
+ case "stop_beep":
468
+ return Vt();
469
+ case "motor_set_speed":
470
+ var C;
471
+ return Ot(Number((C = t.speed) !== null && C !== void 0 ? C : 0), r);
472
+ case "motor_run":
473
+ return A(s, r, Bt(i, r));
474
+ case "motor_stop":
475
+ return Gt(r);
476
+ case "motor_run_for_degrees":
477
+ var f;
478
+ return A(s, r, $t(Number((f = t.degrees) !== null && f !== void 0 ? f : 0), i, r));
479
+ case "motor_run_for_time":
480
+ var p;
481
+ return A(s, r, Wt(Number((p = t.time_ms) !== null && p !== void 0 ? p : 0), i, r));
482
+ case "motor_reset_relative_position":
483
+ var S;
484
+ return Ht(Number((S = t.position) !== null && S !== void 0 ? S : 0), r);
485
+ case "motor_run_to_relative_position":
486
+ var M;
487
+ return A(s, r, Yt(Number((M = t.position) !== null && M !== void 0 ? M : 0), r));
488
+ case "motor_run_to_absolute_position":
489
+ var w;
490
+ return A(s, r, xt(Number((w = t.position) !== null && w !== void 0 ? w : 0), i || 2, r));
491
+ case "motor_set_duty_cycle":
492
+ var U;
493
+ return jt(Number((U = t.duty_cycle) !== null && U !== void 0 ? U : 0), r);
494
+ case "motor_set_end_state":
495
+ var D;
496
+ return qt(Number((D = t.end_state) !== null && D !== void 0 ? D : 0), r);
497
+ case "motor_set_acceleration":
498
+ var L, P;
499
+ return Kt(Number((L = t.acceleration) !== null && L !== void 0 ? L : 0), Number((P = t.deceleration) !== null && P !== void 0 ? P : 0), r);
500
+ case "movement_set_speed":
501
+ var F;
502
+ return Tt(Number((F = t.speed) !== null && F !== void 0 ? F : 0));
503
+ case "movement_move":
504
+ return y(s, Zt(i));
505
+ case "movement_move_for_time":
506
+ var V;
507
+ return y(s, Xt(Number((V = t.time_ms) !== null && V !== void 0 ? V : 0), i));
508
+ case "movement_move_for_degrees":
509
+ var B;
510
+ return y(s, zt(Number((B = t.degrees) !== null && B !== void 0 ? B : 0), i));
511
+ case "movement_move_tank":
512
+ var G, $;
513
+ return Jt(Number((G = t.speed_left) !== null && G !== void 0 ? G : 0), Number(($ = t.speed_right) !== null && $ !== void 0 ? $ : 0));
514
+ case "movement_move_tank_for_degrees":
515
+ var W, H, Y;
516
+ return Qt(Number((W = t.degrees) !== null && W !== void 0 ? W : 0), Number((H = t.speed_left) !== null && H !== void 0 ? H : 50), Number((Y = t.speed_right) !== null && Y !== void 0 ? Y : 50));
517
+ case "movement_turn_for_degrees":
518
+ var x;
519
+ return y(s, to(Number((x = t.degrees) !== null && x !== void 0 ? x : 0), i || 2));
520
+ case "movement_stop":
521
+ return oo();
522
+ case "movement_set_end_state":
523
+ var j;
524
+ return eo(Number((j = t.end_state) !== null && j !== void 0 ? j : 0));
525
+ case "movement_set_acceleration":
526
+ var q, K;
527
+ return no(Number((q = t.acceleration) !== null && q !== void 0 ? q : 0), Number((K = t.deceleration) !== null && K !== void 0 ? K : 0));
528
+ case "movement_set_turn_steering":
529
+ var Z;
530
+ return ro(Number((Z = t.steering) !== null && Z !== void 0 ? Z : 0));
531
+ case "imu_set_yaw_face":
532
+ var X;
533
+ return io(Number((X = t.yaw_face) !== null && X !== void 0 ? X : 0));
534
+ case "imu_reset_yaw_axis":
535
+ var z;
536
+ return so(Number((z = t.value) !== null && z !== void 0 ? z : 0));
537
+ default:
538
+ throw new Error(`RpcCodec: unsupported method "${o}"`);
539
+ }
755
540
  }
756
- //#endregion
757
- //#region src/transport/types.ts
758
- /** Encode a high-level command for MockTransport (not the real LEGO RPC wire format). */
759
- function encodeMockCommand(method, args = {}) {
760
- const text = JSON.stringify({
761
- method,
762
- args,
763
- t: Date.now()
764
- });
765
- return new TextEncoder().encode(text);
541
+ function lo(o, t = {}) {
542
+ const e = JSON.stringify({
543
+ method: o,
544
+ args: t,
545
+ t: Date.now()
546
+ });
547
+ return new TextEncoder().encode(e);
766
548
  }
767
- function decodeMockCommand(message) {
768
- var _parsed$args;
769
- const parsed = JSON.parse(new TextDecoder().decode(message));
770
- return {
771
- method: parsed.method,
772
- args: (_parsed$args = parsed.args) !== null && _parsed$args !== void 0 ? _parsed$args : {}
773
- };
549
+ function uo(o) {
550
+ var t;
551
+ const e = JSON.parse(new TextDecoder().decode(o));
552
+ return {
553
+ method: e.method,
554
+ args: (t = e.args) !== null && t !== void 0 ? t : {}
555
+ };
774
556
  }
775
- //#endregion
776
- //#region \0@oxc-project+runtime@0.151.0/helpers/esm/typeof.js
777
- function _typeof(o) {
778
- "@babel/helpers - typeof";
779
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
780
- return typeof o;
781
- } : function(o) {
782
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
783
- }, _typeof(o);
557
+ function I(o) {
558
+ "@babel/helpers - typeof";
559
+ return I = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(t) {
560
+ return typeof t;
561
+ } : function(t) {
562
+ return t && typeof Symbol == "function" && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
563
+ }, I(o);
784
564
  }
785
- //#endregion
786
- //#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPrimitive.js
787
- function toPrimitive(t, r) {
788
- if ("object" != _typeof(t) || !t) return t;
789
- var e = t[Symbol.toPrimitive];
790
- if (void 0 !== e) {
791
- var i = e.call(t, r || "default");
792
- if ("object" != _typeof(i)) return i;
793
- throw new TypeError("@@toPrimitive must return a primitive value.");
794
- }
795
- return ("string" === r ? String : Number)(t);
565
+ function _o(o, t) {
566
+ if (I(o) != "object" || !o) return o;
567
+ var e = o[Symbol.toPrimitive];
568
+ if (e !== void 0) {
569
+ var n = e.call(o, t || "default");
570
+ if (I(n) != "object") return n;
571
+ throw new TypeError("@@toPrimitive must return a primitive value.");
572
+ }
573
+ return (t === "string" ? String : Number)(o);
796
574
  }
797
- //#endregion
798
- //#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPropertyKey.js
799
- function toPropertyKey(t) {
800
- var i = toPrimitive(t, "string");
801
- return "symbol" == _typeof(i) ? i : i + "";
575
+ function vo(o) {
576
+ var t = _o(o, "string");
577
+ return I(t) == "symbol" ? t : t + "";
802
578
  }
803
- //#endregion
804
- //#region \0@oxc-project+runtime@0.151.0/helpers/esm/defineProperty.js
805
- function _defineProperty(e, r, t) {
806
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
807
- value: t,
808
- enumerable: !0,
809
- configurable: !0,
810
- writable: !0
811
- }) : e[r] = t, e;
579
+ function u(o, t, e) {
580
+ return (t = vo(t)) in o ? Object.defineProperty(o, t, {
581
+ value: e,
582
+ enumerable: !0,
583
+ configurable: !0,
584
+ writable: !0
585
+ }) : o[t] = e, o;
812
586
  }
813
- //#endregion
814
- //#region src/transport/mock.ts
815
- var defaultDevices = [
816
- {
817
- id: "mock-single-motor-1",
818
- name: "Mock Single Motor",
819
- kind: "single-motor",
820
- cardColor: 4,
821
- cardSerial: "3683"
822
- },
823
- {
824
- id: "mock-double-motor-1",
825
- name: "Mock Double Motor",
826
- kind: "double-motor",
827
- cardColor: 4,
828
- cardSerial: "3683"
829
- },
830
- {
831
- id: "mock-color-sensor-1",
832
- name: "Mock Color Sensor",
833
- kind: "color-sensor",
834
- cardColor: 4,
835
- cardSerial: "3683"
836
- },
837
- {
838
- id: "mock-controller-1",
839
- name: "Mock Controller",
840
- kind: "controller",
841
- cardColor: 4,
842
- cardSerial: "3683"
843
- }
587
+ var mo = [
588
+ {
589
+ id: "mock-single-motor-1",
590
+ name: "Mock Single Motor",
591
+ kind: "single-motor",
592
+ cardColor: 4,
593
+ cardSerial: "3683"
594
+ },
595
+ {
596
+ id: "mock-double-motor-1",
597
+ name: "Mock Double Motor",
598
+ kind: "double-motor",
599
+ cardColor: 4,
600
+ cardSerial: "3683"
601
+ },
602
+ {
603
+ id: "mock-color-sensor-1",
604
+ name: "Mock Color Sensor",
605
+ kind: "color-sensor",
606
+ cardColor: 4,
607
+ cardSerial: "3683"
608
+ },
609
+ {
610
+ id: "mock-controller-1",
611
+ name: "Mock Controller",
612
+ kind: "controller",
613
+ cardColor: 4,
614
+ cardSerial: "3683"
615
+ }
844
616
  ];
845
- function matchesFilters(device, filters) {
846
- if (!filters) return true;
847
- if (filters.deviceName && device.name !== filters.deviceName) return false;
848
- if (filters.cardColor != null && device.cardColor !== filters.cardColor) return false;
849
- if (filters.cardSerial && device.cardSerial !== filters.cardSerial) return false;
850
- return true;
617
+ function Eo(o, t) {
618
+ return t ? !(t.deviceName && o.name !== t.deviceName || t.cardColor != null && o.cardColor !== t.cardColor || t.cardSerial && o.cardSerial !== t.cardSerial) : !0;
851
619
  }
852
- /**
853
- * In-memory transport for development and demos — no Bluetooth required.
854
- * Command frames use the skeleton's mock JSON encoding (see encodeMockCommand).
855
- */
856
- var MockTransport = class {
857
- constructor(options = {}) {
858
- var _options$autoConnect, _options$verbose, _options$devices;
859
- _defineProperty(this, "name", "mock");
860
- _defineProperty(this, "autoConnect", void 0);
861
- _defineProperty(this, "verbose", void 0);
862
- _defineProperty(this, "catalog", void 0);
863
- _defineProperty(this, "active", /* @__PURE__ */ new Map());
864
- _defineProperty(this, "notificationHandler", void 0);
865
- _defineProperty(
866
- this,
867
- /** Mutable mock sensor / motor state for demos. */
868
- "state",
869
- {
870
- position: 0,
871
- speed: 0,
872
- color: 0,
873
- leftPercent: 0,
874
- rightPercent: 0
875
- }
876
- );
877
- this.autoConnect = (_options$autoConnect = options.autoConnect) !== null && _options$autoConnect !== void 0 ? _options$autoConnect : true;
878
- this.verbose = (_options$verbose = options.verbose) !== null && _options$verbose !== void 0 ? _options$verbose : true;
879
- this.catalog = (_options$devices = options.devices) !== null && _options$devices !== void 0 ? _options$devices : [...defaultDevices];
880
- }
881
- async scan(kind, filters, _timeoutMs = 5e3) {
882
- return this.catalog.filter((d) => d.kind === kind && matchesFilters(d, filters));
883
- }
884
- async connect(kind, filters, handlers) {
885
- this.notificationHandler = handlers === null || handlers === void 0 ? void 0 : handlers.onNotification;
886
- const found = (await this.scan(kind, filters))[0];
887
- if (!found && !this.autoConnect) throw new Error(`MockTransport: no ${kind} matching filters`);
888
- const device = found !== null && found !== void 0 ? found : {
889
- id: `mock-${kind}-auto`,
890
- name: `Mock ${kind}`,
891
- kind,
892
- cardColor: filters === null || filters === void 0 ? void 0 : filters.cardColor,
893
- cardSerial: filters === null || filters === void 0 ? void 0 : filters.cardSerial
894
- };
895
- const connection = {
896
- deviceId: device.id,
897
- kind: device.kind
898
- };
899
- this.active.set(device.id, connection);
900
- this.log(`connected ${device.kind} (${device.id})`);
901
- return connection;
902
- }
903
- async send(connection, message) {
904
- if (!this.active.has(connection.deviceId)) throw new Error(`MockTransport: not connected (${connection.deviceId})`);
905
- const { method, args } = decodeMockCommand(message);
906
- this.log(`send ${method}`, args);
907
- this.applyCommand(method, args);
908
- if (method.startsWith("motor_") || method.startsWith("movement_")) {
909
- var _this$notificationHan;
910
- const note = new TextEncoder().encode(JSON.stringify({
911
- type: "MotorNotification",
912
- position: this.state.position,
913
- speed: this.state.speed
914
- }));
915
- (_this$notificationHan = this.notificationHandler) === null || _this$notificationHan === void 0 || _this$notificationHan.call(this, note);
916
- }
917
- }
918
- async disconnect(connection) {
919
- this.active.delete(connection.deviceId);
920
- this.log(`disconnected ${connection.deviceId}`);
921
- }
922
- async shutdownAll() {
923
- this.active.clear();
924
- this.log("shutdownAll");
925
- }
926
- applyCommand(method, args) {
927
- switch (method) {
928
- case "motor_run":
929
- case "motor_set_speed":
930
- var _args$speed;
931
- this.state.speed = Number((_args$speed = args.speed) !== null && _args$speed !== void 0 ? _args$speed : 0);
932
- break;
933
- case "motor_run_for_degrees":
934
- var _args$degrees, _args$speed2;
935
- this.state.position += Number((_args$degrees = args.degrees) !== null && _args$degrees !== void 0 ? _args$degrees : 0);
936
- this.state.speed = Number((_args$speed2 = args.speed) !== null && _args$speed2 !== void 0 ? _args$speed2 : this.state.speed);
937
- break;
938
- case "motor_run_for_time":
939
- var _args$speed3;
940
- this.state.speed = Number((_args$speed3 = args.speed) !== null && _args$speed3 !== void 0 ? _args$speed3 : this.state.speed);
941
- break;
942
- case "motor_reset_relative_position":
943
- var _args$position;
944
- this.state.position = Number((_args$position = args.position) !== null && _args$position !== void 0 ? _args$position : 0);
945
- break;
946
- case "motor_run_to_relative_position":
947
- case "motor_run_to_absolute_position":
948
- var _args$position2;
949
- this.state.position = Number((_args$position2 = args.position) !== null && _args$position2 !== void 0 ? _args$position2 : 0);
950
- break;
951
- case "motor_stop":
952
- case "movement_stop":
953
- this.state.speed = 0;
954
- break;
955
- case "movement_move_tank":
956
- var _args$speed_left, _args$speed_right;
957
- this.state.speed = (Number((_args$speed_left = args.speed_left) !== null && _args$speed_left !== void 0 ? _args$speed_left : 0) + Number((_args$speed_right = args.speed_right) !== null && _args$speed_right !== void 0 ? _args$speed_right : 0)) / 2;
958
- }
959
- }
960
- log(message, extra) {
961
- if (!this.verbose) return;
962
- if (extra !== void 0) console.log(`[MockTransport] ${message}`, extra);
963
- else console.log(`[MockTransport] ${message}`);
964
- }
965
- };
966
- //#endregion
967
- //#region src/transport/web-bluetooth.ts
968
- /**
969
- * Browser Web Bluetooth transport (Chrome / Edge, HTTPS or localhost).
970
- *
971
- * Connect skeleton: requestDevice(fd02) → GATT → notify → INFO_REQUEST handshake.
972
- * Command encoding uses `encodeRpcCommand` (official-aligned frames).
973
- */
974
- var WebBluetoothTransport = class WebBluetoothTransport {
975
- constructor(options = {}) {
976
- var _options$enforceProdu, _options$rpcVersionMo, _options$defaultTimeo;
977
- _defineProperty(this, "name", "web-bluetooth");
978
- _defineProperty(this, "enforceProductGroup", void 0);
979
- _defineProperty(this, "rpcVersionMode", void 0);
980
- _defineProperty(this, "defaultTimeoutMs", void 0);
981
- _defineProperty(this, "live", /* @__PURE__ */ new Map());
982
- _defineProperty(
983
- this,
984
- /** FIFO waiters per opcode (matches official Python deque). */
985
- "waiters",
986
- /* @__PURE__ */ new Map()
987
- );
988
- this.enforceProductGroup = (_options$enforceProdu = options.enforceProductGroup) !== null && _options$enforceProdu !== void 0 ? _options$enforceProdu : true;
989
- this.rpcVersionMode = (_options$rpcVersionMo = options.rpcVersionMode) !== null && _options$rpcVersionMo !== void 0 ? _options$rpcVersionMo : "warn";
990
- this.defaultTimeoutMs = (_options$defaultTimeo = options.defaultTimeoutMs) !== null && _options$defaultTimeo !== void 0 ? _options$defaultTimeo : 15e3;
991
- }
992
- encodeCommand(method, args = {}) {
993
- return encodeRpcCommand(method, args);
994
- }
995
- async scan(_kind, _filters, _timeoutMs) {
996
- this.assertBrowser();
997
- return [];
998
- }
999
- async connect(kind, _filters, handlers) {
1000
- this.assertBrowser();
1001
- const device = await navigator.bluetooth.requestDevice({
1002
- filters: [{ services: [SERVICE_UUID] }],
1003
- optionalServices: [SERVICE_UUID]
1004
- });
1005
- if (!device.gatt) throw new Error("WebBluetoothTransport: device has no GATT");
1006
- const server = await device.gatt.connect();
1007
- const service = await server.getPrimaryService(SERVICE_UUID);
1008
- const writeChar = await service.getCharacteristic(WRITE_UUID);
1009
- const notifyChar = await service.getCharacteristic(NOTIFY_UUID);
1010
- const live = {
1011
- deviceId: device.id,
1012
- kind,
1013
- device,
1014
- server,
1015
- writeChar,
1016
- notifyChar,
1017
- onNotification: handlers === null || handlers === void 0 ? void 0 : handlers.onNotification,
1018
- onDisconnect: handlers === null || handlers === void 0 ? void 0 : handlers.onDisconnect
1019
- };
1020
- const onGattDisconnected = () => {
1021
- var _handlers$onDisconnec;
1022
- this.live.delete(device.id);
1023
- this.rejectAllWaiters(/* @__PURE__ */ new Error("Device disconnected"));
1024
- handlers === null || handlers === void 0 || (_handlers$onDisconnec = handlers.onDisconnect) === null || _handlers$onDisconnec === void 0 || _handlers$onDisconnec.call(handlers);
1025
- };
1026
- device.addEventListener("gattserverdisconnected", onGattDisconnected);
1027
- const onNotify = (event) => {
1028
- const value = event.target.value;
1029
- if (!value) return;
1030
- const raw = new Uint8Array(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
1031
- for (const payload of splitNotifyFrames(raw)) {
1032
- var _live$onNotification;
1033
- (_live$onNotification = live.onNotification) === null || _live$onNotification === void 0 || _live$onNotification.call(live, payload);
1034
- this.resolveWaiter(payload[0], payload);
1035
- }
1036
- };
1037
- notifyChar.addEventListener("characteristicvaluechanged", onNotify);
1038
- await notifyChar.startNotifications();
1039
- this.live.set(device.id, live);
1040
- const infoWait = this.waitForOpcode(1, 8e3);
1041
- await this.writeRaw(live, encodeInfoRequest());
1042
- const info = decodeInfoResponse(await infoWait);
1043
- live.info = info;
1044
- this.checkRpcVersion(info);
1045
- this.checkProductGroup(kind, info);
1046
- const notifWait = this.waitForOpcode(41, 5e3);
1047
- await this.writeRaw(live, encodeDeviceNotificationRequest(100));
1048
- await notifWait;
1049
- return live;
1050
- }
1051
- async send(connection, message) {
1052
- const live = this.requireLive(connection.deviceId);
1053
- await this.writeRaw(live, message);
1054
- }
1055
- async waitForOpcode(opcode, timeoutMs = this.defaultTimeoutMs) {
1056
- return new Promise((resolve, reject) => {
1057
- var _this$waiters$get;
1058
- const entry = {
1059
- resolve: (payload) => {
1060
- clearTimeout(entry.timer);
1061
- resolve(payload);
1062
- },
1063
- reject: (err) => {
1064
- clearTimeout(entry.timer);
1065
- reject(err);
1066
- },
1067
- timer: setTimeout(() => {
1068
- const q = this.waiters.get(opcode);
1069
- if (q) {
1070
- const idx = q.indexOf(entry);
1071
- if (idx >= 0) q.splice(idx, 1);
1072
- if (q.length === 0) this.waiters.delete(opcode);
1073
- }
1074
- reject(/* @__PURE__ */ new Error(`Timeout waiting for opcode ${opcode}`));
1075
- }, timeoutMs)
1076
- };
1077
- const q = (_this$waiters$get = this.waiters.get(opcode)) !== null && _this$waiters$get !== void 0 ? _this$waiters$get : [];
1078
- q.push(entry);
1079
- this.waiters.set(opcode, q);
1080
- });
1081
- }
1082
- async disconnect(connection) {
1083
- const live = this.live.get(connection.deviceId);
1084
- if (!live) return;
1085
- try {
1086
- await live.notifyChar.stopNotifications().catch(() => void 0);
1087
- } finally {
1088
- var _live$device$gatt;
1089
- (_live$device$gatt = live.device.gatt) === null || _live$device$gatt === void 0 || _live$device$gatt.disconnect();
1090
- this.live.delete(connection.deviceId);
1091
- }
1092
- }
1093
- async shutdownAll() {
1094
- for (const id of [...this.live.keys()]) await this.disconnect({
1095
- deviceId: id,
1096
- kind: "single-motor"
1097
- });
1098
- this.rejectAllWaiters(/* @__PURE__ */ new Error("shutdownAll"));
1099
- }
1100
- /** Last INFO_RESPONSE for a connection (if handshake completed). */
1101
- getInfo(connection) {
1102
- var _this$live$get;
1103
- return (_this$live$get = this.live.get(connection.deviceId)) === null || _this$live$get === void 0 ? void 0 : _this$live$get.info;
1104
- }
1105
- static isSupported() {
1106
- return typeof navigator !== "undefined" && typeof navigator.bluetooth !== "undefined";
1107
- }
1108
- async writeRaw(live, message) {
1109
- const { writeChar } = live;
1110
- const bytes = new Uint8Array(message);
1111
- if (writeChar.writeValueWithoutResponse) await writeChar.writeValueWithoutResponse(bytes);
1112
- else if (writeChar.writeValue) await writeChar.writeValue(bytes);
1113
- else throw new Error("WebBluetoothTransport: characteristic is not writable");
1114
- }
1115
- requireLive(deviceId) {
1116
- const live = this.live.get(deviceId);
1117
- if (!live) throw new Error(`WebBluetoothTransport: not connected (${deviceId})`);
1118
- return live;
1119
- }
1120
- checkRpcVersion(info) {
1121
- if (this.rpcVersionMode === "ignore") return;
1122
- if (info.rpcMajor === RPC_VERSION.major && info.rpcMinor === RPC_VERSION.minor && info.rpcBuild === RPC_VERSION.build) return;
1123
- const msg = `RPC version mismatch: device=${info.rpcMajor}.${info.rpcMinor}.${info.rpcBuild}, expected=${RPC_VERSION.major}.${RPC_VERSION.minor}.${RPC_VERSION.build}. Update firmware via Coding Canvas or adjust client.`;
1124
- if (this.rpcVersionMode === "throw") throw new Error(msg);
1125
- console.warn(`[WebBluetoothTransport] ${msg}`);
1126
- }
1127
- checkProductGroup(kind, info) {
1128
- if (!this.enforceProductGroup) return;
1129
- const want = {
1130
- "single-motor": 512,
1131
- "double-motor": 513,
1132
- "color-sensor": 514,
1133
- controller: 515
1134
- }[kind];
1135
- if (info.productGroupDevice !== want) throw new Error(`Expected ${kind} (productGroupDevice=${want}), got ${info.productGroupDevice}`);
1136
- }
1137
- resolveWaiter(opcode, payload) {
1138
- const q = this.waiters.get(opcode);
1139
- if (!(q === null || q === void 0 ? void 0 : q.length)) return;
1140
- const waiter = q.shift();
1141
- if (q.length === 0) this.waiters.delete(opcode);
1142
- waiter.resolve(payload);
1143
- }
1144
- rejectAllWaiters(err) {
1145
- for (const [, q] of this.waiters) for (const w of q) w.reject(err);
1146
- this.waiters.clear();
1147
- }
1148
- assertBrowser() {
1149
- if (!WebBluetoothTransport.isSupported()) throw new Error("Web Bluetooth is not available (need Chromium + HTTPS/localhost).");
1150
- }
1151
- };
1152
- //#endregion
1153
- //#region src/devices/base.ts
1154
- var defaultTransport;
1155
- function setDefaultTransport(transport) {
1156
- defaultTransport = transport;
620
+ var Wn = class {
621
+ constructor(o = {}) {
622
+ var t, e, n;
623
+ u(this, "name", "mock"), u(this, "autoConnect", void 0), u(this, "verbose", void 0), u(this, "catalog", void 0), u(this, "active", /* @__PURE__ */ new Map()), u(this, "notificationHandler", void 0), u(this, "state", {
624
+ position: 0,
625
+ speed: 0,
626
+ color: 0,
627
+ leftPercent: 0,
628
+ rightPercent: 0
629
+ }), this.autoConnect = (t = o.autoConnect) !== null && t !== void 0 ? t : !0, this.verbose = (e = o.verbose) !== null && e !== void 0 ? e : !0, this.catalog = (n = o.devices) !== null && n !== void 0 ? n : [...mo];
630
+ }
631
+ async scan(o, t, e = 5e3) {
632
+ return this.catalog.filter((n) => n.kind === o && Eo(n, t));
633
+ }
634
+ async connect(o, t, e) {
635
+ this.notificationHandler = e == null ? void 0 : e.onNotification;
636
+ const n = (await this.scan(o, t))[0];
637
+ if (!n && !this.autoConnect) throw new Error(`MockTransport: no ${o} matching filters`);
638
+ const r = n != null ? n : {
639
+ id: `mock-${o}-auto`,
640
+ name: `Mock ${o}`,
641
+ kind: o,
642
+ cardColor: t == null ? void 0 : t.cardColor,
643
+ cardSerial: t == null ? void 0 : t.cardSerial
644
+ }, i = {
645
+ deviceId: r.id,
646
+ kind: r.kind
647
+ };
648
+ return this.active.set(r.id, i), this.log(`connected ${r.kind} (${r.id})`), i;
649
+ }
650
+ async send(o, t) {
651
+ if (!this.active.has(o.deviceId)) throw new Error(`MockTransport: not connected (${o.deviceId})`);
652
+ const { method: e, args: n } = uo(t);
653
+ if (this.log(`send ${e}`, n), this.applyCommand(e, n), e.startsWith("motor_") || e.startsWith("movement_")) {
654
+ var r;
655
+ const i = new TextEncoder().encode(JSON.stringify({
656
+ type: "MotorNotification",
657
+ position: this.state.position,
658
+ speed: this.state.speed
659
+ }));
660
+ (r = this.notificationHandler) === null || r === void 0 || r.call(this, i);
661
+ }
662
+ }
663
+ async disconnect(o) {
664
+ this.active.delete(o.deviceId), this.log(`disconnected ${o.deviceId}`);
665
+ }
666
+ async shutdownAll() {
667
+ this.active.clear(), this.log("shutdownAll");
668
+ }
669
+ applyCommand(o, t) {
670
+ switch (o) {
671
+ case "motor_run":
672
+ case "motor_set_speed":
673
+ var e;
674
+ this.state.speed = Number((e = t.speed) !== null && e !== void 0 ? e : 0);
675
+ break;
676
+ case "motor_run_for_degrees":
677
+ var n, r;
678
+ this.state.position += Number((n = t.degrees) !== null && n !== void 0 ? n : 0), this.state.speed = Number((r = t.speed) !== null && r !== void 0 ? r : this.state.speed);
679
+ break;
680
+ case "motor_run_for_time":
681
+ var i;
682
+ this.state.speed = Number((i = t.speed) !== null && i !== void 0 ? i : this.state.speed);
683
+ break;
684
+ case "motor_reset_relative_position":
685
+ var s;
686
+ this.state.position = Number((s = t.position) !== null && s !== void 0 ? s : 0);
687
+ break;
688
+ case "motor_run_to_relative_position":
689
+ case "motor_run_to_absolute_position":
690
+ var c;
691
+ this.state.position = Number((c = t.position) !== null && c !== void 0 ? c : 0);
692
+ break;
693
+ case "motor_stop":
694
+ case "movement_stop":
695
+ this.state.speed = 0;
696
+ break;
697
+ case "movement_move_tank":
698
+ var a, d;
699
+ this.state.speed = (Number((a = t.speed_left) !== null && a !== void 0 ? a : 0) + Number((d = t.speed_right) !== null && d !== void 0 ? d : 0)) / 2;
700
+ }
701
+ }
702
+ log(o, t) {
703
+ this.verbose && (t !== void 0 ? console.log(`[MockTransport] ${o}`, t) : console.log(`[MockTransport] ${o}`));
704
+ }
705
+ }, Hn = class ft {
706
+ constructor(t = {}) {
707
+ var e, n, r;
708
+ u(this, "name", "web-bluetooth"), u(this, "enforceProductGroup", void 0), u(this, "rpcVersionMode", void 0), u(this, "defaultTimeoutMs", void 0), u(this, "live", /* @__PURE__ */ new Map()), u(this, "waiters", /* @__PURE__ */ new Map()), this.enforceProductGroup = (e = t.enforceProductGroup) !== null && e !== void 0 ? e : !0, this.rpcVersionMode = (n = t.rpcVersionMode) !== null && n !== void 0 ? n : "warn", this.defaultTimeoutMs = (r = t.defaultTimeoutMs) !== null && r !== void 0 ? r : 15e3;
709
+ }
710
+ encodeCommand(t, e = {}) {
711
+ return co(t, e);
712
+ }
713
+ async scan(t, e, n) {
714
+ return this.assertBrowser(), [];
715
+ }
716
+ async connect(t, e, n) {
717
+ this.assertBrowser();
718
+ const r = await navigator.bluetooth.requestDevice({
719
+ filters: [{ services: [J] }],
720
+ optionalServices: [J]
721
+ });
722
+ if (!r.gatt) throw new Error("WebBluetoothTransport: device has no GATT");
723
+ const i = await r.gatt.connect(), s = await i.getPrimaryService(J), c = await s.getCharacteristic(Nt), a = await s.getCharacteristic(Rt), d = {
724
+ deviceId: r.id,
725
+ kind: t,
726
+ device: r,
727
+ server: i,
728
+ writeChar: c,
729
+ notifyChar: a,
730
+ onNotification: n == null ? void 0 : n.onNotification,
731
+ onDisconnect: n == null ? void 0 : n.onDisconnect
732
+ }, v = () => {
733
+ var f;
734
+ this.live.delete(r.id), this.rejectAllWaiters(/* @__PURE__ */ new Error("Device disconnected")), n == null || (f = n.onDisconnect) === null || f === void 0 || f.call(n), console.log("注销方法!"), r.removeEventListener("gattserverdisconnected", v);
735
+ };
736
+ r.addEventListener("gattserverdisconnected", v);
737
+ const m = (f) => {
738
+ const p = f.target.value;
739
+ if (!p) return;
740
+ const S = new Uint8Array(p.buffer.slice(p.byteOffset, p.byteOffset + p.byteLength));
741
+ for (const w of kt(S)) {
742
+ var M;
743
+ (M = d.onNotification) === null || M === void 0 || M.call(d, w), this.resolveWaiter(w[0], w);
744
+ }
745
+ };
746
+ a.addEventListener("characteristicvaluechanged", m), await a.startNotifications(), this.live.set(r.id, d);
747
+ const E = this.waitForOpcode(1, 8e3);
748
+ await this.writeRaw(d, Et());
749
+ const O = await E, T = ao(O);
750
+ d.info = T, this.checkRpcVersion(T), this.checkProductGroup(t, T);
751
+ const C = this.waitForOpcode(41, 5e3);
752
+ return await this.writeRaw(d, ht(100)), await C, d;
753
+ }
754
+ async send(t, e) {
755
+ const n = this.requireLive(t.deviceId);
756
+ await this.writeRaw(n, e);
757
+ }
758
+ async waitForOpcode(t, e = this.defaultTimeoutMs) {
759
+ return new Promise((n, r) => {
760
+ var i;
761
+ const s = {
762
+ resolve: (a) => {
763
+ clearTimeout(s.timer), n(a);
764
+ },
765
+ reject: (a) => {
766
+ clearTimeout(s.timer), r(a);
767
+ },
768
+ timer: setTimeout(() => {
769
+ const a = this.waiters.get(t);
770
+ if (a) {
771
+ const d = a.indexOf(s);
772
+ d >= 0 && a.splice(d, 1), a.length === 0 && this.waiters.delete(t);
773
+ }
774
+ r(/* @__PURE__ */ new Error(`Timeout waiting for opcode ${t}`));
775
+ }, e)
776
+ }, c = (i = this.waiters.get(t)) !== null && i !== void 0 ? i : [];
777
+ c.push(s), this.waiters.set(t, c);
778
+ });
779
+ }
780
+ async disconnect(t) {
781
+ const e = this.live.get(t.deviceId);
782
+ if (e)
783
+ try {
784
+ await e.notifyChar.stopNotifications().catch(() => {
785
+ });
786
+ } finally {
787
+ var n;
788
+ (n = e.device.gatt) === null || n === void 0 || n.disconnect(), this.live.delete(t.deviceId);
789
+ }
790
+ }
791
+ async shutdownAll() {
792
+ for (const t of [...this.live.keys()]) await this.disconnect({
793
+ deviceId: t,
794
+ kind: "single-motor"
795
+ });
796
+ this.rejectAllWaiters(/* @__PURE__ */ new Error("shutdownAll"));
797
+ }
798
+ getInfo(t) {
799
+ var e;
800
+ return (e = this.live.get(t.deviceId)) === null || e === void 0 ? void 0 : e.info;
801
+ }
802
+ static isSupported() {
803
+ return typeof navigator != "undefined" && typeof navigator.bluetooth != "undefined";
804
+ }
805
+ async writeRaw(t, e) {
806
+ const { writeChar: n } = t, r = new Uint8Array(e);
807
+ if (n.writeValueWithoutResponse) await n.writeValueWithoutResponse(r);
808
+ else if (n.writeValue) await n.writeValue(r);
809
+ else throw new Error("WebBluetoothTransport: characteristic is not writable");
810
+ }
811
+ requireLive(t) {
812
+ const e = this.live.get(t);
813
+ if (!e) throw new Error(`WebBluetoothTransport: not connected (${t})`);
814
+ return e;
815
+ }
816
+ checkRpcVersion(t) {
817
+ if (this.rpcVersionMode === "ignore" || t.rpcMajor === N.major && t.rpcMinor === N.minor && t.rpcBuild === N.build) return;
818
+ const e = `RPC version mismatch: device=${t.rpcMajor}.${t.rpcMinor}.${t.rpcBuild}, expected=${N.major}.${N.minor}.${N.build}. Update firmware via Coding Canvas or adjust client.`;
819
+ if (this.rpcVersionMode === "throw") throw new Error(e);
820
+ console.warn(`[WebBluetoothTransport] ${e}`);
821
+ }
822
+ checkProductGroup(t, e) {
823
+ if (!this.enforceProductGroup) return;
824
+ const n = {
825
+ "single-motor": 512,
826
+ "double-motor": 513,
827
+ "color-sensor": 514,
828
+ controller: 515
829
+ }[t];
830
+ if (e.productGroupDevice !== n) throw new Error(`Expected ${t} (productGroupDevice=${n}), got ${e.productGroupDevice}`);
831
+ }
832
+ resolveWaiter(t, e) {
833
+ const n = this.waiters.get(t);
834
+ if (!(n != null && n.length)) return;
835
+ const r = n.shift();
836
+ n.length === 0 && this.waiters.delete(t), r.resolve(e);
837
+ }
838
+ rejectAllWaiters(t) {
839
+ for (const [, e] of this.waiters) for (const n of e) n.reject(t);
840
+ this.waiters.clear();
841
+ }
842
+ assertBrowser() {
843
+ if (!ft.isSupported()) throw new Error("Web Bluetooth is not available (need Chromium + HTTPS/localhost).");
844
+ }
845
+ }, ot;
846
+ function Yn(o) {
847
+ ot = o;
1157
848
  }
1158
- function getDefaultTransport() {
1159
- return defaultTransport;
849
+ function xn() {
850
+ return ot;
1160
851
  }
1161
- function concatFrames(frames) {
1162
- const total = frames.reduce((n, f) => n + f.length, 0);
1163
- const out = new Uint8Array(total);
1164
- let o = 0;
1165
- for (const f of frames) {
1166
- out.set(f, o);
1167
- o += f.length;
1168
- }
1169
- return out;
852
+ function ho(o) {
853
+ const t = o.reduce((r, i) => r + i.length, 0), e = new Uint8Array(t);
854
+ let n = 0;
855
+ for (const r of o)
856
+ e.set(r, n), n += r.length;
857
+ return e;
1170
858
  }
1171
- /**
1172
- * Shared connect / disconnect / send plumbing for all hardware classes.
1173
- */
1174
- var DeviceBase = class {
1175
- get connected() {
1176
- return this.connection !== null;
1177
- }
1178
- get deviceId() {
1179
- var _this$connection$devi, _this$connection;
1180
- return (_this$connection$devi = (_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.deviceId) !== null && _this$connection$devi !== void 0 ? _this$connection$devi : null;
1181
- }
1182
- constructor(options = {}) {
1183
- var _options$transport;
1184
- _defineProperty(this, "transport", void 0);
1185
- _defineProperty(this, "connection", null);
1186
- _defineProperty(this, "notificationCallback", null);
1187
- _defineProperty(this, "batchBuffer", null);
1188
- const transport = (_options$transport = options.transport) !== null && _options$transport !== void 0 ? _options$transport : defaultTransport;
1189
- if (!transport) throw new Error(`${this.constructor.name}: pass { transport } or call setDefaultTransport(...) first`);
1190
- this.transport = transport;
1191
- }
1192
- async connect(filters = {}, _options) {
1193
- this.connection = await this.transport.connect(this.kind, filters, {
1194
- onNotification: (payload) => {
1195
- var _this$notificationCal;
1196
- this.applyNotification(payload);
1197
- (_this$notificationCal = this.notificationCallback) === null || _this$notificationCal === void 0 || _this$notificationCal.call(this, payload);
1198
- },
1199
- onDisconnect: () => {
1200
- this.connection = null;
1201
- if (_options && _options.onDisconnect && typeof _options.onDisconnect === "function") _options.onDisconnect();
1202
- }
1203
- });
1204
- await this.programFlowNotification(0, { blocking: false });
1205
- }
1206
- applyNotification(_payload) {}
1207
- async disconnect() {
1208
- if (!this.connection) return;
1209
- await this.transport.disconnect(this.connection);
1210
- this.connection = null;
1211
- }
1212
- setNotificationCallback(callback) {
1213
- this.notificationCallback = callback;
1214
- }
1215
- async search(filters, timeoutMs = 5e3) {
1216
- return this.transport.scan(this.kind, filters, timeoutMs);
1217
- }
1218
- /** Python: `light_color(color, ...)` */
1219
- async lightColor(color, options = {}) {
1220
- var _options$pattern, _options$intensity, _options$blocking;
1221
- await this.sendCommand("light_color", {
1222
- color,
1223
- pattern: (_options$pattern = options.pattern) !== null && _options$pattern !== void 0 ? _options$pattern : 0,
1224
- intensity: (_options$intensity = options.intensity) !== null && _options$intensity !== void 0 ? _options$intensity : 100,
1225
- blocking: (_options$blocking = options.blocking) !== null && _options$blocking !== void 0 ? _options$blocking : true
1226
- });
1227
- }
1228
- /** Python: `beep(...)` */
1229
- async beep(options = {}) {
1230
- var _options$pattern2, _options$frequency, _options$count, _options$blocking2;
1231
- await this.sendCommand("beep", {
1232
- pattern: (_options$pattern2 = options.pattern) !== null && _options$pattern2 !== void 0 ? _options$pattern2 : 0,
1233
- frequency: (_options$frequency = options.frequency) !== null && _options$frequency !== void 0 ? _options$frequency : 440,
1234
- count: (_options$count = options.count) !== null && _options$count !== void 0 ? _options$count : 1,
1235
- blocking: (_options$blocking2 = options.blocking) !== null && _options$blocking2 !== void 0 ? _options$blocking2 : true
1236
- });
1237
- }
1238
- /** Python: `stop_beep(...)` */
1239
- async stopBeep(options = {}) {
1240
- var _options$blocking3;
1241
- await this.sendCommand("stop_beep", { blocking: (_options$blocking3 = options.blocking) !== null && _options$blocking3 !== void 0 ? _options$blocking3 : true });
1242
- }
1243
- /** Python: `program_flow_notification(action, ...)` */
1244
- async programFlowNotification(action, options = {}) {
1245
- var _options$blocking4;
1246
- await this.sendCommand("program_flow_notification", {
1247
- action,
1248
- blocking: (_options$blocking4 = options.blocking) !== null && _options$blocking4 !== void 0 ? _options$blocking4 : false
1249
- });
1250
- }
1251
- /** Python: `device_notification_request(delay_ms, ...)` */
1252
- async deviceNotificationRequest(delayMs, options = {}) {
1253
- var _options$blocking5;
1254
- await this.sendCommand("device_notification_request", {
1255
- delay_ms: delayMs,
1256
- blocking: (_options$blocking5 = options.blocking) !== null && _options$blocking5 !== void 0 ? _options$blocking5 : true
1257
- });
1258
- }
1259
- /** Python: `begin_batch()` — client-side queue (motor commands only). */
1260
- beginBatch() {
1261
- this.batchBuffer = [];
1262
- }
1263
- /** Python: `end_batch()` — flush queued frames in one BLE write. */
1264
- async endBatch(options = {}) {
1265
- if (!this.batchBuffer) return;
1266
- if (!this.connection) {
1267
- this.batchBuffer = null;
1268
- throw new Error(`${this.constructor.name}: not connected`);
1269
- }
1270
- const frames = this.batchBuffer;
1271
- this.batchBuffer = null;
1272
- if (frames.length === 0) return;
1273
- await this.transport.send(this.connection, concatFrames(frames));
1274
- }
1275
- /** Python: `cancel_batch()` */
1276
- cancelBatch() {
1277
- var _this$batchBuffer$len, _this$batchBuffer;
1278
- const n = (_this$batchBuffer$len = (_this$batchBuffer = this.batchBuffer) === null || _this$batchBuffer === void 0 ? void 0 : _this$batchBuffer.length) !== null && _this$batchBuffer$len !== void 0 ? _this$batchBuffer$len : 0;
1279
- this.batchBuffer = null;
1280
- return n;
1281
- }
1282
- async sendCommand(method, args = {}) {
1283
- var _this$transport$encod, _this$transport$encod2, _this$transport;
1284
- if (!this.connection) throw new Error(`${this.constructor.name}: not connected`);
1285
- if (this.batchBuffer && method.startsWith("movement_")) throw new Error("Movement commands cannot be called inside a batch. Use motor_* commands instead.");
1286
- const blocking = args.blocking !== false;
1287
- const frame = (_this$transport$encod = (_this$transport$encod2 = (_this$transport = this.transport).encodeCommand) === null || _this$transport$encod2 === void 0 ? void 0 : _this$transport$encod2.call(_this$transport, method, args)) !== null && _this$transport$encod !== void 0 ? _this$transport$encod : encodeMockCommand(method, args);
1288
- if (this.batchBuffer) {
1289
- this.batchBuffer.push(frame);
1290
- return;
1291
- }
1292
- const resultOpcode = resultOpcodeForMethod(method);
1293
- const waitForOpcode = this.transport.waitForOpcode;
1294
- let waitPromise;
1295
- if (blocking && resultOpcode != null && waitForOpcode) {
1296
- var _args$degrees, _args$time_ms;
1297
- const degrees = Number((_args$degrees = args.degrees) !== null && _args$degrees !== void 0 ? _args$degrees : 0);
1298
- const timeMs = Number((_args$time_ms = args.time_ms) !== null && _args$time_ms !== void 0 ? _args$time_ms : 0);
1299
- const timeoutMs = method === "light_color" || method === "beep" || method === "stop_beep" || method === "device_notification_request" ? 5e3 : Math.max(15e3, Math.abs(degrees) * 50 + 5e3, timeMs + 5e3);
1300
- waitPromise = waitForOpcode.call(this.transport, resultOpcode, timeoutMs);
1301
- }
1302
- await this.transport.send(this.connection, frame);
1303
- if (waitPromise) await waitPromise;
1304
- }
1305
- };
1306
- //#endregion
1307
- //#region src/devices/single-motor.ts
1308
- /** Python: `le.SingleMotor()` */
1309
- var SingleMotor = class extends DeviceBase {
1310
- constructor(options = {}) {
1311
- super(options);
1312
- _defineProperty(this, "kind", "single-motor");
1313
- _defineProperty(this, "motor", {
1314
- position: 0,
1315
- speed: 0
1316
- });
1317
- }
1318
- applyNotification(payload) {
1319
- const { motors } = parseDeviceNotifications(payload);
1320
- for (const reading of motors) {
1321
- this.motor.position = reading.position;
1322
- this.motor.speed = reading.speed;
1323
- this.motor.absolutePosition = reading.absolutePosition;
1324
- this.motor.motorState = reading.motorState;
1325
- this.motor.power = reading.power;
1326
- this.motor.gesture = reading.gesture;
1327
- }
1328
- }
1329
- get useCommandSideEstimates() {
1330
- return this.transport.name === "mock";
1331
- }
1332
- async motorSetSpeed(speed, options = {}) {
1333
- var _options$motor, _options$blocking;
1334
- await this.sendCommand("motor_set_speed", {
1335
- speed,
1336
- motor: (_options$motor = options.motor) !== null && _options$motor !== void 0 ? _options$motor : 0,
1337
- blocking: (_options$blocking = options.blocking) !== null && _options$blocking !== void 0 ? _options$blocking : true
1338
- });
1339
- if (this.useCommandSideEstimates) this.motor.speed = speed;
1340
- }
1341
- async motorRun(options = {}) {
1342
- var _options$speed, _options$direction, _options$motor2, _options$blocking2;
1343
- const speed = (_options$speed = options.speed) !== null && _options$speed !== void 0 ? _options$speed : -1;
1344
- await this.sendCommand("motor_run", {
1345
- direction: (_options$direction = options.direction) !== null && _options$direction !== void 0 ? _options$direction : 0,
1346
- motor: (_options$motor2 = options.motor) !== null && _options$motor2 !== void 0 ? _options$motor2 : 0,
1347
- speed,
1348
- blocking: (_options$blocking2 = options.blocking) !== null && _options$blocking2 !== void 0 ? _options$blocking2 : true
1349
- });
1350
- if (this.useCommandSideEstimates && speed !== -1) this.motor.speed = speed;
1351
- }
1352
- async motorRunForTime(timeMs, options = {}) {
1353
- var _options$direction2, _options$motor3, _options$speed2, _options$blocking3;
1354
- await this.sendCommand("motor_run_for_time", {
1355
- time_ms: timeMs,
1356
- direction: (_options$direction2 = options.direction) !== null && _options$direction2 !== void 0 ? _options$direction2 : 0,
1357
- motor: (_options$motor3 = options.motor) !== null && _options$motor3 !== void 0 ? _options$motor3 : 0,
1358
- speed: (_options$speed2 = options.speed) !== null && _options$speed2 !== void 0 ? _options$speed2 : -1,
1359
- blocking: (_options$blocking3 = options.blocking) !== null && _options$blocking3 !== void 0 ? _options$blocking3 : true
1360
- });
1361
- }
1362
- async motorRunForDegrees(degrees, options = {}) {
1363
- var _options$direction3, _options$motor4, _options$speed3, _options$blocking4;
1364
- await this.sendCommand("motor_run_for_degrees", {
1365
- degrees,
1366
- direction: (_options$direction3 = options.direction) !== null && _options$direction3 !== void 0 ? _options$direction3 : 0,
1367
- motor: (_options$motor4 = options.motor) !== null && _options$motor4 !== void 0 ? _options$motor4 : 0,
1368
- speed: (_options$speed3 = options.speed) !== null && _options$speed3 !== void 0 ? _options$speed3 : -1,
1369
- blocking: (_options$blocking4 = options.blocking) !== null && _options$blocking4 !== void 0 ? _options$blocking4 : true
1370
- });
1371
- if (this.useCommandSideEstimates) this.motor.position += degrees;
1372
- }
1373
- async motorResetRelativePosition(options = {}) {
1374
- var _options$position, _options$motor5, _options$blocking5;
1375
- const position = (_options$position = options.position) !== null && _options$position !== void 0 ? _options$position : 0;
1376
- await this.sendCommand("motor_reset_relative_position", {
1377
- motor: (_options$motor5 = options.motor) !== null && _options$motor5 !== void 0 ? _options$motor5 : 0,
1378
- position,
1379
- blocking: (_options$blocking5 = options.blocking) !== null && _options$blocking5 !== void 0 ? _options$blocking5 : true
1380
- });
1381
- if (this.useCommandSideEstimates) this.motor.position = position;
1382
- }
1383
- async motorRunToRelativePosition(position, options = {}) {
1384
- var _options$motor6, _options$speed4, _options$blocking6;
1385
- await this.sendCommand("motor_run_to_relative_position", {
1386
- position,
1387
- motor: (_options$motor6 = options.motor) !== null && _options$motor6 !== void 0 ? _options$motor6 : 0,
1388
- speed: (_options$speed4 = options.speed) !== null && _options$speed4 !== void 0 ? _options$speed4 : -1,
1389
- blocking: (_options$blocking6 = options.blocking) !== null && _options$blocking6 !== void 0 ? _options$blocking6 : true
1390
- });
1391
- if (this.useCommandSideEstimates) this.motor.position = position;
1392
- }
1393
- async motorRunToAbsolutePosition(position, options = {}) {
1394
- var _options$direction4, _options$motor7, _options$speed5, _options$blocking7;
1395
- await this.sendCommand("motor_run_to_absolute_position", {
1396
- position,
1397
- direction: (_options$direction4 = options.direction) !== null && _options$direction4 !== void 0 ? _options$direction4 : 2,
1398
- motor: (_options$motor7 = options.motor) !== null && _options$motor7 !== void 0 ? _options$motor7 : 0,
1399
- speed: (_options$speed5 = options.speed) !== null && _options$speed5 !== void 0 ? _options$speed5 : -1,
1400
- blocking: (_options$blocking7 = options.blocking) !== null && _options$blocking7 !== void 0 ? _options$blocking7 : true
1401
- });
1402
- if (this.useCommandSideEstimates) this.motor.position = position;
1403
- }
1404
- async motorSetDutyCycle(dutyCycle, options = {}) {
1405
- var _options$motor8, _options$blocking8;
1406
- await this.sendCommand("motor_set_duty_cycle", {
1407
- duty_cycle: dutyCycle,
1408
- motor: (_options$motor8 = options.motor) !== null && _options$motor8 !== void 0 ? _options$motor8 : 0,
1409
- blocking: (_options$blocking8 = options.blocking) !== null && _options$blocking8 !== void 0 ? _options$blocking8 : true
1410
- });
1411
- }
1412
- async motorStop(options = {}) {
1413
- var _options$motor9, _options$blocking9;
1414
- await this.sendCommand("motor_stop", {
1415
- motor: (_options$motor9 = options.motor) !== null && _options$motor9 !== void 0 ? _options$motor9 : 0,
1416
- blocking: (_options$blocking9 = options.blocking) !== null && _options$blocking9 !== void 0 ? _options$blocking9 : true
1417
- });
1418
- if (this.useCommandSideEstimates) this.motor.speed = 0;
1419
- }
1420
- async motorSetEndState(endState, options = {}) {
1421
- var _options$motor10, _options$blocking10;
1422
- await this.sendCommand("motor_set_end_state", {
1423
- end_state: endState,
1424
- motor: (_options$motor10 = options.motor) !== null && _options$motor10 !== void 0 ? _options$motor10 : 0,
1425
- blocking: (_options$blocking10 = options.blocking) !== null && _options$blocking10 !== void 0 ? _options$blocking10 : true
1426
- });
1427
- }
1428
- async motorSetAcceleration(acceleration, deceleration, options = {}) {
1429
- var _options$motor11, _options$blocking11;
1430
- await this.sendCommand("motor_set_acceleration", {
1431
- acceleration,
1432
- deceleration,
1433
- motor: (_options$motor11 = options.motor) !== null && _options$motor11 !== void 0 ? _options$motor11 : 0,
1434
- blocking: (_options$blocking11 = options.blocking) !== null && _options$blocking11 !== void 0 ? _options$blocking11 : true
1435
- });
1436
- }
1437
- };
1438
- //#endregion
1439
- //#region src/devices/double-motor.ts
1440
- /** Python: `le.DoubleMotor()` */
1441
- var DoubleMotor = class extends DeviceBase {
1442
- constructor(options = {}) {
1443
- super(options);
1444
- _defineProperty(this, "kind", "double-motor");
1445
- _defineProperty(this, "motor", {
1446
- [0]: {
1447
- position: 0,
1448
- speed: 0
1449
- },
1450
- [1]: {
1451
- position: 0,
1452
- speed: 0
1453
- }
1454
- });
1455
- _defineProperty(this, "imu", {
1456
- orientation: 0,
1457
- yawFace: 0,
1458
- yaw: 0,
1459
- pitch: 0,
1460
- roll: 0,
1461
- accelerometerX: 0,
1462
- accelerometerY: 0,
1463
- accelerometerZ: 0,
1464
- gyroscopeX: 0,
1465
- gyroscopeY: 0,
1466
- gyroscopeZ: 0
1467
- });
1468
- }
1469
- applyNotification(payload) {
1470
- const parsed = parseDeviceNotifications(payload);
1471
- for (const reading of parsed.motors) {
1472
- const sides = [];
1473
- if (reading.motorBitMask & 1) sides.push(0);
1474
- if (reading.motorBitMask & 2) sides.push(1);
1475
- for (const side of sides) {
1476
- this.motor[side].position = reading.position;
1477
- this.motor[side].speed = reading.speed;
1478
- this.motor[side].absolutePosition = reading.absolutePosition;
1479
- this.motor[side].motorState = reading.motorState;
1480
- this.motor[side].power = reading.power;
1481
- this.motor[side].gesture = reading.gesture;
1482
- }
1483
- }
1484
- if (parsed.imu) Object.assign(this.imu, parsed.imu);
1485
- if (parsed.imuGesture !== void 0) this.imu.gesture = parsed.imuGesture;
1486
- }
1487
- get useCommandSideEstimates() {
1488
- return this.transport.name === "mock";
1489
- }
1490
- async motorSetSpeed(speed, options = {}) {
1491
- var _options$motor, _options$blocking;
1492
- const motor = (_options$motor = options.motor) !== null && _options$motor !== void 0 ? _options$motor : 2;
1493
- await this.sendCommand("motor_set_speed", {
1494
- speed,
1495
- motor,
1496
- blocking: (_options$blocking = options.blocking) !== null && _options$blocking !== void 0 ? _options$blocking : true
1497
- });
1498
- if (this.useCommandSideEstimates) this.touchMotor(motor, { speed });
1499
- }
1500
- async motorRun(options = {}) {
1501
- var _options$motor2, _options$speed, _options$direction, _options$blocking2;
1502
- const motor = (_options$motor2 = options.motor) !== null && _options$motor2 !== void 0 ? _options$motor2 : 2;
1503
- const speed = (_options$speed = options.speed) !== null && _options$speed !== void 0 ? _options$speed : -1;
1504
- await this.sendCommand("motor_run", {
1505
- direction: (_options$direction = options.direction) !== null && _options$direction !== void 0 ? _options$direction : 0,
1506
- motor,
1507
- speed,
1508
- blocking: (_options$blocking2 = options.blocking) !== null && _options$blocking2 !== void 0 ? _options$blocking2 : true
1509
- });
1510
- if (this.useCommandSideEstimates && speed !== -1) this.touchMotor(motor, { speed });
1511
- }
1512
- async motorRunForTime(timeMs, options = {}) {
1513
- var _options$direction2, _options$motor3, _options$speed2, _options$blocking3;
1514
- await this.sendCommand("motor_run_for_time", {
1515
- time_ms: timeMs,
1516
- direction: (_options$direction2 = options.direction) !== null && _options$direction2 !== void 0 ? _options$direction2 : 0,
1517
- motor: (_options$motor3 = options.motor) !== null && _options$motor3 !== void 0 ? _options$motor3 : 2,
1518
- speed: (_options$speed2 = options.speed) !== null && _options$speed2 !== void 0 ? _options$speed2 : -1,
1519
- blocking: (_options$blocking3 = options.blocking) !== null && _options$blocking3 !== void 0 ? _options$blocking3 : true
1520
- });
1521
- }
1522
- async motorRunForDegrees(degrees, options = {}) {
1523
- var _options$motor4, _options$direction3, _options$speed3, _options$blocking4;
1524
- const motor = (_options$motor4 = options.motor) !== null && _options$motor4 !== void 0 ? _options$motor4 : 2;
1525
- await this.sendCommand("motor_run_for_degrees", {
1526
- degrees,
1527
- direction: (_options$direction3 = options.direction) !== null && _options$direction3 !== void 0 ? _options$direction3 : 0,
1528
- motor,
1529
- speed: (_options$speed3 = options.speed) !== null && _options$speed3 !== void 0 ? _options$speed3 : -1,
1530
- blocking: (_options$blocking4 = options.blocking) !== null && _options$blocking4 !== void 0 ? _options$blocking4 : true
1531
- });
1532
- if (this.useCommandSideEstimates) this.touchMotor(motor, { positionDelta: degrees });
1533
- }
1534
- async motorResetRelativePosition(options = {}) {
1535
- var _options$position, _options$motor5, _options$blocking5;
1536
- const position = (_options$position = options.position) !== null && _options$position !== void 0 ? _options$position : 0;
1537
- const motor = (_options$motor5 = options.motor) !== null && _options$motor5 !== void 0 ? _options$motor5 : 2;
1538
- await this.sendCommand("motor_reset_relative_position", {
1539
- motor,
1540
- position,
1541
- blocking: (_options$blocking5 = options.blocking) !== null && _options$blocking5 !== void 0 ? _options$blocking5 : true
1542
- });
1543
- if (this.useCommandSideEstimates) this.touchMotor(motor, { position });
1544
- }
1545
- async motorRunToRelativePosition(position, options = {}) {
1546
- var _options$motor6, _options$speed4, _options$blocking6;
1547
- const motor = (_options$motor6 = options.motor) !== null && _options$motor6 !== void 0 ? _options$motor6 : 2;
1548
- await this.sendCommand("motor_run_to_relative_position", {
1549
- position,
1550
- motor,
1551
- speed: (_options$speed4 = options.speed) !== null && _options$speed4 !== void 0 ? _options$speed4 : -1,
1552
- blocking: (_options$blocking6 = options.blocking) !== null && _options$blocking6 !== void 0 ? _options$blocking6 : true
1553
- });
1554
- if (this.useCommandSideEstimates) this.touchMotor(motor, { position });
1555
- }
1556
- async motorRunToAbsolutePosition(position, options = {}) {
1557
- var _options$direction4, _options$motor7, _options$speed5, _options$blocking7;
1558
- await this.sendCommand("motor_run_to_absolute_position", {
1559
- position,
1560
- direction: (_options$direction4 = options.direction) !== null && _options$direction4 !== void 0 ? _options$direction4 : 2,
1561
- motor: (_options$motor7 = options.motor) !== null && _options$motor7 !== void 0 ? _options$motor7 : 2,
1562
- speed: (_options$speed5 = options.speed) !== null && _options$speed5 !== void 0 ? _options$speed5 : -1,
1563
- blocking: (_options$blocking7 = options.blocking) !== null && _options$blocking7 !== void 0 ? _options$blocking7 : true
1564
- });
1565
- }
1566
- async motorSetDutyCycle(dutyCycle, options = {}) {
1567
- var _options$motor8, _options$blocking8;
1568
- await this.sendCommand("motor_set_duty_cycle", {
1569
- duty_cycle: dutyCycle,
1570
- motor: (_options$motor8 = options.motor) !== null && _options$motor8 !== void 0 ? _options$motor8 : 2,
1571
- blocking: (_options$blocking8 = options.blocking) !== null && _options$blocking8 !== void 0 ? _options$blocking8 : true
1572
- });
1573
- }
1574
- async motorStop(options = {}) {
1575
- var _options$motor9, _options$blocking9;
1576
- const motor = (_options$motor9 = options.motor) !== null && _options$motor9 !== void 0 ? _options$motor9 : 2;
1577
- await this.sendCommand("motor_stop", {
1578
- motor,
1579
- blocking: (_options$blocking9 = options.blocking) !== null && _options$blocking9 !== void 0 ? _options$blocking9 : true
1580
- });
1581
- if (this.useCommandSideEstimates) this.touchMotor(motor, { speed: 0 });
1582
- }
1583
- async motorSetEndState(endState, options = {}) {
1584
- var _options$motor10, _options$blocking10;
1585
- await this.sendCommand("motor_set_end_state", {
1586
- end_state: endState,
1587
- motor: (_options$motor10 = options.motor) !== null && _options$motor10 !== void 0 ? _options$motor10 : 2,
1588
- blocking: (_options$blocking10 = options.blocking) !== null && _options$blocking10 !== void 0 ? _options$blocking10 : true
1589
- });
1590
- }
1591
- async motorSetAcceleration(acceleration, deceleration, options = {}) {
1592
- var _options$motor11, _options$blocking11;
1593
- await this.sendCommand("motor_set_acceleration", {
1594
- acceleration,
1595
- deceleration,
1596
- motor: (_options$motor11 = options.motor) !== null && _options$motor11 !== void 0 ? _options$motor11 : 2,
1597
- blocking: (_options$blocking11 = options.blocking) !== null && _options$blocking11 !== void 0 ? _options$blocking11 : true
1598
- });
1599
- }
1600
- async movementMove(options = {}) {
1601
- var _options$direction5, _options$speed6, _options$blocking12;
1602
- await this.sendCommand("movement_move", {
1603
- direction: (_options$direction5 = options.direction) !== null && _options$direction5 !== void 0 ? _options$direction5 : 0,
1604
- speed: (_options$speed6 = options.speed) !== null && _options$speed6 !== void 0 ? _options$speed6 : -1,
1605
- blocking: (_options$blocking12 = options.blocking) !== null && _options$blocking12 !== void 0 ? _options$blocking12 : true
1606
- });
1607
- }
1608
- async movementMoveForTime(timeMs, options = {}) {
1609
- var _options$direction6, _options$speed7, _options$blocking13;
1610
- await this.sendCommand("movement_move_for_time", {
1611
- time_ms: timeMs,
1612
- direction: (_options$direction6 = options.direction) !== null && _options$direction6 !== void 0 ? _options$direction6 : 0,
1613
- speed: (_options$speed7 = options.speed) !== null && _options$speed7 !== void 0 ? _options$speed7 : -1,
1614
- blocking: (_options$blocking13 = options.blocking) !== null && _options$blocking13 !== void 0 ? _options$blocking13 : true
1615
- });
1616
- }
1617
- async movementMoveForDegrees(degrees, options = {}) {
1618
- var _options$direction7, _options$speed8, _options$blocking14;
1619
- await this.sendCommand("movement_move_for_degrees", {
1620
- degrees,
1621
- direction: (_options$direction7 = options.direction) !== null && _options$direction7 !== void 0 ? _options$direction7 : 0,
1622
- speed: (_options$speed8 = options.speed) !== null && _options$speed8 !== void 0 ? _options$speed8 : -1,
1623
- blocking: (_options$blocking14 = options.blocking) !== null && _options$blocking14 !== void 0 ? _options$blocking14 : true
1624
- });
1625
- }
1626
- async movementMoveTank(speedLeft, speedRight, options = {}) {
1627
- var _options$blocking15;
1628
- await this.sendCommand("movement_move_tank", {
1629
- speed_left: speedLeft,
1630
- speed_right: speedRight,
1631
- blocking: (_options$blocking15 = options.blocking) !== null && _options$blocking15 !== void 0 ? _options$blocking15 : true
1632
- });
1633
- if (this.useCommandSideEstimates) {
1634
- this.motor[0].speed = speedLeft;
1635
- this.motor[1].speed = speedRight;
1636
- }
1637
- }
1638
- async movementMoveTankForDegrees(degrees, options = {}) {
1639
- var _options$speedLeft, _options$speedRight, _options$blocking16;
1640
- await this.sendCommand("movement_move_tank_for_degrees", {
1641
- degrees,
1642
- speed_left: (_options$speedLeft = options.speedLeft) !== null && _options$speedLeft !== void 0 ? _options$speedLeft : 50,
1643
- speed_right: (_options$speedRight = options.speedRight) !== null && _options$speedRight !== void 0 ? _options$speedRight : 50,
1644
- blocking: (_options$blocking16 = options.blocking) !== null && _options$blocking16 !== void 0 ? _options$blocking16 : true
1645
- });
1646
- }
1647
- async movementTurnForDegrees(degrees, options = {}) {
1648
- var _options$direction8, _options$speed9, _options$blocking17;
1649
- await this.sendCommand("movement_turn_for_degrees", {
1650
- degrees,
1651
- direction: (_options$direction8 = options.direction) !== null && _options$direction8 !== void 0 ? _options$direction8 : 2,
1652
- speed: (_options$speed9 = options.speed) !== null && _options$speed9 !== void 0 ? _options$speed9 : -1,
1653
- blocking: (_options$blocking17 = options.blocking) !== null && _options$blocking17 !== void 0 ? _options$blocking17 : true
1654
- });
1655
- }
1656
- async movementStop(options = {}) {
1657
- var _options$blocking18;
1658
- await this.sendCommand("movement_stop", { blocking: (_options$blocking18 = options.blocking) !== null && _options$blocking18 !== void 0 ? _options$blocking18 : true });
1659
- if (this.useCommandSideEstimates) {
1660
- this.motor[0].speed = 0;
1661
- this.motor[1].speed = 0;
1662
- }
1663
- }
1664
- async movementSetSpeed(speed, options = {}) {
1665
- var _options$blocking19;
1666
- await this.sendCommand("movement_set_speed", {
1667
- speed,
1668
- blocking: (_options$blocking19 = options.blocking) !== null && _options$blocking19 !== void 0 ? _options$blocking19 : true
1669
- });
1670
- }
1671
- async movementSetEndState(endState, options = {}) {
1672
- var _options$blocking20;
1673
- await this.sendCommand("movement_set_end_state", {
1674
- end_state: endState,
1675
- blocking: (_options$blocking20 = options.blocking) !== null && _options$blocking20 !== void 0 ? _options$blocking20 : true
1676
- });
1677
- }
1678
- async movementSetAcceleration(acceleration, deceleration, options = {}) {
1679
- var _options$blocking21;
1680
- await this.sendCommand("movement_set_acceleration", {
1681
- acceleration,
1682
- deceleration,
1683
- blocking: (_options$blocking21 = options.blocking) !== null && _options$blocking21 !== void 0 ? _options$blocking21 : true
1684
- });
1685
- }
1686
- async movementSetTurnSteering(steering, options = {}) {
1687
- var _options$blocking22;
1688
- await this.sendCommand("movement_set_turn_steering", {
1689
- steering,
1690
- blocking: (_options$blocking22 = options.blocking) !== null && _options$blocking22 !== void 0 ? _options$blocking22 : true
1691
- });
1692
- }
1693
- async imuSetYawFace(yawFace, options = {}) {
1694
- var _options$blocking23;
1695
- await this.sendCommand("imu_set_yaw_face", {
1696
- yaw_face: yawFace,
1697
- blocking: (_options$blocking23 = options.blocking) !== null && _options$blocking23 !== void 0 ? _options$blocking23 : true
1698
- });
1699
- }
1700
- async imuResetYawAxis(value = 0, options = {}) {
1701
- var _options$blocking24;
1702
- await this.sendCommand("imu_reset_yaw_axis", {
1703
- value,
1704
- blocking: (_options$blocking24 = options.blocking) !== null && _options$blocking24 !== void 0 ? _options$blocking24 : true
1705
- });
1706
- }
1707
- touchMotor(motor, patch) {
1708
- const targets = motor === 2 ? [0, 1] : motor === 0 || motor === 1 ? [motor] : [0];
1709
- for (const side of targets) {
1710
- if (patch.speed !== void 0) this.motor[side].speed = patch.speed;
1711
- if (patch.positionDelta !== void 0) this.motor[side].position += patch.positionDelta;
1712
- if (patch.position !== void 0) this.motor[side].position = patch.position;
1713
- }
1714
- }
1715
- };
1716
- //#endregion
1717
- //#region src/devices/color-sensor.ts
1718
- /** Python: `le.ColorSensor()` */
1719
- var ColorSensor = class extends DeviceBase {
1720
- constructor(options = {}) {
1721
- super(options);
1722
- _defineProperty(this, "kind", "color-sensor");
1723
- _defineProperty(this, "sensor", {
1724
- color: 0,
1725
- rawRed: 0,
1726
- rawGreen: 0,
1727
- rawBlue: 0,
1728
- reflection: 0
1729
- });
1730
- }
1731
- applyNotification(payload) {
1732
- const { color } = parseDeviceNotifications(payload);
1733
- if (!color) return;
1734
- this.sensor.color = color.color;
1735
- this.sensor.reflection = color.reflection;
1736
- this.sensor.rawRed = color.rawRed;
1737
- this.sensor.rawGreen = color.rawGreen;
1738
- this.sensor.rawBlue = color.rawBlue;
1739
- this.sensor.hue = color.hue;
1740
- this.sensor.saturation = color.saturation;
1741
- this.sensor.value = color.value;
1742
- }
1743
- /** Demo helper for MockTransport. */
1744
- mockSetColor(partial) {
1745
- Object.assign(this.sensor, partial);
1746
- }
859
+ var g = class {
860
+ get connected() {
861
+ return this.connection !== null;
862
+ }
863
+ get deviceId() {
864
+ var o, t;
865
+ return (o = (t = this.connection) === null || t === void 0 ? void 0 : t.deviceId) !== null && o !== void 0 ? o : null;
866
+ }
867
+ constructor(o = {}) {
868
+ var t;
869
+ u(this, "transport", void 0), u(this, "connection", null), u(this, "notificationCallback", null), u(this, "batchBuffer", null);
870
+ const e = (t = o.transport) !== null && t !== void 0 ? t : ot;
871
+ if (!e) throw new Error(`${this.constructor.name}: pass { transport } or call setDefaultTransport(...) first`);
872
+ this.transport = e;
873
+ }
874
+ async connect(o = {}, t) {
875
+ this.connection = await this.transport.connect(this.kind, o, {
876
+ onNotification: (e) => {
877
+ var n;
878
+ this.applyNotification(e), (n = this.notificationCallback) === null || n === void 0 || n.call(this, e);
879
+ },
880
+ onDisconnect: () => {
881
+ this.connection = null, t && t.onDisconnect && typeof t.onDisconnect == "function" && t.onDisconnect();
882
+ }
883
+ }), await this.programFlowNotification(0, { blocking: !1 });
884
+ }
885
+ applyNotification(o) {
886
+ }
887
+ async disconnect() {
888
+ this.connection && (await this.transport.disconnect(this.connection), this.connection = null);
889
+ }
890
+ setNotificationCallback(o) {
891
+ this.notificationCallback = o;
892
+ }
893
+ async search(o, t = 5e3) {
894
+ return this.transport.scan(this.kind, o, t);
895
+ }
896
+ async lightColor(o, t = {}) {
897
+ var e, n, r;
898
+ await this.sendCommand("light_color", {
899
+ color: o,
900
+ pattern: (e = t.pattern) !== null && e !== void 0 ? e : 0,
901
+ intensity: (n = t.intensity) !== null && n !== void 0 ? n : 100,
902
+ blocking: (r = t.blocking) !== null && r !== void 0 ? r : !0
903
+ });
904
+ }
905
+ async beep(o = {}) {
906
+ var t, e, n, r;
907
+ await this.sendCommand("beep", {
908
+ pattern: (t = o.pattern) !== null && t !== void 0 ? t : 0,
909
+ frequency: (e = o.frequency) !== null && e !== void 0 ? e : 440,
910
+ count: (n = o.count) !== null && n !== void 0 ? n : 1,
911
+ blocking: (r = o.blocking) !== null && r !== void 0 ? r : !0
912
+ });
913
+ }
914
+ async stopBeep(o = {}) {
915
+ var t;
916
+ await this.sendCommand("stop_beep", { blocking: (t = o.blocking) !== null && t !== void 0 ? t : !0 });
917
+ }
918
+ async programFlowNotification(o, t = {}) {
919
+ var e;
920
+ await this.sendCommand("program_flow_notification", {
921
+ action: o,
922
+ blocking: (e = t.blocking) !== null && e !== void 0 ? e : !1
923
+ });
924
+ }
925
+ async deviceNotificationRequest(o, t = {}) {
926
+ var e;
927
+ await this.sendCommand("device_notification_request", {
928
+ delay_ms: o,
929
+ blocking: (e = t.blocking) !== null && e !== void 0 ? e : !0
930
+ });
931
+ }
932
+ beginBatch() {
933
+ this.batchBuffer = [];
934
+ }
935
+ async endBatch(o = {}) {
936
+ if (!this.batchBuffer) return;
937
+ if (!this.connection)
938
+ throw this.batchBuffer = null, new Error(`${this.constructor.name}: not connected`);
939
+ const t = this.batchBuffer;
940
+ this.batchBuffer = null, t.length !== 0 && await this.transport.send(this.connection, ho(t));
941
+ }
942
+ cancelBatch() {
943
+ var o, t;
944
+ const e = (o = (t = this.batchBuffer) === null || t === void 0 ? void 0 : t.length) !== null && o !== void 0 ? o : 0;
945
+ return this.batchBuffer = null, e;
946
+ }
947
+ async sendCommand(o, t = {}) {
948
+ var e, n, r;
949
+ if (!this.connection) throw new Error(`${this.constructor.name}: not connected`);
950
+ if (this.batchBuffer && o.startsWith("movement_")) throw new Error("Movement commands cannot be called inside a batch. Use motor_* commands instead.");
951
+ const i = t.blocking !== !1, s = (e = (n = (r = this.transport).encodeCommand) === null || n === void 0 ? void 0 : n.call(r, o, t)) !== null && e !== void 0 ? e : lo(o, t);
952
+ if (this.batchBuffer) {
953
+ this.batchBuffer.push(s);
954
+ return;
955
+ }
956
+ const c = At(o), a = this.transport.waitForOpcode;
957
+ let d;
958
+ if (i && c != null && a) {
959
+ var v, m;
960
+ const E = Number((v = t.degrees) !== null && v !== void 0 ? v : 0), O = Number((m = t.time_ms) !== null && m !== void 0 ? m : 0), T = o === "light_color" || o === "beep" || o === "stop_beep" || o === "device_notification_request" ? 5e3 : Math.max(15e3, Math.abs(E) * 50 + 5e3, O + 5e3);
961
+ d = a.call(this.transport, c, T);
962
+ }
963
+ await this.transport.send(this.connection, s), d && await d;
964
+ }
965
+ }, jn = class extends g {
966
+ constructor(o = {}) {
967
+ super(o), u(this, "kind", "single-motor"), u(this, "motor", {
968
+ position: 0,
969
+ speed: 0
970
+ });
971
+ }
972
+ applyNotification(o) {
973
+ const { motors: t } = k(o);
974
+ for (const e of t)
975
+ this.motor.position = e.position, this.motor.speed = e.speed, this.motor.absolutePosition = e.absolutePosition, this.motor.motorState = e.motorState, this.motor.power = e.power, this.motor.gesture = e.gesture;
976
+ }
977
+ get useCommandSideEstimates() {
978
+ return this.transport.name === "mock";
979
+ }
980
+ async motorSetSpeed(o, t = {}) {
981
+ var e, n;
982
+ await this.sendCommand("motor_set_speed", {
983
+ speed: o,
984
+ motor: (e = t.motor) !== null && e !== void 0 ? e : 0,
985
+ blocking: (n = t.blocking) !== null && n !== void 0 ? n : !0
986
+ }), this.useCommandSideEstimates && (this.motor.speed = o);
987
+ }
988
+ async motorRun(o = {}) {
989
+ var t, e, n, r;
990
+ const i = (t = o.speed) !== null && t !== void 0 ? t : -1;
991
+ await this.sendCommand("motor_run", {
992
+ direction: (e = o.direction) !== null && e !== void 0 ? e : 0,
993
+ motor: (n = o.motor) !== null && n !== void 0 ? n : 0,
994
+ speed: i,
995
+ blocking: (r = o.blocking) !== null && r !== void 0 ? r : !0
996
+ }), this.useCommandSideEstimates && i !== -1 && (this.motor.speed = i);
997
+ }
998
+ async motorRunForTime(o, t = {}) {
999
+ var e, n, r, i;
1000
+ await this.sendCommand("motor_run_for_time", {
1001
+ time_ms: o,
1002
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 0,
1003
+ motor: (n = t.motor) !== null && n !== void 0 ? n : 0,
1004
+ speed: (r = t.speed) !== null && r !== void 0 ? r : -1,
1005
+ blocking: (i = t.blocking) !== null && i !== void 0 ? i : !0
1006
+ });
1007
+ }
1008
+ async motorRunForDegrees(o, t = {}) {
1009
+ var e, n, r, i;
1010
+ await this.sendCommand("motor_run_for_degrees", {
1011
+ degrees: o,
1012
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 0,
1013
+ motor: (n = t.motor) !== null && n !== void 0 ? n : 0,
1014
+ speed: (r = t.speed) !== null && r !== void 0 ? r : -1,
1015
+ blocking: (i = t.blocking) !== null && i !== void 0 ? i : !0
1016
+ }), this.useCommandSideEstimates && (this.motor.position += o);
1017
+ }
1018
+ async motorResetRelativePosition(o = {}) {
1019
+ var t, e, n;
1020
+ const r = (t = o.position) !== null && t !== void 0 ? t : 0;
1021
+ await this.sendCommand("motor_reset_relative_position", {
1022
+ motor: (e = o.motor) !== null && e !== void 0 ? e : 0,
1023
+ position: r,
1024
+ blocking: (n = o.blocking) !== null && n !== void 0 ? n : !0
1025
+ }), this.useCommandSideEstimates && (this.motor.position = r);
1026
+ }
1027
+ async motorRunToRelativePosition(o, t = {}) {
1028
+ var e, n, r;
1029
+ await this.sendCommand("motor_run_to_relative_position", {
1030
+ position: o,
1031
+ motor: (e = t.motor) !== null && e !== void 0 ? e : 0,
1032
+ speed: (n = t.speed) !== null && n !== void 0 ? n : -1,
1033
+ blocking: (r = t.blocking) !== null && r !== void 0 ? r : !0
1034
+ }), this.useCommandSideEstimates && (this.motor.position = o);
1035
+ }
1036
+ async motorRunToAbsolutePosition(o, t = {}) {
1037
+ var e, n, r, i;
1038
+ await this.sendCommand("motor_run_to_absolute_position", {
1039
+ position: o,
1040
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 2,
1041
+ motor: (n = t.motor) !== null && n !== void 0 ? n : 0,
1042
+ speed: (r = t.speed) !== null && r !== void 0 ? r : -1,
1043
+ blocking: (i = t.blocking) !== null && i !== void 0 ? i : !0
1044
+ }), this.useCommandSideEstimates && (this.motor.position = o);
1045
+ }
1046
+ async motorSetDutyCycle(o, t = {}) {
1047
+ var e, n;
1048
+ await this.sendCommand("motor_set_duty_cycle", {
1049
+ duty_cycle: o,
1050
+ motor: (e = t.motor) !== null && e !== void 0 ? e : 0,
1051
+ blocking: (n = t.blocking) !== null && n !== void 0 ? n : !0
1052
+ });
1053
+ }
1054
+ async motorStop(o = {}) {
1055
+ var t, e;
1056
+ await this.sendCommand("motor_stop", {
1057
+ motor: (t = o.motor) !== null && t !== void 0 ? t : 0,
1058
+ blocking: (e = o.blocking) !== null && e !== void 0 ? e : !0
1059
+ }), this.useCommandSideEstimates && (this.motor.speed = 0);
1060
+ }
1061
+ async motorSetEndState(o, t = {}) {
1062
+ var e, n;
1063
+ await this.sendCommand("motor_set_end_state", {
1064
+ end_state: o,
1065
+ motor: (e = t.motor) !== null && e !== void 0 ? e : 0,
1066
+ blocking: (n = t.blocking) !== null && n !== void 0 ? n : !0
1067
+ });
1068
+ }
1069
+ async motorSetAcceleration(o, t, e = {}) {
1070
+ var n, r;
1071
+ await this.sendCommand("motor_set_acceleration", {
1072
+ acceleration: o,
1073
+ deceleration: t,
1074
+ motor: (n = e.motor) !== null && n !== void 0 ? n : 0,
1075
+ blocking: (r = e.blocking) !== null && r !== void 0 ? r : !0
1076
+ });
1077
+ }
1078
+ }, qn = class extends g {
1079
+ constructor(o = {}) {
1080
+ super(o), u(this, "kind", "double-motor"), u(this, "motor", {
1081
+ 0: {
1082
+ position: 0,
1083
+ speed: 0
1084
+ },
1085
+ 1: {
1086
+ position: 0,
1087
+ speed: 0
1088
+ }
1089
+ }), u(this, "imu", {
1090
+ orientation: 0,
1091
+ yawFace: 0,
1092
+ yaw: 0,
1093
+ pitch: 0,
1094
+ roll: 0,
1095
+ accelerometerX: 0,
1096
+ accelerometerY: 0,
1097
+ accelerometerZ: 0,
1098
+ gyroscopeX: 0,
1099
+ gyroscopeY: 0,
1100
+ gyroscopeZ: 0
1101
+ });
1102
+ }
1103
+ applyNotification(o) {
1104
+ const t = k(o);
1105
+ for (const e of t.motors) {
1106
+ const n = [];
1107
+ e.motorBitMask & 1 && n.push(0), e.motorBitMask & 2 && n.push(1);
1108
+ for (const r of n)
1109
+ this.motor[r].position = e.position, this.motor[r].speed = e.speed, this.motor[r].absolutePosition = e.absolutePosition, this.motor[r].motorState = e.motorState, this.motor[r].power = e.power, this.motor[r].gesture = e.gesture;
1110
+ }
1111
+ t.imu && Object.assign(this.imu, t.imu), t.imuGesture !== void 0 && (this.imu.gesture = t.imuGesture);
1112
+ }
1113
+ get useCommandSideEstimates() {
1114
+ return this.transport.name === "mock";
1115
+ }
1116
+ async motorSetSpeed(o, t = {}) {
1117
+ var e, n;
1118
+ const r = (e = t.motor) !== null && e !== void 0 ? e : 2;
1119
+ await this.sendCommand("motor_set_speed", {
1120
+ speed: o,
1121
+ motor: r,
1122
+ blocking: (n = t.blocking) !== null && n !== void 0 ? n : !0
1123
+ }), this.useCommandSideEstimates && this.touchMotor(r, { speed: o });
1124
+ }
1125
+ async motorRun(o = {}) {
1126
+ var t, e, n, r;
1127
+ const i = (t = o.motor) !== null && t !== void 0 ? t : 2, s = (e = o.speed) !== null && e !== void 0 ? e : -1;
1128
+ await this.sendCommand("motor_run", {
1129
+ direction: (n = o.direction) !== null && n !== void 0 ? n : 0,
1130
+ motor: i,
1131
+ speed: s,
1132
+ blocking: (r = o.blocking) !== null && r !== void 0 ? r : !0
1133
+ }), this.useCommandSideEstimates && s !== -1 && this.touchMotor(i, { speed: s });
1134
+ }
1135
+ async motorRunForTime(o, t = {}) {
1136
+ var e, n, r, i;
1137
+ await this.sendCommand("motor_run_for_time", {
1138
+ time_ms: o,
1139
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 0,
1140
+ motor: (n = t.motor) !== null && n !== void 0 ? n : 2,
1141
+ speed: (r = t.speed) !== null && r !== void 0 ? r : -1,
1142
+ blocking: (i = t.blocking) !== null && i !== void 0 ? i : !0
1143
+ });
1144
+ }
1145
+ async motorRunForDegrees(o, t = {}) {
1146
+ var e, n, r, i;
1147
+ const s = (e = t.motor) !== null && e !== void 0 ? e : 2;
1148
+ await this.sendCommand("motor_run_for_degrees", {
1149
+ degrees: o,
1150
+ direction: (n = t.direction) !== null && n !== void 0 ? n : 0,
1151
+ motor: s,
1152
+ speed: (r = t.speed) !== null && r !== void 0 ? r : -1,
1153
+ blocking: (i = t.blocking) !== null && i !== void 0 ? i : !0
1154
+ }), this.useCommandSideEstimates && this.touchMotor(s, { positionDelta: o });
1155
+ }
1156
+ async motorResetRelativePosition(o = {}) {
1157
+ var t, e, n;
1158
+ const r = (t = o.position) !== null && t !== void 0 ? t : 0, i = (e = o.motor) !== null && e !== void 0 ? e : 2;
1159
+ await this.sendCommand("motor_reset_relative_position", {
1160
+ motor: i,
1161
+ position: r,
1162
+ blocking: (n = o.blocking) !== null && n !== void 0 ? n : !0
1163
+ }), this.useCommandSideEstimates && this.touchMotor(i, { position: r });
1164
+ }
1165
+ async motorRunToRelativePosition(o, t = {}) {
1166
+ var e, n, r;
1167
+ const i = (e = t.motor) !== null && e !== void 0 ? e : 2;
1168
+ await this.sendCommand("motor_run_to_relative_position", {
1169
+ position: o,
1170
+ motor: i,
1171
+ speed: (n = t.speed) !== null && n !== void 0 ? n : -1,
1172
+ blocking: (r = t.blocking) !== null && r !== void 0 ? r : !0
1173
+ }), this.useCommandSideEstimates && this.touchMotor(i, { position: o });
1174
+ }
1175
+ async motorRunToAbsolutePosition(o, t = {}) {
1176
+ var e, n, r, i;
1177
+ await this.sendCommand("motor_run_to_absolute_position", {
1178
+ position: o,
1179
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 2,
1180
+ motor: (n = t.motor) !== null && n !== void 0 ? n : 2,
1181
+ speed: (r = t.speed) !== null && r !== void 0 ? r : -1,
1182
+ blocking: (i = t.blocking) !== null && i !== void 0 ? i : !0
1183
+ });
1184
+ }
1185
+ async motorSetDutyCycle(o, t = {}) {
1186
+ var e, n;
1187
+ await this.sendCommand("motor_set_duty_cycle", {
1188
+ duty_cycle: o,
1189
+ motor: (e = t.motor) !== null && e !== void 0 ? e : 2,
1190
+ blocking: (n = t.blocking) !== null && n !== void 0 ? n : !0
1191
+ });
1192
+ }
1193
+ async motorStop(o = {}) {
1194
+ var t, e;
1195
+ const n = (t = o.motor) !== null && t !== void 0 ? t : 2;
1196
+ await this.sendCommand("motor_stop", {
1197
+ motor: n,
1198
+ blocking: (e = o.blocking) !== null && e !== void 0 ? e : !0
1199
+ }), this.useCommandSideEstimates && this.touchMotor(n, { speed: 0 });
1200
+ }
1201
+ async motorSetEndState(o, t = {}) {
1202
+ var e, n;
1203
+ await this.sendCommand("motor_set_end_state", {
1204
+ end_state: o,
1205
+ motor: (e = t.motor) !== null && e !== void 0 ? e : 2,
1206
+ blocking: (n = t.blocking) !== null && n !== void 0 ? n : !0
1207
+ });
1208
+ }
1209
+ async motorSetAcceleration(o, t, e = {}) {
1210
+ var n, r;
1211
+ await this.sendCommand("motor_set_acceleration", {
1212
+ acceleration: o,
1213
+ deceleration: t,
1214
+ motor: (n = e.motor) !== null && n !== void 0 ? n : 2,
1215
+ blocking: (r = e.blocking) !== null && r !== void 0 ? r : !0
1216
+ });
1217
+ }
1218
+ async movementMove(o = {}) {
1219
+ var t, e, n;
1220
+ await this.sendCommand("movement_move", {
1221
+ direction: (t = o.direction) !== null && t !== void 0 ? t : 0,
1222
+ speed: (e = o.speed) !== null && e !== void 0 ? e : -1,
1223
+ blocking: (n = o.blocking) !== null && n !== void 0 ? n : !0
1224
+ });
1225
+ }
1226
+ async movementMoveForTime(o, t = {}) {
1227
+ var e, n, r;
1228
+ await this.sendCommand("movement_move_for_time", {
1229
+ time_ms: o,
1230
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 0,
1231
+ speed: (n = t.speed) !== null && n !== void 0 ? n : -1,
1232
+ blocking: (r = t.blocking) !== null && r !== void 0 ? r : !0
1233
+ });
1234
+ }
1235
+ async movementMoveForDegrees(o, t = {}) {
1236
+ var e, n, r;
1237
+ await this.sendCommand("movement_move_for_degrees", {
1238
+ degrees: o,
1239
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 0,
1240
+ speed: (n = t.speed) !== null && n !== void 0 ? n : -1,
1241
+ blocking: (r = t.blocking) !== null && r !== void 0 ? r : !0
1242
+ });
1243
+ }
1244
+ async movementMoveTank(o, t, e = {}) {
1245
+ var n;
1246
+ await this.sendCommand("movement_move_tank", {
1247
+ speed_left: o,
1248
+ speed_right: t,
1249
+ blocking: (n = e.blocking) !== null && n !== void 0 ? n : !0
1250
+ }), this.useCommandSideEstimates && (this.motor[0].speed = o, this.motor[1].speed = t);
1251
+ }
1252
+ async movementMoveTankForDegrees(o, t = {}) {
1253
+ var e, n, r;
1254
+ await this.sendCommand("movement_move_tank_for_degrees", {
1255
+ degrees: o,
1256
+ speed_left: (e = t.speedLeft) !== null && e !== void 0 ? e : 50,
1257
+ speed_right: (n = t.speedRight) !== null && n !== void 0 ? n : 50,
1258
+ blocking: (r = t.blocking) !== null && r !== void 0 ? r : !0
1259
+ });
1260
+ }
1261
+ async movementTurnForDegrees(o, t = {}) {
1262
+ var e, n, r;
1263
+ await this.sendCommand("movement_turn_for_degrees", {
1264
+ degrees: o,
1265
+ direction: (e = t.direction) !== null && e !== void 0 ? e : 2,
1266
+ speed: (n = t.speed) !== null && n !== void 0 ? n : -1,
1267
+ blocking: (r = t.blocking) !== null && r !== void 0 ? r : !0
1268
+ });
1269
+ }
1270
+ async movementStop(o = {}) {
1271
+ var t;
1272
+ await this.sendCommand("movement_stop", { blocking: (t = o.blocking) !== null && t !== void 0 ? t : !0 }), this.useCommandSideEstimates && (this.motor[0].speed = 0, this.motor[1].speed = 0);
1273
+ }
1274
+ async movementSetSpeed(o, t = {}) {
1275
+ var e;
1276
+ await this.sendCommand("movement_set_speed", {
1277
+ speed: o,
1278
+ blocking: (e = t.blocking) !== null && e !== void 0 ? e : !0
1279
+ });
1280
+ }
1281
+ async movementSetEndState(o, t = {}) {
1282
+ var e;
1283
+ await this.sendCommand("movement_set_end_state", {
1284
+ end_state: o,
1285
+ blocking: (e = t.blocking) !== null && e !== void 0 ? e : !0
1286
+ });
1287
+ }
1288
+ async movementSetAcceleration(o, t, e = {}) {
1289
+ var n;
1290
+ await this.sendCommand("movement_set_acceleration", {
1291
+ acceleration: o,
1292
+ deceleration: t,
1293
+ blocking: (n = e.blocking) !== null && n !== void 0 ? n : !0
1294
+ });
1295
+ }
1296
+ async movementSetTurnSteering(o, t = {}) {
1297
+ var e;
1298
+ await this.sendCommand("movement_set_turn_steering", {
1299
+ steering: o,
1300
+ blocking: (e = t.blocking) !== null && e !== void 0 ? e : !0
1301
+ });
1302
+ }
1303
+ async imuSetYawFace(o, t = {}) {
1304
+ var e;
1305
+ await this.sendCommand("imu_set_yaw_face", {
1306
+ yaw_face: o,
1307
+ blocking: (e = t.blocking) !== null && e !== void 0 ? e : !0
1308
+ });
1309
+ }
1310
+ async imuResetYawAxis(o = 0, t = {}) {
1311
+ var e;
1312
+ await this.sendCommand("imu_reset_yaw_axis", {
1313
+ value: o,
1314
+ blocking: (e = t.blocking) !== null && e !== void 0 ? e : !0
1315
+ });
1316
+ }
1317
+ touchMotor(o, t) {
1318
+ const e = o === 2 ? [0, 1] : o === 0 || o === 1 ? [o] : [0];
1319
+ for (const n of e)
1320
+ t.speed !== void 0 && (this.motor[n].speed = t.speed), t.positionDelta !== void 0 && (this.motor[n].position += t.positionDelta), t.position !== void 0 && (this.motor[n].position = t.position);
1321
+ }
1322
+ }, Kn = class extends g {
1323
+ constructor(o = {}) {
1324
+ super(o), u(this, "kind", "color-sensor"), u(this, "sensor", {
1325
+ color: 0,
1326
+ rawRed: 0,
1327
+ rawGreen: 0,
1328
+ rawBlue: 0,
1329
+ reflection: 0
1330
+ });
1331
+ }
1332
+ applyNotification(o) {
1333
+ const { color: t } = k(o);
1334
+ t && (this.sensor.color = t.color, this.sensor.reflection = t.reflection, this.sensor.rawRed = t.rawRed, this.sensor.rawGreen = t.rawGreen, this.sensor.rawBlue = t.rawBlue, this.sensor.hue = t.hue, this.sensor.saturation = t.saturation, this.sensor.value = t.value);
1335
+ }
1336
+ mockSetColor(o) {
1337
+ Object.assign(this.sensor, o);
1338
+ }
1339
+ }, Zn = class extends g {
1340
+ constructor(o = {}) {
1341
+ super(o), u(this, "kind", "controller"), u(this, "sensor", {
1342
+ leftPercent: 0,
1343
+ rightPercent: 0,
1344
+ leftAngle: 0,
1345
+ rightAngle: 0
1346
+ }), u(this, "buttonState", 0);
1347
+ }
1348
+ applyNotification(o) {
1349
+ const t = k(o);
1350
+ t.controller && (this.sensor.leftPercent = t.controller.leftPercent, this.sensor.rightPercent = t.controller.rightPercent, this.sensor.leftAngle = t.controller.leftAngle, this.sensor.rightAngle = t.controller.rightAngle), t.buttonState !== void 0 && (this.buttonState = t.buttonState);
1351
+ }
1352
+ mockSetLevers(o) {
1353
+ Object.assign(this.sensor, o);
1354
+ }
1747
1355
  };
1748
- //#endregion
1749
- //#region src/devices/controller.ts
1750
- /** Python: `le.Controller()` */
1751
- var Controller = class extends DeviceBase {
1752
- constructor(options = {}) {
1753
- super(options);
1754
- _defineProperty(this, "kind", "controller");
1755
- _defineProperty(this, "sensor", {
1756
- leftPercent: 0,
1757
- rightPercent: 0,
1758
- leftAngle: 0,
1759
- rightAngle: 0
1760
- });
1761
- _defineProperty(this, "buttonState", 0);
1762
- }
1763
- applyNotification(payload) {
1764
- const parsed = parseDeviceNotifications(payload);
1765
- if (parsed.controller) {
1766
- this.sensor.leftPercent = parsed.controller.leftPercent;
1767
- this.sensor.rightPercent = parsed.controller.rightPercent;
1768
- this.sensor.leftAngle = parsed.controller.leftAngle;
1769
- this.sensor.rightAngle = parsed.controller.rightAngle;
1770
- }
1771
- if (parsed.buttonState !== void 0) this.buttonState = parsed.buttonState;
1772
- }
1773
- /** Demo helper for MockTransport. */
1774
- mockSetLevers(partial) {
1775
- Object.assign(this.sensor, partial);
1776
- }
1356
+ export {
1357
+ Un as BUTTON_STATE_NOTIFICATION,
1358
+ gn as CARD_NOTIFICATION,
1359
+ Ln as COLOR_SENSOR_NOTIFICATION,
1360
+ Pn as CONTROLLER_NOTIFICATION,
1361
+ Kn as ColorSensor,
1362
+ Zn as Controller,
1363
+ yo as DEFAULT_DEVICE_NOTIFICATION_DELAY,
1364
+ ko as DEFAULT_MOTOR,
1365
+ re as DEVICE_FACE_BACK,
1366
+ ne as DEVICE_FACE_BOTTOM,
1367
+ oe as DEVICE_FACE_FRONT,
1368
+ ie as DEVICE_FACE_LEFT,
1369
+ ee as DEVICE_FACE_RIGHT,
1370
+ te as DEVICE_FACE_TOP,
1371
+ Ae as DEVICE_NOTIFICATION,
1372
+ Ce as DEVICE_NOTIFICATION_REQUEST,
1373
+ Se as DEVICE_NOTIFICATION_RESPONSE,
1374
+ g as DeviceBase,
1375
+ qn as DoubleMotor,
1376
+ yn as IMU_DEVICE_NOTIFICATION,
1377
+ Fn as IMU_GESTURE_NOTIFICATION,
1378
+ An as IMU_RESET_YAW_AXIS_COMMAND,
1379
+ In as IMU_RESET_YAW_AXIS_RESULT,
1380
+ Cn as IMU_SET_YAW_FACE_COMMAND,
1381
+ Sn as IMU_SET_YAW_FACE_RESULT,
1382
+ kn as INFO_DEVICE_NOTIFICATION,
1383
+ we as INFO_REQUEST,
1384
+ Ne as INFO_RESPONSE,
1385
+ Ao as LEGO_COLOR_AZURE,
1386
+ bo as LEGO_COLOR_BLUE,
1387
+ wo as LEGO_COLOR_GREEN,
1388
+ Co as LEGO_COLOR_MAGENTA,
1389
+ Oo as LEGO_COLOR_NOCOLOR,
1390
+ To as LEGO_COLOR_NONE,
1391
+ So as LEGO_COLOR_ORANGE,
1392
+ No as LEGO_COLOR_PURPLE,
1393
+ fo as LEGO_COLOR_RED,
1394
+ Mo as LEGO_COLOR_TEAL,
1395
+ Ro as LEGO_COLOR_WHITE,
1396
+ po as LEGO_COLOR_YELLOW,
1397
+ Te as LEGO_COMPANY_ID,
1398
+ Ie as LIGHT_COLOR_COMMAND,
1399
+ ke as LIGHT_COLOR_RESULT,
1400
+ de as LIGHT_PATTERN_BREATHE,
1401
+ Ee as LIGHT_PATTERN_DOUBLE_BLINK,
1402
+ me as LIGHT_PATTERN_LONG_BLINK,
1403
+ _e as LIGHT_PATTERN_PULSE,
1404
+ ve as LIGHT_PATTERN_SHORT_BLINK,
1405
+ ue as LIGHT_PATTERN_SOLID,
1406
+ Gn as MOTOR_BITS_BOTH,
1407
+ Vn as MOTOR_BITS_LEFT,
1408
+ Bn as MOTOR_BITS_RIGHT,
1409
+ xo as MOTOR_BOTH,
1410
+ Do as MOTOR_END_STATE_BRAKE,
1411
+ Uo as MOTOR_END_STATE_COAST,
1412
+ Po as MOTOR_END_STATE_CONTINUE,
1413
+ go as MOTOR_END_STATE_DEFAULT,
1414
+ Lo as MOTOR_END_STATE_HOLD,
1415
+ Vo as MOTOR_END_STATE_SMART_BRAKE,
1416
+ Fo as MOTOR_END_STATE_SMART_COAST,
1417
+ Ho as MOTOR_LEFT,
1418
+ Bo as MOTOR_MOVE_DIRECTION_CLOCKWISE,
1419
+ Go as MOTOR_MOVE_DIRECTION_COUNTERCLOCKWISE,
1420
+ Wo as MOTOR_MOVE_DIRECTION_LONGEST,
1421
+ $o as MOTOR_MOVE_DIRECTION_SHORTEST,
1422
+ Dn as MOTOR_NOTIFICATION,
1423
+ Le as MOTOR_RESET_RELATIVE_POSITION_COMMAND,
1424
+ Pe as MOTOR_RESET_RELATIVE_POSITION_RESULT,
1425
+ Yo as MOTOR_RIGHT,
1426
+ Fe as MOTOR_RUN_COMMAND,
1427
+ Be as MOTOR_RUN_FOR_DEGREES_COMMAND,
1428
+ Ge as MOTOR_RUN_FOR_DEGREES_RESULT,
1429
+ $e as MOTOR_RUN_FOR_TIME_COMMAND,
1430
+ We as MOTOR_RUN_FOR_TIME_RESULT,
1431
+ Ve as MOTOR_RUN_RESULT,
1432
+ He as MOTOR_RUN_TO_ABSOLUTE_POSITION_COMMAND,
1433
+ Ye as MOTOR_RUN_TO_ABSOLUTE_POSITION_RESULT,
1434
+ xe as MOTOR_RUN_TO_RELATIVE_POSITION_COMMAND,
1435
+ je as MOTOR_RUN_TO_RELATIVE_POSITION_RESULT,
1436
+ on as MOTOR_SET_ACCELERATION_COMMAND,
1437
+ en as MOTOR_SET_ACCELERATION_RESULT,
1438
+ qe as MOTOR_SET_DUTY_CYCLE_COMMAND,
1439
+ Ke as MOTOR_SET_DUTY_CYCLE_RESULT,
1440
+ Qe as MOTOR_SET_END_STATE_COMMAND,
1441
+ tn as MOTOR_SET_END_STATE_RESULT,
1442
+ ze as MOTOR_SET_SPEED_COMMAND,
1443
+ Je as MOTOR_SET_SPEED_RESULT,
1444
+ Ze as MOTOR_STOP_COMMAND,
1445
+ Xe as MOTOR_STOP_RESULT,
1446
+ qo as MOVEMENT_DIRECTION_BACKWARD,
1447
+ jo as MOVEMENT_DIRECTION_FORWARD,
1448
+ Ko as MOVEMENT_DIRECTION_LEFT,
1449
+ Zo as MOVEMENT_DIRECTION_RIGHT,
1450
+ nn as MOVEMENT_MOVE_COMMAND,
1451
+ zo as MOVEMENT_MOVE_DIRECTION_BACKWARD,
1452
+ Xo as MOVEMENT_MOVE_DIRECTION_FORWARD,
1453
+ cn as MOVEMENT_MOVE_FOR_DEGREES_COMMAND,
1454
+ ln as MOVEMENT_MOVE_FOR_DEGREES_RESULT,
1455
+ sn as MOVEMENT_MOVE_FOR_TIME_COMMAND,
1456
+ an as MOVEMENT_MOVE_FOR_TIME_RESULT,
1457
+ rn as MOVEMENT_MOVE_RESULT,
1458
+ un as MOVEMENT_MOVE_TANK_COMMAND,
1459
+ _n as MOVEMENT_MOVE_TANK_FOR_DEGREES_COMMAND,
1460
+ vn as MOVEMENT_MOVE_TANK_FOR_DEGREES_RESULT,
1461
+ dn as MOVEMENT_MOVE_TANK_RESULT,
1462
+ Mn as MOVEMENT_SET_ACCELERATION_COMMAND,
1463
+ wn as MOVEMENT_SET_ACCELERATION_RESULT,
1464
+ pn as MOVEMENT_SET_END_STATE_COMMAND,
1465
+ bn as MOVEMENT_SET_END_STATE_RESULT,
1466
+ Tn as MOVEMENT_SET_SPEED_COMMAND,
1467
+ fn as MOVEMENT_SET_SPEED_RESULT,
1468
+ Nn as MOVEMENT_SET_TURN_STEERING_COMMAND,
1469
+ Rn as MOVEMENT_SET_TURN_STEERING_RESULT,
1470
+ hn as MOVEMENT_STOP_COMMAND,
1471
+ On as MOVEMENT_STOP_RESULT,
1472
+ Jo as MOVEMENT_TURN_DIRECTION_LEFT,
1473
+ Qo as MOVEMENT_TURN_DIRECTION_RIGHT,
1474
+ mn as MOVEMENT_TURN_FOR_DEGREES_COMMAND,
1475
+ En as MOVEMENT_TURN_FOR_DEGREES_RESULT,
1476
+ Wn as MockTransport,
1477
+ Ct as NESTED_NOTIFICATION_SIZES,
1478
+ Rt as NOTIFY_UUID,
1479
+ ye as PLAY_BEEP_COMMAND,
1480
+ ge as PLAY_BEEP_RESULT,
1481
+ be as PRODUCT_GROUP_DEVICE_COLOR_SENSOR,
1482
+ Me as PRODUCT_GROUP_DEVICE_CONTROLLER,
1483
+ pe as PRODUCT_GROUP_DEVICE_DOUBLE_MOTOR,
1484
+ fe as PRODUCT_GROUP_DEVICE_SINGLE_MOTOR,
1485
+ he as PROGRAM_ACTION_START,
1486
+ Oe as PROGRAM_ACTION_STOP,
1487
+ Re as PROGRAM_FLOW_NOTIFICATION,
1488
+ N as RPC_VERSION,
1489
+ J as SERVICE_UUID,
1490
+ ae as SOUND_PATTERN_BEEP_DOUBLE,
1491
+ se as SOUND_PATTERN_BEEP_SINGLE,
1492
+ ce as SOUND_PATTERN_BEEP_TRIPLE,
1493
+ le as SOUND_PATTERN_BEEP_UP_MIDDLE_DOWN,
1494
+ Ue as STOP_SOUND_COMMAND,
1495
+ De as STOP_SOUND_RESULT,
1496
+ jn as SingleMotor,
1497
+ Io as UNCHANGED,
1498
+ Nt as WRITE_UUID,
1499
+ Hn as WebBluetoothTransport,
1500
+ wt as appColorToFirmware,
1501
+ ao as decodeInfoResponse,
1502
+ uo as decodeMockCommand,
1503
+ Ft as encodeBeep,
1504
+ ht as encodeDeviceNotificationRequest,
1505
+ so as encodeImuResetYawAxis,
1506
+ io as encodeImuSetYawFace,
1507
+ Et as encodeInfoRequest,
1508
+ Pt as encodeLightColor,
1509
+ lo as encodeMockCommand,
1510
+ Ht as encodeMotorResetRelativePosition,
1511
+ Bt as encodeMotorRun,
1512
+ $t as encodeMotorRunForDegrees,
1513
+ Wt as encodeMotorRunForTime,
1514
+ xt as encodeMotorRunToAbsolutePosition,
1515
+ Yt as encodeMotorRunToRelativePosition,
1516
+ Kt as encodeMotorSetAcceleration,
1517
+ jt as encodeMotorSetDutyCycle,
1518
+ qt as encodeMotorSetEndState,
1519
+ Ot as encodeMotorSetSpeed,
1520
+ Gt as encodeMotorStop,
1521
+ Zt as encodeMovementMove,
1522
+ zt as encodeMovementMoveForDegrees,
1523
+ Xt as encodeMovementMoveForTime,
1524
+ Jt as encodeMovementMoveTank,
1525
+ Qt as encodeMovementMoveTankForDegrees,
1526
+ no as encodeMovementSetAcceleration,
1527
+ eo as encodeMovementSetEndState,
1528
+ Tt as encodeMovementSetSpeed,
1529
+ ro as encodeMovementSetTurnSteering,
1530
+ oo as encodeMovementStop,
1531
+ to as encodeMovementTurnForDegrees,
1532
+ Lt as encodeProgramFlow,
1533
+ co as encodeRpcCommand,
1534
+ Vt as encodeStopBeep,
1535
+ et as firmwareColorToApp,
1536
+ xn as getDefaultTransport,
1537
+ St as motorIndexToBitMask,
1538
+ tt as packU16LE,
1539
+ k as parseDeviceNotifications,
1540
+ $n as parseMotorNotifications,
1541
+ At as resultOpcodeForMethod,
1542
+ Yn as setDefaultTransport,
1543
+ kt as splitNotifyFrames
1777
1544
  };
1778
- //#endregion
1779
- export { BUTTON_STATE_NOTIFICATION, CARD_NOTIFICATION, COLOR_SENSOR_NOTIFICATION, CONTROLLER_NOTIFICATION, ColorSensor, Controller, DEFAULT_DEVICE_NOTIFICATION_DELAY, DEFAULT_MOTOR, DEVICE_FACE_BACK, DEVICE_FACE_BOTTOM, DEVICE_FACE_FRONT, DEVICE_FACE_LEFT, DEVICE_FACE_RIGHT, DEVICE_FACE_TOP, DEVICE_NOTIFICATION, DEVICE_NOTIFICATION_REQUEST, DEVICE_NOTIFICATION_RESPONSE, DeviceBase, DoubleMotor, IMU_DEVICE_NOTIFICATION, IMU_GESTURE_NOTIFICATION, IMU_RESET_YAW_AXIS_COMMAND, IMU_RESET_YAW_AXIS_RESULT, IMU_SET_YAW_FACE_COMMAND, IMU_SET_YAW_FACE_RESULT, INFO_DEVICE_NOTIFICATION, INFO_REQUEST, INFO_RESPONSE, LEGO_COLOR_AZURE, LEGO_COLOR_BLUE, LEGO_COLOR_GREEN, LEGO_COLOR_MAGENTA, LEGO_COLOR_NOCOLOR, LEGO_COLOR_NONE, LEGO_COLOR_ORANGE, LEGO_COLOR_PURPLE, LEGO_COLOR_RED, LEGO_COLOR_TEAL, LEGO_COLOR_WHITE, LEGO_COLOR_YELLOW, LEGO_COMPANY_ID, LIGHT_COLOR_COMMAND, LIGHT_COLOR_RESULT, LIGHT_PATTERN_BREATHE, LIGHT_PATTERN_DOUBLE_BLINK, LIGHT_PATTERN_LONG_BLINK, LIGHT_PATTERN_PULSE, LIGHT_PATTERN_SHORT_BLINK, LIGHT_PATTERN_SOLID, MOTOR_BITS_BOTH, MOTOR_BITS_LEFT, MOTOR_BITS_RIGHT, MOTOR_BOTH, MOTOR_END_STATE_BRAKE, MOTOR_END_STATE_COAST, MOTOR_END_STATE_CONTINUE, MOTOR_END_STATE_DEFAULT, MOTOR_END_STATE_HOLD, MOTOR_END_STATE_SMART_BRAKE, MOTOR_END_STATE_SMART_COAST, MOTOR_LEFT, MOTOR_MOVE_DIRECTION_CLOCKWISE, MOTOR_MOVE_DIRECTION_COUNTERCLOCKWISE, MOTOR_MOVE_DIRECTION_LONGEST, MOTOR_MOVE_DIRECTION_SHORTEST, MOTOR_NOTIFICATION, MOTOR_RESET_RELATIVE_POSITION_COMMAND, MOTOR_RESET_RELATIVE_POSITION_RESULT, MOTOR_RIGHT, MOTOR_RUN_COMMAND, MOTOR_RUN_FOR_DEGREES_COMMAND, MOTOR_RUN_FOR_DEGREES_RESULT, MOTOR_RUN_FOR_TIME_COMMAND, MOTOR_RUN_FOR_TIME_RESULT, MOTOR_RUN_RESULT, MOTOR_RUN_TO_ABSOLUTE_POSITION_COMMAND, MOTOR_RUN_TO_ABSOLUTE_POSITION_RESULT, MOTOR_RUN_TO_RELATIVE_POSITION_COMMAND, MOTOR_RUN_TO_RELATIVE_POSITION_RESULT, MOTOR_SET_ACCELERATION_COMMAND, MOTOR_SET_ACCELERATION_RESULT, MOTOR_SET_DUTY_CYCLE_COMMAND, MOTOR_SET_DUTY_CYCLE_RESULT, MOTOR_SET_END_STATE_COMMAND, MOTOR_SET_END_STATE_RESULT, MOTOR_SET_SPEED_COMMAND, MOTOR_SET_SPEED_RESULT, MOTOR_STOP_COMMAND, MOTOR_STOP_RESULT, MOVEMENT_DIRECTION_BACKWARD, MOVEMENT_DIRECTION_FORWARD, MOVEMENT_DIRECTION_LEFT, MOVEMENT_DIRECTION_RIGHT, MOVEMENT_MOVE_COMMAND, MOVEMENT_MOVE_DIRECTION_BACKWARD, MOVEMENT_MOVE_DIRECTION_FORWARD, MOVEMENT_MOVE_FOR_DEGREES_COMMAND, MOVEMENT_MOVE_FOR_DEGREES_RESULT, MOVEMENT_MOVE_FOR_TIME_COMMAND, MOVEMENT_MOVE_FOR_TIME_RESULT, MOVEMENT_MOVE_RESULT, MOVEMENT_MOVE_TANK_COMMAND, MOVEMENT_MOVE_TANK_FOR_DEGREES_COMMAND, MOVEMENT_MOVE_TANK_FOR_DEGREES_RESULT, MOVEMENT_MOVE_TANK_RESULT, MOVEMENT_SET_ACCELERATION_COMMAND, MOVEMENT_SET_ACCELERATION_RESULT, MOVEMENT_SET_END_STATE_COMMAND, MOVEMENT_SET_END_STATE_RESULT, MOVEMENT_SET_SPEED_COMMAND, MOVEMENT_SET_SPEED_RESULT, MOVEMENT_SET_TURN_STEERING_COMMAND, MOVEMENT_SET_TURN_STEERING_RESULT, MOVEMENT_STOP_COMMAND, MOVEMENT_STOP_RESULT, MOVEMENT_TURN_DIRECTION_LEFT, MOVEMENT_TURN_DIRECTION_RIGHT, MOVEMENT_TURN_FOR_DEGREES_COMMAND, MOVEMENT_TURN_FOR_DEGREES_RESULT, MockTransport, NESTED_NOTIFICATION_SIZES, NOTIFY_UUID, PLAY_BEEP_COMMAND, PLAY_BEEP_RESULT, PRODUCT_GROUP_DEVICE_COLOR_SENSOR, PRODUCT_GROUP_DEVICE_CONTROLLER, PRODUCT_GROUP_DEVICE_DOUBLE_MOTOR, PRODUCT_GROUP_DEVICE_SINGLE_MOTOR, PROGRAM_ACTION_START, PROGRAM_ACTION_STOP, PROGRAM_FLOW_NOTIFICATION, RPC_VERSION, SERVICE_UUID, SOUND_PATTERN_BEEP_DOUBLE, SOUND_PATTERN_BEEP_SINGLE, SOUND_PATTERN_BEEP_TRIPLE, SOUND_PATTERN_BEEP_UP_MIDDLE_DOWN, STOP_SOUND_COMMAND, STOP_SOUND_RESULT, SingleMotor, UNCHANGED, WRITE_UUID, WebBluetoothTransport, appColorToFirmware, decodeInfoResponse, decodeMockCommand, encodeBeep, encodeDeviceNotificationRequest, encodeImuResetYawAxis, encodeImuSetYawFace, encodeInfoRequest, encodeLightColor, encodeMockCommand, encodeMotorResetRelativePosition, encodeMotorRun, encodeMotorRunForDegrees, encodeMotorRunForTime, encodeMotorRunToAbsolutePosition, encodeMotorRunToRelativePosition, encodeMotorSetAcceleration, encodeMotorSetDutyCycle, encodeMotorSetEndState, encodeMotorSetSpeed, encodeMotorStop, encodeMovementMove, encodeMovementMoveForDegrees, encodeMovementMoveForTime, encodeMovementMoveTank, encodeMovementMoveTankForDegrees, encodeMovementSetAcceleration, encodeMovementSetEndState, encodeMovementSetSpeed, encodeMovementSetTurnSteering, encodeMovementStop, encodeMovementTurnForDegrees, encodeProgramFlow, encodeRpcCommand, encodeStopBeep, firmwareColorToApp, getDefaultTransport, motorIndexToBitMask, packU16LE, parseDeviceNotifications, parseMotorNotifications, resultOpcodeForMethod, setDefaultTransport, splitNotifyFrames };
1780
-
1781
- //# sourceMappingURL=index.js.map