Archived
1
0

remove debounced from debounce()

This commit is contained in:
wolfv6 2016-06-01 15:59:59 -06:00
parent 1d3af27ebd
commit 90c420491e
3 changed files with 8 additions and 9 deletions

View File

@ -14,10 +14,11 @@ uint8_t samples[SAMPLE_COUNT]; //bitwise, one bit per key, most
uint8_t samplesIndex = 0; //samples[] current write index
uint8_t previousDebounced = 0; //bitwise, one bit per key
uint8_t debounced; //1 means pressed, 0 means released
uint8_t isFallingEdge; //1 means falling edge
uint8_t isRisingEdge; //1 means rising edge
uint8_t debounce(const uint8_t rowState, uint8_t& debounced)
uint8_t debounce(const uint8_t rowState)
{
uint8_t debouncedChanged; //bitwise
uint8_t all_1 = ~0; //bitwise
@ -63,10 +64,9 @@ int main()
//Test input and output only shows first bit of each byte.
const uint8_t pressed[] = {1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0};
const uint8_t bouncy[] = {1,0,0,0,0,1,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0};
const uint8_t expectDebounced[]= {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0};
const uint8_t expectDebounced[]= {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0}; //SAMPLE_COUNT 4
const uint8_t SCAN_COUNT = sizeof(bouncy)/sizeof(*bouncy);
uint8_t i;
uint8_t debounced; //1 means pressed, 0 means released
uint8_t debouncedChanged; //1 means debounced changed
std::cout << "button pressed: ";
@ -86,7 +86,7 @@ int main()
std::cout << "debounced signal: ";
for (i=0; i<SCAN_COUNT; i++)
{
debouncedChanged = debounce(bouncy[i], debounced);
debouncedChanged = debounce(bouncy[i]);
//pressRelease(debouncedChanged);
std::cout << (int)debounced;
}
@ -103,7 +103,7 @@ int main()
std::cout << "isFallingEdge: ";
for (i=0; i<SCAN_COUNT; i++)
{
debouncedChanged = debounce(bouncy[i], debounced);
debouncedChanged = debounce(bouncy[i]);
pressRelease(debouncedChanged);
std::cout << (int)isFallingEdge;
}
@ -112,7 +112,7 @@ int main()
std::cout << "isRisingEdge: ";
for (i=0; i<SCAN_COUNT; i++)
{
debouncedChanged = debounce(bouncy[i], debounced);
debouncedChanged = debounce(bouncy[i]);
pressRelease(debouncedChanged);
std::cout << (int)isRisingEdge;
}

View File

@ -7,12 +7,11 @@ 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 debounced; //1 means pressed, 0 means released
uint8_t debouncedChanged; //1 means debounced changed
scan(activeHigh); //save column-port-pin values to portState
rowState = getRowState(rowEnd, activeHigh);
debouncedChanged = debounce(rowState, debounced);
debouncedChanged = debounce(rowState);
pressRelease(rowEnd, debouncedChanged);
}

View File

@ -57,7 +57,7 @@ class RowBase
void scan(const bool activeHigh);
uint8_t getRowState(uint16_t& rowEnd, const bool activeHigh);
virtual uint8_t debounce(const uint8_t rowState, uint8_t& debounced)=0;
virtual uint8_t debounce(const uint8_t rowState)=0;
//void detectEdge(uint8_t debounced, uint8_t& isFallingEdge, uint8_t& isRisingEdge);
void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged);
virtual void keyWasPressed();