-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.go
79 lines (66 loc) · 1.54 KB
/
cli.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
package main
import (
"fmt"
"image/color"
devicemanager "nzxt-driver-dev/device"
"os"
"strconv"
)
func main() {
args := os.Args[1:]
if len(args) < 4 {
fmt.Println("Usage: nzxt-led <int|all> <int> <int> <int>")
return
}
commandOrTarget := args[0]
colors := args[1:]
r, err := strconv.Atoi(colors[0])
if err != nil && colors[0] != "all" {
fmt.Println("Invalid argument:", colors[0])
return
}
g, err := strconv.Atoi(colors[1])
if err != nil {
fmt.Println("Invalid argument:", colors[1])
return
}
b, err := strconv.Atoi(colors[2])
if err != nil {
fmt.Println("Invalid argument:", colors[2])
return
}
var isCommandNumber = false
if commandOrTarget != "all" {
_, err := strconv.Atoi(commandOrTarget)
if err == nil {
isCommandNumber = true
}
}
var cmdStr string
if commandOrTarget == "all" {
cmdStr = fmt.Sprintf("Setting color of all LEDs to (%d,%d,%d)", r, g, b)
set(-1, r, g, b)
} else if isCommandNumber {
device, err := strconv.Atoi(commandOrTarget)
if err != nil {
fmt.Println("Invalid argument:", commandOrTarget)
return
}
cmdStr = fmt.Sprintf("Setting color of LED %d to (%d,%d,%d)", device, r, g, b)
set(device, r, g, b)
}
// send the command to the NZXT device here...
fmt.Println(cmdStr)
}
func set(id int, r int, g int, b int) {
devicemanager.GetManagedDriver(0x2011, func(hub devicemanager.RgbFanHub) {
var c = color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: 255}
if id == -1 {
for i := 0; i < 6; i++ {
hub.SetColor(i+1, c)
}
} else {
hub.SetColor(id, c)
}
})
}