func NewContext() *Context { c := &Context{ done: make(chan struct{}), } if errno := C.libusb_init(&c.ctx); errno != 0 { panic(usbError(errno)) } go func() { for { select { case <-c.done: return default: } if errno := C.libusb_handle_events(c.ctx); errno < 0 { log.Printf("handle_events: error: %s", usbError(errno)) continue } log.Printf("handle_events returned") } }() return c }
func NewContext() *Context { c := &Context{ done: make(chan struct{}), } if errno := C.libusb_init(&c.ctx); errno != 0 { panic(usbError(errno)) } go func() { tv := C.struct_timeval{ tv_sec: 0, tv_usec: 100000, } for { select { case <-c.done: return default: } if errno := C.libusb_handle_events_timeout_completed(c.ctx, &tv, nil); errno < 0 { log.Printf("handle_events: error: %s", usbError(errno)) continue } //log.Printf("handle_events returned") } }() return c }
func init() { _, err := decodeUsbError(C.libusb_init(nil)) if err != nil { panic(err) } DefaultContext = &Context{initialized: true} }
func InitLib() bool { v := C.libusb_init(nil) if v != 0 { return false } return true }
// Automatically called when necessary func (ctx *Context) doinit() *UsbError { if !ctx.initialized { _, err := decodeUsbError(C.libusb_init(&ctx.ctx)) if err == nil { ctx.initialized = true } return err } return nil }
func main() { runtime.LockOSThread() rand.Seed(int64(time.Now().UnixNano())) C.libusb_init(nil) StartLibUsb() clr := color.RGBA{0xff, 0, 0, 0} SetColor(clr) EndLibUsb() go StartClock() signals := make(chan os.Signal) signal.Notify(signals) <-signals C.libusb_exit(nil) }
func Start(color chan byte, output chan guinput.KeyEvent) *C.struct_libusb_device_handle { C.libusb_init(nil) fmt.Println(KEYMAP[0x21]) key_device_handle := C.libusb_open_device_with_vid_pid(nil, 0x046d, 0xc22d) //detach any necessary kernel drivers from MY keyboard if C.libusb_kernel_driver_active(key_device_handle, 0) == 1 { log.Print("kernel driver active on main interface") e := C.libusb_detach_kernel_driver(key_device_handle, 0) if e != 0 { log.Fatal("Can't detach kernel driver") } } if C.libusb_kernel_driver_active(key_device_handle, 1) == 1 { fmt.Println("kernel driver active") e := C.libusb_detach_kernel_driver(key_device_handle, 1) if e != 0 { log.Fatal("Can't detach kernel driver") } } //Claim the interfaces we'll be listening on r := C.libusb_claim_interface(key_device_handle, 0) if r != 0 { log.Fatal("Can't claim main interface") } r = C.libusb_claim_interface(key_device_handle, 1) if r != 0 { log.Fatal("Can't claim special interface") } log.Print("Starting libusb goroutines\n") go ColorChange(key_device_handle, color) //go LCDChange(key_device_handle, lcd) go NormalKeyMonitor(key_device_handle, output) go SpecialKeyMonitor(key_device_handle, output) log.Print("Libusb Goroutines started\n") return key_device_handle }
func NewContext() *Context { var r *C.struct_libusb_context C.libusb_init(&r) return (*Context)(r) }
func init() { if err := C.libusb_init(&context); err != C.LIBUSB_SUCCESS { panic(&libusbError{err}) } }
func init() { C.libusb_init(nil) }