pub struct PulseWidthEncoder<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.
PulseWidthEncoder::new(|_dev| |i| PulseWidth::from_duty(i.0 as f32 / 510.).unwrap());
Implementations§
Source§impl<H: Fn(Intensity) -> PulseWidth + Send + Sync, F: Fn(&Device) -> H> PulseWidthEncoder<F>
impl<H: Fn(Intensity) -> PulseWidth + Send + Sync, F: Fn(&Device) -> H> PulseWidthEncoder<F>
Sourcepub const fn new(f: F) -> Self
pub const fn new(f: F) -> Self
Creates a new PulseWidthEncoder
.
Trait Implementations§
Source§impl<F: Clone> Clone for PulseWidthEncoder<F>
impl<F: Clone> Clone for PulseWidthEncoder<F>
Source§fn clone(&self) -> PulseWidthEncoder<F>
fn clone(&self) -> PulseWidthEncoder<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<H: Fn(Intensity) -> PulseWidth + Send + Sync, F: Fn(&Device) -> H> Datagram<'_> for PulseWidthEncoder<F>
impl<H: Fn(Intensity) -> PulseWidth + Send + Sync, F: Fn(&Device) -> H> Datagram<'_> for PulseWidthEncoder<F>
Source§fn option(&self) -> DatagramOption
fn option(&self) -> DatagramOption
Source§impl<F: Debug> Debug for PulseWidthEncoder<F>
impl<F: Debug> Debug for PulseWidthEncoder<F>
Auto Trait Implementations§
impl<F> Freeze for PulseWidthEncoder<F>where
F: Freeze,
impl<F> RefUnwindSafe for PulseWidthEncoder<F>where
F: RefUnwindSafe,
impl<F> Send for PulseWidthEncoder<F>where
F: Send,
impl<F> Sync for PulseWidthEncoder<F>where
F: Sync,
impl<F> Unpin for PulseWidthEncoder<F>where
F: Unpin,
impl<F> UnwindSafe for PulseWidthEncoder<F>where
F: 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.