driver for incremental encoder
Revision 6:2fdce74d2a7b, committed 2019-03-28
- Comitter:
- ianaherne
- Date:
- Thu Mar 28 16:28:55 2019 +0000
- Parent:
- 5:1a5772466668
- Commit message:
- added function to change limits
Changed in this revision
decoder.cpp | Show annotated file Show diff for this revision Revisions of this file |
decoder.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/decoder.cpp Thu Mar 14 16:05:28 2019 +0000 +++ b/decoder.cpp Thu Mar 28 16:28:55 2019 +0000 @@ -16,7 +16,10 @@ _channelA.rise(this, &decoder::isr); _count = 0; - _direction = 0; + _direction = 0; + + _lowerLimit = 0; + _upperLimit = 1; // set as default function must be called to change these values } @@ -42,7 +45,7 @@ if(chB == 1){ - if( _count != UPPER_LIMIT){ + if( _count != _upperLimit){ _count++; } _direction = 1; @@ -55,7 +58,7 @@ if(chB == 0){ - if(_count != LOWER_LIMIT){ + if(_count != _lowerLimit){ _count--; } _direction = 0; @@ -102,6 +105,25 @@ } /** +* @brief setLimits() +* @details sets the limits of the encoder counting +* @param lower limit and upper limit +* @return +* @warning set to 0 and 1 by default by constructor user must change as required +* +*/ + + + +void decoder :: setLimits(int8_t lower, int8_t upper){ + + _lowerLimit = lower; + _upperLimit = upper; + + +} + +/** * @brief reset() * @details function to reset all internal counting and directional variables * @param NA
--- a/decoder.h Thu Mar 14 16:05:28 2019 +0000 +++ b/decoder.h Thu Mar 28 16:28:55 2019 +0000 @@ -9,16 +9,7 @@ public: - - /* These values control the upper and lower limits the the count will go to change limits to suit application*/ - typedef enum{ - - - LOWER_LIMIT = 0, - UPPER_LIMIT = 19 - - - }limits_t; + decoder(PinName channelA,PinName channelB); @@ -26,6 +17,7 @@ int8_t getDirection(); int16_t getCount(); + void setLimits(int8_t lower, int8_t upper); void reset(); @@ -38,6 +30,9 @@ int8_t _direction; int16_t _count; + int8_t _lowerLimit; + int8_t _upperLimit; +