[][src]Trait unflappable::Debounce

pub trait Debounce {
    type Storage: From<u8> + BitAnd<Output = Self::Storage> + BitAndAssign + BitOr<Output = Self::Storage> + BitOrAssign + Not<Output = Self::Storage> + Shl<u8, Output = Self::Storage> + Shr<u8, Output = Self::Storage> + AddAssign + SubAssign + Eq + Copy;

    const MAX_COUNT: Self::Storage;
    const INIT_HIGH: bool;
}

Static configuration of the debouncing algorithm.

Associated Types

type Storage: From<u8> + BitAnd<Output = Self::Storage> + BitAndAssign + BitOr<Output = Self::Storage> + BitOrAssign + Not<Output = Self::Storage> + Shl<u8, Output = Self::Storage> + Shr<u8, Output = Self::Storage> + AddAssign + SubAssign + Eq + Copy

The storage type of the state. For most usages, u8 is plenty big enough. You almost certainly don't need more than a u8.

Loading content...

Associated Constants

const MAX_COUNT: Self::Storage

The number of samples required to mark a state change.

Unlike many debouncing algorithms, the integration approach doesn't require a fixed number of consistent samples in a row. Rather, if in n + m samples we see n of the new state and m of the old state, a transition will be marked if the difference n - m reaches MAX_COUNT.

This should be configured based on the following formula: if d is the minimum debounce delay (in seconds), and f is the number of times the debouncer is polled per second, the MAX_COUNT should be set to the product d * f. For instance, if polling 100 times a second (100 Hz), with a minimum delay of 50 milliseconds, set this to 5.

Note: this must be non zero, and must be represented in two bits fewer than the storage you provide (e.g. if using u8, MAX_COUNT cannot exceed 0x3f. For the algorithm to perform any meaningful debouncing, it must be greater than 1.

const INIT_HIGH: bool

The initial state of the pin.

If INIT_HIGH is true, the debounced pin will start high and wait for the first falling edge. If this is false, the pin will start low and wait for the first debounced rising edge.

Loading content...

Implementors

impl Debounce for ActiveHigh[src]

type Storage = u8

For most usages, u8 is plenty.

const MAX_COUNT: Self::Storage[src]

With a MAX_COUNT of 4, the minimum delay is 40ms at 100Hz.

const INIT_HIGH: bool[src]

Since the switch is active high, INIT_HIGH is false.

impl Debounce for ActiveLow[src]

type Storage = u8

For most usages, u8 is plenty.

const MAX_COUNT: Self::Storage[src]

With a MAX_COUNT of 4, the minimum delay is 40ms at 100Hz.

const INIT_HIGH: bool[src]

Since the switch is active low, INIT_HIGH is true.

impl Debounce for OriginalKuhn[src]

type Storage = u8

For most usages, u8 is plenty.

const MAX_COUNT: Self::Storage[src]

With a MAX_COUNT of 3, the minimum delay is 300ms at 10Hz.

const INIT_HIGH: bool[src]

Kuhn's code fragment doesn't included initialization code, so we've just used a default of false consistent with the comments.

Loading content...