Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 11:24b34deae975, committed 2020-03-03
- Comitter:
- jirrick
- Date:
- Tue Mar 03 12:20:55 2020 +0000
- Parent:
- 10:2502b829d452
- Commit message:
- configure detection of rise and fall events
Changed in this revision
| mRotaryEncoder.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mRotaryEncoder.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2502b829d452 -r 24b34deae975 mRotaryEncoder.cpp
--- a/mRotaryEncoder.cpp Fri Feb 26 20:18:57 2016 +0000
+++ b/mRotaryEncoder.cpp Tue Mar 03 12:20:55 2020 +0000
@@ -2,7 +2,7 @@
#include "mRotaryEncoder.h"
-mRotaryEncoder::mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode, int debounceTime_us) {
+mRotaryEncoder::mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode, int debounceTime_us, int detectRise, int detectFall) {
m_pinA = new PinDetect(pinA); // interrrupts on pinA
m_pinB = new DigitalIn(pinB); // only digitalIn for pinB
@@ -11,8 +11,12 @@
m_pinB->mode(pullMode);
// attach interrrupts on pinA
- m_pinA->attach_asserted(this, &mRotaryEncoder::rise);
- m_pinA->attach_deasserted(this, &mRotaryEncoder::fall);
+ if (detectRise != 0){
+ m_pinA->attach_asserted(this, &mRotaryEncoder::rise);
+ }
+ if (detectFall != 0){
+ m_pinA->attach_deasserted(this, &mRotaryEncoder::fall);
+ }
//start sampling pinA
m_pinA->setSampleFrequency(debounceTime_us); // Start timers an Defaults debounce time.
diff -r 2502b829d452 -r 24b34deae975 mRotaryEncoder.h
--- a/mRotaryEncoder.h Fri Feb 26 20:18:57 2016 +0000
+++ b/mRotaryEncoder.h Tue Mar 03 12:20:55 2020 +0000
@@ -34,6 +34,7 @@
* First version published Thomas Raab raabinator
* 26.11.2010 extended by charly - pushbutton, pullmode, debounce, callback-system
* Feb2011 Changes InterruptIn to PinDetect which does the debounce of mechanical switches
+ * Mar2020 Configurable detection of rise/fall events to account for different types of encoders (half as much dent points)
*
*/
class mRotaryEncoder {
@@ -45,8 +46,10 @@
* @param pinSW Pin for push-button switch
* @param pullmode mode for pinA pinB and pinSW like DigitalIn.mode
* @param debounceTime_us time in micro-seconds to wait for bouncing of mechanical switches to end
+ * @param detectRise Detect rise event as new rotation
+ * @param detectFall Detect fall event as new rotation
*/
- mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode=PullUp, int debounceTime_us=1000);
+ mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode=PullUp, int debounceTime_us=1000, int detectRise=1, int detectFall=1);
/** destroy object
*