From ff5f50db5fda59c0a2c114d215547b32294af396 Mon Sep 17 00:00:00 2001 From: wolfv6 Date: Sun, 5 Jun 2016 16:16:47 -0600 Subject: [PATCH] move RowBase::process() to Row and Row_DH --- src/Row.cpp | 17 +++++++++++++++++ src/Row.h | 1 + src/RowBase.cpp | 17 ----------------- src/RowBase.h | 10 +++++----- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Row.cpp b/src/Row.cpp index 8928abd..10bb8d7 100644 --- a/src/Row.cpp +++ b/src/Row.cpp @@ -4,6 +4,23 @@ For return, 1 means debounced changed. */ #include "Row.h" +/* +process() scans the row and calls any newly pressed or released keys. +*/ +void Row::process(const bool activeHigh) +{ + //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(); + scan(activeHigh); //save column-port-pin values to portState + rowState = getRowState(rowEnd, activeHigh); + debouncedChanged = debounce(rowState); + pressRelease(rowEnd, debouncedChanged); +} + uint8_t Row::debounce(const uint8_t rowState) { return debouncer.debounce(rowState, debounced); diff --git a/src/Row.h b/src/Row.h index 6dc2577..18c114a 100644 --- a/src/Row.h +++ b/src/Row.h @@ -26,5 +26,6 @@ class Row : public RowBase { Debouncer_4Samples debouncer; } + virtual void process(const bool activeHigh); }; #endif diff --git a/src/RowBase.cpp b/src/RowBase.cpp index 7d708ee..534ec56 100644 --- a/src/RowBase.cpp +++ b/src/RowBase.cpp @@ -1,21 +1,4 @@ #include "RowBase.h" -/* -scans the row and calls any newly pressed or released keys. -*/ -void RowBase::process(const bool activeHigh) -{ - //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(); - scan(activeHigh); //save column-port-pin values to portState - rowState = getRowState(rowEnd, activeHigh); - debouncedChanged = debounce(rowState); - 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 7884ee8..1d833ce 100644 --- a/src/RowBase.h +++ b/src/RowBase.h @@ -20,14 +20,15 @@ class RowBase ColPort *const *const ptrsColPorts; //array of column ports const uint8_t colPortCount; + virtual void keyWasPressed(); + protected: + uint8_t debounced; //bitwise, 1 means pressed, 0 means released + void wait(); void scan(const bool activeHigh); uint8_t getRowState(uint16_t& rowEnd, const bool activeHigh); virtual uint8_t debounce(const uint8_t rowState)=0; void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged); - virtual void keyWasPressed(); - protected: - uint8_t debounced; //bitwise, 1 means pressed, 0 means released public: RowBase( RowPort &refRowPort, const uint8_t rowPin, ColPort *const ptrsColPorts[], const uint8_t colPortCount, @@ -35,7 +36,6 @@ class RowBase : ptrsKeys(ptrsKeys), refRowPort(refRowPort), rowPin(rowPin), ptrsColPorts(ptrsColPorts), colPortCount(colPortCount), debounced(0) { } - //Key* getPtrKey(uint8_t col) const; todo delete, no longer needed 5/31/16 - void process(const bool activeHigh); + virtual void process(const bool activeHigh)=0; }; #endif