Struct kiibohd_hall_effect::SenseData
source · 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
impl SenseData
sourcepub fn new(mode: SensorMode, activation: i16, deactivation: i16) -> SenseData
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)
sourcepub fn add<const IDLE_LIMIT: usize>(
&mut self,
reading: u16
) -> Option<&SenseData>
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.
sourcepub fn analysis(&self) -> Option<&SenseAnalysis>
pub fn analysis(&self) -> Option<&SenseAnalysis>
Current sensor analysis
sourcepub fn calibration(&self) -> CalibrationStatus
pub fn calibration(&self) -> CalibrationStatus
Current sensor calibration status
sourcepub fn raw_offset(&self) -> i16
pub fn raw_offset(&self) -> i16
Raw offset value
sourcepub fn mode(&self) -> SensorMode
pub fn mode(&self) -> SensorMode
Current sensor mode
sourcepub fn activation(&self) -> i16
pub fn activation(&self) -> i16
Current activation point
sourcepub fn deactivation(&self) -> i16
pub fn deactivation(&self) -> i16
Current deactivation point
sourcepub fn update_activation(&mut self, activation: i16, deactivation: i16)
pub fn update_activation(&mut self, activation: i16, deactivation: i16)
Update activation/deactivation points
sourcepub fn update_mode(&mut self, mode: SensorMode)
pub fn update_mode(&mut self, mode: SensorMode)
Change sensor mode