autd3_driver/datagram/modulation/
mod.rs

1mod boxed;
2
3pub use boxed::BoxedModulation;
4
5#[cfg(test)]
6pub mod tests {
7    use std::num::NonZeroU16;
8
9    use autd3_core::derive::*;
10
11    use crate::datagram::{
12        with_loop_behavior::WithFiniteLoopInspectionResult,
13        with_segment::WithSegmentInspectionResult,
14    };
15
16    #[derive(Modulation, Clone, PartialEq, Debug)]
17    pub struct TestModulation {
18        pub sampling_config: SamplingConfig,
19    }
20
21    impl Modulation for TestModulation {
22        fn calc(self, _: &FirmwareLimits) -> Result<Vec<u8>, ModulationError> {
23            Ok(vec![0; 2])
24        }
25
26        fn sampling_config(&self) -> SamplingConfig {
27            self.sampling_config
28        }
29    }
30
31    #[test]
32    fn inspect() -> Result<(), Box<dyn std::error::Error>> {
33        let geometry = crate::autd3_device::tests::create_geometry(2);
34
35        TestModulation {
36            sampling_config: SamplingConfig::FREQ_4K,
37        }
38        .inspect(
39            &geometry,
40            &Environment::default(),
41            &DeviceMask::AllEnabled,
42            &FirmwareLimits::unused(),
43        )?
44        .iter()
45        .for_each(|r| {
46            assert_eq!(
47                &Some(ModulationInspectionResult {
48                    data: vec![0, 0],
49                    config: SamplingConfig::FREQ_4K,
50                }),
51                r
52            );
53        });
54
55        Ok(())
56    }
57
58    #[test]
59    fn inspect_with_segment() -> Result<(), Box<dyn std::error::Error>> {
60        let geometry = crate::autd3_device::tests::create_geometry(2);
61
62        crate::datagram::WithSegment {
63            inner: TestModulation {
64                sampling_config: SamplingConfig::FREQ_4K,
65            },
66            segment: Segment::S1,
67            transition_mode: transition_mode::Later,
68        }
69        .inspect(
70            &geometry,
71            &Environment::default(),
72            &DeviceMask::AllEnabled,
73            &FirmwareLimits::unused(),
74        )?
75        .iter()
76        .for_each(|r| {
77            assert_eq!(
78                &Some(WithSegmentInspectionResult {
79                    inner: ModulationInspectionResult {
80                        data: vec![0, 0],
81                        config: SamplingConfig::FREQ_4K,
82                    },
83                    segment: Segment::S1,
84                    transition_mode: transition_mode::Later,
85                }),
86                r
87            );
88        });
89
90        Ok(())
91    }
92
93    #[test]
94    fn inspect_with_loop_behavior() -> Result<(), Box<dyn std::error::Error>> {
95        let geometry = crate::autd3_device::tests::create_geometry(2);
96
97        crate::datagram::WithFiniteLoop {
98            inner: TestModulation {
99                sampling_config: SamplingConfig::FREQ_4K,
100            },
101            segment: Segment::S1,
102            transition_mode: transition_mode::SyncIdx,
103            loop_count: NonZeroU16::MIN,
104        }
105        .inspect(
106            &geometry,
107            &Environment::default(),
108            &DeviceMask::AllEnabled,
109            &FirmwareLimits::unused(),
110        )?
111        .iter()
112        .for_each(|r| {
113            assert_eq!(
114                &Some(WithFiniteLoopInspectionResult {
115                    inner: ModulationInspectionResult {
116                        data: vec![0, 0],
117                        config: SamplingConfig::FREQ_4K,
118                    },
119                    segment: Segment::S1,
120                    transition_mode: transition_mode::SyncIdx,
121                    loop_count: NonZeroU16::MIN,
122                }),
123                r
124            );
125        });
126
127        Ok(())
128    }
129}