Exemplo n.º 1
0
// This function inititalize the freenect library, selects the motor and camera subdevices and begins the event processing loop.
// Event processing occurs in a go routine that will be terminated upon a call to Shutdown()
func Initialize() (*Freenect, int) {
	if _freenect != nil {
		return nil, -999
	}

	var ctx *C.freenect_context
	rc := int(C.freenect_init(&ctx, nil))

	if rc != 0 {
		return nil, rc
	}

	C.freenect_select_subdevices(ctx, (C.freenect_device_flags)(C.FREENECT_DEVICE_MOTOR|C.FREENECT_DEVICE_CAMERA))

	d := int(C.freenect_num_devices(ctx))
	_freenect = &Freenect{ctx, nil, make([]Device, d)}

	for x := 0; x < d; x++ {
		_freenect.Devices[x].index = x
		_freenect.Devices[x].freenect = _freenect
	}

	go func() {
		var to C.struct_timeval
		to.tv_sec = 0
		to.tv_usec = 0
		rc := C.int(0)
		for _freenect != nil && rc >= 0 {
			rc = C.freenect_process_events_timeout(_freenect.ctx, &to)
		}
	}()

	return _freenect, 0
}
Exemplo n.º 2
0
//FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx);
func Init(usbContext *UsbContext) (context *Context, status int) {
	ctx := (**C.freenect_context)(unsafe.Pointer(&context))
	status = int(C.freenect_init(ctx, unsafe.Pointer(usbContext)))
	return
}