Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
enhance software encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Sep 27, 2017
1 parent 8ad448e commit 351cd82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions libraries/RotaryEncoder/SwRotaryEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ bool SwRotaryEncoder::begin(uint8_t pina, uint8_t pinb)
_pina = pina;
_pinb = pinb;

pinMode(_pina, INPUT);
pinMode(_pinb, INPUT);
pinMode(_pina, INPUT_PULLUP);
pinMode(_pinb, INPUT_PULLUP);

_a_last = digitalRead(_pina);

Expand Down Expand Up @@ -120,13 +120,14 @@ void SwRotaryEncoder::clearAbs(void)

void SwRotaryEncoder::_irq_handler(void)
{
uint8_t val = (uint8_t) digitalRead(_pina);
uint32_t val = NRF_GPIO->IN;
uint8_t bita = bitRead(val, _pina);

if ( val != _a_last )
if ( bita != _a_last)
{
int32_t step = 0;
int32_t step;

if ( val != ((uint8_t) digitalRead(_pinb)) )
if ( bita != bitRead(val, _pinb) )
{
step = 1;
}else
Expand All @@ -135,7 +136,7 @@ void SwRotaryEncoder::_irq_handler(void)
}

_abs += step;
_a_last = val;
_a_last = bita;

if (_cb) ada_callback_fromISR(NULL, _cb, step);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/RotaryEncoder/SwRotaryEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SwRotaryEncoder
uint8_t _a_last;

int32_t _abs;
int32_t _last_read;
int32_t _last_read; // debouncing

callback_t _cb;
};
Expand Down

0 comments on commit 351cd82

Please sign in to comment.