int yyyUSB_init(yContextSt *ctx,char *errmsg) { char str[256]; size_t size = sizeof(str); YPROPERR(yReserveGlobalAccess(ctx, errmsg)); if (sysctlbyname("kern.osrelease", str, &size, NULL, 0) ==0){ int numver; //15.x.x OS X 10.11.x El Capitan //14.x.x OS X 10.10.x Yosemite //13.x.x OS X 10.9.x Mavericks //12.x.x OS X 10.8.x Mountain Lion //11.x.x OS X 10.7.x Lion //10.x.x OS X 10.6.x Snow Leopard str[2]=0; numver = atoi(str); if (numver >= 13 && numver < 15){ ctx->osx_flags |= YCTX_OSX_MULTIPLES_HID; } } ctx->usb_thread_state = USB_THREAD_NOT_STARTED; pthread_create(&ctx->usb_thread, NULL, event_thread, ctx); while(ctx->usb_thread_state != USB_THREAD_RUNNING){ usleep(50000); } if (YISERR(setupHIDManager(ctx, &ctx->hid,errmsg))) { return YAPI_IO_ERROR; } return YAPI_SUCCESS; }
int yUSB_init(yContextSt *ctx,char *errmsg) { int c_vendorid = YOCTO_VENDORID; IOReturn tIOReturn; CFMutableDictionaryRef dictionary; CFNumberRef Vendorid; if(!yReserveGlobalAccess(ctx)){ return YERRMSG(YAPI_DOUBLE_ACCES,"Another process is already using yAPI"); } ctx->usb_thread_state = USB_THREAD_NOT_STARTED; pthread_create(&ctx->usb_thread, NULL, event_thread, ctx); yInitializeCriticalSection(&ctx->hidMCS); // Initialize HID Manager ctx->hidM = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); // create dictionary to match Yocto devices dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault,1,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks); Vendorid = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &c_vendorid ); CFDictionarySetValue( dictionary, CFSTR( kIOHIDVendorIDKey ), Vendorid ); // register the dictionary IOHIDManagerSetDeviceMatching( ctx->hidM, dictionary ); // now we can release the dictionary CFRelease(dictionary); IOHIDManagerRegisterDeviceRemovalCallback(ctx->hidM,hid_device_removal_callback,ctx); //register hid into read_thead's RunnLoop while(ctx->usb_thread_state != USB_THREAD_RUNNING){ usleep(50000); } IOHIDManagerScheduleWithRunLoop(ctx->hidM, ctx->usb_run_loop, kCFRunLoopDefaultMode); // Now open the IO HID Manager reference tIOReturn = IOHIDManagerOpen( ctx->hidM, kIOHIDOptionsTypeNone ); CFRelease(Vendorid); if(kIOReturnSuccess != tIOReturn ||CFGetTypeID(ctx->hidM) != IOHIDManagerGetTypeID()){ HALLOG("Unable to Open HID Manager"); return YERRMSG(YAPI_NOT_SUPPORTED,"Unable to Open HID Manager"); } return YAPI_SUCCESS; }
int yyyUSB_init(yContextSt *ctx,char *errmsg) { int res; if(!yReserveGlobalAccess(ctx)){ return YERRMSG(YAPI_DOUBLE_ACCES,"Another process is already using yAPI"); } memset(stringCache, 0, sizeof(stringCache)); yInitializeCriticalSection(&ctx->string_cache_cs); res = libusb_init(&ctx->libusb); if(res !=0){ return yLinSetErr("Unable to start lib USB", res,errmsg); } ctx->usb_thread_state = USB_THREAD_NOT_STARTED; pthread_create(&ctx->usb_thread, NULL, event_thread, ctx); //wait thead start while(ctx->usb_thread_state != USB_THREAD_RUNNING){ usleep(50000); } return YAPI_SUCCESS; }