Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/ESP32RotaryEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
#endif
#endif

static const DRAM_ATTR char *LOG_TAG = "ESP32RotaryEncoder";

typedef enum {
LEFT = -1,
STILL = 0,
RIGHT = 1
} Rotation;

static const Rotation encoderStates[16] = {
STILL, LEFT, RIGHT, STILL,
RIGHT, STILL, STILL, LEFT,
LEFT, STILL, STILL, RIGHT,
STILL, RIGHT, LEFT, STILL
};


RotaryEncoder::RotaryEncoder( uint8_t encoderPinA, uint8_t encoderPinB, int8_t buttonPin, int8_t vccPin, uint8_t encoderSteps )
: encoderPinA{ encoderPinA },
encoderPinB{ encoderPinB },
Expand Down Expand Up @@ -332,10 +348,10 @@ void RotaryEncoder::setEncoderValue( long newValue )

void ARDUINO_ISR_ATTR RotaryEncoder::loop()
{
if( callbackEncoderChanged != NULL && encoderChanged() )
if( callbackEncoderChanged != nullptr && encoderChanged() )
callbackEncoderChanged( getEncoderValue() );

if( callbackButtonPressed != NULL && buttonPressed() )
if( callbackButtonPressed != nullptr && buttonPressed() )
callbackButtonPressed( buttonPressedDuration );
}

Expand Down
19 changes: 2 additions & 17 deletions src/ESP32RotaryEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,8 @@ class RotaryEncoder {
void loop();

private:
const char *LOG_TAG = "ESP32RotaryEncoder";

EncoderCallback callbackEncoderChanged = NULL;
ButtonCallback callbackButtonPressed = NULL;

typedef enum {
LEFT = -1,
STILL = 0,
RIGHT = 1
} Rotation;

Rotation encoderStates[16] = {
STILL, LEFT, RIGHT, STILL,
RIGHT, STILL, STILL, LEFT,
LEFT, STILL, STILL, RIGHT,
STILL, RIGHT, LEFT, STILL
};
EncoderCallback callbackEncoderChanged = nullptr;
ButtonCallback callbackButtonPressed = nullptr;

int encoderPinMode = INPUT;
int buttonPinMode = INPUT;
Expand Down