Пример #1
0
Файл: usb.go Проект: pjvds/gousb
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
}
Пример #2
0
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
}
Пример #3
0
func init() {
	_, err := decodeUsbError(C.libusb_init(nil))
	if err != nil {
		panic(err)
	}
	DefaultContext = &Context{initialized: true}
}
Пример #4
0
func InitLib() bool {
	v := C.libusb_init(nil)
	if v != 0 {
		return false
	} 

	return true
}
Пример #5
0
// 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
}
Пример #6
0
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)
}
Пример #7
0
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
}
Пример #8
0
Файл: usb.go Проект: hanwen/usb
func NewContext() *Context {
	var r *C.struct_libusb_context
	C.libusb_init(&r)
	return (*Context)(r)
}
Пример #9
0
func init() {
	if err := C.libusb_init(&context); err != C.LIBUSB_SUCCESS {
		panic(&libusbError{err})
	}
}
Пример #10
0
func init() {
	C.libusb_init(nil)
}