Browse Source

move Row::process() to RowBase

tags/v0.5.0
wolfv6 8 years ago
parent
commit
2b856afa26
6 changed files with 35 additions and 27 deletions
  1. 16
    0
      src/RowBase.cpp
  2. 3
    1
      src/RowBase.h
  3. 6
    12
      src/Row_IOE.cpp
  4. 2
    1
      src/Row_IOE.h
  5. 6
    12
      src/Row_uC.cpp
  6. 2
    1
      src/Row_uC.h

+ 16
- 0
src/RowBase.cpp View File

#include "RowBase.h" #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. /* wait() delay's scan to give switches time to debounce.
This version of wait() is very simple. More sophisticated versions can override this one. This version of wait() is very simple. More sophisticated versions can override this one.

+ 3
- 1
src/RowBase.h View File

void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged); void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged);
public: public:
RowBase(Key *const ptrsKeys[]) : ptrsKeys(ptrsKeys), debounced(0) { } 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 #endif

+ 6
- 12
src/Row_IOE.cpp View File

#include "Row_IOE.h" #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
return scanner.scan(rowEnd);
}


wait();
rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged);
uint8_t Row_IOE::debounce(const uint8_t rowState, uint8_t& debounced)
{
return debouncer.debounce(rowState, debounced);
} }

+ 2
- 1
src/Row_IOE.h View File

Row_IOE( RowPort& refRowPort, const uint8_t strobePin, Row_IOE( RowPort& refRowPort, const uint8_t strobePin,
ColPort& refColPort, Key *const ptrsKeys[]) ColPort& refColPort, Key *const ptrsKeys[])
: RowBase(ptrsKeys), scanner(refRowPort, strobePin, refColPort) { } : 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 #endif

+ 6
- 12
src/Row_uC.cpp View File

#include "Row_uC.h" #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
return scanner.scan(rowEnd);
}


wait();
rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged);
uint8_t Row_uC::debounce(const uint8_t rowState, uint8_t& debounced)
{
return debouncer.debounce(rowState, debounced);
} }

+ 2
- 1
src/Row_uC.h View File

Row_uC(const uint8_t strobePin, const uint8_t readPins[], const uint8_t READ_PIN_COUNT, Row_uC(const uint8_t strobePin, const uint8_t readPins[], const uint8_t READ_PIN_COUNT,
Key *const ptrsKeys[]) Key *const ptrsKeys[])
: RowBase(ptrsKeys), scanner(strobePin, readPins, READ_PIN_COUNT) { } : 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 #endif