-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzone.go
47 lines (38 loc) · 881 Bytes
/
zone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package openrgb
import (
"encoding/binary"
"fmt"
)
// Zone represents a controller's color zone.
type Zone struct {
Name string
Type uint32
MinLEDs uint32
MaxLEDs uint32
TotalLEDs uint32
}
func readZones(buf []byte, count uint16, offset int) ([]Zone, int) {
zones := make([]Zone, 0)
for zoneIndex := uint16(0); zoneIndex < count; zoneIndex++ {
var z Zone
s, i := readString(buf, offset)
z.Name = s
offset += i
for _, ptr := range []*uint32{
&z.Type,
&z.MinLEDs,
&z.MaxLEDs,
&z.TotalLEDs,
} {
*ptr = binary.LittleEndian.Uint32(buf[offset:])
offset += offset32LEBits
}
matrixSize := binary.LittleEndian.Uint16(buf[offset:])
offset += 2 + int(matrixSize)
zones = append(zones, z)
}
return zones, offset
}
func (z Zone) String() string {
return fmt.Sprintf(`%s (typ %d; LEDs %d)`, z.Name, z.Type, z.TotalLEDs)
}