Fixed repeated press/release of a single key bug.
Caveat: The problem is still there. When the averaging kicks in, there is a window of time where keypresses won't register This fix only delays the window a *really* long time, so the likelihood of hitting the delay is very low. Each keypress resets the countdown.
This commit is contained in:
parent
1a5ae7fd68
commit
c3e1335678
@ -43,18 +43,8 @@
|
|||||||
|
|
||||||
#define ADHSM 7
|
#define ADHSM 7
|
||||||
|
|
||||||
#define RIGHT_JUSTIFY 0
|
// Right justification of ADLAR
|
||||||
#define LEFT_JUSTIFY (0xff)
|
|
||||||
|
|
||||||
// set left or right justification here:
|
|
||||||
#define JUSTIFY_ADC RIGHT_JUSTIFY
|
|
||||||
#define ADLAR_MASK (1 << ADLAR)
|
|
||||||
|
|
||||||
#ifdef JUSTIFY_ADC
|
|
||||||
#define ADLAR_BITS ((ADLAR_MASK) & (JUSTIFY_ADC))
|
|
||||||
#else // defaults to right justification.
|
|
||||||
#define ADLAR_BITS 0
|
#define ADLAR_BITS 0
|
||||||
#endif
|
|
||||||
|
|
||||||
// full muxmask
|
// full muxmask
|
||||||
#define FULL_MUX_MASK ((1 << MUX0) | (1 << MUX1) | (1 << MUX2) | (1 << MUX3) | (1 << MUX4))
|
#define FULL_MUX_MASK ((1 << MUX0) | (1 << MUX1) | (1 << MUX2) | (1 << MUX3) | (1 << MUX4))
|
||||||
@ -79,10 +69,17 @@
|
|||||||
// Number of consecutive samples required to pass debounce
|
// Number of consecutive samples required to pass debounce
|
||||||
#define DEBOUNCE_THRESHOLD 5
|
#define DEBOUNCE_THRESHOLD 5
|
||||||
|
|
||||||
|
// Scans to remain idle after all keys were release before starting averaging
|
||||||
|
// XXX So this makes the initial keypresses fast,
|
||||||
|
// but it's still possible to lose a keypress if you press at the wrong time -HaaTa
|
||||||
|
#define KEY_IDLE_SCANS 30000
|
||||||
|
|
||||||
|
// Total number of muxes/sense lines available
|
||||||
#define MUXES_COUNT 8
|
#define MUXES_COUNT 8
|
||||||
#define MUXES_COUNT_XSHIFT 3
|
#define MUXES_COUNT_XSHIFT 3
|
||||||
|
|
||||||
#define WARMUP_LOOPS ( 2048 )
|
// Number of warm-up loops before starting to scan keys
|
||||||
|
#define WARMUP_LOOPS ( 1024 )
|
||||||
#define WARMUP_STOP (WARMUP_LOOPS - 1)
|
#define WARMUP_STOP (WARMUP_LOOPS - 1)
|
||||||
|
|
||||||
#define SAMPLE_CONTROL 3
|
#define SAMPLE_CONTROL 3
|
||||||
@ -99,7 +96,6 @@
|
|||||||
// mix in 1/4 of the current average to the running average. -> (@mux_mix = 2)
|
// mix in 1/4 of the current average to the running average. -> (@mux_mix = 2)
|
||||||
#define MUX_MIX 2
|
#define MUX_MIX 2
|
||||||
|
|
||||||
#define IDLE_COUNT_MASK 0xff
|
|
||||||
#define IDLE_COUNT_SHIFT 8
|
#define IDLE_COUNT_SHIFT 8
|
||||||
|
|
||||||
// av = (av << shift) - av + sample; av >>= shift
|
// av = (av << shift) - av + sample; av >>= shift
|
||||||
@ -183,6 +179,7 @@ uint16_t samples[MAX_STROBES][MUXES_COUNT]; // Overall table of cap sense ADC
|
|||||||
uint16_t sampleMax[MAX_STROBES][MUXES_COUNT]; // Records the max seen ADC value
|
uint16_t sampleMax[MAX_STROBES][MUXES_COUNT]; // Records the max seen ADC value
|
||||||
|
|
||||||
uint8_t key_activity = 0; // Increments for each detected key per each full scan of the keyboard, it is reset before each full scan
|
uint8_t key_activity = 0; // Increments for each detected key per each full scan of the keyboard, it is reset before each full scan
|
||||||
|
uint16_t key_idle = 0; // Defines how scans after all keys were released before starting averaging again
|
||||||
uint8_t key_release = 0; // Indicates if going from key press state to release state (some keys pressed to no keys pressed)
|
uint8_t key_release = 0; // Indicates if going from key press state to release state (some keys pressed to no keys pressed)
|
||||||
|
|
||||||
uint16_t threshold = THRESHOLD;
|
uint16_t threshold = THRESHOLD;
|
||||||
@ -494,6 +491,9 @@ inline void capsense_scan()
|
|||||||
{
|
{
|
||||||
// No keypress, accumulate averages
|
// No keypress, accumulate averages
|
||||||
if( !key_activity )
|
if( !key_activity )
|
||||||
|
{
|
||||||
|
// Only start averaging once the idle counter has counted down to 0
|
||||||
|
if ( key_idle == 0 )
|
||||||
{
|
{
|
||||||
// Average Debugging
|
// Average Debugging
|
||||||
if ( enableAvgDebug )
|
if ( enableAvgDebug )
|
||||||
@ -531,6 +531,12 @@ inline void capsense_scan()
|
|||||||
// No key presses detected, set key_release indicator
|
// No key presses detected, set key_release indicator
|
||||||
key_release = 1;
|
key_release = 1;
|
||||||
}
|
}
|
||||||
|
// Otherwise decrement the idle counter
|
||||||
|
else
|
||||||
|
{
|
||||||
|
key_idle--;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Keypresses, reset accumulators
|
// Keypresses, reset accumulators
|
||||||
else if ( key_release )
|
else if ( key_release )
|
||||||
{
|
{
|
||||||
@ -779,6 +785,7 @@ void testColumn( uint8_t strobe )
|
|||||||
{
|
{
|
||||||
column |= bit;
|
column |= bit;
|
||||||
key_activity++; // No longer idle, stop averaging ADC data
|
key_activity++; // No longer idle, stop averaging ADC data
|
||||||
|
key_idle = KEY_IDLE_SCANS; // Reset idle count-down
|
||||||
|
|
||||||
// Only register keypresses once the warmup is complete, or not enough debounce info
|
// Only register keypresses once the warmup is complete, or not enough debounce info
|
||||||
if ( keys_debounce[key] <= DEBOUNCE_THRESHOLD )
|
if ( keys_debounce[key] <= DEBOUNCE_THRESHOLD )
|
||||||
|
Reference in New Issue
Block a user