tinkerforge_async/bindings/uv_light_v2_bricklet.rs
1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16. *
3 * *
4 * Rust Bindings Version 2.0.20 *
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//! Measures UV-A, UV-B and UV index.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/UVLightV2_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16 base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17 low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum UvLightV2BrickletFunction {
24 GetUva,
25 SetUvaCallbackConfiguration,
26 GetUvaCallbackConfiguration,
27 GetUvb,
28 SetUvbCallbackConfiguration,
29 GetUvbCallbackConfiguration,
30 GetUvi,
31 SetUviCallbackConfiguration,
32 GetUviCallbackConfiguration,
33 SetConfiguration,
34 GetConfiguration,
35 GetSpitfpErrorCount,
36 SetBootloaderMode,
37 GetBootloaderMode,
38 SetWriteFirmwarePointer,
39 WriteFirmware,
40 SetStatusLedConfig,
41 GetStatusLedConfig,
42 GetChipTemperature,
43 Reset,
44 WriteUid,
45 ReadUid,
46 GetIdentity,
47 CallbackUva,
48 CallbackUvb,
49 CallbackUvi,
50}
51impl From<UvLightV2BrickletFunction> for u8 {
52 fn from(fun: UvLightV2BrickletFunction) -> Self {
53 match fun {
54 UvLightV2BrickletFunction::GetUva => 1,
55 UvLightV2BrickletFunction::SetUvaCallbackConfiguration => 2,
56 UvLightV2BrickletFunction::GetUvaCallbackConfiguration => 3,
57 UvLightV2BrickletFunction::GetUvb => 5,
58 UvLightV2BrickletFunction::SetUvbCallbackConfiguration => 6,
59 UvLightV2BrickletFunction::GetUvbCallbackConfiguration => 7,
60 UvLightV2BrickletFunction::GetUvi => 9,
61 UvLightV2BrickletFunction::SetUviCallbackConfiguration => 10,
62 UvLightV2BrickletFunction::GetUviCallbackConfiguration => 11,
63 UvLightV2BrickletFunction::SetConfiguration => 13,
64 UvLightV2BrickletFunction::GetConfiguration => 14,
65 UvLightV2BrickletFunction::GetSpitfpErrorCount => 234,
66 UvLightV2BrickletFunction::SetBootloaderMode => 235,
67 UvLightV2BrickletFunction::GetBootloaderMode => 236,
68 UvLightV2BrickletFunction::SetWriteFirmwarePointer => 237,
69 UvLightV2BrickletFunction::WriteFirmware => 238,
70 UvLightV2BrickletFunction::SetStatusLedConfig => 239,
71 UvLightV2BrickletFunction::GetStatusLedConfig => 240,
72 UvLightV2BrickletFunction::GetChipTemperature => 242,
73 UvLightV2BrickletFunction::Reset => 243,
74 UvLightV2BrickletFunction::WriteUid => 248,
75 UvLightV2BrickletFunction::ReadUid => 249,
76 UvLightV2BrickletFunction::GetIdentity => 255,
77 UvLightV2BrickletFunction::CallbackUva => 4,
78 UvLightV2BrickletFunction::CallbackUvb => 8,
79 UvLightV2BrickletFunction::CallbackUvi => 12,
80 }
81 }
82}
83pub const UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
84pub const UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
85pub const UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
86pub const UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
87pub const UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
88pub const UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_50MS: u8 = 0;
89pub const UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_100MS: u8 = 1;
90pub const UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_200MS: u8 = 2;
91pub const UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_400MS: u8 = 3;
92pub const UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_800MS: u8 = 4;
93pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
94pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
95pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
96pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
97pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
98pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
99pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
100pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
101pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
102pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
103pub const UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
104pub const UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
105pub const UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
106pub const UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
107pub const UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
108
109#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
110pub struct UvaCallbackConfiguration {
111 pub period: u32,
112 pub value_has_to_change: bool,
113 pub option: char,
114 pub min: i32,
115 pub max: i32,
116}
117impl FromByteSlice for UvaCallbackConfiguration {
118 fn bytes_expected() -> usize {
119 14
120 }
121 fn from_le_byte_slice(bytes: &[u8]) -> UvaCallbackConfiguration {
122 UvaCallbackConfiguration {
123 period: <u32>::from_le_byte_slice(&bytes[0..4]),
124 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
125 option: <char>::from_le_byte_slice(&bytes[5..6]),
126 min: <i32>::from_le_byte_slice(&bytes[6..10]),
127 max: <i32>::from_le_byte_slice(&bytes[10..14]),
128 }
129 }
130}
131
132#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
133pub struct UvbCallbackConfiguration {
134 pub period: u32,
135 pub value_has_to_change: bool,
136 pub option: char,
137 pub min: i32,
138 pub max: i32,
139}
140impl FromByteSlice for UvbCallbackConfiguration {
141 fn bytes_expected() -> usize {
142 14
143 }
144 fn from_le_byte_slice(bytes: &[u8]) -> UvbCallbackConfiguration {
145 UvbCallbackConfiguration {
146 period: <u32>::from_le_byte_slice(&bytes[0..4]),
147 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
148 option: <char>::from_le_byte_slice(&bytes[5..6]),
149 min: <i32>::from_le_byte_slice(&bytes[6..10]),
150 max: <i32>::from_le_byte_slice(&bytes[10..14]),
151 }
152 }
153}
154
155#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
156pub struct UviCallbackConfiguration {
157 pub period: u32,
158 pub value_has_to_change: bool,
159 pub option: char,
160 pub min: i32,
161 pub max: i32,
162}
163impl FromByteSlice for UviCallbackConfiguration {
164 fn bytes_expected() -> usize {
165 14
166 }
167 fn from_le_byte_slice(bytes: &[u8]) -> UviCallbackConfiguration {
168 UviCallbackConfiguration {
169 period: <u32>::from_le_byte_slice(&bytes[0..4]),
170 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
171 option: <char>::from_le_byte_slice(&bytes[5..6]),
172 min: <i32>::from_le_byte_slice(&bytes[6..10]),
173 max: <i32>::from_le_byte_slice(&bytes[10..14]),
174 }
175 }
176}
177
178#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
179pub struct SpitfpErrorCount {
180 pub error_count_ack_checksum: u32,
181 pub error_count_message_checksum: u32,
182 pub error_count_frame: u32,
183 pub error_count_overflow: u32,
184}
185impl FromByteSlice for SpitfpErrorCount {
186 fn bytes_expected() -> usize {
187 16
188 }
189 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
190 SpitfpErrorCount {
191 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
192 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
193 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
194 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
195 }
196 }
197}
198
199#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
200pub struct Identity {
201 pub uid: String,
202 pub connected_uid: String,
203 pub position: char,
204 pub hardware_version: [u8; 3],
205 pub firmware_version: [u8; 3],
206 pub device_identifier: u16,
207}
208impl FromByteSlice for Identity {
209 fn bytes_expected() -> usize {
210 25
211 }
212 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
213 Identity {
214 uid: <String>::from_le_byte_slice(&bytes[0..8]),
215 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
216 position: <char>::from_le_byte_slice(&bytes[16..17]),
217 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
218 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
219 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
220 }
221 }
222}
223
224/// Measures UV-A, UV-B and UV index
225#[derive(Clone)]
226pub struct UvLightV2Bricklet {
227 device: Device,
228}
229impl UvLightV2Bricklet {
230 pub const DEVICE_IDENTIFIER: u16 = 2118;
231 pub const DEVICE_DISPLAY_NAME: &'static str = "UV Light Bricklet 2.0";
232 /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
233 pub fn new(uid: Uid, connection: AsyncIpConnection) -> UvLightV2Bricklet {
234 let mut result = UvLightV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
235 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetUva) as usize] = ResponseExpectedFlag::AlwaysTrue;
236 result.device.response_expected[u8::from(UvLightV2BrickletFunction::SetUvaCallbackConfiguration) as usize] =
237 ResponseExpectedFlag::True;
238 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetUvaCallbackConfiguration) as usize] =
239 ResponseExpectedFlag::AlwaysTrue;
240 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetUvb) as usize] = ResponseExpectedFlag::AlwaysTrue;
241 result.device.response_expected[u8::from(UvLightV2BrickletFunction::SetUvbCallbackConfiguration) as usize] =
242 ResponseExpectedFlag::True;
243 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetUvbCallbackConfiguration) as usize] =
244 ResponseExpectedFlag::AlwaysTrue;
245 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetUvi) as usize] = ResponseExpectedFlag::AlwaysTrue;
246 result.device.response_expected[u8::from(UvLightV2BrickletFunction::SetUviCallbackConfiguration) as usize] =
247 ResponseExpectedFlag::True;
248 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetUviCallbackConfiguration) as usize] =
249 ResponseExpectedFlag::AlwaysTrue;
250 result.device.response_expected[u8::from(UvLightV2BrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
251 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
252 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetSpitfpErrorCount) as usize] =
253 ResponseExpectedFlag::AlwaysTrue;
254 result.device.response_expected[u8::from(UvLightV2BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
255 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
256 result.device.response_expected[u8::from(UvLightV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
257 ResponseExpectedFlag::False;
258 result.device.response_expected[u8::from(UvLightV2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
259 result.device.response_expected[u8::from(UvLightV2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
260 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetStatusLedConfig) as usize] =
261 ResponseExpectedFlag::AlwaysTrue;
262 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetChipTemperature) as usize] =
263 ResponseExpectedFlag::AlwaysTrue;
264 result.device.response_expected[u8::from(UvLightV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
265 result.device.response_expected[u8::from(UvLightV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
266 result.device.response_expected[u8::from(UvLightV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
267 result.device.response_expected[u8::from(UvLightV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
268 result
269 }
270
271 /// Returns the response expected flag for the function specified by the function ID parameter.
272 /// It is true if the function is expected to send a response, false otherwise.
273 ///
274 /// For getter functions this is enabled by default and cannot be disabled, because those
275 /// functions will always send a response. For callback configuration functions it is enabled
276 /// by default too, but can be disabled by [`set_response_expected`](crate::uv_light_v2_bricklet::UvLightV2Bricklet::set_response_expected).
277 /// For setter functions it is disabled by default and can be enabled.
278 ///
279 /// Enabling the response expected flag for a setter function allows to detect timeouts
280 /// and other error conditions calls of this setter as well. The device will then send a response
281 /// for this purpose. If this flag is disabled for a setter function then no response is sent
282 /// and errors are silently ignored, because they cannot be detected.
283 ///
284 /// See [`set_response_expected`](crate::uv_light_v2_bricklet::UvLightV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
285 pub fn get_response_expected(&mut self, fun: UvLightV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
286 self.device.get_response_expected(u8::from(fun))
287 }
288
289 /// Changes the response expected flag of the function specified by the function ID parameter.
290 /// This flag can only be changed for setter (default value: false) and callback configuration
291 /// functions (default value: true). For getter functions it is always enabled.
292 ///
293 /// Enabling the response expected flag for a setter function allows to detect timeouts and
294 /// other error conditions calls of this setter as well. The device will then send a response
295 /// for this purpose. If this flag is disabled for a setter function then no response is sent
296 /// and errors are silently ignored, because they cannot be detected.
297 pub fn set_response_expected(
298 &mut self,
299 fun: UvLightV2BrickletFunction,
300 response_expected: bool,
301 ) -> Result<(), SetResponseExpectedError> {
302 self.device.set_response_expected(u8::from(fun), response_expected)
303 }
304
305 /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
306 pub fn set_response_expected_all(&mut self, response_expected: bool) {
307 self.device.set_response_expected_all(response_expected)
308 }
309
310 /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
311 /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
312 pub fn get_api_version(&self) -> [u8; 3] {
313 self.device.api_version
314 }
315
316 /// This receiver is triggered periodically according to the configuration set by
317 /// [`set_uva_callback_configuration`].
318 ///
319 /// The parameter is the same as [`get_uva`].
320 ///
321 /// [`get_uva`]: #method.get_uva
322 /// [`set_uva_callback_configuration`]: #method.set_uva_callback_configuration
323 pub async fn get_uva_callback_receiver(&mut self) -> impl Stream<Item = i32> {
324 self.device.get_callback_receiver(u8::from(UvLightV2BrickletFunction::CallbackUva)).await.map(|p| i32::from_le_byte_slice(p.body()))
325 }
326
327 /// This receiver is triggered periodically according to the configuration set by
328 /// [`set_uvb_callback_configuration`].
329 ///
330 /// The parameter is the same as [`get_uvb`].
331 pub async fn get_uvb_callback_receiver(&mut self) -> impl Stream<Item = i32> {
332 self.device.get_callback_receiver(u8::from(UvLightV2BrickletFunction::CallbackUvb)).await.map(|p| i32::from_le_byte_slice(p.body()))
333 }
334
335 /// This receiver is triggered periodically according to the configuration set by
336 /// [`set_uvi_callback_configuration`].
337 ///
338 /// The parameter is the same as [`get_uvi`].
339 pub async fn get_uvi_callback_receiver(&mut self) -> impl Stream<Item = i32> {
340 self.device.get_callback_receiver(u8::from(UvLightV2BrickletFunction::CallbackUvi)).await.map(|p| i32::from_le_byte_slice(p.body()))
341 }
342
343 /// Returns the UVA intensity of the sensor.
344 /// The sensor has not weighted the intensity with the erythemal
345 /// action spectrum to get the skin-affecting irradiation. Therefore, you cannot
346 /// just divide the value by 250 to get the UVA index. To get the UV index use
347 /// [`get_uvi`].
348 ///
349 /// If the sensor is saturated, then -1 is returned, see [`set_configuration`].
350 ///
351 /// If you want to get the intensity periodically, it is recommended to use the
352 /// [`get_uva_callback_receiver`] receiver and set the period with
353 /// [`set_uva_callback_configuration`].
354 ///
355 ///
356 /// If you want to get the value periodically, it is recommended to use the
357 /// [`get_uva_callback_receiver`] receiver. You can set the receiver configuration
358 /// with [`set_uva_callback_configuration`].
359 pub async fn get_uva(&mut self) -> Result<i32, TinkerforgeError> {
360 let payload = [0; 0];
361
362 #[allow(unused_variables)]
363 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetUva), &payload).await?;
364 Ok(i32::from_le_byte_slice(result.body()))
365 }
366
367 /// The period is the period with which the [`get_uva_callback_receiver`] receiver is triggered
368 /// periodically. A value of 0 turns the receiver off.
369 ///
370 /// If the `value has to change`-parameter is set to true, the receiver is only
371 /// triggered after the value has changed. If the value didn't change
372 /// within the period, the receiver is triggered immediately on change.
373 ///
374 /// If it is set to false, the receiver is continuously triggered with the period,
375 /// independent of the value.
376 ///
377 /// It is furthermore possible to constrain the receiver with thresholds.
378 ///
379 /// The `option`-parameter together with min/max sets a threshold for the [`get_uva_callback_receiver`] receiver.
380 ///
381 /// The following options are possible:
382 ///
383 /// Option| Description
384 /// --- | ---
385 /// 'x'| Threshold is turned off
386 /// 'o'| Threshold is triggered when the value is *outside* the min and max values
387 /// 'i'| Threshold is triggered when the value is *inside* or equal to the min and max values
388 /// '<'| Threshold is triggered when the value is smaller than the min value (max is ignored)
389 /// '>'| Threshold is triggered when the value is greater than the min value (max is ignored)
390 ///
391 /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
392 ///
393 /// Associated constants:
394 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OFF
395 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
396 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
397 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
398 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_GREATER
399 pub async fn set_uva_callback_configuration(
400 &mut self,
401 period: u32,
402 value_has_to_change: bool,
403 option: char,
404 min: i32,
405 max: i32,
406 ) -> Result<(), TinkerforgeError> {
407 let mut payload = [0; 14];
408 period.write_to_slice(&mut payload[0..4]);
409 value_has_to_change.write_to_slice(&mut payload[4..5]);
410 option.write_to_slice(&mut payload[5..6]);
411 min.write_to_slice(&mut payload[6..10]);
412 max.write_to_slice(&mut payload[10..14]);
413
414 #[allow(unused_variables)]
415 let result = self.device.set(u8::from(UvLightV2BrickletFunction::SetUvaCallbackConfiguration), &payload).await?;
416 Ok(())
417 }
418
419 /// Returns the receiver configuration as set by [`set_uva_callback_configuration`].
420 ///
421 /// Associated constants:
422 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OFF
423 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
424 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
425 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
426 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_GREATER
427 pub async fn get_uva_callback_configuration(&mut self) -> Result<UvaCallbackConfiguration, TinkerforgeError> {
428 let payload = [0; 0];
429
430 #[allow(unused_variables)]
431 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetUvaCallbackConfiguration), &payload).await?;
432 Ok(UvaCallbackConfiguration::from_le_byte_slice(result.body()))
433 }
434
435 /// Returns the UVB intensity of the sensor.
436 /// The sensor has not weighted the intensity with the erythemal
437 /// action spectrum to get the skin-affecting irradiation. Therefore, you cannot
438 /// just divide the value by 250 to get the UVB index. To get the UV index use
439 /// [`get_uvi`].
440 ///
441 /// If the sensor is saturated, then -1 is returned, see [`set_configuration`].
442 ///
443 /// If you want to get the intensity periodically, it is recommended to use the
444 /// [`get_uvb_callback_receiver`] receiver and set the period with
445 /// [`set_uvb_callback_configuration`].
446 ///
447 ///
448 /// If you want to get the value periodically, it is recommended to use the
449 /// [`get_uvb_callback_receiver`] receiver. You can set the receiver configuration
450 /// with [`set_uvb_callback_configuration`].
451 pub async fn get_uvb(&mut self) -> Result<i32, TinkerforgeError> {
452 let payload = [0; 0];
453
454 #[allow(unused_variables)]
455 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetUvb), &payload).await?;
456 Ok(i32::from_le_byte_slice(result.body()))
457 }
458
459 /// The period is the period with which the [`get_uvb_callback_receiver`] receiver is triggered
460 /// periodically. A value of 0 turns the receiver off.
461 ///
462 /// If the `value has to change`-parameter is set to true, the receiver is only
463 /// triggered after the value has changed. If the value didn't change
464 /// within the period, the receiver is triggered immediately on change.
465 ///
466 /// If it is set to false, the receiver is continuously triggered with the period,
467 /// independent of the value.
468 ///
469 /// It is furthermore possible to constrain the receiver with thresholds.
470 ///
471 /// The `option`-parameter together with min/max sets a threshold for the [`get_uvb_callback_receiver`] receiver.
472 ///
473 /// The following options are possible:
474 ///
475 /// Option| Description
476 /// --- | ---
477 /// 'x'| Threshold is turned off
478 /// 'o'| Threshold is triggered when the value is *outside* the min and max values
479 /// 'i'| Threshold is triggered when the value is *inside* or equal to the min and max values
480 /// '<'| Threshold is triggered when the value is smaller than the min value (max is ignored)
481 /// '>'| Threshold is triggered when the value is greater than the min value (max is ignored)
482 ///
483 /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
484 ///
485 /// Associated constants:
486 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OFF
487 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
488 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
489 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
490 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_GREATER
491 pub async fn set_uvb_callback_configuration(
492 &mut self,
493 period: u32,
494 value_has_to_change: bool,
495 option: char,
496 min: i32,
497 max: i32,
498 ) -> Result<(), TinkerforgeError> {
499 let mut payload = [0; 14];
500 period.write_to_slice(&mut payload[0..4]);
501 value_has_to_change.write_to_slice(&mut payload[4..5]);
502 option.write_to_slice(&mut payload[5..6]);
503 min.write_to_slice(&mut payload[6..10]);
504 max.write_to_slice(&mut payload[10..14]);
505
506 #[allow(unused_variables)]
507 let result = self.device.set(u8::from(UvLightV2BrickletFunction::SetUvbCallbackConfiguration), &payload).await?;
508 Ok(())
509 }
510
511 /// Returns the receiver configuration as set by [`set_uvb_callback_configuration`].
512 ///
513 /// Associated constants:
514 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OFF
515 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
516 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
517 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
518 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_GREATER
519 pub async fn get_uvb_callback_configuration(&mut self) -> Result<UvbCallbackConfiguration, TinkerforgeError> {
520 let payload = [0; 0];
521
522 #[allow(unused_variables)]
523 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetUvbCallbackConfiguration), &payload).await?;
524 Ok(UvbCallbackConfiguration::from_le_byte_slice(result.body()))
525 }
526
527 /// Returns the UV index of the sensor, the index is given in 1/10.
528 ///
529 /// If the sensor is saturated, then -1 is returned, see [`set_configuration`].
530 ///
531 /// If you want to get the intensity periodically, it is recommended to use the
532 /// [`get_uvi_callback_receiver`] receiver and set the period with
533 /// [`set_uvi_callback_configuration`].
534 ///
535 ///
536 /// If you want to get the value periodically, it is recommended to use the
537 /// [`get_uvi_callback_receiver`] receiver. You can set the receiver configuration
538 /// with [`set_uvi_callback_configuration`].
539 pub async fn get_uvi(&mut self) -> Result<i32, TinkerforgeError> {
540 let payload = [0; 0];
541
542 #[allow(unused_variables)]
543 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetUvi), &payload).await?;
544 Ok(i32::from_le_byte_slice(result.body()))
545 }
546
547 /// The period is the period with which the [`get_uvi_callback_receiver`] receiver is triggered
548 /// periodically. A value of 0 turns the receiver off.
549 ///
550 /// If the `value has to change`-parameter is set to true, the receiver is only
551 /// triggered after the value has changed. If the value didn't change
552 /// within the period, the receiver is triggered immediately on change.
553 ///
554 /// If it is set to false, the receiver is continuously triggered with the period,
555 /// independent of the value.
556 ///
557 /// It is furthermore possible to constrain the receiver with thresholds.
558 ///
559 /// The `option`-parameter together with min/max sets a threshold for the [`get_uvi_callback_receiver`] receiver.
560 ///
561 /// The following options are possible:
562 ///
563 /// Option| Description
564 /// --- | ---
565 /// 'x'| Threshold is turned off
566 /// 'o'| Threshold is triggered when the value is *outside* the min and max values
567 /// 'i'| Threshold is triggered when the value is *inside* or equal to the min and max values
568 /// '<'| Threshold is triggered when the value is smaller than the min value (max is ignored)
569 /// '>'| Threshold is triggered when the value is greater than the min value (max is ignored)
570 ///
571 /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
572 ///
573 /// Associated constants:
574 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OFF
575 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
576 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
577 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
578 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_GREATER
579 pub async fn set_uvi_callback_configuration(
580 &mut self,
581 period: u32,
582 value_has_to_change: bool,
583 option: char,
584 min: i32,
585 max: i32,
586 ) -> Result<(), TinkerforgeError> {
587 let mut payload = [0; 14];
588 period.write_to_slice(&mut payload[0..4]);
589 value_has_to_change.write_to_slice(&mut payload[4..5]);
590 option.write_to_slice(&mut payload[5..6]);
591 min.write_to_slice(&mut payload[6..10]);
592 max.write_to_slice(&mut payload[10..14]);
593
594 #[allow(unused_variables)]
595 let result = self.device.set(u8::from(UvLightV2BrickletFunction::SetUviCallbackConfiguration), &payload).await?;
596 Ok(())
597 }
598
599 /// Returns the receiver configuration as set by [`set_uvi_callback_configuration`].
600 ///
601 /// Associated constants:
602 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OFF
603 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
604 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
605 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
606 /// * UV_LIGHT_V2_BRICKLET_THRESHOLD_OPTION_GREATER
607 pub async fn get_uvi_callback_configuration(&mut self) -> Result<UviCallbackConfiguration, TinkerforgeError> {
608 let payload = [0; 0];
609
610 #[allow(unused_variables)]
611 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetUviCallbackConfiguration), &payload).await?;
612 Ok(UviCallbackConfiguration::from_le_byte_slice(result.body()))
613 }
614
615 /// Sets the configuration of the sensor. The integration time can be configured
616 /// between 50 and 800 ms. With a shorter integration time the sensor reading updates
617 /// more often but contains more noise. With a longer integration the sensor reading
618 /// contains less noise but updates less often.
619 ///
620 /// With a longer integration time (especially 800 ms) and a higher UV intensity the
621 /// sensor can be saturated. If this happens the UVA/UVB/UVI readings are all -1.
622 /// In this case you need to choose a shorter integration time.
623 ///
624 /// Associated constants:
625 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_50MS
626 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_100MS
627 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_200MS
628 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_400MS
629 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_800MS
630 pub async fn set_configuration(&mut self, integration_time: u8) -> Result<(), TinkerforgeError> {
631 let mut payload = [0; 1];
632 integration_time.write_to_slice(&mut payload[0..1]);
633
634 #[allow(unused_variables)]
635 let result = self.device.set(u8::from(UvLightV2BrickletFunction::SetConfiguration), &payload).await?;
636 Ok(())
637 }
638
639 /// Returns the configuration as set by [`set_configuration`].
640 ///
641 /// Associated constants:
642 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_50MS
643 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_100MS
644 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_200MS
645 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_400MS
646 /// * UV_LIGHT_V2_BRICKLET_INTEGRATION_TIME_800MS
647 pub async fn get_configuration(&mut self) -> Result<u8, TinkerforgeError> {
648 let payload = [0; 0];
649
650 #[allow(unused_variables)]
651 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetConfiguration), &payload).await?;
652 Ok(u8::from_le_byte_slice(result.body()))
653 }
654
655 /// Returns the error count for the communication between Brick and Bricklet.
656 ///
657 /// The errors are divided into
658 ///
659 /// * ACK checksum errors,
660 /// * message checksum errors,
661 /// * framing errors and
662 /// * overflow errors.
663 ///
664 /// The errors counts are for errors that occur on the Bricklet side. All
665 /// Bricks have a similar function that returns the errors on the Brick side.
666 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
667 let payload = [0; 0];
668
669 #[allow(unused_variables)]
670 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
671 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
672 }
673
674 /// Sets the bootloader mode and returns the status after the requested
675 /// mode change was instigated.
676 ///
677 /// You can change from bootloader mode to firmware mode and vice versa. A change
678 /// from bootloader mode to firmware mode will only take place if the entry function,
679 /// device identifier and CRC are present and correct.
680 ///
681 /// This function is used by Brick Viewer during flashing. It should not be
682 /// necessary to call it in a normal user program.
683 ///
684 /// Associated constants:
685 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
686 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
687 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
688 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
689 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
690 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_OK
691 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
692 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
693 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
694 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
695 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
696 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
697 let mut payload = [0; 1];
698 mode.write_to_slice(&mut payload[0..1]);
699
700 #[allow(unused_variables)]
701 let result = self.device.get(u8::from(UvLightV2BrickletFunction::SetBootloaderMode), &payload).await?;
702 Ok(u8::from_le_byte_slice(result.body()))
703 }
704
705 /// Returns the current bootloader mode, see [`set_bootloader_mode`].
706 ///
707 /// Associated constants:
708 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
709 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
710 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
711 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
712 /// * UV_LIGHT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
713 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
714 let payload = [0; 0];
715
716 #[allow(unused_variables)]
717 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetBootloaderMode), &payload).await?;
718 Ok(u8::from_le_byte_slice(result.body()))
719 }
720
721 /// Sets the firmware pointer for [`write_firmware`]. The pointer has
722 /// to be increased by chunks of size 64. The data is written to flash
723 /// every 4 chunks (which equals to one page of size 256).
724 ///
725 /// This function is used by Brick Viewer during flashing. It should not be
726 /// necessary to call it in a normal user program.
727 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
728 let mut payload = [0; 4];
729 pointer.write_to_slice(&mut payload[0..4]);
730
731 #[allow(unused_variables)]
732 let result = self.device.set(u8::from(UvLightV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
733 Ok(())
734 }
735
736 /// Writes 64 Bytes of firmware at the position as written by
737 /// [`set_write_firmware_pointer`] before. The firmware is written
738 /// to flash every 4 chunks.
739 ///
740 /// You can only write firmware in bootloader mode.
741 ///
742 /// This function is used by Brick Viewer during flashing. It should not be
743 /// necessary to call it in a normal user program.
744 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
745 let mut payload = [0; 64];
746 data.write_to_slice(&mut payload[0..64]);
747
748 #[allow(unused_variables)]
749 let result = self.device.get(u8::from(UvLightV2BrickletFunction::WriteFirmware), &payload).await?;
750 Ok(u8::from_le_byte_slice(result.body()))
751 }
752
753 /// Sets the status LED configuration. By default the LED shows
754 /// communication traffic between Brick and Bricklet, it flickers once
755 /// for every 10 received data packets.
756 ///
757 /// You can also turn the LED permanently on/off or show a heartbeat.
758 ///
759 /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
760 ///
761 /// Associated constants:
762 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_OFF
763 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_ON
764 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
765 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
766 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
767 let mut payload = [0; 1];
768 config.write_to_slice(&mut payload[0..1]);
769
770 #[allow(unused_variables)]
771 let result = self.device.set(u8::from(UvLightV2BrickletFunction::SetStatusLedConfig), &payload).await?;
772 Ok(())
773 }
774
775 /// Returns the configuration as set by [`set_status_led_config`]
776 ///
777 /// Associated constants:
778 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_OFF
779 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_ON
780 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
781 /// * UV_LIGHT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
782 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
783 let payload = [0; 0];
784
785 #[allow(unused_variables)]
786 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetStatusLedConfig), &payload).await?;
787 Ok(u8::from_le_byte_slice(result.body()))
788 }
789
790 /// Returns the temperature as measured inside the microcontroller. The
791 /// value returned is not the ambient temperature!
792 ///
793 /// The temperature is only proportional to the real temperature and it has bad
794 /// accuracy. Practically it is only useful as an indicator for
795 /// temperature changes.
796 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
797 let payload = [0; 0];
798
799 #[allow(unused_variables)]
800 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetChipTemperature), &payload).await?;
801 Ok(i16::from_le_byte_slice(result.body()))
802 }
803
804 /// Calling this function will reset the Bricklet. All configurations
805 /// will be lost.
806 ///
807 /// After a reset you have to create new device objects,
808 /// calling functions on the existing ones will result in
809 /// undefined behavior!
810 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
811 let payload = [0; 0];
812
813 #[allow(unused_variables)]
814 let result = self.device.set(u8::from(UvLightV2BrickletFunction::Reset), &payload).await?;
815 Ok(())
816 }
817
818 /// Writes a new UID into flash. If you want to set a new UID
819 /// you have to decode the Base58 encoded UID string into an
820 /// integer first.
821 ///
822 /// We recommend that you use Brick Viewer to change the UID.
823 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
824 let mut payload = [0; 4];
825 uid.write_to_slice(&mut payload[0..4]);
826
827 #[allow(unused_variables)]
828 let result = self.device.set(u8::from(UvLightV2BrickletFunction::WriteUid), &payload).await?;
829 Ok(())
830 }
831
832 /// Returns the current UID as an integer. Encode as
833 /// Base58 to get the usual string version.
834 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
835 let payload = [0; 0];
836
837 #[allow(unused_variables)]
838 let result = self.device.get(u8::from(UvLightV2BrickletFunction::ReadUid), &payload).await?;
839 Ok(u32::from_le_byte_slice(result.body()))
840 }
841
842 /// Returns the UID, the UID where the Bricklet is connected to,
843 /// the position, the hardware and firmware version as well as the
844 /// device identifier.
845 ///
846 /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
847 /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
848 /// position 'z'.
849 ///
850 /// The device identifier numbers can be found [here](device_identifier).
851 /// |device_identifier_constant|
852 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
853 let payload = [0; 0];
854
855 #[allow(unused_variables)]
856 let result = self.device.get(u8::from(UvLightV2BrickletFunction::GetIdentity), &payload).await?;
857 Ok(Identity::from_le_byte_slice(result.body()))
858 }
859}