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

View File

@ -16,6 +16,7 @@ Layout
// ################## GLOBAL ###################
// ================= INCLUDES ==================
#include <Debug.h>
#include <ScanDelay.h>
//Codes
#include <Code_Sc.h>
@ -26,7 +27,7 @@ Layout
#include <Row_ShiftRegisters.h>
// =============== 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 uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;
@ -163,6 +164,8 @@ void loop()
row_R0.process();
row_R1.process();
scanDelay.delay();
//delay(100);
//Keyboard.println("");
//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_t debouncedChanged; //1 means debounced changed
rowDelay.delay();
rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged);

View File

@ -2,7 +2,6 @@
#define ROWIOE_H
#include <RowBase.h>
#include <RowDelay.h>
#include <RowScanner_PinsBitwise.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
{
private:
RowDelay rowDelay;
RowScanner_PinsBitwise scanner;
Debouncer_4Samples debouncer;
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_t debouncedChanged; //1 means debounced changed
rowDelay.delay();
rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged);

View File

@ -2,7 +2,6 @@
#define ROW_SHIFTREGISTERS_H
#include <RowBase.h>
#include <RowDelay.h>
#include <RowScanner_SPIShiftRegisters.h>
#include <Debouncer_4Samples.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
{
private:
RowDelay rowDelay;
RowScanner_SPIShiftRegisters scanner;
Debouncer_4Samples debouncer;
//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_t debouncedChanged; //1 means debounced changed
rowDelay.delay();
rowState = scanner.scan(rowEnd);
debouncedChanged = debouncer.debounce(rowState, debounced);
pressRelease(rowEnd, debouncedChanged);

View File

@ -2,7 +2,6 @@
#define ROW_H
#include <RowBase.h>
#include <RowDelay.h>
#include <RowScanner_PinsArray.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
{
private:
RowDelay rowDelay;
RowScanner_PinsArray scanner;
Debouncer_4Samples debouncer;
public:

View File

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

View File

@ -1,18 +1,16 @@
#ifndef ROWDELAY_H
#define ROWDELAY_H
#ifndef SCANDELAY_H
#define SCANDELAY_H
#include <Arduino.h>
#include <inttypes.h>
/* RowDelay() 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).
/* ScanDelay() delay's scan to give switches time to debounce.
DELAY_MICROSECONDS explained
----------------------------
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:
Initialize DELAY_MICROSECONDS in your sketch:
const unsigned int RowDelay::DELAY_MICROSECONDS = 1000;
Intantiate DELAY_MICROSECONDS in your sketch:
ScanDelay scanDelay(1000);
Add this to the sketch's loop() function:
debug.print_microseconds_per_scan();
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
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
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:
const unsigned int RowDelay::DELAY_MICROSECONDS = 0;
DELAY_MICROSECONDS is static so multiple row types can share it.
For example, primary and secondary matrices would share the same DELAY_MICROSECONDS.
Could put delay directly in loop(), but then it's harder to finding this documentation.
delay(5);
*/
class RowDelay
class ScanDelay
{
private:
static const unsigned int DELAY_MICROSECONDS; //delay between each Row scan for debouncing
public:
const unsigned int DELAY_MICROSECONDS; //delay each loop() for debouncing
public:
ScanDelay(const unsigned int DELAY_MICROSECONDS): DELAY_MICROSECONDS(DELAY_MICROSECONDS) {}
void delay();
};
#endif