Keypad icon indicating copy to clipboard operation
Keypad copied to clipboard

SetDebounceTime, SetHoldTime bugs

Open alexandarZ opened this issue 7 years ago • 0 comments

In Keypad.cpp, method SetDebounceTime have argument debounce which is unsigned int. If we pass -1 for example debounce will have value 65535, because of nature of unsigned int type (https://www.arduino.cc/en/Reference/UnsignedInt). So if ( debounce < 1 ) { debounceTime = 1;} will never be reached in code and keypad will become unstable. This also happens in SetHoldTime method!

void Keypad::setDebounceTime(uint debounce) { debounce<1 ? debounceTime=1 : debounceTime=debounce; }

Solution idea:

define MAX_DEBOUNCE_VALUE 255

void Keypad::setDebounceTime(uint debounce) { if( debounce > MAX_DEBOUNCE_VALUE ) { debounceTime = MAX_DEBOUNCE_VALUE; } else { debounceTime = debounce; } }

Now if debounce ≥ 0 && debounce ≤ MAX_DEBOUNCE_VALUE debounceTime = debounce else debounceTime = MAX_DEBOUNCE_VALUE

alexandarZ avatar May 28 '17 11:05 alexandarZ