-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathblync.go
54 lines (47 loc) · 1.32 KB
/
blync.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
package led
import (
"github.com/boombuler/hid"
"image/color"
)
// Device type: Blync
var Blync DeviceType
func init() {
Blync = addDriver(blyncDriver{
usbDriver{
Name: "Blync",
Type: &Blync,
VendorId: 0x1130,
ProductId: 0x0001,
Open: func(d hid.Device) (Device, error) {
return &simpleHidDevice{
device: d,
setColorFn: blyncDevSetColor,
}, nil
},
},
})
}
type blyncDriver struct {
usbDriver
}
func (drv blyncDriver) convert(hDev *hid.DeviceInfo) DeviceInfo {
// blync adds two devices. but only the one which accepts feature reports will work.
if hDev.FeatureReportLength == 0 {
return drv.usbDriver.convert(hDev)
}
return nil
}
func blyncDevSetColor(d hid.Device, c color.Color) error {
palette := color.Palette{
color.RGBA{0x00, 0x00, 0x00, 0x00}, // black
color.RGBA{0xff, 0xff, 0xff, 0xff}, // white
color.RGBA{0x00, 0xff, 0xff, 0xff}, // cyan
color.RGBA{0xff, 0x00, 0xff, 0xff}, // magenta
color.RGBA{0x00, 0x00, 0xff, 0xff}, // blue
color.RGBA{0xff, 0xff, 0x00, 0xff}, // yellow
color.RGBA{0x00, 0xff, 0x00, 0xff}, // lime
color.RGBA{0xff, 0x00, 0x00, 0xff}, // red
}
value := byte((palette.Index(c) * 16) + 127)
return d.Write([]byte{0x00, 0x55, 0x53, 0x42, 0x43, 0x00, 0x40, 0x02, value})
}