autd3capi_def/
custom.rs

1/*
2 * File: custom.rs
3 * Project: src
4 * Created Date: 24/08/2023
5 * Author: Shun Suzuki
6 * -----
7 * Last Modified: 29/11/2023
8 * Modified By: Shun Suzuki (suzuki@hapis.k.u-tokyo.ac.jp)
9 * -----
10 * Copyright (c) 2023 Shun Suzuki. All rights reserved.
11 *
12 */
13
14use std::collections::HashMap;
15
16use autd3_derive::{Gain, Modulation};
17use autd3_driver::derive::prelude::*;
18
19#[derive(Gain, Default)]
20pub struct CustomGain {
21    drives: HashMap<usize, Vec<Drive>>,
22}
23
24impl CustomGain {
25    pub fn new() -> Self {
26        Self {
27            drives: Default::default(),
28        }
29    }
30
31    pub fn set(self, dev_idx: usize, drives: Vec<Drive>) -> Self {
32        let mut new = self;
33        new.drives.insert(dev_idx, drives);
34        new
35    }
36}
37
38impl autd3_driver::datagram::Gain for CustomGain {
39    fn calc(
40        &self,
41        _geometry: &Geometry,
42        _filter: GainFilter,
43    ) -> Result<HashMap<usize, Vec<Drive>>, AUTDInternalError> {
44        Ok(self.drives.clone())
45    }
46}
47
48#[derive(Modulation)]
49pub struct CustomModulation {
50    pub buf: Vec<EmitIntensity>,
51    pub config: SamplingConfiguration,
52}
53
54impl autd3_driver::datagram::Modulation for CustomModulation {
55    fn calc(&self) -> Result<Vec<EmitIntensity>, AUTDInternalError> {
56        Ok(self.buf.clone())
57    }
58}