set rowState bit | set rowState bit | ||||
strobe row off | strobe row off | ||||
Debouncer_4Samples::debounce() debounce | Debouncer_4Samples::debounce() debounce | ||||
Row::pressRelease() for each key in row | |||||
Row::send() for each key in row | |||||
if falling edge | if falling edge | ||||
Key_*::release() scanCode->release() | Key_*::release() scanCode->release() | ||||
Code_*::release() Keyboard.release(scancode) | Code_*::release() Keyboard.release(scancode) |
Split keyboards with a long connecting wire or in environment with | Split keyboards with a long connecting wire or in environment with | ||||
strong electromagnetic interference (EMI) may need a larger SAMPLE_COUNT for reliability. | strong electromagnetic interference (EMI) may need a larger SAMPLE_COUNT for reliability. | ||||
*/ | */ | ||||
#include "Debouncer_4Samples.h" | |||||
#include "Debouncer_Samples.h" | |||||
/* debounce() sets debounced and returns debouncedChanged. All variables are bitwise. | /* debounce() sets debounced and returns debouncedChanged. All variables are bitwise. | ||||
For parameters, 1 means pressed, 0 means released. | For parameters, 1 means pressed, 0 means released. | ||||
For return, 1 means debounced changed. | For return, 1 means debounced changed. | ||||
*/ | */ | ||||
read_pins_t Debouncer_4Samples::debounce(const read_pins_t rawSignal, read_pins_t& debounced) | |||||
read_pins_t Debouncer_Samples::debounce(const read_pins_t rawSignal, read_pins_t& debounced) | |||||
{ | { | ||||
read_pins_t previousDebounced; //bitwise, 1 means pressed, 0 means released | read_pins_t previousDebounced; //bitwise, 1 means pressed, 0 means released | ||||
read_pins_t all_1 = ~0; //bitwise | read_pins_t all_1 = ~0; //bitwise |
#include <config_keybrd.h> | #include <config_keybrd.h> | ||||
#include <DebouncerInterface.h> | #include <DebouncerInterface.h> | ||||
/* Debouncer_4Samples | |||||
/* Debouncer_Samples | |||||
Configuration: #define SAMPLE_COUNT in config_keybrd.h | Configuration: #define SAMPLE_COUNT in config_keybrd.h | ||||
*/ | */ | ||||
class Debouncer_4Samples : public DebouncerInterface | |||||
class Debouncer_Samples : public DebouncerInterface | |||||
{ | { | ||||
private: | private: | ||||
read_pins_t samples[SAMPLE_COUNT]; //bitwise, one bit per key, most recent readings | read_pins_t samples[SAMPLE_COUNT]; //bitwise, one bit per key, most recent readings | ||||
uint8_t samplesIndex; //samples[] current write index | uint8_t samplesIndex; //samples[] current write index | ||||
public: | public: | ||||
Debouncer_4Samples(): samplesIndex(0) {} | |||||
Debouncer_Samples(): samplesIndex(0) {} | |||||
virtual read_pins_t debounce(const read_pins_t rawSignal, read_pins_t& debounced); | virtual read_pins_t debounce(const read_pins_t rawSignal, read_pins_t& debounced); | ||||
}; | }; | ||||
#endif | #endif |
#include "Row.h" | #include "Row.h" | ||||
/* | /* | ||||
pressRelease() calls key's press() or release() function if it was pressed or released. | |||||
send() calls key's press() or release() function if it was pressed or released. | |||||
Both parameters are bitwise. | Both parameters are bitwise. | ||||
*/ | */ | ||||
void Row::pressRelease(const uint8_t readPinCount, const read_pins_t debouncedChanged) | |||||
void Row::send(const uint8_t readPinCount, const read_pins_t debouncedChanged) | |||||
{ | { | ||||
read_pins_t isFallingEdge; //bitwise, 1 means falling edge | read_pins_t isFallingEdge; //bitwise, 1 means falling edge | ||||
read_pins_t isRisingEdge; //bitwise, 1 means rising edge | read_pins_t isRisingEdge; //bitwise, 1 means rising edge |
virtual void keyWasPressed(); | virtual void keyWasPressed(); | ||||
protected: | protected: | ||||
read_pins_t debounced; //bitwise, 1 means pressed, 0 means released | read_pins_t debounced; //bitwise, 1 means pressed, 0 means released | ||||
void pressRelease(const uint8_t readPinCount, const read_pins_t debouncedChanged); | |||||
void send(const uint8_t readPinCount, const read_pins_t debouncedChanged); | |||||
public: | public: | ||||
Row(Key *const ptrsKeys[]) : ptrsKeys(ptrsKeys), debounced(0) { } | Row(Key *const ptrsKeys[]) : ptrsKeys(ptrsKeys), debounced(0) { } | ||||
virtual void process()=0; | virtual void process()=0; |
readState = scanner.scan(); | readState = scanner.scan(); | ||||
debouncedChanged = debouncer.debounce(readState, debounced); | debouncedChanged = debouncer.debounce(readState, debounced); | ||||
pressRelease(READ_PIN_COUNT, debouncedChanged); | |||||
send(READ_PIN_COUNT, debouncedChanged); | |||||
} | } | ||||
void Row_ShiftRegisters::begin() | void Row_ShiftRegisters::begin() |
#include <Row.h> | #include <Row.h> | ||||
#include <Scanner_ShiftRegs74HC165.h> | #include <Scanner_ShiftRegs74HC165.h> | ||||
#include <Debouncer_4Samples.h> | |||||
#include <Debouncer_Samples.h> | |||||
//#include <Debouncer_Not.h> | //#include <Debouncer_Not.h> | ||||
/* Row_DH_IOE is a row connected to an Input/Output Expander. | /* Row_DH_IOE is a row connected to an Input/Output Expander. | ||||
{ | { | ||||
private: | private: | ||||
Scanner_ShiftRegs74HC165 scanner; | Scanner_ShiftRegs74HC165 scanner; | ||||
Debouncer_4Samples debouncer; | |||||
Debouncer_Samples debouncer; | |||||
//Debouncer_Not debouncer; //passed test | //Debouncer_Not debouncer; //passed test | ||||
const uint8_t READ_PIN_COUNT; //number of read pins | const uint8_t READ_PIN_COUNT; //number of read pins | ||||
public: | public: |
readState = scanner.scan(); | readState = scanner.scan(); | ||||
debouncedChanged = debouncer.debounce(readState, debounced); | debouncedChanged = debouncer.debounce(readState, debounced); | ||||
pressRelease(READ_PIN_COUNT, debouncedChanged); | |||||
send(READ_PIN_COUNT, debouncedChanged); | |||||
} | } |
#include <Row.h> | #include <Row.h> | ||||
#include <Scanner_uC.h> | #include <Scanner_uC.h> | ||||
#include <Debouncer_4Samples.h> | |||||
#include <Debouncer_Samples.h> | |||||
/* Row_uC is a row connected to a micro controller. | /* Row_uC is a row connected to a micro controller. | ||||
{ | { | ||||
private: | private: | ||||
Scanner_uC scanner; | Scanner_uC scanner; | ||||
Debouncer_4Samples debouncer; | |||||
Debouncer_Samples debouncer; | |||||
const uint8_t READ_PIN_COUNT; //number of read pins | const uint8_t READ_PIN_COUNT; //number of read pins | ||||
public: | public: | ||||
Row_uC(const uint8_t strobePin, const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT, | Row_uC(const uint8_t strobePin, const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT, |