* Converted tabs to spaces
* Sanitized indentation
This commit is contained in:
+47
-47
@@ -1,4 +1,3 @@
|
||||
|
||||
// Please read Bounce2.h for information about the liscence and authors
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
@@ -14,80 +13,81 @@
|
||||
|
||||
|
||||
Bounce::Bounce()
|
||||
: previous_millis(0)
|
||||
, interval_millis(10)
|
||||
, state(0)
|
||||
, pin(0)
|
||||
: previous_millis(0)
|
||||
, interval_millis(10)
|
||||
, state(0)
|
||||
, pin(0)
|
||||
{}
|
||||
|
||||
void Bounce::attach(int pin) {
|
||||
this->pin = pin;
|
||||
bool read = digitalRead(pin);
|
||||
state = 0;
|
||||
if (digitalRead(pin)) {
|
||||
state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
|
||||
}
|
||||
#ifdef BOUNCE_LOCK_OUT
|
||||
previous_millis = 0;
|
||||
#else
|
||||
previous_millis = millis();
|
||||
#endif
|
||||
this->pin = pin;
|
||||
bool read = digitalRead(pin);
|
||||
state = 0;
|
||||
if (digitalRead(pin)) {
|
||||
state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
|
||||
}
|
||||
#ifdef BOUNCE_LOCK_OUT
|
||||
previous_millis = 0;
|
||||
#else
|
||||
previous_millis = millis();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Bounce::interval(uint16_t interval_millis)
|
||||
{
|
||||
this->interval_millis = interval_millis;
|
||||
this->interval_millis = interval_millis;
|
||||
}
|
||||
|
||||
bool Bounce::update()
|
||||
{
|
||||
#ifdef BOUNCE_LOCK_OUT
|
||||
state &= ~_BV(STATE_CHANGED);
|
||||
// Ignore everything if we are locked out
|
||||
if (millis() - previous_millis >= interval_millis) {
|
||||
bool currentState = digitalRead(pin);
|
||||
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(DEBOUNCED_STATE);
|
||||
state |= _BV(STATE_CHANGED);
|
||||
}
|
||||
}
|
||||
return state & _BV(STATE_CHANGED);
|
||||
// Ignore everything if we are locked out
|
||||
if (millis() - previous_millis >= interval_millis) {
|
||||
bool currentState = digitalRead(pin);
|
||||
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(DEBOUNCED_STATE);
|
||||
state |= _BV(STATE_CHANGED);
|
||||
}
|
||||
}
|
||||
return state & _BV(STATE_CHANGED);
|
||||
#else
|
||||
// Lire l'etat de l'interrupteur dans une variable temporaire.
|
||||
bool currentState = digitalRead(pin);
|
||||
// Lire l'etat de l'interrupteur dans une variable temporaire.
|
||||
bool currentState = digitalRead(pin);
|
||||
state &= ~_BV(STATE_CHANGED);
|
||||
|
||||
// Redemarrer le compteur timeStamp tant et aussi longtemps que
|
||||
// la lecture ne se stabilise pas.
|
||||
if ( currentState != (bool)(state & _BV(UNSTABLE_STATE)) ) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(UNSTABLE_STATE);
|
||||
} else if ( millis() - previous_millis >= interval_millis ) {
|
||||
// Rendu ici, la lecture est stable
|
||||
// Est-ce que la lecture est différente de l'etat emmagasine de l'interrupteur?
|
||||
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(DEBOUNCED_STATE);
|
||||
state |= _BV(STATE_CHANGED);
|
||||
}
|
||||
}
|
||||
// Redemarrer le compteur timeStamp tant et aussi longtemps que
|
||||
// la lecture ne se stabilise pas.
|
||||
if ( currentState != (bool)(state & _BV(UNSTABLE_STATE)) ) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(UNSTABLE_STATE);
|
||||
} else
|
||||
if ( millis() - previous_millis >= interval_millis ) {
|
||||
// Rendu ici, la lecture est stable
|
||||
// Est-ce que la lecture est différente de l'etat emmagasine de l'interrupteur?
|
||||
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(DEBOUNCED_STATE);
|
||||
state |= _BV(STATE_CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
return state & _BV(STATE_CHANGED);
|
||||
return state & _BV(STATE_CHANGED);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Bounce::read()
|
||||
{
|
||||
return state & _BV(DEBOUNCED_STATE);
|
||||
return state & _BV(DEBOUNCED_STATE);
|
||||
}
|
||||
|
||||
bool Bounce::rose()
|
||||
{
|
||||
return ( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
|
||||
return ( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
|
||||
}
|
||||
|
||||
bool Bounce::fell()
|
||||
{
|
||||
return !( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
|
||||
return !( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user