pub struct SenseData { /* private fields */ }
Expand description

Sense data is store per ADC source element (e.g. per key) The analysis is stored in a queue, where old values expire out min/max is used to handle offsets from the distance lookups Higher order calculations assume a constant unit of time between measurements Any division is left to compile-time comparisions as it’s not necessary to actually compute the final higher order values in order to make a decision. This diagram can give a sense of how the incoming data is used. The number represents the last ADC sample required to calculate the value.


           4  5 ... <- Jerk (e.g. m/2^3)
         / | /|
        3  4  5 ... <- Acceleration (e.g. m/2^2)
      / | /| /|
     2  3  4  5 ... <- Velocity (e.g. m/s)
   / | /| /| /|
  1  2  3  4  5 ... <- Distance (e.g. m)
 ----------------------
  1  2  3  4  5 ... <== ADC Averaged Sample

Distance => Min/Max adjusted lookup Velocity => (d_current - d_previous) / 1 (constant time) There is 1 time unit between samples 1 and 2 Acceleration => (v_current - v_previous) / 2 (constant time) There are 2 time units between samples 1 and 3 Jerk => (a_current - a_previous) / 3 (constant time) There are 3 time units between samples 1 and 4

NOTE: Division is computed at compile time for jerk (/ 3)

Time is simplified to 1 unit (normally sampling will be at a constant time-rate, so this should be somewhat accurate).

A variety of thresholds are used during calibration and normal operating modes. These values are generics as there’s no reason to store each of the thresholds at runtime for each sensor (wastes precious sram per sensor).

Implementations§

source§

impl SenseData

source

pub fn new(mode: SensorMode, activation: i16, deactivation: i16) -> SenseData

Create a new SenseData instance

  • mode: Sensor mode
  • activation: Activation point (distance, push direction)
  • deactivation: Deactivation point (distance, release direction)
source

pub fn add<const IDLE_LIMIT: usize>( &mut self, reading: u16 ) -> Option<&SenseData>

Add new sensor reading Only returns a value once the sensor has been properly calibrated and is within the expected range.

source

pub fn analysis(&self) -> Option<&SenseAnalysis>

Current sensor analysis

source

pub fn calibration(&self) -> CalibrationStatus

Current sensor calibration status

source

pub fn data(&self) -> &RawData

Current raw sensor data

source

pub fn raw_offset(&self) -> i16

Raw offset value

source

pub fn mode(&self) -> SensorMode

Current sensor mode

source

pub fn activation(&self) -> i16

Current activation point

source

pub fn deactivation(&self) -> i16

Current deactivation point

source

pub fn update_activation(&mut self, activation: i16, deactivation: i16)

Update activation/deactivation points

source

pub fn update_mode(&mut self, mode: SensorMode)

Change sensor mode

Trait Implementations§

source§

impl Clone for SenseData

source§

fn clone(&self) -> SenseData

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SenseData

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.