autd3_core/defined/
mod.rs1mod angle;
2mod freq;
3
4pub use std::f32::consts::PI;
5
6#[cfg(feature = "use_meter")]
7mod unit {
8 pub const METER: f32 = 1.0;
10}
11#[cfg(not(feature = "use_meter"))]
12mod unit {
13 pub const METER: f32 = 1000.0;
15}
16pub use unit::*;
17
18pub use angle::*;
19pub use freq::*;
20
21pub const MILLIMETER: f32 = METER / 1000.0;
23
24pub const ABSOLUTE_THRESHOLD_OF_HEARING: f32 = 20e-6;
26
27pub const T4010A1_AMPLITUDE: f32 = 275.574_25 * 200.0 * MILLIMETER; pub const DEFAULT_TIMEOUT: std::time::Duration = std::time::Duration::from_millis(200);
32
33pub const ULTRASOUND_PERIOD_COUNT: usize = 256;
35
36#[cfg(not(feature = "dynamic_freq"))]
37mod inner {
38 use super::Freq;
39 use std::time::Duration;
40
41 #[inline(always)]
42 #[must_use]
43 pub const fn ultrasound_freq() -> Freq<u32> {
45 Freq { freq: 40000 }
46 }
47
48 #[inline(always)]
49 #[must_use]
50 pub const fn ultrasound_period() -> Duration {
52 Duration::from_micros(25)
53 }
54}
55
56#[cfg(feature = "dynamic_freq")]
57mod inner {
58 use std::sync::LazyLock;
59
60 use super::Freq;
61 use crate::defined::Hz;
62
63 static LAZY_FREQ: LazyLock<Freq<u32>> =
64 LazyLock::new(|| match std::env::var("AUTD3_ULTRASOUND_FREQ") {
65 Ok(freq) => match freq.parse::<u32>() {
66 Ok(freq) => {
67 tracing::info!("Set ultrasound frequency to {} Hz.", freq);
68 freq * Hz
69 }
70 Err(_) => {
71 tracing::error!(
72 "Invalid ultrasound frequency ({} Hz), fallback to 40 kHz.",
73 freq
74 );
75 Freq { freq: 40000 }
76 }
77 },
78 Err(_) => {
79 tracing::warn!(
80 "Environment variable AUTD3_ULTRASOUND_FREQ is not set, fallback to 40 kHz."
81 );
82 Freq { freq: 40000 }
83 }
84 });
85
86 #[inline]
87 #[must_use]
88 pub fn ultrasound_freq() -> Freq<u32> {
90 *LAZY_FREQ
91 }
92
93 #[doc(hidden)]
94 pub const DRP_ROM_SIZE: usize = 32;
95}
96
97pub use inner::*;
98
99#[allow(non_upper_case_globals)]
101pub const mm: f32 = MILLIMETER;