pub struct PulseWidthEncoder<P, F> { /* private fields */ }Expand description
Datagram to configure pulse width encoder table.
The pulse width encoder table is a table to determine the pulse width (or duty ratio) from the intensity. In the firmware, the intensity (0-255) is used as the index of the table to determine the pulse width. For firmware v11 or later, the period of the ultrasound is mapped to 512, therefore, the ultrasound output becomes maximum when the pulse width is 256 (50% in duty ratio). For firmware v10, the period of the ultrasound is mapped to 256, therefore, the ultrasound output becomes maximum when the pulse width is 128 (50% in duty ratio).
The default table is set by the arcsin function so that Intensity is linearly proportional to output ultrasound pressure; that is, table[i] = round(T*arcsin(i/255)/π) where T is the period of the ultrasound.
§Example
To set the pulse width encoder table, please specify a function that takes the index of the table as an argument and returns the pulse width for each device.
The following example sets the pulse width to be linearly proportional to the intensity for all devices.
// For firmware version 11 or later
PulseWidthEncoder::new(|_dev| |i| PulseWidth::<9, u16>::from_duty(i.0 as f32 / 510.).unwrap());
// For firmware version 10
PulseWidthEncoder::new(|_dev| |i| PulseWidth::<8, u8>::from_duty(i.0 as f32 / 510.).unwrap());Implementations§
Source§impl<const BITS: usize, T: Copy + TryFrom<usize> + Zero + PartialOrd, H: Fn(Intensity) -> PulseWidth<BITS, T> + Send + Sync, F: Fn(&Device) -> H> PulseWidthEncoder<PulseWidth<BITS, T>, F>
impl<const BITS: usize, T: Copy + TryFrom<usize> + Zero + PartialOrd, H: Fn(Intensity) -> PulseWidth<BITS, T> + Send + Sync, F: Fn(&Device) -> H> PulseWidthEncoder<PulseWidth<BITS, T>, F>
Sourcepub const fn new(f: F) -> Self
pub const fn new(f: F) -> Self
Creates a new PulseWidthEncoder.
Trait Implementations§
Source§impl<P: Clone, F: Clone> Clone for PulseWidthEncoder<P, F>
impl<P: Clone, F: Clone> Clone for PulseWidthEncoder<P, F>
Source§fn clone(&self) -> PulseWidthEncoder<P, F>
fn clone(&self) -> PulseWidthEncoder<P, F>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const BITS: usize, T: Copy + TryFrom<usize> + Zero + PartialOrd, H: Fn(Intensity) -> PulseWidth<BITS, T> + Send + Sync, F: Fn(&Device) -> H> Datagram for PulseWidthEncoder<PulseWidth<BITS, T>, F>
impl<const BITS: usize, T: Copy + TryFrom<usize> + Zero + PartialOrd, H: Fn(Intensity) -> PulseWidth<BITS, T> + Send + Sync, F: Fn(&Device) -> H> Datagram for PulseWidthEncoder<PulseWidth<BITS, T>, F>
Source§fn option(&self) -> DatagramOption
fn option(&self) -> DatagramOption
Source§impl<P, F> Debug for PulseWidthEncoder<P, F>where
PhantomData<P>: Debug,
impl<P, F> Debug for PulseWidthEncoder<P, F>where
PhantomData<P>: Debug,
Source§impl<const BITS: usize, T: Copy + TryFrom<usize> + Zero + PartialOrd> Default for PulseWidthEncoder<PulseWidth<BITS, T>, fn(&Device) -> fn(Intensity) -> PulseWidth<BITS, T>>
impl<const BITS: usize, T: Copy + TryFrom<usize> + Zero + PartialOrd> Default for PulseWidthEncoder<PulseWidth<BITS, T>, fn(&Device) -> fn(Intensity) -> PulseWidth<BITS, T>>
Auto Trait Implementations§
impl<P, F> Freeze for PulseWidthEncoder<P, F>where
F: Freeze,
impl<P, F> RefUnwindSafe for PulseWidthEncoder<P, F>where
F: RefUnwindSafe,
P: RefUnwindSafe,
impl<P, F> Send for PulseWidthEncoder<P, F>
impl<P, F> Sync for PulseWidthEncoder<P, F>
impl<P, F> Unpin for PulseWidthEncoder<P, F>
impl<P, F> UnwindSafe for PulseWidthEncoder<P, F>where
F: UnwindSafe,
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.