hink / go-blink1

Thingm Blink(1) interface library for Go
20 stars 9 forks source link

panic: Unable to write to blink(1) #9

Open 6UzoTE opened 1 year ago

6UzoTE commented 1 year ago

On Ubuntu Ubuntu 22.04.1 LTS (x86_64) I get the err "panic: Unable to write to blink(1)". Building the tool worked fine. Blink works well with blink1-tool

Any idea were I could investigate ?

todbot commented 1 year ago

Are you using sudo for blink1-tool or do you have the udev rules installed?

6UzoTE commented 1 year ago

Very fast reply. Thank you. udev rules are installed as per instructions: https://github.com/todbot/blink1-tool

todbot commented 1 year ago

Hmm, well I tried the simple example on the README on my Ubuntu 22 x86 box and while it doesn't panic, it also doesn't seem to actually do anything. Unfortunately, I don't know much about Go, so I can't really help.

This library does seem to be using the much older libusb-0.1 API instead of the current libusb-1.0 API. Also in general on Linux, it's better to use the hidraw API instead of libusb.

It looks like there is a (Go wrapper on hidapi](https://pkg.go.dev/github.com/karalabe/hid), which would be the preferred way of interfacing with blink(1), or any HID device.

As a work-around, I recommend creating a function that abstracts away your blink(1) calls and for now uses the blink1-tool command-line program like:

package main
import "fmt"
import "os/exec"

func main() {
    stdout,err := exec.Command("blink1-tool", "--rgb", "FF00FF").Output()
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    fmt.Print(string(stdout))
}
6UzoTE commented 1 year ago

Thank you. Compiled the program. Ran it. blink turns purple. Output: set dev:0:0 to rgb:0xff,0x00,0xff over 300 msec Use go-blink test program and still err "panic: Unable to write to blink(1)"

6UzoTE commented 1 year ago

As a work-around, I recommend creating a function that abstracts away your blink(1) calls and for now uses the blink1-tool command-line program like:

This is how I do it today. I wanted to get rid of using ugly exec calls.