1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * File: static.rs
 * Project: modulation
 * Created Date: 30/04/2022
 * Author: Shun Suzuki
 * -----
 * Last Modified: 01/12/2023
 * Modified By: Shun Suzuki (suzuki@hapis.k.u-tokyo.ac.jp)
 * -----
 * Copyright (c) 2022-2023 Shun Suzuki. All rights reserved.
 *
 */

use autd3_derive::Modulation;

use autd3_driver::{common::EmitIntensity, derive::prelude::*};

/// Without modulation
#[derive(Modulation, Clone, Copy)]
pub struct Static {
    intensity: EmitIntensity,
    #[no_change]
    config: SamplingConfiguration,
}

impl Static {
    /// constructor
    pub fn new() -> Self {
        Self {
            intensity: EmitIntensity::MAX,
            config: SamplingConfiguration::from_frequency(4e3).unwrap(),
        }
    }

    /// set emission intensity
    ///
    /// # Arguments
    ///
    /// * `intensity` - normalized emission intensity of the ultrasound (from 0 to 1)
    ///
    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)]
        );
    }
}