@@ -14,10 +14,9 @@ type DuplexMatrixKeyboard struct {
1414 Col []machine.Pin
1515 Row []machine.Pin
1616 cycleCounter []uint8
17+ debounce uint8
1718}
1819
19- const duplexMatrixCyclesToPreventChattering = uint8 (4 )
20-
2120func (d * Device ) AddDuplexMatrixKeyboard (colPins , rowPins []machine.Pin , keys [][]Keycode ) * DuplexMatrixKeyboard {
2221 col := len (colPins )
2322 row := len (rowPins )
@@ -49,6 +48,7 @@ func (d *Device) AddDuplexMatrixKeyboard(colPins, rowPins []machine.Pin, keys []
4948 State : state ,
5049 Keys : keydef ,
5150 callback : func (layer , index int , state State ) {},
51+ debounce : 8 ,
5252 }
5353
5454 d .kb = append (d .kb , k )
@@ -75,7 +75,7 @@ func (d *DuplexMatrixKeyboard) Get() []State {
7575 switch d .State [idx ] {
7676 case None :
7777 if current {
78- if d .cycleCounter [idx ] >= duplexMatrixCyclesToPreventChattering {
78+ if d .cycleCounter [idx ] >= d . debounce {
7979 d .State [idx ] = NoneToPress
8080 d .cycleCounter [idx ] = 0
8181 } else {
@@ -90,7 +90,7 @@ func (d *DuplexMatrixKeyboard) Get() []State {
9090 if current {
9191 d .cycleCounter [idx ] = 0
9292 } else {
93- if d .cycleCounter [idx ] >= duplexMatrixCyclesToPreventChattering {
93+ if d .cycleCounter [idx ] >= d . debounce {
9494 d .State [idx ] = PressToRelease
9595 d .cycleCounter [idx ] = 0
9696 } else {
@@ -114,7 +114,7 @@ func (d *DuplexMatrixKeyboard) Get() []State {
114114 switch d .State [idx ] {
115115 case None :
116116 if current {
117- if d .cycleCounter [idx ] >= duplexMatrixCyclesToPreventChattering {
117+ if d .cycleCounter [idx ] >= d . debounce {
118118 d .State [idx ] = NoneToPress
119119 d .cycleCounter [idx ] = 0
120120 } else {
@@ -129,7 +129,7 @@ func (d *DuplexMatrixKeyboard) Get() []State {
129129 if current {
130130 d .cycleCounter [idx ] = 0
131131 } else {
132- if d .cycleCounter [idx ] >= duplexMatrixCyclesToPreventChattering {
132+ if d .cycleCounter [idx ] >= d . debounce {
133133 d .State [idx ] = PressToRelease
134134 d .cycleCounter [idx ] = 0
135135 } else {
0 commit comments