/* * open disk (obtain disk drive control block) * open a device indicated by `devnm', and return the disk information in `dcb'. * devnm can specify a device name with partition number. * return the partition number specified by devnm. * return value 0 : entire disks * 1 - : partition number * < 0 : error */ EXPORT W openDisk( const UB *devnm, DISKCB **dcb_p ) { const CFGDISK *cfg; DISKCB *dcb; W pno; ER err; /* search for a device */ pno = searchDevice(devnm, &cfg); if ( pno < E_OK ) return pno; /* allocating a disk control block */ dcb = getDISKCB(cfg); /* initialize disk */ err = (*cfg->initdisk)(dcb, cfg); if ( err < E_OK ) return err; if ( dcb->blksz == 0 ) return E_NOMDA; if ( dcb->boot == 0xff ) { /* read the partition information */ err = readPart(dcb); if ( err < E_OK ) return err; } *dcb_p = dcb; return pno; }
int keyboard_read(int num, USB_KEYBOARD_DATA *data) { int adr; memset(data, 0, sizeof(USB_KEYBOARD_DATA)); if((adr = searchDevice(HID_KEYBOARD, num)) != -1){ if(hid_device_read(adr, data)) return 1; else return 0; }else{ return -1; } }
int sensorsDetect(void) { char *dirname =(char *) "/sys/class/input"; char buf[256]; char classPath[256]; int res; DIR *dir; struct dirent *de; int fd = -1; int ret = 0; memset(&buf,0,sizeof(buf)); statusInit(); dir = opendir(dirname); if (dir == NULL) return -1; while((de = readdir(dir))) { if (strncmp(de->d_name, "input", strlen("input")) != 0) { continue; } sprintf(classPath, "%s/%s", dirname, de->d_name); snprintf(buf, sizeof(buf), "%s/name", classPath); fd = open(buf, O_RDONLY); if (fd < 0) { continue; } if ((res = read(fd, buf, sizeof(buf))) < 0) { close(fd); continue; } buf[res - 1] = '\0'; #ifdef DEBUG_SENSOR ALOGD("buf:%s\n", buf); #endif ret = searchDevice(buf, classPath); close(fd); fd = -1; } closedir(dir); return 0; }
/////////////////////////////////////////////////////////////////////////////// // connect() - connect to AOA device /////////////////////////////////////////////////////////////////////////////// //argument // none //return // 0 : connection success // -1 : connection failed.(AOA device not found) // -2 : connection failed.(Accessory mode switch failed) // -3 : connection failed.(libusb_claim_interface failed) // int AOA::connect(int retry) { if(libusb_init(&ctx) < 0){ printf("libusb_init failed\n"); return 1; } unsigned char ioBuffer[2]; int protocol; int res; int tries = retry; uint16_t idVendor, idProduct; // Search for AOA support device in the all USB devices if ((protocol=searchDevice(ctx, &idVendor, &idProduct)) < 0) { printf("AOA device not found.\n"); return -1; } //already in accessory mode ? if( protocol == 0 ) { handle = libusb_open_device_with_vid_pid(ctx, idVendor, idProduct); libusb_claim_interface(handle, 0); return 0; } verProtocol = protocol; handle = libusb_open_device_with_vid_pid(ctx, idVendor, idProduct); libusb_claim_interface(handle, 0); usleep(1000);//sometimes hangs on the next transfer :( // Send accessory identifications sendString(ACCESSORY_STRING_MANUFACTURER, (char*)manufacturer); sendString(ACCESSORY_STRING_MODEL, (char*)model); sendString(ACCESSORY_STRING_DESCRIPTION, (char*)description); sendString(ACCESSORY_STRING_VERSION, (char*)version); sendString(ACCESSORY_STRING_URI, (char*)uri); sendString(ACCESSORY_STRING_SERIAL, (char*)serial); // Switch to accessory mode res = libusb_control_transfer(handle,0x40,ACCESSORY_START,0,0,NULL,0,0); if(res < 0){ libusb_close(handle); handle = NULL; return -2; } if(handle != NULL){ libusb_close(handle); handle = NULL; } // Wait a moment usleep(10000); printf("connect to new PID...\n"); //attempt to connect to new PID, if that doesn't work try ACCESSORY_PID_ALT for(;;){ tries--; if(searchDevice(ctx, &idVendor, &idProduct) != 0 ){ sleep(1); continue; } if((handle = libusb_open_device_with_vid_pid(ctx, idVendor, idProduct)) == NULL){ if(tries < 0){ return -1; } }else{ break; } sleep(1); } res = libusb_claim_interface(handle, 0); if(res < 0){ return -3; } printf("Established AOA connection.\n"); return 0; }
Function* Doc::createFunction(QList<QString> &list) { Function* f = NULL; DMXDevice* d = NULL; QString name; QString type; unsigned long device = 0; unsigned long id = ULONG_MAX; for (QString* s = list.next(); s != NULL; s = list.next()) { if (*s == QString("Entry")) { s = list.prev(); break; } else if (*s == QString("Name")) { name = *(list.next()); } else if (*s == QString("Type")) { type = *(list.next()); } else if (*s == QString("ID")) { id = list.next()->toInt(); } else if (*s == QString("Device")) { device = list.next()->toInt(); break; } else { // Unknown keyword (at this time) list.next(); } } if (id == ULONG_MAX) { f = NULL; } else { if (device == 0) { d = NULL; } else { d = searchDevice(device); if (d == NULL) { // This function's device was not found qDebug("Unable to find device %ld for function %s. Discarding function.", device, (const char*) name); return NULL; } } if (type == QString("Collection")) { f = (Function*) new FunctionCollection(); f->setName(name); f->setDevice(d); } else if (type == QString("Chaser")) { f = (Function*) new Chaser(); f->setName(name); f->setDevice(d); } else if (type == QString("Scene")) { f = (Function*) new Scene(id); f->setName(name); f->setDevice(d); } else if (type == QString("Sequence")) { f = NULL; } else { f = NULL; } } return f; }
void Doc::createFunctionContents(QList<QString> &list) { Function* function = NULL; DMXDevice* device = NULL; unsigned long deviceId = 0; unsigned long functionId = ULONG_MAX; QString name; for (QString* s = list.next(); s != NULL; s = list.next()) { if (*s == QString("Entry")) { s = list.prev(); break; } else if (*s == QString("Name")) { name = *(list.next()); } else if (*s == QString("Type")) { list.next(); } else if (*s == QString("ID")) { functionId = list.next()->toULong(); } else if (*s == QString("Device")) { deviceId = list.next()->toInt(); if (deviceId == 0) { device = NULL; } else { device = searchDevice(deviceId); } break; } else { // Unknown keyword (at this time) list.next(); } } if (functionId == ULONG_MAX) { qDebug("Couldn't find an ID for function <" + name + ">"); } else { function = searchFunction(functionId); if (function != NULL) { function->setDevice(device); function->createContents(list); } else { qDebug("Couldn't find function <" + name + ">"); } } }
Function* Doc::createFunction(QList<QString> &list) { Function* f = NULL; DMXDevice* d = NULL; QString name; QString type; QString device; for (QString* s = list.next(); s != NULL; s = list.next()) { if (*s == QString("Entry")) { s = list.prev(); break; } else if (*s == QString("Name")) { name = *(list.next()); } else if (*s == QString("Type")) { type = *(list.next()); } else if (*s == QString("Device")) { device = *(list.next()); break; } else { // Unknown keyword (at this time) list.next(); } } if (name != QString::null && type != QString::null) { if (device == QString("Global")) { d = NULL; } else { d = searchDevice(device); if (d == NULL) { // This function's device was not found qDebug("Unable to find device %s for function %s. Discarding function.", (const char*) device, (const char*) name); return NULL; } } if (type == QString("Collection")) { f = (Function*) new FunctionCollection(); f->setName(name); f->setDevice(d); } else if (type == QString("Chaser")) { f = (Function*) new Chaser(); f->setName(name); f->setDevice(d); } else if (type == QString("Scene")) { f = (Function*) new Scene(); f->setName(name); f->setDevice(d); } else if (type == QString("Sequence")) { f = NULL; } else { f = NULL; } } else { f = NULL; } return f; }
void Doc::createFunctionContents(QList<QString> &list) { Function* f = NULL; DMXDevice* d = NULL; QString name; QString type; QString device; for (QString* s = list.next(); s != NULL; s = list.next()) { if (*s == QString("Entry")) { s = list.prev(); break; } else if (*s == QString("Name")) { name = *(list.next()); } else if (*s == QString("Type")) { type = *(list.next()); } else if (*s == QString("Device")) { device = *(list.next()); if (device == QString("Global")) { d = NULL; } else { d = searchDevice(device); } break; } else { // Unknown keyword (at this time) list.next(); } } if (name != QString::null && type != QString::null) { if (d != NULL) { f = d->searchFunction(name); } else { f = searchFunction(name); } if (f != NULL) { f->setDevice(d); f->createContents(list); } else { qDebug("Invalid or missing information for function <%s>", (const char*) name); } } else { qDebug("Invalid or missing information for function <%s>", (const char*) name); } }