Archived
1
0

move Row::process() to RowBase

This commit is contained in:
wolfv6 2016-06-09 21:11:18 -06:00
parent 1b091ecde5
commit 2b856afa26
6 changed files with 37 additions and 29 deletions

View File

@ -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.

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}

View File

@ -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