Archived
1
0

delete RowDelay, replace with scanDelay in loop()

This commit is contained in:
wolfv6 2016-07-05 15:45:58 -06:00
parent 4b1eeaaf73
commit 2431659b2b
10 changed files with 24 additions and 29 deletions

View File

@ -94,6 +94,7 @@ Keybrd library class inheritance diagram
| |
Debouncer_4Samples Debouncer_4Samples
ScanDelay
LayerStateInterface LayerStateInterface
| |
@ -244,7 +245,6 @@ Refer to it like a table of contents while reading the keybrd library.
``` ```
loop() for each row loop() for each row
RowBase::process() RowBase::process()
RowBase::wait() delay time for debounce
RowScanner_PinsArray::scan() strobe row on RowScanner_PinsArray::scan() strobe row on
for each readPin for each readPin
set rowState bit set rowState bit
@ -257,6 +257,8 @@ Refer to it like a table of contents while reading the keybrd library.
if rising edge if rising edge
Key_*::press() scanCode->press() Key_*::press() scanCode->press()
Code_*::press() Keyboard.press(scancode) Code_*::press() Keyboard.press(scancode)
scanDelay.delay();
``` ```
## The Arduino libraries ## The Arduino libraries

View File

@ -16,6 +16,7 @@ Layout
// ################## GLOBAL ################### // ################## GLOBAL ###################
// ================= INCLUDES ================== // ================= INCLUDES ==================
#include <Debug.h> #include <Debug.h>
#include <ScanDelay.h>
//Codes //Codes
#include <Code_Sc.h> #include <Code_Sc.h>
@ -26,7 +27,7 @@ Layout
#include <Row_ShiftRegisters.h> #include <Row_ShiftRegisters.h>
// =============== CONFIGURATION =============== // =============== CONFIGURATION ===============
const unsigned int RowDelay::DELAY_MICROSECONDS = 0; //500 ScanDelay scanDelay(9000);
const bool RowScanner_PinsArray::ACTIVE_HIGH = 0; //left matrix is active low const bool RowScanner_PinsArray::ACTIVE_HIGH = 0; //left matrix is active low
const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10; const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;
@ -163,6 +164,8 @@ void loop()
row_R0.process(); row_R0.process();
row_R1.process(); row_R1.process();
scanDelay.delay();
//delay(100); //delay(100);
//Keyboard.println(""); //Keyboard.println("");
//debug.print_microseconds_per_scan(); //debug.print_microseconds_per_scan();

View File

@ -7,7 +7,6 @@ void Row_IOE::process()
read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row
read_pins_t debouncedChanged; //1 means debounced changed read_pins_t debouncedChanged; //1 means debounced changed
rowDelay.delay();
rowState = scanner.scan(rowEnd); rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced); debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged); pressRelease(rowEnd, debouncedChanged);

View File

@ -2,7 +2,6 @@
#define ROWIOE_H #define ROWIOE_H
#include <RowBase.h> #include <RowBase.h>
#include <RowDelay.h>
#include <RowScanner_PinsBitwise.h> #include <RowScanner_PinsBitwise.h>
#include <Debouncer_4Samples.h> #include <Debouncer_4Samples.h>
@ -35,7 +34,6 @@ Number of pins in colPort0 should equal number of keys in ptrsKeys_0[] array.
class Row_IOE : public RowBase class Row_IOE : public RowBase
{ {
private: private:
RowDelay rowDelay;
RowScanner_PinsBitwise scanner; RowScanner_PinsBitwise scanner;
Debouncer_4Samples debouncer; Debouncer_4Samples debouncer;
public: public:

View File

@ -7,7 +7,6 @@ void Row_ShiftRegisters::process()
read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row
read_pins_t debouncedChanged; //1 means debounced changed read_pins_t debouncedChanged; //1 means debounced changed
rowDelay.delay();
rowState = scanner.scan(rowEnd); rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced); debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged); pressRelease(rowEnd, debouncedChanged);

View File

@ -2,7 +2,6 @@
#define ROW_SHIFTREGISTERS_H #define ROW_SHIFTREGISTERS_H
#include <RowBase.h> #include <RowBase.h>
#include <RowDelay.h>
#include <RowScanner_SPIShiftRegisters.h> #include <RowScanner_SPIShiftRegisters.h>
#include <Debouncer_4Samples.h> #include <Debouncer_4Samples.h>
//#include <Debouncer_Not.h> //#include <Debouncer_Not.h>
@ -28,7 +27,6 @@ Number of pins in colPort0 should equal number of keys in ptrsKeys_0[] array.
class Row_ShiftRegisters : public RowBase class Row_ShiftRegisters : public RowBase
{ {
private: private:
RowDelay rowDelay;
RowScanner_SPIShiftRegisters scanner; RowScanner_SPIShiftRegisters scanner;
Debouncer_4Samples debouncer; Debouncer_4Samples debouncer;
//Debouncer_Not debouncer; //passed test //Debouncer_Not debouncer; //passed test

View File

@ -10,7 +10,6 @@ void Row_uC::process()
read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row
read_pins_t debouncedChanged; //1 means debounced changed read_pins_t debouncedChanged; //1 means debounced changed
rowDelay.delay();
rowState = scanner.scan(rowEnd); rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced); debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged); pressRelease(rowEnd, debouncedChanged);

