Quellcode durchsuchen

move RowBase::process() to Row and Row_DH

tags/v0.5.0
wolfv6 vor 8 Jahren
Ursprung
Commit
ff5f50db5f
4 geänderte Dateien mit 23 neuen und 22 gelöschten Zeilen
  1. 17
    0
      src/Row.cpp
  2. 1
    0
      src/Row.h
  3. 0
    17
      src/RowBase.cpp
  4. 5
    5
      src/RowBase.h

+ 17
- 0
src/Row.cpp Datei anzeigen

*/ */
#include "Row.h" #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) uint8_t Row::debounce(const uint8_t rowState)
{ {
return debouncer.debounce(rowState, debounced); return debouncer.debounce(rowState, debounced);

+ 1
- 0
src/Row.h Datei anzeigen

{ {
Debouncer_4Samples debouncer; Debouncer_4Samples debouncer;
} }
virtual void process(const bool activeHigh);
}; };
#endif #endif

+ 0
- 17
src/RowBase.cpp Datei anzeigen

#include "RowBase.h" #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. /* 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.

+ 5
- 5
src/RowBase.h Datei anzeigen

ColPort *const *const ptrsColPorts; //array of column ports ColPort *const *const ptrsColPorts; //array of column ports
const uint8_t colPortCount; const uint8_t colPortCount;
virtual void keyWasPressed();
protected:
uint8_t debounced; //bitwise, 1 means pressed, 0 means released
void wait(); void wait();
void scan(const bool activeHigh); void scan(const bool activeHigh);
uint8_t getRowState(uint16_t& rowEnd, const bool activeHigh); uint8_t getRowState(uint16_t& rowEnd, const bool activeHigh);
virtual uint8_t debounce(const uint8_t rowState)=0; virtual uint8_t debounce(const uint8_t rowState)=0;
void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged); 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: public:
RowBase( RowPort &refRowPort, const uint8_t rowPin, RowBase( RowPort &refRowPort, const uint8_t rowPin,
ColPort *const ptrsColPorts[], const uint8_t colPortCount, ColPort *const ptrsColPorts[], const uint8_t colPortCount,
: ptrsKeys(ptrsKeys), refRowPort(refRowPort), rowPin(rowPin), : ptrsKeys(ptrsKeys), refRowPort(refRowPort), rowPin(rowPin),
ptrsColPorts(ptrsColPorts), colPortCount(colPortCount), ptrsColPorts(ptrsColPorts), colPortCount(colPortCount),
debounced(0) { } 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 #endif