From 9c9bc8d9492ec1ab34c0da86c3f418bc67494d0c Mon Sep 17 00:00:00 2001 From: wolfv6 Date: Sat, 2 Jul 2016 15:10:02 -0600 Subject: [PATCH] moved Debouncer_Not to Keybrd lib --- .../keybrd_shift_register.ino | 4 ++-- src/Debouncer_Not.cpp | 15 +++++++++++++ src/Debouncer_Not.h | 21 +++++++++++++++++++ src/RowScanner_PinsArray.h | 8 +++---- src/RowScanner_SPIShiftRegisters.cpp | 1 - src/RowScanner_SPIShiftRegisters.h | 6 ++++++ src/Row_ShiftRegisters.h | 4 ++-- 7 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/Debouncer_Not.cpp create mode 100644 src/Debouncer_Not.h diff --git a/examples/keybrd_shift_register/keybrd_shift_register.ino b/examples/keybrd_shift_register/keybrd_shift_register.ino index 04b44ba..5faa3d7 100644 --- a/examples/keybrd_shift_register/keybrd_shift_register.ino +++ b/examples/keybrd_shift_register/keybrd_shift_register.ino @@ -104,7 +104,7 @@ const uint8_t KEY_R0_COUNT = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0); Row_ShiftRegisters row_R0(8, ptrsKeys_R0, KEY_R0_COUNT); */ -//prints 0 1 2 3 4 5 6 7 8, microseconds_per_scan=87 +//prints 0 1 2 3 4 5 6 7 8, microseconds_per_scan=87 with SAMPLE_COUNT 4 Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z, &s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z, &s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z, @@ -163,5 +163,5 @@ void loop() //delay(100); //Keyboard.println(""); -debug.print_microseconds_per_scan(); +//debug.print_microseconds_per_scan(); } diff --git a/src/Debouncer_Not.cpp b/src/Debouncer_Not.cpp new file mode 100644 index 0000000..4138226 --- /dev/null +++ b/src/Debouncer_Not.cpp @@ -0,0 +1,15 @@ +#include "Debouncer_Not.h" + +/* debounce() sets debounced and returns debouncedChanged. All variables are bitwise. +For parameters, 1 means pressed, 0 means released. +For return, 1 means debounced changed. +*/ +read_pins_t Debouncer_Not::debounce(const read_pins_t rawSignal, read_pins_t& debounced) +{ + read_pins_t previousDebounced; //bitwise, 1 means pressed, 0 means released + + previousDebounced = debounced; + debounced = rawSignal; + return debounced xor previousDebounced; +} + diff --git a/src/Debouncer_Not.h b/src/Debouncer_Not.h new file mode 100644 index 0000000..c8e9a0c --- /dev/null +++ b/src/Debouncer_Not.h @@ -0,0 +1,21 @@ +#ifndef DEBOUNCER_NOT_H +#define DEBOUNCER_NOT_H +#include +#include +#include +#include + +/* Debouncer_Not does not debounce. +debounce() returns raw signal, no debouncing is performed. + +A keyboard does not need a debouncing if one of the following is true: + * keypad has hardware debouncers + * poling I2C makes scan rate slower than debounce time + * optic switches are used (because they don't bounce) +*/ +class Debouncer_Not : public DebouncerInterface +{ + public: + virtual read_pins_t debounce(const read_pins_t rawSignal, read_pins_t& debounced); +}; +#endif diff --git a/src/RowScanner_PinsArray.h b/src/RowScanner_PinsArray.h index 3f66048..a54f539 100644 --- a/src/RowScanner_PinsArray.h +++ b/src/RowScanner_PinsArray.h @@ -14,10 +14,10 @@ Constructor is in RowScanner_PinsArray.cpp class RowScanner_PinsArray : public RowScannerInterface { private: - static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh - const uint8_t STROBE_PIN; //Arduino pin number connected to this row - const uint8_t* const READ_PINS; //array of read pin numbers - const uint8_t READ_PIN_COUNT; //number of read pins + static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh + const uint8_t STROBE_PIN; //Arduino pin number connected to this row + const uint8_t* const READ_PINS; //array of read pin numbers + const uint8_t READ_PIN_COUNT; //number of read pins public: RowScanner_PinsArray(const uint8_t STROBE_PIN, const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT); diff --git a/src/RowScanner_SPIShiftRegisters.cpp b/src/RowScanner_SPIShiftRegisters.cpp index 00a6d6a..669cc53 100644 --- a/src/RowScanner_SPIShiftRegisters.cpp +++ b/src/RowScanner_SPIShiftRegisters.cpp @@ -35,7 +35,6 @@ read_pins_t RowScanner_SPIShiftRegisters::scan(read_pins_mask_t& rowEnd) digitalWrite(STROBE_PIN, LOW); rowEnd = ROW_END; - //rowEnd = 1 << 8; //clear unpowered pins (for testing bb) todo rowState &= 0b01010001000100010001000100010001; //also 31st key diff --git a/src/RowScanner_SPIShiftRegisters.h b/src/RowScanner_SPIShiftRegisters.h index a9e1054..fc031d3 100644 --- a/src/RowScanner_SPIShiftRegisters.h +++ b/src/RowScanner_SPIShiftRegisters.h @@ -21,6 +21,12 @@ The shift registers are active high: 10k pull-down resistors are grounded connect controller's MISO pin to shift register's QH pin +The shift register needs 5 wires. +In addition, each row needs to be connected to a strobe pin from controller. +The two parts of a split keyboard can be connected by one of: + * eSATA cable (has 7 wires, good for 2 rows) + * Ethernet cable (has 8 wires, good for 3 rows) + */ class RowScanner_SPIShiftRegisters : public RowScannerInterface { diff --git a/src/Row_ShiftRegisters.h b/src/Row_ShiftRegisters.h index 5166845..e2bf572 100644 --- a/src/Row_ShiftRegisters.h +++ b/src/Row_ShiftRegisters.h @@ -4,7 +4,7 @@ #include #include #include -//todo #include +//#include /* Row_DH_IOE is a row connected to an Input/Output Expander. @@ -29,7 +29,7 @@ class Row_ShiftRegisters : public RowBase private: RowScanner_SPIShiftRegisters scanner; Debouncer_4Samples debouncer; - //Debouncer_Not debouncer; //todo test + //Debouncer_Not debouncer; //tested public: Row_ShiftRegisters(const uint8_t STROBE_PIN, Key *const ptrsKeys[], uint8_t KEY_COUNT) : RowBase(ptrsKeys), scanner(STROBE_PIN, KEY_COUNT) { }