autd3_core/modulation/
error.rsuse std::{convert::Infallible, time::Duration};
use derive_more::Display;
use derive_new::new;
use thiserror::Error;
use crate::defined::Freq;
#[derive(new, Error, Debug, Display, PartialEq, Clone)]
#[display("{}", msg)]
pub struct ModulationError {
msg: String,
}
#[derive(Error, Debug, PartialEq, Copy, Clone)]
pub enum SamplingConfigError {
#[error("Sampling division must not be zero")]
SamplingDivisionInvalid,
#[error("Sampling frequency ({0:?}) must divide the ultrasound frequency")]
SamplingFreqInvalid(Freq<u32>),
#[error("Sampling frequency ({0:?}) must divide the ultrasound frequency")]
SamplingFreqInvalidF(Freq<f32>),
#[error("Sampling period ({0:?}) must be a multiple of the ultrasound period")]
SamplingPeriodInvalid(Duration),
#[error("Sampling frequency ({0:?}) is out of range ([{1:?}, {2:?}])")]
SamplingFreqOutOfRange(Freq<u32>, Freq<u32>, Freq<u32>),
#[error("Sampling frequency ({0:?}) is out of range ([{1:?}, {2:?}])")]
SamplingFreqOutOfRangeF(Freq<f32>, Freq<f32>, Freq<f32>),
#[error("Sampling period ({0:?}) is out of range ([{1:?}, {2:?}])")]
SamplingPeriodOutOfRange(Duration, Duration, Duration),
}
impl From<Infallible> for SamplingConfigError {
fn from(_: Infallible) -> Self {
unreachable!()
}
}
impl From<Infallible> for ModulationError {
fn from(_: Infallible) -> Self {
unreachable!()
}
}
impl From<SamplingConfigError> for ModulationError {
fn from(e: SamplingConfigError) -> Self {
Self::new(e.to_string())
}
}