View File

@ -2,7 +2,6 @@
#define ROW_H #define ROW_H
#include <RowBase.h> #include <RowBase.h>
#include <RowDelay.h>
#include <RowScanner_PinsArray.h> #include <RowScanner_PinsArray.h>
#include <Debouncer_4Samples.h> #include <Debouncer_4Samples.h>
@ -30,7 +29,6 @@ Number of colPins should equal number of keys in ptrsKeys_0[] array.
class Row_uC : public RowBase class Row_uC : public RowBase
{ {
private: private:
RowDelay rowDelay;
RowScanner_PinsArray scanner; RowScanner_PinsArray scanner;
Debouncer_4Samples debouncer; Debouncer_4Samples debouncer;
public: public:

View File

@ -1,6 +1,6 @@
#include "RowDelay.h" #include "ScanDelay.h"
void RowDelay::delay() void ScanDelay::delay()
{ {
delayMicroseconds(DELAY_MICROSECONDS); delayMicroseconds(DELAY_MICROSECONDS);
} }

View File

@ -1,18 +1,16 @@
#ifndef ROWDELAY_H #ifndef SCANDELAY_H
#define ROWDELAY_H #define SCANDELAY_H
#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h> #include <inttypes.h>
/* RowDelay() delay's scan to give switches time to debounce. /* ScanDelay() delay's scan to give switches time to debounce.
For fastest response time, RowDelay() should be placed before scan() or after pressRelease()
(RowDelay() between scan and send would unnecessarily delay send).
DELAY_MICROSECONDS explained DELAY_MICROSECONDS explained
---------------------------- ----------------------------
A keyboard with a faster scan rate responds faster. A keyboard with a faster scan rate responds faster.
Follow these step to tune DELAY_MICROSECONDS for maximum scan rate for a given SAMPLE_COUNT: Follow these step to tune DELAY_MICROSECONDS for maximum scan rate for a given SAMPLE_COUNT:
Initialize DELAY_MICROSECONDS in your sketch: Intantiate DELAY_MICROSECONDS in your sketch:
const unsigned int RowDelay::DELAY_MICROSECONDS = 1000; ScanDelay scanDelay(1000);
Add this to the sketch's loop() function: Add this to the sketch's loop() function:
debug.print_microseconds_per_scan(); debug.print_microseconds_per_scan();
Compile and load the sketch into the microcontroller; microseconds_per_scan is printed every second. Compile and load the sketch into the microcontroller; microseconds_per_scan is printed every second.
@ -24,22 +22,23 @@ Cherry MX specifies 5msec bounce time http://www.cherrycorp.com/english/switches
hasu measured Cherry MX bounce times .3ms to 1.4ms http://geekhack.org/index.php?topic=42385.0 hasu measured Cherry MX bounce times .3ms to 1.4ms http://geekhack.org/index.php?topic=42385.0
Tactile switch MJTP series bounce 10 ms http://www.apem.com/files/apem/brochures/MJTP_6MM.pdf Tactile switch MJTP series bounce 10 ms http://www.apem.com/files/apem/brochures/MJTP_6MM.pdf
The largest allowable DELAY_MICROSECONDS is 65535 (65.535 ms).
Avoid sampling the switch input at a rate synchronous to events in the environment Avoid sampling the switch input at a rate synchronous to events in the environment
that might create periodic EMI. For instance, 50 and 60 Hz. that might create periodic EMI. For instance, 50 and 60 Hz.
The largest allowable DELAY_MICROSECONDS is 65535 (.065535 seconds). Polling I2C may slow the scan rate enough so that no additional delay is needed
and scanDelay(0) can be omitted from the loop().
Polling I2C may slow the scan rate enough so that no additional delay is needed: Could put delay directly in loop(), but then it's harder to finding this documentation.
const unsigned int RowDelay::DELAY_MICROSECONDS = 0; delay(5);
DELAY_MICROSECONDS is static so multiple row types can share it.
For example, primary and secondary matrices would share the same DELAY_MICROSECONDS.
*/ */
class RowDelay class ScanDelay
{ {
private: private:
static const unsigned int DELAY_MICROSECONDS; //delay between each Row scan for debouncing const unsigned int DELAY_MICROSECONDS; //delay each loop() for debouncing
public: public:
ScanDelay(const unsigned int DELAY_MICROSECONDS): DELAY_MICROSECONDS(DELAY_MICROSECONDS) {}
void delay(); void delay();
}; };
#endif #endif