Skip to content

Commit

Permalink
Initial rotary encoder commit. In beta. see issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
gilmaimon committed May 9, 2019
1 parent aa601ad commit f71f507
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/ArduinoComponents/Components/RotaryEncoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "RotaryEncoder.h"
namespace components
{
RotaryEncoder::RotaryEncoder( uint8_t a, uint8_t b, uint8_t clicks )
: Component(),
A( a, TriggerOn::Low, InputPull::Up ),
B( b, TriggerOn::Low, InputPull::Up ),
detents( clicks )
{
RegisterChild(A);
A.onPress( [&] {
if ( B.isPressed() == LOW )
{
rotation--;
onRotate(-1);
}
else
{
rotation++;
onRotate(+1);
}
delay(5);
} );
RegisterChild(B);
B.onPress( [&] {
delay(5);
} );
}

int32_t RotaryEncoder::onRotate( int8_t dr )
{
if ( dr > 0 )
{
Serial.print( 'R' );
}
else
{
Serial.print( 'L' );
}
Serial.print( ' ' );
if ( detents )
rotation %= detents;
Serial.println( rotation );
return rotation;
}

void RotaryEncoder::privateLoop( void )
{

}
}
17 changes: 17 additions & 0 deletions src/ArduinoComponents/Components/RotaryEncoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "TactileButton.h"
#include "Component.h"
namespace components
{
class RotaryEncoder : public Component
{
public:
RotaryEncoder( uint8_t a, uint8_t b, uint8_t clicks = 0 );
private:
int32_t rotation;
int32_t onRotate( int8_t dr );
uint8_t detents;
TactileButton A;
TactileButton B;
void privateLoop( void );
};
}

0 comments on commit f71f507

Please sign in to comment.