embedded_tfluna/types.rs
1//! Types of returned data from TF-Luna.
2
3/// Structure containing major, minor, and revision numbers.
4#[derive(Clone, Copy, Debug, PartialEq)]
5#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6pub struct FirmwareVersion {
7 /// Major version number
8 pub major: u8,
9 /// Minor version number
10 pub minor: u8,
11 /// Revision version number
12 pub revision: u8,
13}
14
15/// Structure containing the serial number of the device.
16#[derive(Clone, Copy, Debug, PartialEq)]
17#[cfg_attr(feature = "defmt", derive(defmt::Format))]
18pub struct SerialNumber(pub [u8; 14]);
19
20/// ASCII signature of the device.
21///
22/// The TF-Luna's signature is: 'L', 'U', 'N', 'A'
23#[derive(Clone, Copy, Debug, PartialEq)]
24pub struct Signature(pub [u8; 4]);
25
26/// Ranging modes of the device.
27#[derive(Debug, Clone, Copy, PartialEq)]
28#[cfg_attr(feature = "defmt", derive(defmt::Format))]
29pub enum RangingMode {
30 /// In Continuous ranging mode, the TF-Luna will keep tracking
31 /// the distance at a 500hz frequency, but as the configured
32 /// output framerate (frequency) is lower (defaults to 100Hz),
33 /// the output will be the average.
34 Continuous = 0,
35 /// In trigger ranging mode, the TF-Luna stops measuring on its own
36 /// and will only measure distance when explicitly triggered.
37 Trigger = 1,
38}
39
40/// Enum containing the different power modes of the TF-Luna
41#[derive(Debug, Clone, Copy, PartialEq)]
42#[cfg_attr(feature = "defmt", derive(defmt::Format))]
43pub enum PowerMode {
44 /// Normal power mode with largest power consumption
45 ///
46 /// When the power is supplied with 5V, the power consumption is about 350mW.
47 Normal,
48 /// Power saving mode with second largest power consumption
49 PowerSaving,
50 /// Ultra-low power mode with lowest power consumption
51 UltraLow,
52}
53
54/// Structure containing distance, signal strength, temperature, and timestamp.
55#[derive(Clone, Copy, Debug, PartialEq)]
56#[cfg_attr(feature = "defmt", derive(defmt::Format))]
57pub struct SensorReading {
58 /// Distance in centimeters
59 pub distance: u16,
60 /// Signal strength (amplitude in manual) value between 0 and 1000.
61 pub signal_strength: u16,
62 /// Internal device temperature in °C with 0.01 precision.
63 pub temperature: f32,
64 /// Clock ticks since device was powered on.
65 pub timestamp: u16,
66 /// Error code
67 pub error: u16,
68}