1use crate::{
15 byte_converter::*,
16 converting_callback_receiver::ConvertingCallbackReceiver,
17 converting_high_level_callback_receiver::ConvertingHighLevelCallbackReceiver,
18 converting_receiver::{BrickletRecvTimeoutError, ConvertingReceiver},
19 device::*,
20 ip_connection::GetRequestSender,
21 low_level_traits::*,
22};
23pub enum DmxBrickletFunction {
24 SetDmxMode,
25 GetDmxMode,
26 WriteFrameLowLevel,
27 ReadFrameLowLevel,
28 SetFrameDuration,
29 GetFrameDuration,
30 GetFrameErrorCount,
31 SetCommunicationLedConfig,
32 GetCommunicationLedConfig,
33 SetErrorLedConfig,
34 GetErrorLedConfig,
35 SetFrameCallbackConfig,
36 GetFrameCallbackConfig,
37 GetSpitfpErrorCount,
38 SetBootloaderMode,
39 GetBootloaderMode,
40 SetWriteFirmwarePointer,
41 WriteFirmware,
42 SetStatusLedConfig,
43 GetStatusLedConfig,
44 GetChipTemperature,
45 Reset,
46 WriteUid,
47 ReadUid,
48 GetIdentity,
49 CallbackFrameStarted,
50 CallbackFrameAvailable,
51 CallbackFrameLowLevel,
52 CallbackFrameErrorCount,
53}
54impl From<DmxBrickletFunction> for u8 {
55 fn from(fun: DmxBrickletFunction) -> Self {
56 match fun {
57 DmxBrickletFunction::SetDmxMode => 1,
58 DmxBrickletFunction::GetDmxMode => 2,
59 DmxBrickletFunction::WriteFrameLowLevel => 3,
60 DmxBrickletFunction::ReadFrameLowLevel => 4,
61 DmxBrickletFunction::SetFrameDuration => 5,
62 DmxBrickletFunction::GetFrameDuration => 6,
63 DmxBrickletFunction::GetFrameErrorCount => 7,
64 DmxBrickletFunction::SetCommunicationLedConfig => 8,
65 DmxBrickletFunction::GetCommunicationLedConfig => 9,
66 DmxBrickletFunction::SetErrorLedConfig => 10,
67 DmxBrickletFunction::GetErrorLedConfig => 11,
68 DmxBrickletFunction::SetFrameCallbackConfig => 12,
69 DmxBrickletFunction::GetFrameCallbackConfig => 13,
70 DmxBrickletFunction::GetSpitfpErrorCount => 234,
71 DmxBrickletFunction::SetBootloaderMode => 235,
72 DmxBrickletFunction::GetBootloaderMode => 236,
73 DmxBrickletFunction::SetWriteFirmwarePointer => 237,
74 DmxBrickletFunction::WriteFirmware => 238,
75 DmxBrickletFunction::SetStatusLedConfig => 239,
76 DmxBrickletFunction::GetStatusLedConfig => 240,
77 DmxBrickletFunction::GetChipTemperature => 242,
78 DmxBrickletFunction::Reset => 243,
79 DmxBrickletFunction::WriteUid => 248,
80 DmxBrickletFunction::ReadUid => 249,
81 DmxBrickletFunction::GetIdentity => 255,
82 DmxBrickletFunction::CallbackFrameStarted => 14,
83 DmxBrickletFunction::CallbackFrameAvailable => 15,
84 DmxBrickletFunction::CallbackFrameLowLevel => 16,
85 DmxBrickletFunction::CallbackFrameErrorCount => 17,
86 }
87 }
88}
89pub const DMX_BRICKLET_DMX_MODE_MASTER: u8 = 0;
90pub const DMX_BRICKLET_DMX_MODE_SLAVE: u8 = 1;
91pub const DMX_BRICKLET_COMMUNICATION_LED_CONFIG_OFF: u8 = 0;
92pub const DMX_BRICKLET_COMMUNICATION_LED_CONFIG_ON: u8 = 1;
93pub const DMX_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
94pub const DMX_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION: u8 = 3;
95pub const DMX_BRICKLET_ERROR_LED_CONFIG_OFF: u8 = 0;
96pub const DMX_BRICKLET_ERROR_LED_CONFIG_ON: u8 = 1;
97pub const DMX_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
98pub const DMX_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR: u8 = 3;
99pub const DMX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
100pub const DMX_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
101pub const DMX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
102pub const DMX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
103pub const DMX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
104pub const DMX_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
105pub const DMX_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
106pub const DMX_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
107pub const DMX_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
108pub const DMX_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
109pub const DMX_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
110pub const DMX_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
111pub const DMX_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
112pub const DMX_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
113pub const DMX_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
114
115#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
116pub struct WriteFrameLowLevel {}
117impl FromByteSlice for WriteFrameLowLevel {
118 fn bytes_expected() -> usize { 0 }
119 fn from_le_byte_slice(_bytes: &[u8]) -> WriteFrameLowLevel { WriteFrameLowLevel {} }
120}
121impl LowLevelWrite<WriteFrameResult> for WriteFrameLowLevel {
122 fn ll_message_written(&self) -> usize { 60 }
123
124 fn get_result(&self) -> WriteFrameResult { WriteFrameResult {} }
125}
126
127#[derive(Clone, Copy)]
128pub struct ReadFrameLowLevel {
129 pub frame_length: u16,
130 pub frame_chunk_offset: u16,
131 pub frame_chunk_data: [u8; 56],
132 pub frame_number: u32,
133}
134impl FromByteSlice for ReadFrameLowLevel {
135 fn bytes_expected() -> usize { 64 }
136 fn from_le_byte_slice(bytes: &[u8]) -> ReadFrameLowLevel {
137 ReadFrameLowLevel {
138 frame_length: <u16>::from_le_byte_slice(&bytes[0..2]),
139 frame_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
140 frame_chunk_data: <[u8; 56]>::from_le_byte_slice(&bytes[4..60]),
141 frame_number: <u32>::from_le_byte_slice(&bytes[60..64]),
142 }
143 }
144}
145impl LowLevelRead<u8, ReadFrameResult> for ReadFrameLowLevel {
146 fn ll_message_length(&self) -> usize { self.frame_length as usize }
147
148 fn ll_message_chunk_offset(&self) -> usize { self.frame_chunk_offset as usize }
149
150 fn ll_message_chunk_data(&self) -> &[u8] { &self.frame_chunk_data }
151
152 fn get_result(&self) -> ReadFrameResult { ReadFrameResult { frame_number: self.frame_number } }
153}
154
155#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
156pub struct FrameErrorCount {
157 pub overrun_error_count: u32,
158 pub framing_error_count: u32,
159}
160impl FromByteSlice for FrameErrorCount {
161 fn bytes_expected() -> usize { 8 }
162 fn from_le_byte_slice(bytes: &[u8]) -> FrameErrorCount {
163 FrameErrorCount {
164 overrun_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
165 framing_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
166 }
167 }
168}
169
170#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
171pub struct FrameCallbackConfig {
172 pub frame_started_callback_enabled: bool,
173 pub frame_available_callback_enabled: bool,
174 pub frame_callback_enabled: bool,
175 pub frame_error_count_callback_enabled: bool,
176}
177impl FromByteSlice for FrameCallbackConfig {
178 fn bytes_expected() -> usize { 4 }
179 fn from_le_byte_slice(bytes: &[u8]) -> FrameCallbackConfig {
180 FrameCallbackConfig {
181 frame_started_callback_enabled: <bool>::from_le_byte_slice(&bytes[0..1]),
182 frame_available_callback_enabled: <bool>::from_le_byte_slice(&bytes[1..2]),
183 frame_callback_enabled: <bool>::from_le_byte_slice(&bytes[2..3]),
184 frame_error_count_callback_enabled: <bool>::from_le_byte_slice(&bytes[3..4]),
185 }
186 }
187}
188
189#[derive(Clone, Copy)]
190pub struct FrameLowLevelEvent {
191 pub frame_length: u16,
192 pub frame_chunk_offset: u16,
193 pub frame_chunk_data: [u8; 56],
194 pub frame_number: u32,
195}
196impl FromByteSlice for FrameLowLevelEvent {
197 fn bytes_expected() -> usize { 64 }
198 fn from_le_byte_slice(bytes: &[u8]) -> FrameLowLevelEvent {
199 FrameLowLevelEvent {
200 frame_length: <u16>::from_le_byte_slice(&bytes[0..2]),
201 frame_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
202 frame_chunk_data: <[u8; 56]>::from_le_byte_slice(&bytes[4..60]),
203 frame_number: <u32>::from_le_byte_slice(&bytes[60..64]),
204 }
205 }
206}
207impl LowLevelRead<u8, FrameResult> for FrameLowLevelEvent {
208 fn ll_message_length(&self) -> usize { self.frame_length as usize }
209
210 fn ll_message_chunk_offset(&self) -> usize { self.frame_chunk_offset as usize }
211
212 fn ll_message_chunk_data(&self) -> &[u8] { &self.frame_chunk_data }
213
214 fn get_result(&self) -> FrameResult { FrameResult { frame_number: self.frame_number } }
215}
216
217#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
218pub struct FrameErrorCountEvent {
219 pub overrun_error_count: u32,
220 pub framing_error_count: u32,
221}
222impl FromByteSlice for FrameErrorCountEvent {
223 fn bytes_expected() -> usize { 8 }
224 fn from_le_byte_slice(bytes: &[u8]) -> FrameErrorCountEvent {
225 FrameErrorCountEvent {
226 overrun_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
227 framing_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
228 }
229 }
230}
231
232#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
233pub struct SpitfpErrorCount {
234 pub error_count_ack_checksum: u32,
235 pub error_count_message_checksum: u32,
236 pub error_count_frame: u32,
237 pub error_count_overflow: u32,
238}
239impl FromByteSlice for SpitfpErrorCount {
240 fn bytes_expected() -> usize { 16 }
241 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
242 SpitfpErrorCount {
243 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
244 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
245 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
246 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
247 }
248 }
249}
250
251#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
252pub struct Identity {
253 pub uid: String,
254 pub connected_uid: String,
255 pub position: char,
256 pub hardware_version: [u8; 3],
257 pub firmware_version: [u8; 3],
258 pub device_identifier: u16,
259}
260impl FromByteSlice for Identity {
261 fn bytes_expected() -> usize { 25 }
262 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
263 Identity {
264 uid: <String>::from_le_byte_slice(&bytes[0..8]),
265 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
266 position: <char>::from_le_byte_slice(&bytes[16..17]),
267 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
268 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
269 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
270 }
271 }
272}
273
274#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
275pub struct WriteFrameResult {}
276
277#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
278pub struct ReadFrameResult {
279 pub frame_number: u32,
280}
281
282#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
283pub struct FrameResult {
284 pub frame_number: u32,
285}
286
287#[derive(Clone)]
289pub struct DmxBricklet {
290 device: Device,
291}
292impl DmxBricklet {
293 pub const DEVICE_IDENTIFIER: u16 = 285;
294 pub const DEVICE_DISPLAY_NAME: &'static str = "DMX Bricklet";
295 pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> DmxBricklet {
297 let mut result = DmxBricklet { device: Device::new([2, 0, 0], uid, req_sender, 3) };
298 result.device.response_expected[u8::from(DmxBrickletFunction::SetDmxMode) as usize] = ResponseExpectedFlag::False;
299 result.device.response_expected[u8::from(DmxBrickletFunction::GetDmxMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
300 result.device.response_expected[u8::from(DmxBrickletFunction::WriteFrameLowLevel) as usize] = ResponseExpectedFlag::True;
301 result.device.response_expected[u8::from(DmxBrickletFunction::ReadFrameLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
302 result.device.response_expected[u8::from(DmxBrickletFunction::SetFrameDuration) as usize] = ResponseExpectedFlag::False;
303 result.device.response_expected[u8::from(DmxBrickletFunction::GetFrameDuration) as usize] = ResponseExpectedFlag::AlwaysTrue;
304 result.device.response_expected[u8::from(DmxBrickletFunction::GetFrameErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
305 result.device.response_expected[u8::from(DmxBrickletFunction::SetCommunicationLedConfig) as usize] = ResponseExpectedFlag::False;
306 result.device.response_expected[u8::from(DmxBrickletFunction::GetCommunicationLedConfig) as usize] =
307 ResponseExpectedFlag::AlwaysTrue;
308 result.device.response_expected[u8::from(DmxBrickletFunction::SetErrorLedConfig) as usize] = ResponseExpectedFlag::False;
309 result.device.response_expected[u8::from(DmxBrickletFunction::GetErrorLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
310 result.device.response_expected[u8::from(DmxBrickletFunction::SetFrameCallbackConfig) as usize] = ResponseExpectedFlag::True;
311 result.device.response_expected[u8::from(DmxBrickletFunction::GetFrameCallbackConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
312 result.device.response_expected[u8::from(DmxBrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
313 result.device.response_expected[u8::from(DmxBrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
314 result.device.response_expected[u8::from(DmxBrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
315 result.device.response_expected[u8::from(DmxBrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
316 result.device.response_expected[u8::from(DmxBrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
317 result.device.response_expected[u8::from(DmxBrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
318 result.device.response_expected[u8::from(DmxBrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
319 result.device.response_expected[u8::from(DmxBrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
320 result.device.response_expected[u8::from(DmxBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
321 result.device.response_expected[u8::from(DmxBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
322 result.device.response_expected[u8::from(DmxBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
323 result.device.response_expected[u8::from(DmxBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
324 result
325 }
326
327 pub fn get_response_expected(&mut self, fun: DmxBrickletFunction) -> Result<bool, GetResponseExpectedError> {
342 self.device.get_response_expected(u8::from(fun))
343 }
344
345 pub fn set_response_expected(&mut self, fun: DmxBrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
354 self.device.set_response_expected(u8::from(fun), response_expected)
355 }
356
357 pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
359
360 pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
363
364 pub fn get_frame_started_callback_receiver(&self) -> ConvertingCallbackReceiver<()> {
377 self.device.get_callback_receiver(u8::from(DmxBrickletFunction::CallbackFrameStarted))
378 }
379
380 pub fn get_frame_available_callback_receiver(&self) -> ConvertingCallbackReceiver<u32> {
390 self.device.get_callback_receiver(u8::from(DmxBrickletFunction::CallbackFrameAvailable))
391 }
392
393 pub fn get_frame_low_level_callback_receiver(&self) -> ConvertingCallbackReceiver<FrameLowLevelEvent> {
395 self.device.get_callback_receiver(u8::from(DmxBrickletFunction::CallbackFrameLowLevel))
396 }
397
398 pub fn get_frame_callback_receiver(&self) -> ConvertingHighLevelCallbackReceiver<u8, FrameResult, FrameLowLevelEvent> {
408 ConvertingHighLevelCallbackReceiver::new(self.device.get_callback_receiver(u8::from(DmxBrickletFunction::CallbackFrameLowLevel)))
409 }
410
411 pub fn get_frame_error_count_callback_receiver(&self) -> ConvertingCallbackReceiver<FrameErrorCountEvent> {
414 self.device.get_callback_receiver(u8::from(DmxBrickletFunction::CallbackFrameErrorCount))
415 }
416
417 pub fn set_dmx_mode(&self, dmx_mode: u8) -> ConvertingReceiver<()> {
425 let mut payload = vec![0; 1];
426 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(dmx_mode));
427
428 self.device.set(u8::from(DmxBrickletFunction::SetDmxMode), payload)
429 }
430
431 pub fn get_dmx_mode(&self) -> ConvertingReceiver<u8> {
437 let payload = vec![0; 0];
438
439 self.device.get(u8::from(DmxBrickletFunction::GetDmxMode), payload)
440 }
441
442 pub fn write_frame_low_level(
463 &self,
464 frame_length: u16,
465 frame_chunk_offset: u16,
466 frame_chunk_data: [u8; 60],
467 ) -> ConvertingReceiver<WriteFrameLowLevel> {
468 let mut payload = vec![0; 64];
469 payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(frame_length));
470 payload[2..4].copy_from_slice(&<u16>::to_le_byte_vec(frame_chunk_offset));
471 payload[4..64].copy_from_slice(&<[u8; 60]>::to_le_byte_vec(frame_chunk_data));
472
473 self.device.set(u8::from(DmxBrickletFunction::WriteFrameLowLevel), payload)
474 }
475
476 pub fn write_frame(&self, frame: &[u8]) -> Result<(), BrickletRecvTimeoutError> {
497 let _ll_result = self.device.set_high_level(0, frame, 65535, 60, &mut |length: usize, chunk_offset: usize, chunk: &[u8]| {
498 let chunk_length = chunk.len() as u16;
499 let mut chunk_array = [<u8>::default(); 60];
500 chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);
501
502 let result = self.write_frame_low_level(length as u16, chunk_offset as u16, chunk_array).recv();
503 if let Err(BrickletRecvTimeoutError::SuccessButResponseExpectedIsDisabled) = result {
504 Ok(Default::default())
505 } else {
506 result
507 }
508 })?;
509 Ok(())
510 }
511
512 pub fn read_frame_low_level(&self) -> ConvertingReceiver<ReadFrameLowLevel> {
532 let payload = vec![0; 0];
533
534 self.device.get(u8::from(DmxBrickletFunction::ReadFrameLowLevel), payload)
535 }
536
537 pub fn read_frame(&self) -> Result<(Vec<u8>, u32), BrickletRecvTimeoutError> {
557 let ll_result = self.device.get_high_level(1, &mut || self.read_frame_low_level().recv())?;
558 Ok((ll_result.0, ll_result.1.frame_number))
559 }
560
561 pub fn set_frame_duration(&self, frame_duration: u16) -> ConvertingReceiver<()> {
571 let mut payload = vec![0; 2];
572 payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(frame_duration));
573
574 self.device.set(u8::from(DmxBrickletFunction::SetFrameDuration), payload)
575 }
576
577 pub fn get_frame_duration(&self) -> ConvertingReceiver<u16> {
579 let payload = vec![0; 0];
580
581 self.device.get(u8::from(DmxBrickletFunction::GetFrameDuration), payload)
582 }
583
584 pub fn get_frame_error_count(&self) -> ConvertingReceiver<FrameErrorCount> {
586 let payload = vec![0; 0];
587
588 self.device.get(u8::from(DmxBrickletFunction::GetFrameErrorCount), payload)
589 }
590
591 pub fn set_communication_led_config(&self, config: u8) -> ConvertingReceiver<()> {
604 let mut payload = vec![0; 1];
605 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
606
607 self.device.set(u8::from(DmxBrickletFunction::SetCommunicationLedConfig), payload)
608 }
609
610 pub fn get_communication_led_config(&self) -> ConvertingReceiver<u8> {
618 let payload = vec![0; 0];
619
620 self.device.get(u8::from(DmxBrickletFunction::GetCommunicationLedConfig), payload)
621 }
622
623 pub fn set_error_led_config(&self, config: u8) -> ConvertingReceiver<()> {
639 let mut payload = vec![0; 1];
640 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
641
642 self.device.set(u8::from(DmxBrickletFunction::SetErrorLedConfig), payload)
643 }
644
645 pub fn get_error_led_config(&self) -> ConvertingReceiver<u8> {
653 let payload = vec![0; 0];
654
655 self.device.get(u8::from(DmxBrickletFunction::GetErrorLedConfig), payload)
656 }
657
658 pub fn set_frame_callback_config(
666 &self,
667 frame_started_callback_enabled: bool,
668 frame_available_callback_enabled: bool,
669 frame_callback_enabled: bool,
670 frame_error_count_callback_enabled: bool,
671 ) -> ConvertingReceiver<()> {
672 let mut payload = vec![0; 4];
673 payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(frame_started_callback_enabled));
674 payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(frame_available_callback_enabled));
675 payload[2..3].copy_from_slice(&<bool>::to_le_byte_vec(frame_callback_enabled));
676 payload[3..4].copy_from_slice(&<bool>::to_le_byte_vec(frame_error_count_callback_enabled));
677
678 self.device.set(u8::from(DmxBrickletFunction::SetFrameCallbackConfig), payload)
679 }
680
681 pub fn get_frame_callback_config(&self) -> ConvertingReceiver<FrameCallbackConfig> {
683 let payload = vec![0; 0];
684
685 self.device.get(u8::from(DmxBrickletFunction::GetFrameCallbackConfig), payload)
686 }
687
688 pub fn get_spitfp_error_count(&self) -> ConvertingReceiver<SpitfpErrorCount> {
700 let payload = vec![0; 0];
701
702 self.device.get(u8::from(DmxBrickletFunction::GetSpitfpErrorCount), payload)
703 }
704
705 pub fn set_bootloader_mode(&self, mode: u8) -> ConvertingReceiver<u8> {
728 let mut payload = vec![0; 1];
729 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
730
731 self.device.get(u8::from(DmxBrickletFunction::SetBootloaderMode), payload)
732 }
733
734 pub fn get_bootloader_mode(&self) -> ConvertingReceiver<u8> {
743 let payload = vec![0; 0];
744
745 self.device.get(u8::from(DmxBrickletFunction::GetBootloaderMode), payload)
746 }
747
748 pub fn set_write_firmware_pointer(&self, pointer: u32) -> ConvertingReceiver<()> {
755 let mut payload = vec![0; 4];
756 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(pointer));
757
758 self.device.set(u8::from(DmxBrickletFunction::SetWriteFirmwarePointer), payload)
759 }
760
761 pub fn write_firmware(&self, data: [u8; 64]) -> ConvertingReceiver<u8> {
770 let mut payload = vec![0; 64];
771 payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));
772
773 self.device.get(u8::from(DmxBrickletFunction::WriteFirmware), payload)
774 }
775
776 pub fn set_status_led_config(&self, config: u8) -> ConvertingReceiver<()> {
790 let mut payload = vec![0; 1];
791 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
792
793 self.device.set(u8::from(DmxBrickletFunction::SetStatusLedConfig), payload)
794 }
795
796 pub fn get_status_led_config(&self) -> ConvertingReceiver<u8> {
804 let payload = vec![0; 0];
805
806 self.device.get(u8::from(DmxBrickletFunction::GetStatusLedConfig), payload)
807 }
808
809 pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
816 let payload = vec![0; 0];
817
818 self.device.get(u8::from(DmxBrickletFunction::GetChipTemperature), payload)
819 }
820
821 pub fn reset(&self) -> ConvertingReceiver<()> {
828 let payload = vec![0; 0];
829
830 self.device.set(u8::from(DmxBrickletFunction::Reset), payload)
831 }
832
833 pub fn write_uid(&self, uid: u32) -> ConvertingReceiver<()> {
839 let mut payload = vec![0; 4];
840 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(uid));
841
842 self.device.set(u8::from(DmxBrickletFunction::WriteUid), payload)
843 }
844
845 pub fn read_uid(&self) -> ConvertingReceiver<u32> {
848 let payload = vec![0; 0];
849
850 self.device.get(u8::from(DmxBrickletFunction::ReadUid), payload)
851 }
852
853 pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
864 let payload = vec![0; 0];
865
866 self.device.get(u8::from(DmxBrickletFunction::GetIdentity), payload)
867 }
868}