Skip to content

Commit 5c5c402

Browse files
authored
Merge pull request #60 from dontsovcmc/debounce_safe
Debounce safe buttons support by KeyStream
2 parents 46e93c1 + f369f83 commit 5c5c402

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/keyStream.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ struct keyMap {
1919
int8_t code;
2020
};
2121

22+
23+
#ifndef BOUNCE_TICK
24+
#define BOUNCE_TICK 30
25+
#endif
26+
2227
//if you hold/repeat a key for this ammount of time we will consider it an escape
2328
#ifndef ESCAPE_TIME
2429
#define ESCAPE_TIME 1500
@@ -38,8 +43,17 @@ class keyLook:public Stream {
3843
if (lastkey==-1) {
3944
lastkey=ch;
4045
pressMills=millis();
41-
} else if (ESCAPE_TIME&&millis()-pressMills>ESCAPE_TIME) return 1;
46+
}
47+
else if (ch == -1 && millis()-pressMills < BOUNCE_TICK)
48+
{
49+
lastkey = -1; //released = it's bounce. reset lastkey
50+
return 0;
51+
}
52+
else if (ch != -1 && millis()-pressMills > BOUNCE_TICK) return 1;
53+
else if (ESCAPE_TIME&&millis()-pressMills>ESCAPE_TIME) return 1;
54+
4255
if (ch==lastkey) return 0;
56+
4357
return 1;
4458
/*int cnt=0;
4559
for(int n=0;n<N;n++) {

0 commit comments

Comments
 (0)