diff -r daf26b083899 -r b43536c064f6 lib/keypad/Keypad.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/keypad/Keypad.cpp Mon Jan 28 21:51:45 2019 +0100 @@ -0,0 +1,88 @@ +#include "mbed.h" +#include "Keypad.h" + + +Keypad::Keypad(uint8_t nRows, DigitalIn rows[], + uint8_t nColumns, DigitalOut cols[], + int debounce_ms): + _rows(), + _columns(), + _debounce(debounce_ms), + _started(false), + _nrows(nRows), + _ncols(nColumns) +{ + printf("Setup Keypad: %dx%d\r\n", nColumns, nRows); + for(uint8_t c=0; c 0) + { + _keys[row + _nrows*col]--; + if ((_keys[row + _nrows*col] == 0) && _kr_callback) + _kr_callback.call(row, col); + } + } + } + _columns[col].write(0); + col = (col+1) % _ncols; + Thread::wait(5); + } +} + +void Keypad::attach(const keyevent_callback_t& kp_callback, + const keyevent_callback_t& kr_callback) +{ + _kp_callback = kp_callback; + _kr_callback = kr_callback; +} + +void Keypad::start(void) +{ +if (_started) + return; +_started = true; +_loop.start(this, &Keypad::run); +} + +void Keypad::stop(void) +{ + _started = false; +}