enc
Fork of QEI by
QEI.h
- Committer:
- ohtake_i
- Date:
- 2013-12-09
- Revision:
- 1:7e60713aefc2
- Parent:
- 0:5c2ad81551aa
File content as of revision 1:7e60713aefc2:
#ifndef QEI_H #define QEI_H #include "mbed.h" #define PREV_MASK 0x1 //Mask for the previous state in determining direction of rotation. #define CURR_MASK 0x2 //Mask for the current state in determining direction of rotation. #define INVALID 0x3 //XORing two states where both bits have changed. class QEI { public: typedef enum Encoding { X2_ENCODING, X4_ENCODING } Encoding; QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding = X2_ENCODING); void reset(void); int getCurrentState(void); int getPulses(void); int getRevolutions(void); private: void encode(void); void index(void); Encoding encoding_; InterruptIn channelA_; InterruptIn channelB_; InterruptIn index_; int pulsesPerRev_; int prevState_; int currState_; volatile int pulses_; volatile int revolutions_; }; #endif