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.
Diff: REnc.cpp
- Revision:
- 4:916992052518
- Parent:
- 3:9dfe441065e9
- Child:
- 5:3e6931797218
--- a/REnc.cpp Wed Aug 06 23:54:19 2014 +0000
+++ b/REnc.cpp Tue Aug 12 01:49:49 2014 +0000
@@ -1,42 +1,16 @@
#include "REnc.h"
#include "mbed.h"
-/** class to make sound with a buzzer, based on a PwmOut
- * The class use a timeout to switch off the sound - it is not blocking while making noise
+/**
+ * @file REnc.cpp
+ * Project Rotary Encoder handling Library
+ * @brief Rotary Encoder handling library for mbed
+ * @version 1.0
+ * @author Chuck Timber
+ * @date 12/08/2014
+ */
+/** class to handle a rotary encoder
*
- * Example:
- * @code
- * // REnc sample
- * #include "mbed.h"
- * #include "REnc.h"
- * void proc_REnc_right(void);
- * void proc_REnc_left(void);
- *
- * // void proc_REnc_right(void) { }
- * // void proc_REnc_left(void) { }
- *
- * REnc renc(dp1, dp2);
- *
- * int main()
- * {
- *
- * // renc.setHandleRight(&proc_REnc_right);
- * // renc.setHandleLeft(&proc_REnc_left);
- *
- * while(1) {
- * if (renc.CMD == CLOCKWISE) {
- * proc_REnc_right();
- * renc.CMD = STOP;
- * } else if (renc.CMD == COUNTERCLOCKWISE) {
- * proc_REnc_left();
- * renc.CMD = STOP;
- * }
- * if (renc.STABLE) {
- * // do_something
- * }
- * }
- * }
- * @endcode
*/
using namespace mbed;
@@ -59,14 +33,14 @@
CMD = CLOCKWISE;
cnt = RENC_EXECUTION_DELAY;
STABLE = 0;
- if (mRightCallback != NULL) { mRightCallback(); CMD = STOP; }
+ if (mCCCallback != NULL) { mCCCallback(); CMD = STOP; }
break;
case 0xb:
case 0xd:
CMD = COUNTERCLOCKWISE;
cnt = RENC_EXECUTION_DELAY;
STABLE = 0;
- if (mLeftCallback != NULL) { mLeftCallback(); CMD = STOP; }
+ if (mCCWCallback != NULL) { mCCWCallback(); CMD = STOP; }
break;
default:
CMD = STOP;
@@ -77,20 +51,24 @@
}
}
-void REnc::setHandleRight(void (*fptr)(void)) { mRightCallback = fptr; }
-void REnc::setHandleLeft(void (*fptr)(void)) { mLeftCallback = fptr; }
+/** set callback function to Clockwise TURN */
+void REnc::setHandleCC(void (*fptr)(void)) { mCCCallback = fptr; }
+/** set callback function to Counterclockwise TURN */
+void REnc::setHandleCCW(void (*fptr)(void)) { mCCWCallback = fptr; }
// constructor
- /** Create an REnc object connected to DigitalIn pins
- *
- * @param pina - Digital Input to A-phase of the rotary encoder
- * @param pinb - Digital Input to B-phase of the rotary encoder
- */
+/** Create an REnc object connected to DigitalIn pins
+ *
+ * @param pina - Digital Input to A-phase of the rotary encoder
+ * @param pinb - Digital Input to B-phase of the rotary encoder
+ */
REnc::REnc(PinName pina, PinName pinb) : _pina(pina), _pinb(pinb)
{
+ _pina.mode(PullUp);
+ _pinb.mode(PullUp);
CMD = STOP;
STABLE = 1;
- mRightCallback = NULL;
- mLeftCallback = NULL;
+ mCCCallback = NULL;
+ mCCWCallback = NULL;
_tick.attach(this, &REnc::sample_encoder, RENC_SAMPLING_PERIOD);
}