@@ -18,6 +18,7 @@ type deviceType struct {
18
18
resetPacket []byte
19
19
numberOfButtons uint
20
20
brightnessPacket []byte
21
+ buttonReadOffset uint
21
22
}
22
23
23
24
var deviceTypes []deviceType
@@ -30,6 +31,7 @@ func RegisterDevicetype(
30
31
resetPacket []byte ,
31
32
numberOfButtons uint ,
32
33
brightnessPacket []byte ,
34
+ buttonReadOffset uint ,
33
35
) {
34
36
d := deviceType {
35
37
name : name ,
@@ -38,6 +40,7 @@ func RegisterDevicetype(
38
40
resetPacket : resetPacket ,
39
41
numberOfButtons : numberOfButtons ,
40
42
brightnessPacket : brightnessPacket ,
43
+ buttonReadOffset : buttonReadOffset ,
41
44
}
42
45
deviceTypes = append (deviceTypes , d )
43
46
}
@@ -136,18 +139,19 @@ func (d *Device) WriteImageToButton(btnIndex int, filename string) error {
136
139
}
137
140
138
141
func (d * Device ) buttonPressListener () {
139
- var buttonMask [32 ]bool
142
+ var buttonMask []bool
143
+ buttonMask = make ([]bool , d .deviceType .numberOfButtons )
140
144
for {
141
- data := make ([]byte , 50 )
145
+ data := make ([]byte , d . deviceType . numberOfButtons + d . deviceType . buttonReadOffset )
142
146
_ , err := d .fd .Read (data )
143
147
if err != nil {
144
148
d .sendButtonPressEvent (- 1 , err )
145
149
break
146
150
}
147
- for i := 0 ; i < 32 ; i ++ {
148
- if data [4 + i ] == 1 {
151
+ for i := uint ( 0 ) ; i < d . deviceType . numberOfButtons ; i ++ {
152
+ if data [d . deviceType . buttonReadOffset + i ] == 1 {
149
153
if ! buttonMask [i ] {
150
- d .sendButtonPressEvent (i , nil )
154
+ d .sendButtonPressEvent (int ( i ) , nil )
151
155
}
152
156
buttonMask [i ] = true
153
157
} else {
0 commit comments