-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.rs
More file actions
674 lines (576 loc) · 20.3 KB
/
protocol.rs
File metadata and controls
674 lines (576 loc) · 20.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/// IPI FLY PRO – HID frame builder and checksum helpers.
///
/// All frames are 16 bytes. Byte 0 is the global checksum:
/// byte[0] = (0x4D - sum(byte[2..=15])) & 0xFF
/// Byte 6 is the local mini-checksum for most config commands:
/// byte[6] = 0x57 - byte[4] - byte[5]
/// Byte 15 is a tail checksum for config commands:
/// byte[15] = 0xF1 - byte[3] - byte[4]
pub const FRAME_LEN: usize = 16;
pub fn checksum(frame: &mut [u8; FRAME_LEN]) {
let sum: u16 = frame[2..].iter().map(|&b| b as u16).sum();
frame[0] = ((0x4Du16.wrapping_sub(sum)) & 0xFF) as u8;
}
pub fn mini_checksum(frame: &mut [u8; FRAME_LEN]) {
frame[6] = 0x57u8.wrapping_sub(frame[4]).wrapping_sub(frame[5]);
}
pub fn tail_checksum(frame: &mut [u8; FRAME_LEN]) {
frame[15] = 0xF1u8.wrapping_sub(frame[3]).wrapping_sub(frame[4]);
}
pub fn build(mut f: [u8; FRAME_LEN]) -> [u8; FRAME_LEN] {
mini_checksum(&mut f);
tail_checksum(&mut f);
checksum(&mut f);
f
}
// ── Commands ────────────────────────────────────────────────────────────────
pub fn cmd_status() -> [u8; FRAME_LEN] {
[0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a]
}
pub fn cmd_battery() -> [u8; FRAME_LEN] {
[0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49]
}
pub fn cmd_select_stage(stage: u8) -> [u8; FRAME_LEN] {
// stage 0-3
let mut f = [0u8; FRAME_LEN];
f[2] = 0x00;
f[3] = 0x04;
f[4] = 0x02;
f[5] = stage & 0x03;
build(f)
}
pub fn cmd_set_dpi(stage: u8, dpi: u16) -> [u8; FRAME_LEN] {
// dpi = 50..=42000, step 50. Byte 5 == byte 6 == (dpi/50)-1.
// Byte 8 purpose is unverified; 0x77 is the only captured working value so far.
let _stage = stage;
let val = ((dpi / 50).saturating_sub(1)) as u8;
let mut f = [0u8; FRAME_LEN];
f[3] = 0x18;
f[4] = 0x04;
f[5] = val;
f[6] = val; // not mini-checksum; both bytes carry the encoded DPI
f[8] = 0x77;
tail_checksum(&mut f);
checksum(&mut f);
f
}
#[derive(serde::Deserialize, serde::Serialize, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub enum DpiLedMode {
#[serde(rename = "Off")]
Off,
#[serde(rename = "Solid")]
Solid,
#[serde(rename = "Breathing")]
Breathing,
}
/// Set frame (0x4C) — only sent for Solid and Breathing, not Off.
pub fn cmd_dpi_led_mode(mode: DpiLedMode) -> Option<[u8; FRAME_LEN]> {
let value = match mode {
DpiLedMode::Off => return None,
DpiLedMode::Solid => 0x01,
DpiLedMode::Breathing => 0x02,
};
let mut f = [0u8; FRAME_LEN];
f[3] = 0x4C;
f[4] = 0x02;
f[5] = value;
Some(build(f))
}
/// Apply frame (0x52) — always sent; 0x01 = LED active (any mode), 0x00 = Off.
pub fn cmd_dpi_led_apply(mode: DpiLedMode) -> [u8; FRAME_LEN] {
let value = match mode {
DpiLedMode::Off => 0x00,
DpiLedMode::Solid | DpiLedMode::Breathing => 0x01,
};
let mut f = [0u8; FRAME_LEN];
f[3] = 0x52;
f[4] = 0x02;
f[5] = value;
build(f)
}
pub fn is_verified_dpi_led_mode(_mode: DpiLedMode) -> bool {
true
}
/// Brightness for the DPI LED. Slider 0-10 maps to raw 0-255 (n * 255 / 10).
pub fn cmd_dpi_led_brightness(raw: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0x4E;
f[4] = 0x02;
f[5] = raw;
build(f)
}
pub fn brightness_to_raw(level: u8) -> u8 {
((level.min(10) as u16 * 255) / 10) as u8
}
/// Breathing speed. ENCAP=0x50, raw value 1-5 (verified: 2,3,4,5 from captures).
pub fn cmd_breathing_speed(speed: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0x50;
f[4] = 0x02;
f[5] = speed.clamp(1, 5);
build(f)
}
#[derive(serde::Deserialize, serde::Serialize, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub enum PollingRate {
#[serde(rename = "Hz125")]
Hz125,
#[serde(rename = "Hz250")]
Hz250,
#[serde(rename = "Hz500")]
Hz500,
#[serde(rename = "Hz1000")]
Hz1000,
#[serde(rename = "Hz2000")]
Hz2000,
#[serde(rename = "Hz4000")]
Hz4000,
#[serde(rename = "Hz8000")]
Hz8000,
}
pub fn is_verified_polling_rate(rate: PollingRate) -> bool {
matches!(
rate,
PollingRate::Hz125
| PollingRate::Hz250
| PollingRate::Hz500
| PollingRate::Hz1000
| PollingRate::Hz2000
| PollingRate::Hz4000
| PollingRate::Hz8000
)
}
fn polling_rate_value(rate: PollingRate) -> u8 {
match rate {
PollingRate::Hz125 => 0x08,
PollingRate::Hz250 => 0x04,
PollingRate::Hz500 => 0x02,
PollingRate::Hz1000 => 0x01,
PollingRate::Hz2000 => 0x10,
PollingRate::Hz4000 => 0x20,
PollingRate::Hz8000 => 0x40,
}
}
pub fn cmd_polling_rate(rate: PollingRate) -> [u8; FRAME_LEN] {
cmd_polling_rate_with_encap(rate, 0x00)
}
pub fn cmd_polling_rate_apply(rate: PollingRate) -> [u8; FRAME_LEN] {
cmd_polling_rate_with_encap(rate, 0xB9)
}
fn cmd_polling_rate_with_encap(rate: PollingRate, encap: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = encap;
f[4] = 0x02;
f[5] = polling_rate_value(rate);
build(f)
}
#[derive(serde::Deserialize, serde::Serialize, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub enum Lod {
#[serde(rename = "Mm07")]
Mm07,
#[serde(rename = "Mm1")]
Mm1,
#[serde(rename = "Mm2")]
Mm2,
}
pub fn is_verified_lod(lod: Lod) -> bool {
matches!(lod, Lod::Mm07 | Lod::Mm1 | Lod::Mm2)
}
pub fn cmd_lod(lod: Lod) -> [u8; FRAME_LEN] {
let val: u8 = match lod {
Lod::Mm07 => 0x03,
Lod::Mm1 => 0x01,
Lod::Mm2 => 0x02,
};
let mut f = [0u8; FRAME_LEN];
f[3] = 0x0A;
f[4] = 0x02;
f[5] = val;
build(f)
}
pub fn cmd_linear_correction(enabled: bool) -> [u8; FRAME_LEN] {
// Captured on-frame: 07 00 00 af 02 01 54 00 ... 40.
// Off is the same toggle shape with byte[5]=0.
let mut f = [0u8; FRAME_LEN];
f[3] = 0xAF;
f[4] = 0x02;
f[5] = u8::from(enabled);
build(f)
}
pub fn cmd_waveform_control(enabled: bool) -> [u8; FRAME_LEN] {
// Captured on-frame: 07 00 00 b1 02 01 54 00 ... 3e.
let mut f = [0u8; FRAME_LEN];
f[3] = 0xB1;
f[4] = 0x02;
f[5] = u8::from(enabled);
build(f)
}
pub fn cmd_motion_sync(enabled: bool) -> [u8; FRAME_LEN] {
// Captured on-frame: 07 00 00 ab 02 01 54 00 ... 44.
let mut f = [0u8; FRAME_LEN];
f[3] = 0xAB;
f[4] = 0x02;
f[5] = u8::from(enabled);
build(f)
}
/// Work mode. ENCAP=0xB9. 0=low power, 1=high performance (ultra/2 not yet captured).
pub fn cmd_work_mode(mode: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xB9;
f[4] = 0x02;
f[5] = mode;
build(f)
}
/// Key debounce time in ms. ENCAP=0xA9. Raw value = ms (verified: 0,5,6,7,8,20).
pub fn cmd_debounce(ms: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xA9;
f[4] = 0x02;
f[5] = ms;
build(f)
}
/// Full-power / rage mode toggle. ENCAP=0xB5. 0=off, 1=on.
pub fn cmd_working_mode(mode: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xB5;
f[4] = 0x02;
f[5] = mode;
build(f)
}
/// Rage-time duration. ENCAP=0xB7. Raw seconds value.
/// Verified values: 1, 3, 6, 12, 18, 36, 60, 90.
pub fn cmd_rage_time(seconds: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xB7;
f[4] = 0x02;
f[5] = seconds;
build(f)
}
/// Long-distance mode (block-write style).
/// ON: 16 00 00 00 0a 01 00 00 00 00 00 00 00 00 00 2c
/// OFF: 16 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 2d
pub fn cmd_long_distance(enabled: bool) -> [u8; FRAME_LEN] {
let v = u8::from(enabled);
let mut f = [0u8; FRAME_LEN];
f[3] = 0x00;
f[4] = 0x0A;
f[5] = v;
f[15] = 0x2Du8.wrapping_sub(v);
checksum(&mut f);
f
}
/// 20K FPS sensor scan rate. ENCAP=0xE1.
pub fn cmd_fps20k(enabled: bool) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xE1;
f[4] = 0x02;
f[5] = u8::from(enabled);
build(f)
}
/// Sleep timer. ENCAP=0xAD, raw value (verified: 7, 8, 100 from captures).
pub fn cmd_sleep(value: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xAD;
f[4] = 0x02;
f[5] = value;
build(f)
}
// ── Block write ────────────────────────────────────────────────────────────
/// Receiver LED (battery indicator on the USB dongle).
/// mode 1 = Hz indicator, mode 2 = battery level, mode 3 = warning only
/// (all three verified by capture; mode 0/off has no capture).
/// byte[15] = 0x33 - mode keeps sum(bytes[2..16]) = 0x39 so byte[0] = 0x14.
pub fn cmd_receiver_led(mode: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0x00;
f[4] = 0x0A;
f[5] = mode;
f[6] = 0x00;
f[7] = 0xFF;
f[8] = 0x00;
f[9] = 0xFF;
f[10] = 0xFF;
f[11] = 0x00;
f[12] = 0xFF;
f[13] = 0x00;
f[14] = 0x00;
f[15] = 0x33u8.wrapping_sub(mode);
checksum(&mut f);
f
}
// ── Block read ─────────────────────────────────────────────────────────────
/// Build a 10-byte block-read frame for the given start address.
/// The device responds with 10 bytes of config memory starting at `addr`.
pub fn cmd_block_read(addr: u8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = addr;
f[4] = 0x0A;
// tail: 0x3B - addr keeps global checksum at 0x08
f[15] = 0x3Bu8.wrapping_sub(addr);
// global checksum: sum(f[2..]) = addr + 0x0A + (0x3B - addr) = 0x45; 0x4D-0x45=0x08
f[0] = 0x08;
f
}
/// Angle snapping enable/disable. ENCAP=0xBF. 0=off, 1=on.
pub fn cmd_angle_enable(enabled: bool) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xBF;
f[4] = 0x02;
f[5] = u8::from(enabled);
build(f)
}
/// Angle snapping value. ENCAP=0xBD. Range: -45..=+45.
/// Positive values stored as-is; negative as two's-complement u8 (e.g. -10 → 0xF6).
pub fn cmd_angle(angle: i8) -> [u8; FRAME_LEN] {
let mut f = [0u8; FRAME_LEN];
f[3] = 0xBD;
f[4] = 0x02;
f[5] = angle as u8;
build(f)
}
/// Factory reset. Hardcoded frame verified from capture.
pub fn cmd_factory_reset() -> [u8; FRAME_LEN] {
[0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44]
}
/// Scalar read that returns the currently active DPI stage index (0-3).
pub fn cmd_read_dpi_stage() -> [u8; FRAME_LEN] {
// byte[15] = 0x3B; checksum = 0x4D - 0x3B = 0x12
let mut f = [0u8; FRAME_LEN];
f[15] = 0x3B;
f[0] = 0x12;
f
}
// ── Unit tests ──────────────────────────────────────────────────────────────
#[cfg(test)]
mod tests {
use super::*;
fn hex(s: &str) -> [u8; FRAME_LEN] {
let bytes: Vec<u8> = s
.split_whitespace()
.map(|h| u8::from_str_radix(h, 16).unwrap())
.collect();
bytes.try_into().expect("frame must be 16 bytes")
}
#[test]
fn test_select_stage_1() {
assert_eq!(cmd_select_stage(0), hex("07 00 00 04 02 00 55 00 00 00 00 00 00 00 00 eb"));
}
#[test]
fn test_status_poll() {
assert_eq!(cmd_status(), hex("03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4a"));
}
#[test]
fn test_battery_query() {
assert_eq!(cmd_battery(), hex("04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 49"));
}
#[test]
fn test_select_stage_2() {
assert_eq!(cmd_select_stage(1), hex("07 00 00 04 02 01 54 00 00 00 00 00 00 00 00 eb"));
}
#[test]
fn test_select_stage_3() {
assert_eq!(cmd_select_stage(2), hex("07 00 00 04 02 02 53 00 00 00 00 00 00 00 00 eb"));
}
#[test]
fn test_select_stage_4() {
assert_eq!(cmd_select_stage(3), hex("07 00 00 04 02 03 52 00 00 00 00 00 00 00 00 eb"));
}
#[test]
fn test_polling_250() {
assert_eq!(cmd_polling_rate(PollingRate::Hz250), hex("07 00 00 00 02 04 51 00 00 00 00 00 00 00 00 ef"));
}
#[test]
fn test_dpi_led_off_apply() {
assert_eq!(cmd_dpi_led_apply(DpiLedMode::Off), hex("07 00 00 52 02 00 55 00 00 00 00 00 00 00 00 9d"));
}
#[test]
fn test_dpi_led_solid() {
assert_eq!(cmd_dpi_led_mode(DpiLedMode::Solid), Some(hex("07 00 00 4c 02 01 54 00 00 00 00 00 00 00 00 a3")));
}
#[test]
fn test_dpi_led_solid_apply() {
assert_eq!(cmd_dpi_led_apply(DpiLedMode::Solid), hex("07 00 00 52 02 01 54 00 00 00 00 00 00 00 00 9d"));
}
#[test]
fn test_dpi_led_breathing() {
assert_eq!(cmd_dpi_led_mode(DpiLedMode::Breathing), Some(hex("07 00 00 4c 02 02 53 00 00 00 00 00 00 00 00 a3")));
}
#[test]
fn test_dpi_led_breathing_apply() {
// Apply frame always sends 0x01 (enabled) regardless of Solid vs Breathing
assert_eq!(cmd_dpi_led_apply(DpiLedMode::Breathing), hex("07 00 00 52 02 01 54 00 00 00 00 00 00 00 00 9d"));
}
#[test]
fn test_dpi_led_off_no_set_frame() {
assert_eq!(cmd_dpi_led_mode(DpiLedMode::Off), None);
}
#[test]
fn test_polling_125() {
assert_eq!(cmd_polling_rate(PollingRate::Hz125), hex("07 00 00 00 02 08 4d 00 00 00 00 00 00 00 00 ef"));
}
#[test]
fn test_polling_125_apply() {
assert_eq!(cmd_polling_rate_apply(PollingRate::Hz125), hex("07 00 00 b9 02 08 4d 00 00 00 00 00 00 00 00 36"));
}
#[test]
fn test_polling_500() {
assert_eq!(cmd_polling_rate(PollingRate::Hz500), hex("07 00 00 00 02 02 53 00 00 00 00 00 00 00 00 ef"));
}
#[test]
fn test_polling_500_apply() {
assert_eq!(cmd_polling_rate_apply(PollingRate::Hz500), hex("07 00 00 b9 02 02 53 00 00 00 00 00 00 00 00 36"));
}
#[test]
fn test_polling_1000() {
assert_eq!(cmd_polling_rate(PollingRate::Hz1000), hex("07 00 00 00 02 01 54 00 00 00 00 00 00 00 00 ef"));
}
#[test]
fn test_polling_1000_apply() {
assert_eq!(cmd_polling_rate_apply(PollingRate::Hz1000), hex("07 00 00 b9 02 01 54 00 00 00 00 00 00 00 00 36"));
}
#[test]
fn test_polling_2000() {
assert_eq!(cmd_polling_rate(PollingRate::Hz2000), hex("07 00 00 00 02 10 45 00 00 00 00 00 00 00 00 ef"));
}
#[test]
fn test_polling_2000_apply() {
assert_eq!(cmd_polling_rate_apply(PollingRate::Hz2000), hex("07 00 00 b9 02 10 45 00 00 00 00 00 00 00 00 36"));
}
#[test]
fn test_polling_4000() {
assert_eq!(cmd_polling_rate(PollingRate::Hz4000), hex("07 00 00 00 02 20 35 00 00 00 00 00 00 00 00 ef"));
}
#[test]
fn test_polling_4000_apply() {
assert_eq!(cmd_polling_rate_apply(PollingRate::Hz4000), hex("07 00 00 b9 02 20 35 00 00 00 00 00 00 00 00 36"));
}
#[test]
fn test_polling_8000() {
assert_eq!(cmd_polling_rate(PollingRate::Hz8000), hex("07 00 00 00 02 40 15 00 00 00 00 00 00 00 00 ef"));
}
#[test]
fn test_lod_07() {
assert_eq!(cmd_lod(Lod::Mm07), hex("07 00 00 0a 02 03 52 00 00 00 00 00 00 00 00 e5"));
}
#[test]
fn test_lod_1mm() {
assert_eq!(cmd_lod(Lod::Mm1), hex("07 00 00 0a 02 01 54 00 00 00 00 00 00 00 00 e5"));
}
#[test]
fn test_lod_2mm() {
assert_eq!(cmd_lod(Lod::Mm2), hex("07 00 00 0a 02 02 53 00 00 00 00 00 00 00 00 e5"));
}
#[test]
fn test_linear_correction_on() {
assert_eq!(cmd_linear_correction(true), hex("07 00 00 af 02 01 54 00 00 00 00 00 00 00 00 40"));
}
#[test]
fn test_linear_correction_off() {
assert_eq!(cmd_linear_correction(false), hex("07 00 00 af 02 00 55 00 00 00 00 00 00 00 00 40"));
}
#[test]
fn test_waveform_control_on() {
assert_eq!(cmd_waveform_control(true), hex("07 00 00 b1 02 01 54 00 00 00 00 00 00 00 00 3e"));
}
#[test]
fn test_waveform_control_off() {
assert_eq!(cmd_waveform_control(false), hex("07 00 00 b1 02 00 55 00 00 00 00 00 00 00 00 3e"));
}
#[test]
fn test_motion_sync_on() {
assert_eq!(cmd_motion_sync(true), hex("07 00 00 ab 02 01 54 00 00 00 00 00 00 00 00 44"));
}
#[test]
fn test_motion_sync_off() {
assert_eq!(cmd_motion_sync(false), hex("07 00 00 ab 02 00 55 00 00 00 00 00 00 00 00 44"));
}
#[test]
fn test_work_mode_low() { assert_eq!(cmd_work_mode(0), hex("07 00 00 b9 02 00 55 00 00 00 00 00 00 00 00 36")); }
#[test]
fn test_work_mode_high() { assert_eq!(cmd_work_mode(1), hex("07 00 00 b9 02 01 54 00 00 00 00 00 00 00 00 36")); }
#[test]
fn test_debounce_8ms() { assert_eq!(cmd_debounce(8), hex("07 00 00 a9 02 08 4d 00 00 00 00 00 00 00 00 46")); }
#[test]
fn test_debounce_20ms() { assert_eq!(cmd_debounce(20), hex("07 00 00 a9 02 14 41 00 00 00 00 00 00 00 00 46")); }
#[test]
fn test_debounce_0ms() { assert_eq!(cmd_debounce(0), hex("07 00 00 a9 02 00 55 00 00 00 00 00 00 00 00 46")); }
#[test]
fn test_working_mode_off() {
assert_eq!(cmd_working_mode(0), hex("07 00 00 b5 02 00 55 00 00 00 00 00 00 00 00 3a"));
}
#[test]
fn test_working_mode_on() {
assert_eq!(cmd_working_mode(1), hex("07 00 00 b5 02 01 54 00 00 00 00 00 00 00 00 3a"));
}
#[test]
fn test_rage_time_1s() { assert_eq!(cmd_rage_time(1), hex("07 00 00 b7 02 01 54 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_rage_time_3s() { assert_eq!(cmd_rage_time(3), hex("07 00 00 b7 02 03 52 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_rage_time_6s() { assert_eq!(cmd_rage_time(6), hex("07 00 00 b7 02 06 4f 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_rage_time_12s() { assert_eq!(cmd_rage_time(12), hex("07 00 00 b7 02 0c 49 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_rage_time_18s() { assert_eq!(cmd_rage_time(18), hex("07 00 00 b7 02 12 43 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_rage_time_36s() { assert_eq!(cmd_rage_time(36), hex("07 00 00 b7 02 24 31 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_rage_time_60s() { assert_eq!(cmd_rage_time(60), hex("07 00 00 b7 02 3c 19 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_rage_time_90s() { assert_eq!(cmd_rage_time(90), hex("07 00 00 b7 02 5a fb 00 00 00 00 00 00 00 00 38")); }
#[test]
fn test_long_distance_on() {
assert_eq!(cmd_long_distance(true), hex("16 00 00 00 0a 01 00 00 00 00 00 00 00 00 00 2c"));
}
#[test]
fn test_long_distance_off() {
assert_eq!(cmd_long_distance(false), hex("16 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 2d"));
}
#[test]
fn test_fps20k_on() {
assert_eq!(cmd_fps20k(true), hex("07 00 00 e1 02 01 54 00 00 00 00 00 00 00 00 0e"));
}
#[test]
fn test_fps20k_off() {
assert_eq!(cmd_fps20k(false), hex("07 00 00 e1 02 00 55 00 00 00 00 00 00 00 00 0e"));
}
#[test]
fn test_receiver_led_hz() {
assert_eq!(cmd_receiver_led(1), hex("14 00 00 00 0a 01 00 ff 00 ff ff 00 ff 00 00 32"));
}
#[test]
fn test_receiver_led_battery() {
assert_eq!(cmd_receiver_led(2), hex("14 00 00 00 0a 02 00 ff 00 ff ff 00 ff 00 00 31"));
}
#[test]
fn test_receiver_led_warning_only() {
assert_eq!(cmd_receiver_led(3), hex("14 00 00 00 0a 03 00 ff 00 ff ff 00 ff 00 00 30"));
}
#[test]
fn test_block_read_addr_00() {
assert_eq!(cmd_block_read(0x00), hex("08 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 3b"));
}
#[test]
fn test_block_read_addr_0a() {
assert_eq!(cmd_block_read(0x0A), hex("08 00 00 0a 0a 00 00 00 00 00 00 00 00 00 00 31"));
}
#[test]
fn test_block_read_addr_14() {
assert_eq!(cmd_block_read(0x14), hex("08 00 00 14 0a 00 00 00 00 00 00 00 00 00 00 27"));
}
#[test]
fn test_block_read_addr_aa() {
assert_eq!(cmd_block_read(0xAA), hex("08 00 00 aa 0a 00 00 00 00 00 00 00 00 00 00 91"));
}
#[test]
fn test_read_dpi_stage() {
assert_eq!(cmd_read_dpi_stage(), hex("12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3b"));
}
#[test]
fn test_set_dpi_5600_stage4() {
assert_eq!(cmd_set_dpi(3, 5600), hex("07 00 00 18 04 6f 6f 00 77 00 00 00 00 00 00 d5"));
}
}