From ce763a9957a5ec899720bceedc77ec4c6f1e444c Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Wed, 19 Sep 2018 20:48:06 -0600 Subject: [PATCH] Initial commit --- README.md | 11 +++++++++ main.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 main.go diff --git a/README.md b/README.md index e69de29..c53080b 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,11 @@ +## Bose Companion 5 - Fix Sound + +I got really fed up with the sound constantly cutting out on the Bose Companion 5, and so made this. Bose should really fix the issue, as all this does is perform a reset of the device whenever it happens. + +To use install Go and then run: + +```shell +go build +chmod +x bose-usbfix +./bose-usbfix +``` \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..6b26a23 --- /dev/null +++ b/main.go @@ -0,0 +1,69 @@ +package main + +//The below C code is compiled and executed using CGo. + +//#include +//#include +//#include +//#include +//#include +// +//#include +// +// +//int resetUSB(char *filearg) +//{ +// const char *filename; +// int fd; +// int rc; +// +// filename = filearg; +// +// fd = open(filename, O_WRONLY); +// if (fd < 0) { +// perror("Error opening output file"); +// return 1; +// } +// +// printf("Resetting USB device %s\n", filename); +// rc = ioctl(fd, USBDEVFS_RESET, 0); +// if (rc < 0) { +// perror("Error in ioctl"); +// return 1; +// } +// printf("Reset successful\n"); +// +// close(fd); +// return 0; +//} +import "C" +import ( + "bufio" + "bytes" + "fmt" + "log" + "os" + "os/exec" + "strings" +) + +func main() { + lsusbCmd := exec.Command("lsusb") + lsusbOut, err := lsusbCmd.Output() + if err != nil { + log.Fatalf("could not get output of lsusb: %v", err) + } + + scanner := bufio.NewScanner(bytes.NewReader(lsusbOut)) + for scanner.Scan() { + if strings.Contains(scanner.Text(), "Bose Corp.") { + busID := "002" + devID := "005" + usbFilename := C.CString(fmt.Sprintf("/dev/bus/usb/%s/%s", busID, devID)) + C.resetUSB(usbFilename) + } + } + if err := scanner.Err(); err != nil { + fmt.Fprintln(os.Stderr, "reading standard input:", err) + } +}