use autd3_derive::Modulation;
use autd3_driver::derive::prelude::*;
#[derive(Modulation, Clone, Copy)]
pub struct Static {
amp: float,
#[no_change]
freq_div: u32,
}
impl Static {
pub fn new() -> Self {
Self {
amp: 1.0,
freq_div: 5120,
}
}
pub fn with_amp(self, amp: float) -> Self {
Self { amp, ..self }
}
pub fn amp(&self) -> float {
self.amp
}
}
impl Modulation for Static {
fn calc(&self) -> Result<Vec<float>, AUTDInternalError> {
Ok(vec![self.amp; 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_approx_eq::assert_approx_eq!(m.amp, 1.0);
assert_eq!(m.calc().unwrap(), vec![1.0, 1.0]);
}
#[test]
fn test_static_new() {
let m = Static::new();
assert_approx_eq::assert_approx_eq!(m.amp, 1.0);
assert_eq!(m.calc().unwrap(), vec![1.0, 1.0]);
}
#[test]
fn test_static_with_amp() {
let m = Static::new().with_amp(0.5);
assert_approx_eq::assert_approx_eq!(m.amp, 0.5);
assert_eq!(m.calc().unwrap(), vec![0.5, 0.5]);
}
}