-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
50 lines (41 loc) · 869 Bytes
/
command.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
package blink
import "time"
const reportID = 0x01
type command interface {
bytes() []byte
}
type setRGBCommand struct {
Color // 24-bit RGB color
}
func (c *setRGBCommand) bytes() []byte {
return []byte{reportID,
'n',
c.R, c.G, c.B,
0, 0, 0,
}
}
type fadeRGBCommand struct {
Color // 24-bit RGB color
duration time.Duration // how long the fade should last
n byte // which LED to address: 0=all, 1=led#1, 2=led#2, etc. (mk2 only)
}
func (c *fadeRGBCommand) bytes() []byte {
t := c.duration.Nanoseconds() / 1E7
return []byte{reportID,
'c',
c.R, c.G, c.B,
byte(t >> 8), byte(t & 0xff),
c.n,
}
}
type readRGBCommand struct {
n byte // which LED to address: 0=all, 1=led#1, 2=led#2, etc. (mk2 only)
}
func (c *readRGBCommand) bytes() []byte {
return []byte{reportID,
'r',
0, 0, 0,
0, 0,
c.n,
}
}