Skip to content

Commit e3e352d

Browse files
committed
Added button read support to the device definitions
1 parent afda22f commit e3e352d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

comms.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type deviceType struct {
1818
resetPacket []byte
1919
numberOfButtons uint
2020
brightnessPacket []byte
21+
buttonReadOffset uint
2122
}
2223

2324
var deviceTypes []deviceType
@@ -30,6 +31,7 @@ func RegisterDevicetype(
3031
resetPacket []byte,
3132
numberOfButtons uint,
3233
brightnessPacket []byte,
34+
buttonReadOffset uint,
3335
) {
3436
d := deviceType{
3537
name: name,
@@ -38,6 +40,7 @@ func RegisterDevicetype(
3840
resetPacket: resetPacket,
3941
numberOfButtons: numberOfButtons,
4042
brightnessPacket: brightnessPacket,
43+
buttonReadOffset: buttonReadOffset,
4144
}
4245
deviceTypes = append(deviceTypes, d)
4346
}
@@ -136,18 +139,19 @@ func (d *Device) WriteImageToButton(btnIndex int, filename string) error {
136139
}
137140

138141
func (d *Device) buttonPressListener() {
139-
var buttonMask [32]bool
142+
var buttonMask []bool
143+
buttonMask = make([]bool, d.deviceType.numberOfButtons)
140144
for {
141-
data := make([]byte, 50)
145+
data := make([]byte, d.deviceType.numberOfButtons+d.deviceType.buttonReadOffset)
142146
_, err := d.fd.Read(data)
143147
if err != nil {
144148
d.sendButtonPressEvent(-1, err)
145149
break
146150
}
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 {
149153
if !buttonMask[i] {
150-
d.sendButtonPressEvent(i, nil)
154+
d.sendButtonPressEvent(int(i), nil)
151155
}
152156
buttonMask[i] = true
153157
} else {

devices/xl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ func init() {
1414
[]byte{'\x03', '\x02'}, // Reset packet
1515
32, // Number of buttons
1616
[]byte{'\x03', '\x08'}, // Set brightness packet preamble
17+
4, // Button read offset
1718
)
1819
}

0 commit comments

Comments
 (0)