diff --git a/src/RowBase.cpp b/src/RowBase.cpp index 00fc002..0a345d0 100644 --- a/src/RowBase.cpp +++ b/src/RowBase.cpp @@ -1,4 +1,20 @@ #include "RowBase.h" +/* +process() scans the row and calls any newly pressed or released keys. +*/ +void RowBase::process() +{ + //these variables are all bitwise, one bit per key + uint8_t rowState; //1 means pressed, 0 means released + uint16_t rowEnd; //1 bit marks positioned after last key of row + uint8_t debouncedChanged; //1 means debounced changed + + wait(); + rowState = scan(rowEnd); + debouncedChanged = debounce(rowState, debounced); + pressRelease(rowEnd, debouncedChanged); +} + /* wait() delay's scan to give switches time to debounce. This version of wait() is very simple. More sophisticated versions can override this one. diff --git a/src/RowBase.h b/src/RowBase.h index c6dfd4b..63214a3 100644 --- a/src/RowBase.h +++ b/src/RowBase.h @@ -23,6 +23,8 @@ class RowBase void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged); public: RowBase(Key *const ptrsKeys[]) : ptrsKeys(ptrsKeys), debounced(0) { } - virtual void process()=0; + virtual void process(); + virtual uint8_t scan(uint16_t& rowEnd)=0; + virtual uint8_t debounce(const uint8_t rowState, uint8_t& debounced)=0; }; #endif diff --git a/src/Row_IOE.cpp b/src/Row_IOE.cpp index 714a615..67527b3 100644 --- a/src/Row_IOE.cpp +++ b/src/Row_IOE.cpp @@ -1,17 +1,11 @@ #include "Row_IOE.h" -/* -process() scans the row and calls any newly pressed or released keys. -*/ -void Row_IOE::process() +uint8_t Row_IOE::scan(uint16_t& rowEnd) { - //these variables are all bitwise, one bit per key - uint8_t rowState; //1 means pressed, 0 means released - uint16_t rowEnd; //1 bit marks positioned after last key of row - uint8_t debouncedChanged; //1 means debounced changed - - wait(); - rowState = scanner.scan(rowEnd); - debouncedChanged = debouncer.debounce(rowState, debounced); - pressRelease(rowEnd, debouncedChanged); + return scanner.scan(rowEnd); +} + +uint8_t Row_IOE::debounce(const uint8_t rowState, uint8_t& debounced) +{ + return debouncer.debounce(rowState, debounced); } diff --git a/src/Row_IOE.h b/src/Row_IOE.h index c9752a4..7c856e9 100644 --- a/src/Row_IOE.h +++ b/src/Row_IOE.h @@ -23,6 +23,7 @@ class Row_IOE : public RowBase Row_IOE( RowPort& refRowPort, const uint8_t strobePin, ColPort& refColPort, Key *const ptrsKeys[]) : RowBase(ptrsKeys), scanner(refRowPort, strobePin, refColPort) { } - virtual void process(); + uint8_t scan(uint16_t& rowEnd); + uint8_t debounce(const uint8_t rowState, uint8_t& debounced); }; #endif diff --git a/src/Row_uC.cpp b/src/Row_uC.cpp index 6da513b..a3c7ee7 100644 --- a/src/Row_uC.cpp +++ b/src/Row_uC.cpp @@ -1,17 +1,11 @@ #include "Row_uC.h" -/* -process() scans the row and calls any newly pressed or released keys. -*/ -void Row_uC::process() +uint8_t Row_uC::scan(uint16_t& rowEnd) { - //these variables are all bitwise, one bit per key - uint8_t rowState; //1 means pressed, 0 means released - uint16_t rowEnd; //1 bit marks positioned after last key of row - uint8_t debouncedChanged; //1 means debounced changed - - wait(); - rowState = scanner.scan(rowEnd); - debouncedChanged = debouncer.debounce(rowState, debounced); - pressRelease(rowEnd, debouncedChanged); + return scanner.scan(rowEnd); +} + +uint8_t Row_uC::debounce(const uint8_t rowState, uint8_t& debounced) +{ + return debouncer.debounce(rowState, debounced); } diff --git a/src/Row_uC.h b/src/Row_uC.h index 60d1236..3af67be 100644 --- a/src/Row_uC.h +++ b/src/Row_uC.h @@ -22,6 +22,7 @@ class Row_uC : public RowBase Row_uC(const uint8_t strobePin, const uint8_t readPins[], const uint8_t READ_PIN_COUNT, Key *const ptrsKeys[]) : RowBase(ptrsKeys), scanner(strobePin, readPins, READ_PIN_COUNT) { } - virtual void process(); + uint8_t scan(uint16_t& rowEnd); + uint8_t debounce(const uint8_t rowState, uint8_t& debounced); }; #endif