-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmode.go
89 lines (78 loc) · 1.63 KB
/
mode.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package openrgb
import (
"encoding/binary"
"fmt"
)
// Mode is a controller's lighting mode (static, breathing, etc).
type Mode struct {
Name string
Value uint32
Flags uint32
MinSpeed uint32
MaxSpeed uint32
MinColors uint32
MaxColors uint32
Speed uint32
Direction uint32
ColorMode uint32
Colors []Color
}
func readMode(buf []byte, modeCount uint16, offset int) ([]Mode, int, error) {
modes := make([]Mode, 0)
colors := make([]Color, 0)
for modeIndex := uint16(0); modeIndex < modeCount; modeIndex++ {
modeName, i := readString(buf, offset)
offset += i
mode := Mode{Name: modeName}
for _, ptr := range []*uint32{
&mode.Value,
&mode.Flags,
&mode.MinSpeed,
&mode.MaxSpeed,
&mode.MinColors,
&mode.MaxColors,
&mode.Speed,
&mode.Direction,
&mode.ColorMode,
} {
*ptr = binary.LittleEndian.Uint32(buf[offset:])
offset += offset32LEBits
}
colorLength := binary.LittleEndian.Uint16(buf[offset:])
offset += offset16LEBits
var ci uint16 = 0
for ; ci < colorLength; ci++ {
color, err := readColor(buf, offset)
if err != nil {
return nil, 0, err
}
offset += offset32LEBits
colors = append(colors, color)
}
mode.Colors = colors
modes = append(modes, mode)
}
return modes, offset, nil
}
func (m Mode) String() string {
return fmt.Sprintf(`%s
Speed : %d (%d - %d)
ColorMode : %s
Colors: %v`,
m.Name,
m.Speed, m.MinSpeed, m.MaxSpeed,
colorMode(m.ColorMode),
m.Colors)
}
func colorMode(mode uint32) string {
switch mode {
case 1:
return "Per-LED"
case 2:
return "Mode-Specific"
case 3:
return "Random"
default:
return "Unidentified"
}
}