Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition causing lost events #9

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
625b9a3
Fix race condition causing lost events
soligen2010 Feb 19, 2016
97dd97e
Fix bug when double click disabled
soligen2010 Feb 19, 2016
3831274
accelerationEnabled
soligen2010 Feb 19, 2016
e08e7fa
Added method to enable/disable the button hold/release events
soligen2010 Feb 19, 2016
9937dd4
Adjusted double click time
soligen2010 Feb 19, 2016
9798ec8
Allow multiple instances of object to co-exist
soligen2010 Feb 19, 2016
5b63c46
Fixed "FLAKY" mode
soligen2010 Feb 19, 2016
3546f7a
Added ability to use button without encoder and allow pin 0 to be used
soligen2010 Feb 19, 2016
14e6607
Added example showing how to use 2 devices simultaneously
soligen2010 Feb 19, 2016
f60058c
Restored original behavior for button on pin 0, but can now optionall…
soligen2010 Feb 20, 2016
d9e6f8a
Added support for ESP8266 and example
soligen2010 Feb 20, 2016
97fd7e5
Filter out transient events on the button
soligen2010 Mar 20, 2016
4124fc6
@PlatformIO Library Registry manifest file
valeros May 4, 2016
2ea30f4
Merge pull request #1 from valeros/patch-2
soligen2010 May 4, 2016
2ad751f
Change conditional on AVR included
soligen2010 Jun 23, 2016
c471bc1
Revert "Change conditional on AVR included"
soligen2010 Jun 24, 2016
98982a5
Revert "Revert "Change conditional on AVR included""
soligen2010 Jun 24, 2016
a351ccb
Change cli and sei to noInterrupts and interrupts
soligen2010 Jun 24, 2016
b1ee276
Added methods to customize double click and hold/release times for bu…
soligen2010 Oct 15, 2016
9efede6
Added ability to have multiple buttons on one analog pin/Button race …
soligen2010 Nov 1, 2016
4dacba3
moved interupts() in getValue to be sure no race condition happens
soligen2010 Nov 1, 2016
dba405b
Steps Per Notch default changes to 4
soligen2010 Feb 12, 2017
e2cf703
Fixed ambiguous constructor. Analog buttons are now a seperate object
soligen2010 Feb 13, 2017
e30f7ac
Changed TwoDevices example to use DigitalButton
soligen2010 Feb 13, 2017
31ca2f7
Corrected IF statement to check both pinA and pinB
soligen2010 Feb 18, 2017
16505d9
Support for STM23duino
soligen2010 Apr 11, 2017
f376418
Fix Typo
soligen2010 Apr 21, 2017
4b3b30b
Fix for Due
soligen2010 Apr 29, 2017
9337a0c
Another way to access the clickEncoder class (#9)
aster94 Jan 15, 2018
9d0d226
Update ESP8266Example.ino
soligen2010 Jan 23, 2021
2081c04
CCW Negative Bit Fix
soligen2010 Jan 23, 2021
7d11d48
Reset Encoder Method; Improved Timing
soligen2010 Feb 13, 2022
0de753b
Add library.properties and update folder structure for Arduino librar…
robaol Sep 8, 2023
58a6c82
ESP32 Fix
soligen2010 Sep 8, 2023
6c41ff6
improved ESP32 fix
soligen2010 Sep 8, 2023
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
221 changes: 0 additions & 221 deletions ClickEncoder.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ or see it in action at my modified [reflow oven controller]
### Encoder
The library supports **acceleration**, so when the encoder is rotated faster, the encoders value will increment faster.

Acceleration can be enabled or disabled at runtine using `setAccelerationEnabled(bool)`.
Acceleration can be enabled or disabled at runtime using `setAccelerationEnabled(bool)`.

For instance, it makes sense to disable acceleration when entering a configuration menu that will be navigated using the encoder.

Expand Down
68 changes: 68 additions & 0 deletions examples/ArduinoStyle/ArduinoStyle.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <ClickEncoder.h>
#include <TimerOne.h>

int16_t oldEncPos, encPos;
uint8_t buttonState;

#define pinA A2
#define pinB A1
#define pinSw A0 //switch
#define STEPS 4

ClickEncoder encoder(pinA, pinB, pinSw, STEPS);

void setup() {
Serial.begin(9600);

Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);

encoder.setAccelerationEnabled(true);

Serial.print("Acceleration is ");
Serial.println((encoder.getAccelerationEnabled()) ? "enabled" : "disabled");

oldEncPos = -1;
}

void loop() {
encPos += encoder.getValue();

if (encPos != oldEncPos) {
oldEncPos = encPos;
Serial.print("Encoder Value: ");
Serial.println(encPos);
}

buttonState = encoder.getButton();

if (buttonState != 0) {
Serial.print("Button: "); Serial.println(buttonState);
switch (buttonState) {
case ClickEncoder::Open: //0
break;

case ClickEncoder::Closed: //1
break;

case ClickEncoder::Pressed: //2
break;

case ClickEncoder::Held: //3
break;

case ClickEncoder::Released: //4
break;

case ClickEncoder::Clicked: //5
break;

case ClickEncoder::DoubleClicked: //6
break;
}
}
}

void timerIsr() {
encoder.service();
}
66 changes: 66 additions & 0 deletions examples/ESP8266Example/ESP8266Example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*

This example demonstrates the use of the library on an ESP8266. without using a timer interrupt

*/

#include <ClickEncoder.h>
//#include <TimerOne.h>


#define ENCODER_PINA 13
#define ENCODER_PINB 14
#define ENCODER_BTN 0

#define ENCODER_STEPS_PER_NOTCH 4 // Change this depending on which encoder is used

ClickEncoder encoder = ClickEncoder(ENCODER_PINA,ENCODER_PINB,ENCODER_BTN,ENCODER_STEPS_PER_NOTCH);

void setup() {
Serial.begin(115200);

encoder.setButtonHeldEnabled(true);
encoder.setDoubleClickEnabled(true);

// Enable the button to be on pin 0. Normally pin 0 is not recognized as a valid pin for a button,
// this is to maintain backward compatibility with an old version of the library
// This version can have the button on pin zero, and this call enables the feature.
// in this version best to use pin -1 instead of 0 to disable button functions
encoder.setButtonOnPinZeroEnabled(true);

}

void loop() {

//Call Service in loop becasue using timer interrupts may affect ESP8266 WIFI
//however call no more than 1 time per millisecond to reduce encoder bounce
static uint32_t lastService = 0;
if (micros() - lastService >= 1000) {
lastService = micros();
encoder.service();
}


static int16_t last, value;
value += encoder.getValue();

if (value != last) {
last = value;
Serial.print("Encoder Value: ");
Serial.println(value);

}

ClickEncoder::Button b = encoder.getButton();
if (b != ClickEncoder::Open) {
Serial.print("Button: ");
#define VERBOSECASE(label) case label: Serial.println(#label); break;
switch (b) {
VERBOSECASE(ClickEncoder::Pressed);
VERBOSECASE(ClickEncoder::Held)
VERBOSECASE(ClickEncoder::Released)
VERBOSECASE(ClickEncoder::Clicked)
VERBOSECASE(ClickEncoder::DoubleClicked)
}
}
}
Loading