# HG changeset patch # User David Douard # Date 1603660535 -3600 # Node ID 167010858b8db9c798b7fdca9dea8d10c0264a41 # Parent bc1d6ecbb0cc91453903da4d4a16beffacaaf0dc Reformat Keypad.cpp diff -r bc1d6ecbb0cc -r 167010858b8d lib/keypad/Keypad.cpp --- a/lib/keypad/Keypad.cpp Sun Oct 25 22:15:03 2020 +0100 +++ b/lib/keypad/Keypad.cpp Sun Oct 25 22:15:35 2020 +0100 @@ -1,95 +1,96 @@ -#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; - ThisThread::sleep_for(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(callback(this, &Keypad::run)); -} - -void Keypad::stop(void) -{ - _started = false; -} +#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; + ThisThread::sleep_for(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(callback(this, &Keypad::run)); +} + +void Keypad::stop(void) +{ + _started = false; +}