Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions blink1.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package led
import (
"github.com/boombuler/hid"
"image/color"
)
// Device type: blink(1)
var Blink1 DeviceType
func init() {
Blink1 = addDriver(usbDriver{
Name: "blink(1)",
Type: &Blink1,
VendorId: 0x27B8,
ProductId: 0x01ED,
Open: func(d hid.Device) (Device, error) {
return &simpleHidDevice{
device: d,
setColorFn: blink1SetColor,
}, nil
},
})
}
func blink1SetColor(d hid.Device, c color.Color) error {
r, g, b, _ := c.RGBA()
return d.WriteFeature([]byte{0x01, 0x63, byte(r >> 8), byte(g >> 8), byte(b >> 8), 0x00, 0x00, 0x00, 0x00})
}
package led

import (
"github.com/boombuler/hid"
"image/color"
)

// Device type: blink(1)
var Blink1 DeviceType

func init() {
Blink1 = addDriver(usbDriver{
Name: "blink(1)",
Type: &Blink1,
VendorId: 0x27B8,
ProductId: 0x01ED,
Open: func(d hid.Device) (Device, error) {
return &simpleHidDevice{
device: d,
setColorFn: blink1SetColor,
}, nil
},
})
}

func blink1SetColor(d hid.Device, c color.Color) error {
r, g, b, _ := c.RGBA()
return d.WriteFeature([]byte{0x01, 0x63, byte(r >> 8), byte(g >> 8), byte(b >> 8), 0x00, 0x00, 0x00, 0x00})
}
58 changes: 29 additions & 29 deletions blinkm.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package led
import (
"github.com/boombuler/hid"
"image/color"
)
// Device type: LinkM / BlinkM
var BlinkM DeviceType
func init() {
BlinkM = addDriver(usbDriver{
Name: "LinkM / BlinkM",
Type: &BlinkM,
VendorId: 0x20A0,
ProductId: 0x4110,
Open: func(d hid.Device) (Device, error) {
return &simpleHidDevice{
device: d,
setColorFn: blinkMSetColor,
}, nil
},
})
}
func blinkMSetColor(d hid.Device, c color.Color) error {
r, g, b, _ := c.RGBA()
return d.WriteFeature([]byte{0x01, 0xDA, 0x01, 0x05, 0x00, 0x09, 0x6E, byte(r >> 8), byte(g >> 8), byte(b >> 8)})
}
package led

import (
"github.com/boombuler/hid"
"image/color"
)

// Device type: LinkM / BlinkM
var BlinkM DeviceType

func init() {
BlinkM = addDriver(usbDriver{
Name: "LinkM / BlinkM",
Type: &BlinkM,
VendorId: 0x20A0,
ProductId: 0x4110,
Open: func(d hid.Device) (Device, error) {
return &simpleHidDevice{
device: d,
setColorFn: blinkMSetColor,
}, nil
},
})
}

func blinkMSetColor(d hid.Device, c color.Color) error {
r, g, b, _ := c.RGBA()
return d.WriteFeature([]byte{0x01, 0xDA, 0x01, 0x05, 0x00, 0x09, 0x6E, byte(r >> 8), byte(g >> 8), byte(b >> 8)})
}
58 changes: 29 additions & 29 deletions blinkstick.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package led
import (
"github.com/boombuler/hid"
"image/color"
)
// Device type: BlinkStick
var BlinkStick DeviceType
func init() {
BlinkStick = addDriver(usbDriver{
Name: "BlinkStick",
Type: &BlinkStick,
VendorId: 0x20a0,
ProductId: 0x41e5,
Open: func(d hid.Device) (Device, error) {
return &simpleHidDevice{
device: d,
setColorFn: blinkStickSetColor,
}, nil
},
})
}
func blinkStickSetColor(d hid.Device, c color.Color) error {
r, g, b, _ := c.RGBA()
return d.WriteFeature([]byte{0x01, byte(r >> 8), byte(g >> 8), byte(b >> 8)})
}
package led

import (
"github.com/boombuler/hid"
"image/color"
)

// Device type: BlinkStick
var BlinkStick DeviceType

func init() {
BlinkStick = addDriver(usbDriver{
Name: "BlinkStick",
Type: &BlinkStick,
VendorId: 0x20a0,
ProductId: 0x41e5,
Open: func(d hid.Device) (Device, error) {
return &simpleHidDevice{
device: d,
setColorFn: blinkStickSetColor,
}, nil
},
})
}

func blinkStickSetColor(d hid.Device, c color.Color) error {
r, g, b, _ := c.RGBA()
return d.WriteFeature([]byte{0x01, byte(r >> 8), byte(g >> 8), byte(b >> 8)})
}
108 changes: 54 additions & 54 deletions blync.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,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})
}
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})
}
Loading