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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
/* ***********************************************************
 * This file was automatically generated on 2018-11-21.      *
 *                                                           *
 * Rust Bindings Version 2.0.4                               *
 *                                                           *
 * If you have a bugfix for this file and want to commit it, *
 * please fix the bug in the generator. You can find a link  *
 * to the generators git repository on tinkerforge.com       *
 *************************************************************/

//! Drives up to 7 RC Servos with up to 3A
//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricks/Servo_Brick_Rust.html).
use crate::{
    byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
    ip_connection::IpConnection,
};
pub enum ServoBrickFunction {
    Enable,
    Disable,
    IsEnabled,
    SetPosition,
    GetPosition,
    GetCurrentPosition,
    SetVelocity,
    GetVelocity,
    GetCurrentVelocity,
    SetAcceleration,
    GetAcceleration,
    SetOutputVoltage,
    GetOutputVoltage,
    SetPulseWidth,
    GetPulseWidth,
    SetDegree,
    GetDegree,
    SetPeriod,
    GetPeriod,
    GetServoCurrent,
    GetOverallCurrent,
    GetStackInputVoltage,
    GetExternalInputVoltage,
    SetMinimumVoltage,
    GetMinimumVoltage,
    EnablePositionReachedCallback,
    DisablePositionReachedCallback,
    IsPositionReachedCallbackEnabled,
    EnableVelocityReachedCallback,
    DisableVelocityReachedCallback,
    IsVelocityReachedCallbackEnabled,
    SetSpitfpBaudrateConfig,
    GetSpitfpBaudrateConfig,
    GetSendTimeoutCount,
    SetSpitfpBaudrate,
    GetSpitfpBaudrate,
    GetSpitfpErrorCount,
    EnableStatusLed,
    DisableStatusLed,
    IsStatusLedEnabled,
    GetProtocol1BrickletName,
    GetChipTemperature,
    Reset,
    GetIdentity,
    CallbackUnderVoltage,
    CallbackPositionReached,
    CallbackVelocityReached,
}
impl From<ServoBrickFunction> for u8 {
    fn from(fun: ServoBrickFunction) -> Self {
        match fun {
            ServoBrickFunction::Enable => 1,
            ServoBrickFunction::Disable => 2,
            ServoBrickFunction::IsEnabled => 3,
            ServoBrickFunction::SetPosition => 4,
            ServoBrickFunction::GetPosition => 5,
            ServoBrickFunction::GetCurrentPosition => 6,
            ServoBrickFunction::SetVelocity => 7,
            ServoBrickFunction::GetVelocity => 8,
            ServoBrickFunction::GetCurrentVelocity => 9,
            ServoBrickFunction::SetAcceleration => 10,
            ServoBrickFunction::GetAcceleration => 11,
            ServoBrickFunction::SetOutputVoltage => 12,
            ServoBrickFunction::GetOutputVoltage => 13,
            ServoBrickFunction::SetPulseWidth => 14,
            ServoBrickFunction::GetPulseWidth => 15,
            ServoBrickFunction::SetDegree => 16,
            ServoBrickFunction::GetDegree => 17,
            ServoBrickFunction::SetPeriod => 18,
            ServoBrickFunction::GetPeriod => 19,
            ServoBrickFunction::GetServoCurrent => 20,
            ServoBrickFunction::GetOverallCurrent => 21,
            ServoBrickFunction::GetStackInputVoltage => 22,
            ServoBrickFunction::GetExternalInputVoltage => 23,
            ServoBrickFunction::SetMinimumVoltage => 24,
            ServoBrickFunction::GetMinimumVoltage => 25,
            ServoBrickFunction::EnablePositionReachedCallback => 29,
            ServoBrickFunction::DisablePositionReachedCallback => 30,
            ServoBrickFunction::IsPositionReachedCallbackEnabled => 31,
            ServoBrickFunction::EnableVelocityReachedCallback => 32,
            ServoBrickFunction::DisableVelocityReachedCallback => 33,
            ServoBrickFunction::IsVelocityReachedCallbackEnabled => 34,
            ServoBrickFunction::SetSpitfpBaudrateConfig => 231,
            ServoBrickFunction::GetSpitfpBaudrateConfig => 232,
            ServoBrickFunction::GetSendTimeoutCount => 233,
            ServoBrickFunction::SetSpitfpBaudrate => 234,
            ServoBrickFunction::GetSpitfpBaudrate => 235,
            ServoBrickFunction::GetSpitfpErrorCount => 237,
            ServoBrickFunction::EnableStatusLed => 238,
            ServoBrickFunction::DisableStatusLed => 239,
            ServoBrickFunction::IsStatusLedEnabled => 240,
            ServoBrickFunction::GetProtocol1BrickletName => 241,
            ServoBrickFunction::GetChipTemperature => 242,
            ServoBrickFunction::Reset => 243,
            ServoBrickFunction::GetIdentity => 255,
            ServoBrickFunction::CallbackUnderVoltage => 26,
            ServoBrickFunction::CallbackPositionReached => 27,
            ServoBrickFunction::CallbackVelocityReached => 28,
        }
    }
}
pub const SERVO_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
pub const SERVO_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
pub const SERVO_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
pub const SERVO_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
pub const SERVO_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
pub const SERVO_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
pub const SERVO_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
pub const SERVO_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct PulseWidth {
    pub min: u16,
    pub max: u16,
}
impl FromByteSlice for PulseWidth {
    fn bytes_expected() -> usize { 4 }
    fn from_le_bytes(bytes: &[u8]) -> PulseWidth {
        PulseWidth { min: <u16>::from_le_bytes(&bytes[0..2]), max: <u16>::from_le_bytes(&bytes[2..4]) }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Degree {
    pub min: i16,
    pub max: i16,
}
impl FromByteSlice for Degree {
    fn bytes_expected() -> usize { 4 }
    fn from_le_bytes(bytes: &[u8]) -> Degree { Degree { min: <i16>::from_le_bytes(&bytes[0..2]), max: <i16>::from_le_bytes(&bytes[2..4]) } }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct PositionReachedEvent {
    pub servo_num: u8,
    pub position: i16,
}
impl FromByteSlice for PositionReachedEvent {
    fn bytes_expected() -> usize { 3 }
    fn from_le_bytes(bytes: &[u8]) -> PositionReachedEvent {
        PositionReachedEvent { servo_num: <u8>::from_le_bytes(&bytes[0..1]), position: <i16>::from_le_bytes(&bytes[1..3]) }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct VelocityReachedEvent {
    pub servo_num: u8,
    pub velocity: i16,
}
impl FromByteSlice for VelocityReachedEvent {
    fn bytes_expected() -> usize { 3 }
    fn from_le_bytes(bytes: &[u8]) -> VelocityReachedEvent {
        VelocityReachedEvent { servo_num: <u8>::from_le_bytes(&bytes[0..1]), velocity: <i16>::from_le_bytes(&bytes[1..3]) }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpBaudrateConfig {
    pub enable_dynamic_baudrate: bool,
    pub minimum_dynamic_baudrate: u32,
}
impl FromByteSlice for SpitfpBaudrateConfig {
    fn bytes_expected() -> usize { 5 }
    fn from_le_bytes(bytes: &[u8]) -> SpitfpBaudrateConfig {
        SpitfpBaudrateConfig {
            enable_dynamic_baudrate: <bool>::from_le_bytes(&bytes[0..1]),
            minimum_dynamic_baudrate: <u32>::from_le_bytes(&bytes[1..5]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpErrorCount {
    pub error_count_ack_checksum: u32,
    pub error_count_message_checksum: u32,
    pub error_count_frame: u32,
    pub error_count_overflow: u32,
}
impl FromByteSlice for SpitfpErrorCount {
    fn bytes_expected() -> usize { 16 }
    fn from_le_bytes(bytes: &[u8]) -> SpitfpErrorCount {
        SpitfpErrorCount {
            error_count_ack_checksum: <u32>::from_le_bytes(&bytes[0..4]),
            error_count_message_checksum: <u32>::from_le_bytes(&bytes[4..8]),
            error_count_frame: <u32>::from_le_bytes(&bytes[8..12]),
            error_count_overflow: <u32>::from_le_bytes(&bytes[12..16]),
        }
    }
}

#[derive(Clone)]
pub struct Protocol1BrickletName {
    pub protocol_version: u8,
    pub firmware_version: [u8; 3],
    pub name: String,
}
impl FromByteSlice for Protocol1BrickletName {
    fn bytes_expected() -> usize { 44 }
    fn from_le_bytes(bytes: &[u8]) -> Protocol1BrickletName {
        Protocol1BrickletName {
            protocol_version: <u8>::from_le_bytes(&bytes[0..1]),
            firmware_version: <[u8; 3]>::from_le_bytes(&bytes[1..4]),
            name: <String>::from_le_bytes(&bytes[4..44]),
        }
    }
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Identity {
    pub uid: String,
    pub connected_uid: String,
    pub position: char,
    pub hardware_version: [u8; 3],
    pub firmware_version: [u8; 3],
    pub device_identifier: u16,
}
impl FromByteSlice for Identity {
    fn bytes_expected() -> usize { 25 }
    fn from_le_bytes(bytes: &[u8]) -> Identity {
        Identity {
            uid: <String>::from_le_bytes(&bytes[0..8]),
            connected_uid: <String>::from_le_bytes(&bytes[8..16]),
            position: <char>::from_le_bytes(&bytes[16..17]),
            hardware_version: <[u8; 3]>::from_le_bytes(&bytes[17..20]),
            firmware_version: <[u8; 3]>::from_le_bytes(&bytes[20..23]),
            device_identifier: <u16>::from_le_bytes(&bytes[23..25]),
        }
    }
}

/// Drives up to 7 RC Servos with up to 3A
#[derive(Clone)]
pub struct ServoBrick {
    device: Device,
}
impl ServoBrick {
    pub const DEVICE_IDENTIFIER: u16 = 14;
    pub const DEVICE_DISPLAY_NAME: &'static str = "Servo Brick";
    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
    pub fn new(uid: &str, ip_connection: &IpConnection) -> ServoBrick {
        let mut result = ServoBrick { device: Device::new([2, 0, 4], uid, ip_connection, 0) };
        result.device.response_expected[u8::from(ServoBrickFunction::Enable) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::Disable) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::IsEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetPosition) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetCurrentPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetVelocity) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetCurrentVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetAcceleration) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetAcceleration) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetOutputVoltage) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetOutputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetPulseWidth) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetPulseWidth) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetDegree) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetDegree) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetPeriod) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetServoCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetOverallCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetStackInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetExternalInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetMinimumVoltage) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(ServoBrickFunction::GetMinimumVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::EnablePositionReachedCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(ServoBrickFunction::DisablePositionReachedCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(ServoBrickFunction::IsPositionReachedCallbackEnabled) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::EnableVelocityReachedCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(ServoBrickFunction::DisableVelocityReachedCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(ServoBrickFunction::IsVelocityReachedCallbackEnabled) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetProtocol1BrickletName) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(ServoBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(ServoBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result
    }

    /// Returns the response expected flag for the function specified by the function ID parameter.
    /// It is true if the function is expected to send a response, false otherwise.
    ///
    /// For getter functions this is enabled by default and cannot be disabled, because those
    /// functions will always send a response. For callback configuration functions it is enabled
    /// by default too, but can be disabled by [`set_response_expected`](crate::servo_brick::ServoBrick::set_response_expected).
    /// For setter functions it is disabled by default and can be enabled.
    ///
    /// Enabling the response expected flag for a setter function allows to detect timeouts
    /// and other error conditions calls of this setter as well. The device will then send a response
    /// for this purpose. If this flag is disabled for a setter function then no response is send
    /// and errors are silently ignored, because they cannot be detected.
    ///
    /// See [`set_response_expected`](crate::servo_brick::ServoBrick::set_response_expected) for the list of function ID constants available for this function.
    pub fn get_response_expected(&mut self, fun: ServoBrickFunction) -> Result<bool, GetResponseExpectedError> {
        self.device.get_response_expected(u8::from(fun))
    }

    /// Changes the response expected flag of the function specified by the function ID parameter.
    /// This flag can only be changed for setter (default value: false) and callback configuration
    /// functions (default value: true). For getter functions it is always enabled.
    ///
    /// Enabling the response expected flag for a setter function allows to detect timeouts and
    /// other error conditions calls of this setter as well. The device will then send a response
    /// for this purpose. If this flag is disabled for a setter function then no response is send
    /// and errors are silently ignored, because they cannot be detected.
    pub fn set_response_expected(&mut self, fun: ServoBrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
        self.device.set_response_expected(u8::from(fun), response_expected)
    }

    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
    pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }

    /// This receiver is triggered when the input voltage drops below the value set by
    /// [`set_minimum_voltage`]. The parameter is the current voltage given
    /// in mV.
    ///
    /// [`set_minimum_voltage`]: #method.set_minimum_voltage
    pub fn get_under_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
        self.device.get_callback_receiver(u8::from(ServoBrickFunction::CallbackUnderVoltage))
    }

    /// This receiver is triggered when a position set by [`set_position`]
    /// is reached. If the new position matches the current position then the
    /// receiver is not triggered, because the servo didn't move.
    /// The parameters are the servo and the position that is reached.
    ///
    /// You can enable this receiver with [`enable_position_reached_callback`].
    ///
    /// # Note
    ///  Since we can't get any feedback from the servo, this only works if the
    ///  velocity (see [`set_velocity`]) is set smaller or equal to the
    ///  maximum velocity of the servo. Otherwise the servo will lag behind the
    ///  control value and the receiver will be triggered too early.
    ///
    /// [`set_position`]: #method.set_position
    /// [`set_velocity`]: #method.set_velocity
    /// [`enable_position_reached_callback`]: #method.enable_position_reached_callback
    pub fn get_position_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<PositionReachedEvent> {
        self.device.get_callback_receiver(u8::from(ServoBrickFunction::CallbackPositionReached))
    }

    /// This receiver is triggered when a velocity set by [`set_velocity`]
    /// is reached. The parameters are the servo and the velocity that is reached.
    ///
    /// You can enable this receiver with [`enable_velocity_reached_callback`].
    ///
    /// # Note
    ///  Since we can't get any feedback from the servo, this only works if the
    ///  acceleration (see [`set_acceleration`]) is set smaller or equal to the
    ///  maximum acceleration of the servo. Otherwise the servo will lag behind the
    ///  control value and the receiver will be triggered too early.
    ///
    /// [`set_velocity`]: #method.set_velocity
    /// [`set_acceleration`]: #method.set_acceleration
    /// [`enable_velocity_reached_callback`]: #method.enable_velocity_reached_callback
    pub fn get_velocity_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<VelocityReachedEvent> {
        self.device.get_callback_receiver(u8::from(ServoBrickFunction::CallbackVelocityReached))
    }

    /// Enables a servo (0 to 6). If a servo is enabled, the configured position,
    /// velocity, acceleration, etc. are applied immediately.
    pub fn enable(&self, servo_num: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.set(u8::from(ServoBrickFunction::Enable), payload)
    }

    /// Disables a servo (0 to 6). Disabled servos are not driven at all, i.e. a
    /// disabled servo will not hold its position if a load is applied.
    pub fn disable(&self, servo_num: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.set(u8::from(ServoBrickFunction::Disable), payload)
    }

    /// Returns *true* if the specified servo is enabled, *false* otherwise.
    pub fn is_enabled(&self, servo_num: u8) -> ConvertingReceiver<bool> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::IsEnabled), payload)
    }

