tinkerforge/bindings/
industrial_quad_relay_v2_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-27.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.21                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! 4 galvanically isolated solid state relays.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/IndustrialQuadRelayV2_Bricklet_Rust.html).
14use crate::{
15    byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
16    ip_connection::GetRequestSender,
17};
18pub enum IndustrialQuadRelayV2BrickletFunction {
19    SetValue,
20    GetValue,
21    SetMonoflop,
22    GetMonoflop,
23    SetSelectedValue,
24    SetChannelLedConfig,
25    GetChannelLedConfig,
26    GetSpitfpErrorCount,
27    SetBootloaderMode,
28    GetBootloaderMode,
29    SetWriteFirmwarePointer,
30    WriteFirmware,
31    SetStatusLedConfig,
32    GetStatusLedConfig,
33    GetChipTemperature,
34    Reset,
35    WriteUid,
36    ReadUid,
37    GetIdentity,
38    CallbackMonoflopDone,
39}
40impl From<IndustrialQuadRelayV2BrickletFunction> for u8 {
41    fn from(fun: IndustrialQuadRelayV2BrickletFunction) -> Self {
42        match fun {
43            IndustrialQuadRelayV2BrickletFunction::SetValue => 1,
44            IndustrialQuadRelayV2BrickletFunction::GetValue => 2,
45            IndustrialQuadRelayV2BrickletFunction::SetMonoflop => 3,
46            IndustrialQuadRelayV2BrickletFunction::GetMonoflop => 4,
47            IndustrialQuadRelayV2BrickletFunction::SetSelectedValue => 5,
48            IndustrialQuadRelayV2BrickletFunction::SetChannelLedConfig => 6,
49            IndustrialQuadRelayV2BrickletFunction::GetChannelLedConfig => 7,
50            IndustrialQuadRelayV2BrickletFunction::GetSpitfpErrorCount => 234,
51            IndustrialQuadRelayV2BrickletFunction::SetBootloaderMode => 235,
52            IndustrialQuadRelayV2BrickletFunction::GetBootloaderMode => 236,
53            IndustrialQuadRelayV2BrickletFunction::SetWriteFirmwarePointer => 237,
54            IndustrialQuadRelayV2BrickletFunction::WriteFirmware => 238,
55            IndustrialQuadRelayV2BrickletFunction::SetStatusLedConfig => 239,
56            IndustrialQuadRelayV2BrickletFunction::GetStatusLedConfig => 240,
57            IndustrialQuadRelayV2BrickletFunction::GetChipTemperature => 242,
58            IndustrialQuadRelayV2BrickletFunction::Reset => 243,
59            IndustrialQuadRelayV2BrickletFunction::WriteUid => 248,
60            IndustrialQuadRelayV2BrickletFunction::ReadUid => 249,
61            IndustrialQuadRelayV2BrickletFunction::GetIdentity => 255,
62            IndustrialQuadRelayV2BrickletFunction::CallbackMonoflopDone => 8,
63        }
64    }
65}
66pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_OFF: u8 = 0;
67pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_ON: u8 = 1;
68pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
69pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS: u8 = 3;
70pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
71pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
72pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
73pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
74pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
75pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
76pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
77pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
78pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
79pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
80pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
81pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
82pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
83pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
84pub const INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
85
86#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
87pub struct Monoflop {
88    pub value: bool,
89    pub time: u32,
90    pub time_remaining: u32,
91}
92impl FromByteSlice for Monoflop {
93    fn bytes_expected() -> usize { 9 }
94    fn from_le_byte_slice(bytes: &[u8]) -> Monoflop {
95        Monoflop {
96            value: <bool>::from_le_byte_slice(&bytes[0..1]),
97            time: <u32>::from_le_byte_slice(&bytes[1..5]),
98            time_remaining: <u32>::from_le_byte_slice(&bytes[5..9]),
99        }
100    }
101}
102
103#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
104pub struct MonoflopDoneEvent {
105    pub channel: u8,
106    pub value: bool,
107}
108impl FromByteSlice for MonoflopDoneEvent {
109    fn bytes_expected() -> usize { 2 }
110    fn from_le_byte_slice(bytes: &[u8]) -> MonoflopDoneEvent {
111        MonoflopDoneEvent { channel: <u8>::from_le_byte_slice(&bytes[0..1]), value: <bool>::from_le_byte_slice(&bytes[1..2]) }
112    }
113}
114
115#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
116pub struct SpitfpErrorCount {
117    pub error_count_ack_checksum: u32,
118    pub error_count_message_checksum: u32,
119    pub error_count_frame: u32,
120    pub error_count_overflow: u32,
121}
122impl FromByteSlice for SpitfpErrorCount {
123    fn bytes_expected() -> usize { 16 }
124    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
125        SpitfpErrorCount {
126            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
127            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
128            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
129            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
130        }
131    }
132}
133
134#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
135pub struct Identity {
136    pub uid: String,
137    pub connected_uid: String,
138    pub position: char,
139    pub hardware_version: [u8; 3],
140    pub firmware_version: [u8; 3],
141    pub device_identifier: u16,
142}
143impl FromByteSlice for Identity {
144    fn bytes_expected() -> usize { 25 }
145    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
146        Identity {
147            uid: <String>::from_le_byte_slice(&bytes[0..8]),
148            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
149            position: <char>::from_le_byte_slice(&bytes[16..17]),
150            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
151            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
152            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
153        }
154    }
155}
156
157/// 4 galvanically isolated solid state relays
158#[derive(Clone)]
159pub struct IndustrialQuadRelayV2Bricklet {
160    device: Device,
161}
162impl IndustrialQuadRelayV2Bricklet {
163    pub const DEVICE_IDENTIFIER: u16 = 2102;
164    pub const DEVICE_DISPLAY_NAME: &'static str = "Industrial Quad Relay Bricklet 2.0";
165    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
166    pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> IndustrialQuadRelayV2Bricklet {
167        let mut result = IndustrialQuadRelayV2Bricklet { device: Device::new([2, 0, 0], uid, req_sender, 0) };
168        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::SetValue) as usize] = ResponseExpectedFlag::False;
169        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetValue) as usize] =
170            ResponseExpectedFlag::AlwaysTrue;
171        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::SetMonoflop) as usize] =
172            ResponseExpectedFlag::False;
173        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetMonoflop) as usize] =
174            ResponseExpectedFlag::AlwaysTrue;
175        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::SetSelectedValue) as usize] =
176            ResponseExpectedFlag::False;
177        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::SetChannelLedConfig) as usize] =
178            ResponseExpectedFlag::False;
179        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetChannelLedConfig) as usize] =
180            ResponseExpectedFlag::AlwaysTrue;
181        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetSpitfpErrorCount) as usize] =
182            ResponseExpectedFlag::AlwaysTrue;
183        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::SetBootloaderMode) as usize] =
184            ResponseExpectedFlag::AlwaysTrue;
185        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetBootloaderMode) as usize] =
186            ResponseExpectedFlag::AlwaysTrue;
187        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
188            ResponseExpectedFlag::False;
189        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::WriteFirmware) as usize] =
190            ResponseExpectedFlag::AlwaysTrue;
191        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::SetStatusLedConfig) as usize] =
192            ResponseExpectedFlag::False;
193        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetStatusLedConfig) as usize] =
194            ResponseExpectedFlag::AlwaysTrue;
195        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetChipTemperature) as usize] =
196            ResponseExpectedFlag::AlwaysTrue;
197        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
198        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
199        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::ReadUid) as usize] =
200            ResponseExpectedFlag::AlwaysTrue;
201        result.device.response_expected[u8::from(IndustrialQuadRelayV2BrickletFunction::GetIdentity) as usize] =
202            ResponseExpectedFlag::AlwaysTrue;
203        result
204    }
205
206    /// Returns the response expected flag for the function specified by the function ID parameter.
207    /// It is true if the function is expected to send a response, false otherwise.
208    ///
209    /// For getter functions this is enabled by default and cannot be disabled, because those
210    /// functions will always send a response. For callback configuration functions it is enabled
211    /// by default too, but can be disabled by [`set_response_expected`](crate::industrial_quad_relay_v2_bricklet::IndustrialQuadRelayV2Bricklet::set_response_expected).
212    /// For setter functions it is disabled by default and can be enabled.
213    ///
214    /// Enabling the response expected flag for a setter function allows to detect timeouts
215    /// and other error conditions calls of this setter as well. The device will then send a response
216    /// for this purpose. If this flag is disabled for a setter function then no response is sent
217    /// and errors are silently ignored, because they cannot be detected.
218    ///
219    /// See [`set_response_expected`](crate::industrial_quad_relay_v2_bricklet::IndustrialQuadRelayV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
220    pub fn get_response_expected(&mut self, fun: IndustrialQuadRelayV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
221        self.device.get_response_expected(u8::from(fun))
222    }
223
224    /// Changes the response expected flag of the function specified by the function ID parameter.
225    /// This flag can only be changed for setter (default value: false) and callback configuration
226    /// functions (default value: true). For getter functions it is always enabled.
227    ///
228    /// Enabling the response expected flag for a setter function allows to detect timeouts and
229    /// other error conditions calls of this setter as well. The device will then send a response
230    /// for this purpose. If this flag is disabled for a setter function then no response is sent
231    /// and errors are silently ignored, because they cannot be detected.
232    pub fn set_response_expected(
233        &mut self,
234        fun: IndustrialQuadRelayV2BrickletFunction,
235        response_expected: bool,
236    ) -> Result<(), SetResponseExpectedError> {
237        self.device.set_response_expected(u8::from(fun), response_expected)
238    }
239
240    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
241    pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
242
243    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
244    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
245    pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
246
247    /// This receiver is triggered whenever a monoflop timer reaches 0. The
248    /// parameters contain the channel and the current value of the channel
249    /// (the value after the monoflop).
250    pub fn get_monoflop_done_callback_receiver(&self) -> ConvertingCallbackReceiver<MonoflopDoneEvent> {
251        self.device.get_callback_receiver(u8::from(IndustrialQuadRelayV2BrickletFunction::CallbackMonoflopDone))
252    }
253
254    /// Sets the value of all four relays. A value of *true* closes the
255    /// relay and a value of *false* opens the relay.
256    ///
257    /// Use [`set_selected_value`] to only change one relay.
258    ///
259    /// All running monoflop timers will be aborted if this function is called.
260    pub fn set_value(&self, value: [bool; 4]) -> ConvertingReceiver<()> {
261        let mut payload = vec![0; 1];
262        payload[0..1].copy_from_slice(&<[bool; 4]>::to_le_byte_vec(value));
263
264        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::SetValue), payload)
265    }
266
267    /// Returns the values as set by [`set_value`].
268    pub fn get_value(&self) -> ConvertingReceiver<[bool; 4]> {
269        let payload = vec![0; 0];
270
271        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetValue), payload)
272    }
273
274    /// Configures a monoflop of the specified channel.
275    ///
276    /// The second parameter is the desired value of the specified
277    /// channel. A *true* means relay closed and a *false* means relay open.
278    ///
279    /// The third parameter indicates the time that the channels should hold
280    /// the value.
281    ///
282    /// If this function is called with the parameters (0, 1, 1500) channel 0 will
283    /// close and in 1.5s channel 0 will open again
284    ///
285    /// A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
286    /// have a RS485 bus and a Industrial Quad Relay Bricklet 2.0 connected to one of
287    /// the slave stacks. You can now call this function every second, with a time
288    /// parameter of two seconds and channel 0 closed. Channel 0 will be closed all the
289    /// time. If now the RS485 connection is lost, then channel 0 will be opened in at
290    /// most two seconds.
291    pub fn set_monoflop(&self, channel: u8, value: bool, time: u32) -> ConvertingReceiver<()> {
292        let mut payload = vec![0; 6];
293        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
294        payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(value));
295        payload[2..6].copy_from_slice(&<u32>::to_le_byte_vec(time));
296
297        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::SetMonoflop), payload)
298    }
299
300    /// Returns (for the given channel) the current value and the time as set by
301    /// [`set_monoflop`] as well as the remaining time until the value flips.
302    ///
303    /// If the timer is not running currently, the remaining time will be returned
304    /// as 0.
305    pub fn get_monoflop(&self, channel: u8) -> ConvertingReceiver<Monoflop> {
306        let mut payload = vec![0; 1];
307        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
308
309        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetMonoflop), payload)
310    }
311
312    /// Sets the output value of the specified channel without affecting the other
313    /// channels.
314    ///
315    /// A running monoflop timer for the specified channel will be aborted if this
316    /// function is called.
317    pub fn set_selected_value(&self, channel: u8, value: bool) -> ConvertingReceiver<()> {
318        let mut payload = vec![0; 2];
319        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
320        payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(value));
321
322        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::SetSelectedValue), payload)
323    }
324
325    /// Each channel has a corresponding LED. You can turn the LED off, on or show a
326    /// heartbeat. You can also set the LED to Channel Status. In this mode the
327    /// LED is on if the channel is high and off otherwise.
328    ///
329    /// Associated constants:
330    /// * INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_OFF
331    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_ON
332    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT
333    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS
334    pub fn set_channel_led_config(&self, channel: u8, config: u8) -> ConvertingReceiver<()> {
335        let mut payload = vec![0; 2];
336        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
337        payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(config));
338
339        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::SetChannelLedConfig), payload)
340    }
341
342    /// Returns the channel LED configuration as set by [`set_channel_led_config`]
343    ///
344    /// Associated constants:
345    /// * INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_OFF
346    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_ON
347    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT
348    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS
349    pub fn get_channel_led_config(&self, channel: u8) -> ConvertingReceiver<u8> {
350        let mut payload = vec![0; 1];
351        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
352
353        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetChannelLedConfig), payload)
354    }
355
356    /// Returns the error count for the communication between Brick and Bricklet.
357    ///
358    /// The errors are divided into
359    ///
360    /// * ACK checksum errors,
361    /// * message checksum errors,
362    /// * framing errors and
363    /// * overflow errors.
364    ///
365    /// The errors counts are for errors that occur on the Bricklet side. All
366    /// Bricks have a similar function that returns the errors on the Brick side.
367    pub fn get_spitfp_error_count(&self) -> ConvertingReceiver<SpitfpErrorCount> {
368        let payload = vec![0; 0];
369
370        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetSpitfpErrorCount), payload)
371    }
372
373    /// Sets the bootloader mode and returns the status after the requested
374    /// mode change was instigated.
375    ///
376    /// You can change from bootloader mode to firmware mode and vice versa. A change
377    /// from bootloader mode to firmware mode will only take place if the entry function,
378    /// device identifier and CRC are present and correct.
379    ///
380    /// This function is used by Brick Viewer during flashing. It should not be
381    /// necessary to call it in a normal user program.
382    ///
383    /// Associated constants:
384    /// * INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
385    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
386    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
387    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
388    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
389    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_OK
390    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
391    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
392    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
393    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
394    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
395    pub fn set_bootloader_mode(&self, mode: u8) -> ConvertingReceiver<u8> {
396        let mut payload = vec![0; 1];
397        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
398
399        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::SetBootloaderMode), payload)
400    }
401
402    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
403    ///
404    /// Associated constants:
405    /// * INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
406    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
407    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
408    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
409    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
410    pub fn get_bootloader_mode(&self) -> ConvertingReceiver<u8> {
411        let payload = vec![0; 0];
412
413        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetBootloaderMode), payload)
414    }
415
416    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
417    /// to be increased by chunks of size 64. The data is written to flash
418    /// every 4 chunks (which equals to one page of size 256).
419    ///
420    /// This function is used by Brick Viewer during flashing. It should not be
421    /// necessary to call it in a normal user program.
422    pub fn set_write_firmware_pointer(&self, pointer: u32) -> ConvertingReceiver<()> {
423        let mut payload = vec![0; 4];
424        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(pointer));
425
426        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::SetWriteFirmwarePointer), payload)
427    }
428
429    /// Writes 64 Bytes of firmware at the position as written by
430    /// [`set_write_firmware_pointer`] before. The firmware is written
431    /// to flash every 4 chunks.
432    ///
433    /// You can only write firmware in bootloader mode.
434    ///
435    /// This function is used by Brick Viewer during flashing. It should not be
436    /// necessary to call it in a normal user program.
437    pub fn write_firmware(&self, data: [u8; 64]) -> ConvertingReceiver<u8> {
438        let mut payload = vec![0; 64];
439        payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));
440
441        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::WriteFirmware), payload)
442    }
443
444    /// Sets the status LED configuration. By default the LED shows
445    /// communication traffic between Brick and Bricklet, it flickers once
446    /// for every 10 received data packets.
447    ///
448    /// You can also turn the LED permanently on/off or show a heartbeat.
449    ///
450    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
451    ///
452    /// Associated constants:
453    /// * INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_OFF
454    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_ON
455    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
456    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
457    pub fn set_status_led_config(&self, config: u8) -> ConvertingReceiver<()> {
458        let mut payload = vec![0; 1];
459        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
460
461        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::SetStatusLedConfig), payload)
462    }
463
464    /// Returns the configuration as set by [`set_status_led_config`]
465    ///
466    /// Associated constants:
467    /// * INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_OFF
468    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_ON
469    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
470    ///	* INDUSTRIAL_QUAD_RELAY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
471    pub fn get_status_led_config(&self) -> ConvertingReceiver<u8> {
472        let payload = vec![0; 0];
473
474        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetStatusLedConfig), payload)
475    }
476
477    /// Returns the temperature as measured inside the microcontroller. The
478    /// value returned is not the ambient temperature!
479    ///
480    /// The temperature is only proportional to the real temperature and it has bad
481    /// accuracy. Practically it is only useful as an indicator for
482    /// temperature changes.
483    pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
484        let payload = vec![0; 0];
485
486        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetChipTemperature), payload)
487    }
488
489    /// Calling this function will reset the Bricklet. All configurations
490    /// will be lost.
491    ///
492    /// After a reset you have to create new device objects,
493    /// calling functions on the existing ones will result in
494    /// undefined behavior!
495    pub fn reset(&self) -> ConvertingReceiver<()> {
496        let payload = vec![0; 0];
497
498        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::Reset), payload)
499    }
500
501    /// Writes a new UID into flash. If you want to set a new UID
502    /// you have to decode the Base58 encoded UID string into an
503    /// integer first.
504    ///
505    /// We recommend that you use Brick Viewer to change the UID.
506    pub fn write_uid(&self, uid: u32) -> ConvertingReceiver<()> {
507        let mut payload = vec![0; 4];
508        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(uid));
509
510        self.device.set(u8::from(IndustrialQuadRelayV2BrickletFunction::WriteUid), payload)
511    }
512
513    /// Returns the current UID as an integer. Encode as
514    /// Base58 to get the usual string version.
515    pub fn read_uid(&self) -> ConvertingReceiver<u32> {
516        let payload = vec![0; 0];
517
518        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::ReadUid), payload)
519    }
520
521    /// Returns the UID, the UID where the Bricklet is connected to,
522    /// the position, the hardware and firmware version as well as the
523    /// device identifier.
524    ///
525    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
526    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
527    /// position 'z'.
528    ///
529    /// The device identifier numbers can be found [here](device_identifier).
530    /// |device_identifier_constant|
531    pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
532        let payload = vec![0; 0];
533
534        self.device.get(u8::from(IndustrialQuadRelayV2BrickletFunction::GetIdentity), payload)
535    }
536}