Initial commit

This commit is contained in:
Steven Polley 2018-09-19 20:48:06 -06:00
parent 1c002a3672
commit ce763a9957
2 changed files with 80 additions and 0 deletions

View File

@ -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
```

69
main.go Normal file
View File

@ -0,0 +1,69 @@
package main
//The below C code is compiled and executed using CGo.
//#include <stdio.h>
//#include <unistd.h>
//#include <fcntl.h>
//#include <errno.h>
//#include <sys/ioctl.h>
//
//#include <linux/usbdevice_fs.h>
//
//
//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)
}
}