    /// Sets the position in °/100 for the specified servo.
    ///
    /// The default range of the position is -9000 to 9000, but it can be specified
    /// according to your servo with [`set_degree`].
    ///
    /// If you want to control a linear servo or RC brushless motor controller or
    /// similar with the Servo Brick, you can also define lengths or speeds with
    /// [`set_degree`].
    ///
    /// [`set_degree`]: #method.set_degree
    pub fn set_position(&self, servo_num: u8, position: i16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 3];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));
        payload[1..3].copy_from_slice(&<i16>::to_le_bytes(position));

        self.device.set(u8::from(ServoBrickFunction::SetPosition), payload)
    }

    /// Returns the position of the specified servo as set by [`set_position`].
    ///
    /// [`set_position`]: #method.set_position
    pub fn get_position(&self, servo_num: u8) -> ConvertingReceiver<i16> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetPosition), payload)
    }

    /// Returns the *current* position of the specified servo. This may not be the
    /// value of [`set_position`] if the servo is currently approaching a
    /// position goal.
    ///
    /// [`set_position`]: #method.set_position
    pub fn get_current_position(&self, servo_num: u8) -> ConvertingReceiver<i16> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetCurrentPosition), payload)
    }

    /// Sets the maximum velocity of the specified servo in °/100s. The velocity
    /// is accelerated according to the value set by [`set_acceleration`].
    ///
    /// The minimum velocity is 0 (no movement) and the maximum velocity is 65535.
    /// With a value of 65535 the position will be set immediately (no velocity).
    ///
    /// The default value is 65535.
    ///
    /// [`set_acceleration`]: #method.set_acceleration
    pub fn set_velocity(&self, servo_num: u8, velocity: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 3];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));
        payload[1..3].copy_from_slice(&<u16>::to_le_bytes(velocity));

        self.device.set(u8::from(ServoBrickFunction::SetVelocity), payload)
    }

    /// Returns the velocity of the specified servo as set by [`set_velocity`].
    ///
    /// [`set_velocity`]: #method.set_velocity
    pub fn get_velocity(&self, servo_num: u8) -> ConvertingReceiver<u16> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetVelocity), payload)
    }

    /// Returns the *current* velocity of the specified servo. This may not be the
    /// value of [`set_velocity`] if the servo is currently approaching a
    /// velocity goal.
    ///
    /// [`set_velocity`]: #method.set_velocity
    pub fn get_current_velocity(&self, servo_num: u8) -> ConvertingReceiver<u16> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetCurrentVelocity), payload)
    }

    /// Sets the acceleration of the specified servo in °/100s².
    ///
    /// The minimum acceleration is 1 and the maximum acceleration is 65535.
    /// With a value of 65535 the velocity will be set immediately (no acceleration).
    ///
    /// The default value is 65535.
    pub fn set_acceleration(&self, servo_num: u8, acceleration: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 3];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));
        payload[1..3].copy_from_slice(&<u16>::to_le_bytes(acceleration));

        self.device.set(u8::from(ServoBrickFunction::SetAcceleration), payload)
    }

    /// Returns the acceleration for the specified servo as set by
    /// [`set_acceleration`].
    ///
    /// [`set_acceleration`]: #method.set_acceleration
    pub fn get_acceleration(&self, servo_num: u8) -> ConvertingReceiver<u16> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetAcceleration), payload)
    }

    /// Sets the output voltages with which the servos are driven in mV.
    /// The minimum output voltage is 2000mV and the maximum output voltage is
    /// 9000mV.
    ///
    /// # Note
    ///  We recommend that you set this value to the maximum voltage that is
    ///  specified for your servo, most servos achieve their maximum force only
    ///  with high voltages.
    ///
    /// The default value is 5000.
    pub fn set_output_voltage(&self, voltage: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 2];
        payload[0..2].copy_from_slice(&<u16>::to_le_bytes(voltage));

        self.device.set(u8::from(ServoBrickFunction::SetOutputVoltage), payload)
    }

    /// Returns the output voltage as specified by [`set_output_voltage`].
    ///
    /// [`set_output_voltage`]: #method.set_output_voltage
    pub fn get_output_voltage(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetOutputVoltage), payload)
    }

    /// Sets the minimum and maximum pulse width of the specified servo in µs.
    ///
    /// Usually, servos are controlled with a
    /// [PWM](https://en.wikipedia.org/wiki/Pulse-width_modulation)__, whereby the
    /// length of the pulse controls the position of the servo. Every servo has
    /// different minimum and maximum pulse widths, these can be specified with
    /// this function.
    ///
    /// If you have a datasheet for your servo that specifies the minimum and
    /// maximum pulse width, you should set the values accordingly. If your servo
    /// comes without any datasheet you have to find the values via trial and error.
    ///
    /// Both values have a range from 1 to 65535 (unsigned 16-bit integer). The
    /// minimum must be smaller than the maximum.
    ///
    /// The default values are 1000µs (1ms) and 2000µs (2ms) for minimum and
    /// maximum pulse width.
    pub fn set_pulse_width(&self, servo_num: u8, min: u16, max: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 5];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));
        payload[1..3].copy_from_slice(&<u16>::to_le_bytes(min));
        payload[3..5].copy_from_slice(&<u16>::to_le_bytes(max));

        self.device.set(u8::from(ServoBrickFunction::SetPulseWidth), payload)
    }

    /// Returns the minimum and maximum pulse width for the specified servo as set by
    /// [`set_pulse_width`].
    ///
    /// [`set_pulse_width`]: #method.set_pulse_width
    pub fn get_pulse_width(&self, servo_num: u8) -> ConvertingReceiver<PulseWidth> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetPulseWidth), payload)
    }

    /// Sets the minimum and maximum degree for the specified servo (by default
    /// given as °/100).
    ///
    /// This only specifies the abstract values between which the minimum and maximum
    /// pulse width is scaled. For example: If you specify a pulse width of 1000µs
    /// to 2000µs and a degree range of -90° to 90°, a call of [`set_position`]
    /// with 0 will result in a pulse width of 1500µs
    /// (-90° = 1000µs, 90° = 2000µs, etc.).
    ///
    /// Possible usage:
    ///
    /// * The datasheet of your servo specifies a range of 200° with the middle position
    ///   at 110°. In this case you can set the minimum to -9000 and the maximum to 11000.
    /// * You measure a range of 220° on your servo and you don't have or need a middle
    ///   position. In this case you can set the minimum to 0 and the maximum to 22000.
    /// * You have a linear servo with a drive length of 20cm, In this case you could
    ///   set the minimum to 0 and the maximum to 20000. Now you can set the Position
    ///   with [`set_position`] with a resolution of cm/100. Also the velocity will
    ///   have a resolution of cm/100s and the acceleration will have a resolution of
    ///   cm/100s².
    /// * You don't care about units and just want the highest possible resolution. In
    ///   this case you should set the minimum to -32767 and the maximum to 32767.
    /// * You have a brushless motor with a maximum speed of 10000 rpm and want to
    ///   control it with a RC brushless motor controller. In this case you can set the
    ///   minimum to 0 and the maximum to 10000. [`set_position`] now controls the rpm.
    ///
    /// Both values have a possible range from -32767 to 32767
    /// (signed 16-bit integer). The minimum must be smaller than the maximum.
    ///
    /// The default values are -9000 and 9000 for the minimum and maximum degree.
    ///
    /// [`set_position`]: #method.set_position
    pub fn set_degree(&self, servo_num: u8, min: i16, max: i16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 5];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));
        payload[1..3].copy_from_slice(&<i16>::to_le_bytes(min));
        payload[3..5].copy_from_slice(&<i16>::to_le_bytes(max));

        self.device.set(u8::from(ServoBrickFunction::SetDegree), payload)
    }

    /// Returns the minimum and maximum degree for the specified servo as set by
    /// [`set_degree`].
    ///
    /// [`set_degree`]: #method.set_degree
    pub fn get_degree(&self, servo_num: u8) -> ConvertingReceiver<Degree> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetDegree), payload)
    }

    /// Sets the period of the specified servo in µs.
    ///
    /// Usually, servos are controlled with a
    /// [PWM](https://en.wikipedia.org/wiki/Pulse-width_modulation)__. Different
    /// servos expect PWMs with different periods. Most servos run well with a
    /// period of about 20ms.
    ///
    /// If your servo comes with a datasheet that specifies a period, you should
    /// set it accordingly. If you don't have a datasheet and you have no idea
    /// what the correct period is, the default value (19.5ms) will most likely
    /// work fine.
    ///
    /// The minimum possible period is 1µs and the maximum is 65535µs.
    ///
    /// The default value is 19.5ms (19500µs).
    pub fn set_period(&self, servo_num: u8, period: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 3];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));
        payload[1..3].copy_from_slice(&<u16>::to_le_bytes(period));

        self.device.set(u8::from(ServoBrickFunction::SetPeriod), payload)
    }

    /// Returns the period for the specified servo as set by [`set_period`].
    ///
    /// [`set_period`]: #method.set_period
    pub fn get_period(&self, servo_num: u8) -> ConvertingReceiver<u16> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetPeriod), payload)
    }

    /// Returns the current consumption of the specified servo in mA.
    pub fn get_servo_current(&self, servo_num: u8) -> ConvertingReceiver<u16> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(servo_num));

        self.device.get(u8::from(ServoBrickFunction::GetServoCurrent), payload)
    }

    /// Returns the current consumption of all servos together in mA.
    pub fn get_overall_current(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetOverallCurrent), payload)
    }

    /// Returns the stack input voltage in mV. The stack input voltage is the
    /// voltage that is supplied via the stack, i.e. it is given by a
    /// Step-Down or Step-Up Power Supply.
    pub fn get_stack_input_voltage(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetStackInputVoltage), payload)
    }

    /// Returns the external input voltage in mV. The external input voltage is
    /// given via the black power input connector on the Servo Brick.
    ///
    /// If there is an external input voltage and a stack input voltage, the motors
    /// will be driven by the external input voltage. If there is only a stack
    /// voltage present, the motors will be driven by this voltage.
    ///
    /// # Warning
    ///  This means, if you have a high stack voltage and a low external voltage,
    ///  the motors will be driven with the low external voltage. If you then remove
    ///  the external connection, it will immediately be driven by the high
    ///  stack voltage
    pub fn get_external_input_voltage(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetExternalInputVoltage), payload)
    }

    /// Sets the minimum voltage in mV, below which the [`get_under_voltage_callback_receiver`] receiver
    /// is triggered. The minimum possible value that works with the Servo Brick is 5V.
    /// You can use this function to detect the discharge of a battery that is used
    /// to drive the stepper motor. If you have a fixed power supply, you likely do
    /// not need this functionality.
    ///
    /// The default value is 5V (5000mV).
    ///
    /// [`get_under_voltage_callback_receiver`]: #method.get_under_voltage_callback_receiver
    pub fn set_minimum_voltage(&self, voltage: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 2];
        payload[0..2].copy_from_slice(&<u16>::to_le_bytes(voltage));

        self.device.set(u8::from(ServoBrickFunction::SetMinimumVoltage), payload)
    }

    /// Returns the minimum voltage as set by [`set_minimum_voltage`]
    ///
    /// [`set_minimum_voltage`]: #method.set_minimum_voltage
    pub fn get_minimum_voltage(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetMinimumVoltage), payload)
    }

    /// Enables the [`get_position_reached_callback_receiver`] receiver.
    ///
    /// Default is disabled.
    ///
    /// [`get_position_reached_callback_receiver`]: #method.get_position_reached_callback_receiver
    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
    pub fn enable_position_reached_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(ServoBrickFunction::EnablePositionReachedCallback), payload)
    }

    /// Disables the [`get_position_reached_callback_receiver`] receiver.
    ///
    /// Default is disabled.
    ///
    /// [`get_position_reached_callback_receiver`]: #method.get_position_reached_callback_receiver
    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
    pub fn disable_position_reached_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(ServoBrickFunction::DisablePositionReachedCallback), payload)
    }

    /// Returns *true* if [`get_position_reached_callback_receiver`] receiver is enabled, *false* otherwise.
    ///
    /// [`get_position_reached_callback_receiver`]: #method.get_position_reached_callback_receiver
    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
    pub fn is_position_reached_callback_enabled(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::IsPositionReachedCallbackEnabled), payload)
    }

    /// Enables the [`get_velocity_reached_callback_receiver`] receiver.
    ///
    /// Default is disabled.
    ///
    /// [`get_velocity_reached_callback_receiver`]: #method.get_velocity_reached_callback_receiver
    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
    pub fn enable_velocity_reached_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(ServoBrickFunction::EnableVelocityReachedCallback), payload)
    }

    /// Disables the [`get_velocity_reached_callback_receiver`] receiver.
    ///
    /// Default is disabled.
    ///
    /// [`get_velocity_reached_callback_receiver`]: #method.get_velocity_reached_callback_receiver
    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
    pub fn disable_velocity_reached_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(ServoBrickFunction::DisableVelocityReachedCallback), payload)
    }

    /// Returns *true* if [`get_velocity_reached_callback_receiver`] receiver is enabled, *false* otherwise.
    ///
    /// [`get_velocity_reached_callback_receiver`]: #method.get_velocity_reached_callback_receiver
    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
    pub fn is_velocity_reached_callback_enabled(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::IsVelocityReachedCallbackEnabled), payload)
    }

    /// The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is
    /// enabled, the Brick will try to adapt the baudrate for the communication
    /// between Bricks and Bricklets according to the amount of data that is transferred.
    ///
    /// The baudrate will be increased exponentially if lots of data is send/received and
    /// decreased linearly if little data is send/received.
    ///
    /// This lowers the baudrate in applications where little data is transferred (e.g.
    /// a weather station) and increases the robustness. If there is lots of data to transfer
    /// (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.
    ///
    /// In cases where some data has to transferred as fast as possible every few seconds
    /// (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn
    /// the dynamic baudrate off to get the highest possible performance.
    ///
    /// The maximum value of the baudrate can be set per port with the function
    /// [`set_spitfp_baudrate`]. If the dynamic baudrate is disabled, the baudrate
    /// as set by [`set_spitfp_baudrate`] will be used statically.
    ///
    /// The minimum dynamic baudrate has a value range of 400000 to 2000000 baud.
    ///
    /// By default dynamic baudrate is enabled and the minimum dynamic baudrate is 400000.
    ///
    /// [`set_spitfp_baudrate`]: #method.set_spitfp_baudrate
    /// .. versionadded:: 2.3.4$nbsp;(Firmware)
    pub fn set_spitfp_baudrate_config(&self, enable_dynamic_baudrate: bool, minimum_dynamic_baudrate: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 5];
        payload[0..1].copy_from_slice(&<bool>::to_le_bytes(enable_dynamic_baudrate));
        payload[1..5].copy_from_slice(&<u32>::to_le_bytes(minimum_dynamic_baudrate));

        self.device.set(u8::from(ServoBrickFunction::SetSpitfpBaudrateConfig), payload)
    }

    /// Returns the baudrate config, see [`set_spitfp_baudrate_config`].
    ///
    /// [`set_spitfp_baudrate_config`]: #method.set_spitfp_baudrate_config
    /// .. versionadded:: 2.3.4$nbsp;(Firmware)
    pub fn get_spitfp_baudrate_config(&self) -> ConvertingReceiver<SpitfpBaudrateConfig> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetSpitfpBaudrateConfig), payload)
    }

    /// Returns the timeout count for the different communication methods.
    ///
    /// The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.
    ///
    /// This function is mostly used for debugging during development, in normal operation
    /// the counters should nearly always stay at 0.
    ///
    ///
    /// .. versionadded:: 2.3.2$nbsp;(Firmware)
    ///
    /// Associated constants:
    /// * SERVO_BRICK_COMMUNICATION_METHOD_NONE
    ///	* SERVO_BRICK_COMMUNICATION_METHOD_USB
    ///	* SERVO_BRICK_COMMUNICATION_METHOD_SPI_STACK
    ///	* SERVO_BRICK_COMMUNICATION_METHOD_CHIBI
    ///	* SERVO_BRICK_COMMUNICATION_METHOD_RS485
    ///	* SERVO_BRICK_COMMUNICATION_METHOD_WIFI
    ///	* SERVO_BRICK_COMMUNICATION_METHOD_ETHERNET
    ///	* SERVO_BRICK_COMMUNICATION_METHOD_WIFI_V2
    pub fn get_send_timeout_count(&self, communication_method: u8) -> ConvertingReceiver<u32> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(communication_method));

        self.device.get(u8::from(ServoBrickFunction::GetSendTimeoutCount), payload)
    }

    /// Sets the baudrate for a specific Bricklet port ('a' - 'd'). The
    /// baudrate can be in the range 400000 to 2000000.
    ///
    /// If you want to increase the throughput of Bricklets you can increase
    /// the baudrate. If you get a high error count because of high
    /// interference (see [`get_spitfp_error_count`]) you can decrease the
    /// baudrate.
    ///
    /// If the dynamic baudrate feature is enabled, the baudrate set by this
    /// function corresponds to the maximum baudrate (see [`set_spitfp_baudrate_config`]).
    ///
    /// Regulatory testing is done with the default baudrate. If CE compatibility
    /// or similar is necessary in you applications we recommend to not change
    /// the baudrate.
    ///
    /// The default baudrate for all ports is 1400000.
    ///
    /// [`set_spitfp_baudrate_config`]: #method.set_spitfp_baudrate_config
    /// [`get_spitfp_error_count`]: #method.get_spitfp_error_count
    /// .. versionadded:: 2.3.2$nbsp;(Firmware)
    pub fn set_spitfp_baudrate(&self, bricklet_port: char, baudrate: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 5];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(bricklet_port));
        payload[1..5].copy_from_slice(&<u32>::to_le_bytes(baudrate));

        self.device.set(u8::from(ServoBrickFunction::SetSpitfpBaudrate), payload)
    }

    /// Returns the baudrate for a given Bricklet port, see [`set_spitfp_baudrate`].
    ///
    /// [`set_spitfp_baudrate`]: #method.set_spitfp_baudrate
    /// .. versionadded:: 2.3.2$nbsp;(Firmware)
    pub fn get_spitfp_baudrate(&self, bricklet_port: char) -> ConvertingReceiver<u32> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(bricklet_port));

        self.device.get(u8::from(ServoBrickFunction::GetSpitfpBaudrate), payload)
    }

    /// Returns the error count for the communication between Brick and Bricklet.
    ///
    /// The errors are divided into
    ///
    /// * ACK checksum errors,
    /// * message checksum errors,
    /// * framing errors and
    /// * overflow errors.
    ///
    /// The errors counts are for errors that occur on the Brick side. All
    /// Bricklets have a similar function that returns the errors on the Bricklet side.
    ///
    ///
    /// .. versionadded:: 2.3.2$nbsp;(Firmware)
    pub fn get_spitfp_error_count(&self, bricklet_port: char) -> ConvertingReceiver<SpitfpErrorCount> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(bricklet_port));

        self.device.get(u8::from(ServoBrickFunction::GetSpitfpErrorCount), payload)
    }

    /// Enables the status LED.
    ///
    /// The status LED is the blue LED next to the USB connector. If enabled is is
    /// on and it flickers if data is transfered. If disabled it is always off.
    ///
    /// The default state is enabled.
    ///
    ///
    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
    pub fn enable_status_led(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(ServoBrickFunction::EnableStatusLed), payload)
    }

    /// Disables the status LED.
    ///
    /// The status LED is the blue LED next to the USB connector. If enabled is is
    /// on and it flickers if data is transfered. If disabled it is always off.
    ///
    /// The default state is enabled.
    ///
    ///
    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
    pub fn disable_status_led(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(ServoBrickFunction::DisableStatusLed), payload)
    }

    /// Returns *true* if the status LED is enabled, *false* otherwise.
    ///
    ///
    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
    pub fn is_status_led_enabled(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::IsStatusLedEnabled), payload)
    }

    /// Returns the firmware and protocol version and the name of the Bricklet for a
    /// given port.
    ///
    /// This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
    /// plugins.
    pub fn get_protocol1_bricklet_name(&self, port: char) -> ConvertingReceiver<Protocol1BrickletName> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(port));

        self.device.get(u8::from(ServoBrickFunction::GetProtocol1BrickletName), payload)
    }

    /// Returns the temperature in °C/10 as measured inside the microcontroller. The
    /// value returned is not the ambient temperature!
    ///
    /// The temperature is only proportional to the real temperature and it has an
    /// accuracy of +-15%. Practically it is only useful as an indicator for
    /// temperature changes.
    pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetChipTemperature), payload)
    }

    /// Calling this function will reset the Brick. Calling this function
    /// on a Brick inside of a stack will reset the whole stack.
    ///
    /// After a reset you have to create new device objects,
    /// calling functions on the existing ones will result in
    /// undefined behavior!
    pub fn reset(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(ServoBrickFunction::Reset), payload)
    }

    /// Returns the UID, the UID where the Brick is connected to,
    /// the position, the hardware and firmware version as well as the
    /// device identifier.
    ///
    /// The position can be '0'-'8' (stack position).
    ///
    /// The device identifier numbers can be found [here](device_identifier).
    /// |device_identifier_constant|
    pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
        let payload = vec![0; 0];

        self.device.get(u8::from(ServoBrickFunction::GetIdentity), payload)
    }
}