mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-25 08:59:00 +00:00
makeybutton: use smaller buffer for faster response
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
committed by
Daniel Esteban
parent
d0163c67f5
commit
1f54c7dd23
@@ -1,6 +1,6 @@
|
|||||||
package makeybutton
|
package makeybutton
|
||||||
|
|
||||||
const bufferSize = 10
|
const bufferSize = 6
|
||||||
|
|
||||||
// Buffer is a buffer to keep track of the most recent readings for a button.
|
// Buffer is a buffer to keep track of the most recent readings for a button.
|
||||||
type Buffer struct {
|
type Buffer struct {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func (b *Button) Get() ButtonEvent {
|
|||||||
b.readings.Put(pressed)
|
b.readings.Put(pressed)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case pressed && avg > 0:
|
case pressed && avg > -1 * bufferSize - 2:
|
||||||
if b.state == Press {
|
if b.state == Press {
|
||||||
return NotChanged
|
return NotChanged
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user