fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
818d962
gram
1#ifndef _DEBOUNCE_HPP 2#define _DEBOUNCE_HPP 3 4#include "stdlib.hpp" 5 6typedef struct _DebounceState { 7absolute_time_t locked_until = 0 ; 8bool pressed = false; 9}DebounceState ; 10 11inline bool update_debounce_state ( 12DebounceState & debounce_state , 13bool current_reading , 14uint32_t debounce_period_ms 15) { 16// If currently locked out, do nothing. 17if (!time_reached (debounce_state .locked_until )) { 18return false; 19 } 20 21// If latest reading differs from the last known state, update the value and timeout. 22if (current_reading != debounce_state .pressed ) { 23debounce_state .pressed = current_reading ; 24debounce_state .locked_until = make_timeout_time_ms (debounce_period_ms ); 25return true; 26 } 27 28return false; 29} 30 31#endif