use autd3_derive::Modulation;
use autd3_driver::{common::EmitIntensity, derive::prelude::*};
#[derive(Modulation, Clone, Copy)]
pub struct Static {
intensity: EmitIntensity,
#[no_change]
config: SamplingConfiguration,
}
impl Static {
pub fn new() -> Self {
Self {
intensity: EmitIntensity::MAX,
config: SamplingConfiguration::from_frequency(4e3).unwrap(),
}
}
pub fn with_intensity<A: Into<EmitIntensity>>(self, intensity: A) -> Self {
Self {
intensity: intensity.into(),
..self
}
}
pub fn intensity(&self) -> EmitIntensity {
self.intensity
}
}
impl Modulation for Static {
fn calc(&self) -> Result<Vec<EmitIntensity>, AUTDInternalError> {
Ok(vec![self.intensity; 2])
}
}
impl Default for Static {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_static_default() {
let m = Static::default();
assert_eq!(m.intensity, EmitIntensity::MAX);
assert_eq!(
m.calc().unwrap(),
vec![EmitIntensity::MAX, EmitIntensity::MAX]
);
}
#[test]
fn test_static_new() {
let m = Static::new();
assert_eq!(m.intensity, EmitIntensity::MAX);
assert_eq!(
m.calc().unwrap(),
vec![EmitIntensity::MAX, EmitIntensity::MAX]
);
}
#[test]
fn test_static_with_intensity() {
let m = Static::new().with_intensity(0x1F);
assert_eq!(m.intensity, EmitIntensity::new(0x1F));
assert_eq!(
m.calc().unwrap(),
vec![EmitIntensity::new(0x1F), EmitIntensity::new(0x1F)]
);
}
}