Beispiel #1
0
REALTOUCH_DECLSPEC int realtouch_open(struct realtouch* s, unsigned int device_index)
{
	int count = 0;
	struct hid_device_info* devices_new;
	struct hid_device_info* device_cur;
	if (!s->_is_inited)
	{
		return E_REALTOUCH_NOT_INITED;
	}
	devices_new = hid_enumerate(REALTOUCH_VID, REALTOUCH_PID);


	device_cur = devices_new;
	while(device_cur) {
		if(count == device_index) {
			s->_dev = hid_open_path(device_cur->path);
			break;
		}
		++count;
		device_cur = device_cur->next;
	}

	hid_free_enumeration(devices_new);
	if(!s->_dev) {
		return E_REALTOUCH_NOT_OPENED;
	}
	s->_is_open = 1;
	return 0;
}
Beispiel #2
0
hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, wchar_t *serial_number)
{
	struct hid_device_info *devs, *cur_dev;
	const char *path_to_open = NULL;
	hid_device *handle = NULL;
	
	devs = hid_enumerate(vendor_id, product_id);
	cur_dev = devs;
	while (cur_dev) {
		if (cur_dev->vendor_id == vendor_id &&
		    cur_dev->product_id == product_id) {
			if (serial_number) {
				if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
					path_to_open = cur_dev->path;
					break;
				}
			}
			else {
				path_to_open = cur_dev->path;
				break;
			}
		}
		cur_dev = cur_dev->next;
	}

	if (path_to_open) {
		/* Open the device */
		handle = hid_open_path(path_to_open);
	}

	hid_free_enumeration(devs);
	
	return handle;
}
	void open(unsigned int port)
	{
		const std::string devicePath = getDevicePath(port);

		if (devicePath.empty())
		{
			throw IOException(Poco::format("Failed to open usb port (index: %u).\n"
			                                       "USB Interface not exist or already opened", port));
		}

		handle_ = hid_open_path(devicePath.c_str());
		if (!handle_)
		{
			throw IOException(Poco::format("Failed to open usb port (index: %u).\n"
			                                       "USB Interface not exist or already opened", port));
		}

		port_ = port;

		const UsbDeviceInfo& deviceInfo = getDeviceInfo(port);
		vendorId_ = deviceInfo.getVendorId();
		productId_ = deviceInfo.getProductId();
		manufacturer_ = deviceInfo.getManufacturer();
		product_ = deviceInfo.getProduct();
		serialNumber_ = deviceInfo.getSerialNumber();
	}
Beispiel #4
0
hid_device * HID_API_EXPORT hid_open(uint16_t vendor_id, uint16_t product_id)
{
    /* This function is identical to the Linux version. Platform independent. */
    struct hid_device_info *devs, *cur_dev;
    const char *path_to_open = NULL;
    hid_device * handle = NULL;

    devs = hid_enumerate(vendor_id, product_id);
    cur_dev = devs;
    while (cur_dev)
    {
        if (cur_dev->vendor_id == vendor_id &&
                cur_dev->product_id == product_id)
        {
            path_to_open = cur_dev->path;
            break;
        }
        cur_dev = cur_dev->next;
    }

    if (path_to_open)
    {
        /* Open the device */
        handle = hid_open_path(path_to_open);
    }

    hid_free_enumeration(devs);

    return handle;
}
Beispiel #5
0
/**********************************************************
 * Function set_relay_hidapi()
 * 
 * Description: Set new relay state
 * 
 * Parameters: portname (in)     - communication port
 *             relay (in)        - relay number
 *             relay_state (in)  - current relay state
 *             serial (in)       - serial number [not used]
 *
 * Return:   o - success
 *          -1 - fail
 *********************************************************/
int set_relay_hidapi(char* portname, uint8_t relay, relay_state_t relay_state, char* serial)
{ 
   hid_device *hid_dev;
   unsigned char buf[REPORT_LEN];  

   if (relay<FIRST_RELAY || relay>(FIRST_RELAY+g_num_relays-1))
   {  
      fprintf(stderr, "ERROR: Relay number out of range\n");
      return -1;      
   }

   /* Open HID API device */
   if ((hid_dev = hid_open_path(portname)) == NULL)
   {
      fprintf(stderr, "unable to open HID API device %s\n", portname);
      return -2;
   }

   /* Write relay state by sending an output report to the device */
   memset(buf, 0, sizeof(buf));
   buf[REPORT_WRCMD_OFFSET] = (relay_state==ON) ? CMD_ON : CMD_OFF;
   buf[REPORT_WRREL_OFFSET] = relay;
   //printf("DBG: Write relay data %02X %02X\n", buf[REPORT_WRCMD_OFFSET], buf[REPORT_WRREL_OFFSET]);
   if (hid_write(hid_dev, buf, sizeof(buf)) < 0)
   {
      fprintf(stderr, "unable to write output report to device %s (%ls)\n", portname, hid_error(hid_dev));
      return -3;
   }
   
   hid_close(hid_dev);
   return 0;
}
Beispiel #6
0
void vmarker::condisHandler(){
    if(this->connected){
        //CHECK IF DISCONNECTED
        unsigned char *data;
        if(hid_read_timeout(this->vmarkerdev,data,0,200)<0){
            this->connected = false;
            qDebug("Vmarker Disconnected");
            emit(Disconnect());
            hid_close(this->vmarkerdev);
        }
    }else{
        //SEARCH FOR VMARKER
        struct hid_device_info *devs,*cur_dev;
        int i = 0;
        for(i = 0; i<numPIDlist;i++){
            devs = hid_enumerate(VID,PIDlist[i]);
            cur_dev = devs;
            while(cur_dev){
                qDebug(cur_dev->path);
                if(cur_dev->interface_number == MIlist[i]){
                    this->vmarkerdev = hid_open_path(cur_dev->path);
                    if(this->vmarkerdev){
                        this->productID = PIDlist[i];
                        this->connected = true;
                        qDebug("Vmarker Connected");
                        emit (Connected());
                    }
                }
                cur_dev = cur_dev->next;
            }
            hid_free_enumeration(devs);
        }
    }
}
Beispiel #7
0
/**********************************************************
 * Function get_relay_hidapi()
 * 
 * Description: Get the current relay state
 * 
 * Parameters: portname (in)     - communication port
 *             relay (in)        - relay number
 *             relay_state (out) - current relay state
 *             serial (in)       - serial number [not used]
 *
 * Return:   0 - success
 *          -1 - fail
 *********************************************************/
int get_relay_hidapi(char* portname, uint8_t relay, relay_state_t* relay_state, char* serial)
{
   hid_device *hid_dev;
   unsigned char buf[REPORT_LEN];  

   if (relay<FIRST_RELAY || relay>(FIRST_RELAY+g_num_relays-1))
   {  
      fprintf(stderr, "ERROR: Relay number out of range\n");
      return -1;      
   }

   /* Open HID API device */
   if ((hid_dev = hid_open_path(portname)) == NULL)
   {
      fprintf(stderr, "unable to open HID API device %s\n", portname);
      return -2;
   }

   /* Read relay states requesting a feature report with Id 0x01 */
   buf[0] = 0x01;
   if (hid_get_feature_report(hid_dev, buf, sizeof(buf)) != REPORT_LEN)
   {
      fprintf(stderr, "unable to read feature report from device %s (%ls)\n", portname, hid_error(hid_dev));
      return -3;
   }
   //printf("DBG: Relay ID: %s\n", buf);
   //printf("DBG: Read relay bits %02X\n", buf[REPORT_RDDAT_OFFSET]);
   relay = relay-1;
   *relay_state = (buf[REPORT_RDDAT_OFFSET] & (0x01<<relay)) ? ON : OFF;
   
   hid_close(hid_dev);
   return 0;
}
/* 
    PsychHIDGetDeviceRecordPtrFromIndex()
    
    The inverse of PsychHIDGetIndexFromRecord()
    
    Accept the index from the list of device records and return a pointer to the indicated record.  Externally the list is one-indexed.  
*/
pRecDevice PsychHIDGetDeviceRecordPtrFromIndex(int deviceIndex)
{
    int				i;
    pRecDevice 		currentDevice=NULL;

    PsychHIDVerifyInit();
    i=1;
    for(currentDevice=HIDGetFirstDevice(); currentDevice != NULL; currentDevice=HIDGetNextDevice(currentDevice)){    
        if(i==deviceIndex) {
            #if PSYCH_SYSTEM != PSYCH_OSX
                if (!currentDevice->interface) {
                    currentDevice->interface = (void*) hid_open_path(currentDevice->transport);
                    if (!currentDevice->interface) PsychErrorExitMsg(PsychError_system, "HIDLIB Failed to open USB device!");

                    // Set read ops on device to non-blocking:
                    hid_set_nonblocking((hid_device*) currentDevice->interface, 1);
                }
            #endif
            return(currentDevice);
        }
        ++i;
    }
    
    PsychErrorExitMsg(PsychError_user, "Invalid device index specified. Has a device been unplugged? Try rebuilding the device list");
    return(NULL);  //make the compiler happy.
}
Beispiel #9
0
int check_target_device(unsigned int vid, unsigned int pid)
{

	assert((0xffff0000 & vid) == 0);
	assert((0xffff0000 & pid) == 0);

	dev = hid_enumerate((unsigned short)vid, (unsigned short)pid);
	if (dev) {

		target = hid_open_path(dev->path);
		DBG_INFO("%s", dev->path);
		if (target == NULL) {
			perror("Error");
			return -1;
		}

		printf("Device Info -\n");
		printf("\tManufacturer: %ls\n", dev->manufacturer_string);
		printf("\tProduct: %ls\n", dev->product_string);
		printf("\tVendor ID: %x, Product ID: %x\n", dev->vendor_id, dev->product_id);
		printf("\tSerial Number: %ls\n", dev->serial_number);

		return 0;
	}

	return -1;
}
Beispiel #10
0
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
	/* TODO: Merge this functions with the Linux version. This function should be platform independent. */
	struct hid_device_info *devs, *cur_dev;
	const char *path_to_open = NULL;
	hid_device *handle = NULL;
	
	devs = hid_enumerate(vendor_id, product_id);
	cur_dev = devs;
	while (cur_dev) {
		if (cur_dev->vendor_id == vendor_id &&
		    cur_dev->product_id == product_id) {
			if (serial_number) {
				if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
					path_to_open = cur_dev->path;
					break;
				}
			}
			else {
				path_to_open = cur_dev->path;
				break;
			}
		}
		cur_dev = cur_dev->next;
	}

	if (path_to_open) {
		/* Open the device */
		handle = hid_open_path(path_to_open);
	}

	hid_free_enumeration(devs);
	
	return handle;
}
Beispiel #11
0
JNIEXPORT jobject JNICALL Java_com_codeminders_hidapi_HIDDeviceInfo_open
  (JNIEnv *env, jobject obj)
{
    jclass thiscls = env->FindClass(DEVINFO_CLASS);
    if (!thiscls)
        return NULL;
    
    jfieldID path_field_id = env->GetFieldID(thiscls, "path", "Ljava/lang/String;");
    jstring jpathstr = (jstring) env->GetObjectField(obj, path_field_id);

    const char *jpathbytes = env->GetStringUTFChars(jpathstr, NULL);
    if(!jpathbytes)
        return NULL;
    
    hid_device *dev = hid_open_path(jpathbytes);
    env->ReleaseStringUTFChars(jpathstr, jpathbytes); 
    if(!dev)
        return NULL;
    
    jlong peer = (jlong)dev;
    // Construct and return object
    jclass cls = env->FindClass(DEV_CLASS);
    if (cls == NULL) {
        return NULL; /* exception thrown */
    }

    jmethodID cid = env->GetMethodID(cls,
                                        "<init>", "(J)V");
    if (cid == NULL) {
        return NULL; /* exception thrown */
    }
    return env->NewObject(cls, cid, peer);
}
void HidDevice::open()
{
    devHandle = hid_open_path(devPath.c_str());
    if(!devHandle)
    {
        throw HidDeviceError("Failed to open device");
    }
}
Beispiel #13
0
int HidController::open() {
    if (isOpen()) {
        qDebug() << "HID device" << getName() << "already open";
        return -1;
    }

    // Open device by path
    if (debugging()) {
        qDebug() << "Opening HID device"
                 << getName() << "by HID path" << hid_path;
    }
    m_pHidDevice = hid_open_path(hid_path);

    // If that fails, try to open device with vendor/product/serial #
    if (m_pHidDevice == NULL) {
        if (debugging())
            qDebug() << "Failed. Trying to open with make, model & serial no:"
                << hid_vendor_id << hid_product_id << hid_serial;
        m_pHidDevice = hid_open(hid_vendor_id, hid_product_id, hid_serial_raw);
    }

    // If it does fail, try without serial number WARNING: This will only open
    // one of multiple identical devices
    if (m_pHidDevice == NULL) {
        qWarning() << "Unable to open specific HID device" << getName()
                   << "Trying now with just make and model."
                   << "(This may only open the first of multiple identical devices.)";
        m_pHidDevice = hid_open(hid_vendor_id, hid_product_id, NULL);
    }

    // If that fails, we give up!
    if (m_pHidDevice == NULL) {
        qWarning()  << "Unable to open HID device" << getName();
        return -1;
    }

    setOpen(true);
    startEngine();

    if (m_pReader != NULL) {
        qWarning() << "HidReader already present for" << getName();
    } else {
        m_pReader = new HidReader(m_pHidDevice);
        m_pReader->setObjectName(QString("HidReader %1").arg(getName()));

        connect(m_pReader, SIGNAL(incomingData(QByteArray)),
                this, SLOT(receive(QByteArray)));

        // Controller input needs to be prioritized since it can affect the
        // audio directly, like when scratching
        m_pReader->start(QThread::HighPriority);
    }

    return 0;
}
Beispiel #14
0
bool WiimoteHidapi::ConnectInternal()
{
  if (m_handle != nullptr)
    return true;

  m_handle = hid_open_path(m_device_path.c_str());
  if (m_handle == nullptr)
  {
    ERROR_LOG(WIIMOTE, "Could not connect to Wii Remote at \"%s\". "
                       "Do you have permission to access the device?",
              m_device_path.c_str());
  }
  return m_handle != nullptr;
}
Beispiel #15
0
bool UsbHid::open(QString devicePath)
{
	close();

	bool res = false;
	hid_device *h;

    if ((h = hid_open_path(devicePath.toLatin1().data())) != 0)
	{
		hidDevice = h;
		res = true;
	}

	return res;
}
Beispiel #16
0
int touchmouse_open(touchmouse_device **dev, touchmouse_device_info *dev_info)
{
	touchmouse_device* t_dev = (touchmouse_device*)malloc(sizeof(touchmouse_device));
	memset(t_dev, 0, sizeof(touchmouse_device));
	char* path = ((struct hid_device_info**)dev_info->opaque)[0]->path;
	t_dev->dev = hid_open_path(path);
	if (!t_dev->dev) {
		TM_ERROR("hid_open() failed for device with path %s\n", path);
		free(t_dev);
		return -1;
	}
	hid_set_nonblocking(t_dev->dev, 1); // Enable nonblocking reads
	*dev = t_dev;
	return 0;
}
Beispiel #17
0
void __fastcall TForm1::deviceConnect(TObject *Sender)
{
	/* Метод поиска и подключения необходимого HID-устройства */

	// Структура для поиска HID-устройств
	struct hid_device_info *devs, *cur_dev;

	// Установка отметки "Searching"
	Button3->ImageIndex = 0;
	// Вывод статуса
	Label2->Text = "Поиск устройства...";

	// Запуск поиска HID-устройства
	devs = hid_enumerate(VID, PID);

	// Помещение найденных устройств с указанными VID и PID в динамический массив
	cur_dev = devs;

	/* Поиск устройства по строке описания продукта 'Product Name' */
	while (cur_dev) {
		if ((cur_dev->product_string) == productString)
			break;
		cur_dev = cur_dev->next;
	}

	/* Если устройство найдено и успешно открыто... */
	if (cur_dev && (handle_device = hid_open_path(cur_dev->path)))
	{
		// Остановка таймера, который вызывает данный метод
		Timer1->Enabled = false;
		// Установка отметки "Connected"
		Button3->ImageIndex = 1;
		// Вывод статуса
		Label2->Text = "Устройство подключено";
	}
	else
	{
		// Установка отметки "Disconnected"
		Button3->ImageIndex = 0;
		//Button3->ImageIndex = 2;
		// Вывод статуса
		Label2->Text = "Поиск устройства...";
		//Label2->Text = "Устройство не найдено";
	}

	// Удаление списка
	hid_free_enumeration(devs);
}
Beispiel #18
0
void HIDDMXDevice::init()
{
    /* Device name */
    m_handle = hid_open_path(path().toUtf8().constData());
    
    if (!m_handle)
    {
        QMessageBox::warning(NULL, (tr("HID DMX Interface Error")),
            (tr("Unable to open %1. Make sure the udev rule is installed.").arg(name())),
             QMessageBox::AcceptRole, QMessageBox::AcceptRole);
    }

    /** Reset channels when opening the interface: */
    m_dmx_cmp.fill(0, 512);
    m_dmx_in_cmp.fill(0, 512);
    outputDMX(m_dmx_cmp, true);
}
Beispiel #19
0
int relay_get_state(const char * path) {
	hid_device *dev;
	unsigned char buf[RELAY_COMMAND_SIZE];

	if((dev = hid_open_path(path)) == NULL) {
		return -1;
	}
	buf[0] = 0x01; // get first page
	if(hid_get_feature_report(dev, buf, sizeof(buf)) == -1) {
		return -1;
	}
	/*
	printf("buffer -> %d %d %d %d %d %d %d %d %d\n", 
			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]);
	*/
	return buf[7] & 1;
}
Beispiel #20
0
int USB_Open(int id)
{
    // Open the device using the VID, PID,
    // and optionally the Serial number.
	struct hid_device_info *devs, *cur_dev;

	devs = hid_enumerate(MY_VID, MY_PID);
	cur_dev = devs;
	
	int i = 0;

	while (cur_dev) {

		if (wcscmp(cur_dev->product_string, L"DDP442X") == 0)
		{
			if (i == id)
				DeviceHandle = hid_open_path(cur_dev->path);

			printf("Device Found\n  type: %04hx %04hx\n  path: %s\n  serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
			printf("\n");
			printf("  Manufacturer: %ls\n", cur_dev->manufacturer_string);
			printf("  Product:      %ls\n", cur_dev->product_string);
			printf("  Release:      %hx\n", cur_dev->release_number);
			printf("  Interface:    %d\n", cur_dev->interface_number);
			printf("\n");

			i++;
		}

		cur_dev = cur_dev->next;
	}

	hid_free_enumeration(devs);
		
	//DeviceHandle = hid_open(MY_VID, MY_PID, NULL);
	
    if(DeviceHandle == NULL)
    {
        USBConnected = false;
        return -1;
    }
    USBConnected = true;
    return 0;
}
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
	// TODO: Merge this functions with the Linux version. This function should be platform independent.
	struct hid_device_info *devs, *cur_dev;
	const char *path_to_open = NULL;
    hid_device *handle = NULL;

#ifdef STICK20_DEBUG
{ // For debugging
    char text[1000];
    sprintf(text,"hid_open: VID %04x PID %04x\n", vendor_id,product_id);
    DebugAppendText (text);
}
#endif

	devs = hid_enumerate(vendor_id, product_id);
	cur_dev = devs;
	while (cur_dev) {
		if (cur_dev->vendor_id == vendor_id &&
		    cur_dev->product_id == product_id) {
			if (serial_number) {
				if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
					path_to_open = cur_dev->path;
					break;
				}
			}
			else {
				path_to_open = cur_dev->path;
				break;
			}
		}
		cur_dev = cur_dev->next;
	}

	if (path_to_open) {
		/* Open the device */
		handle = hid_open_path(path_to_open);
	}

	hid_free_enumeration(devs);
	
	return handle;
}
Beispiel #22
0
void init_pid(unsigned short vid, unsigned short pid) {
#ifdef OSX
    hid_init();
    dev = hid_open(vid, pid, NULL);
#else
    struct hid_device_info *info = NULL, *ptr = NULL;
    hid_init();
    info = hid_enumerate(vid, pid);
    ptr = info;
    while (ptr != NULL) {
        if (ptr->interface_number == 1) {
            dev = hid_open_path(ptr->path);
            break;
        }
        ptr = ptr->next;
    }
    hid_free_enumeration(info);
#endif
}
Beispiel #23
0
/**
 * constructor
 */
boca_hid_printer_t *boca_hid_new(const char *device_path) {
    boca_hid_printer_t *self = (boca_hid_printer_t *) calloc(1, sizeof(boca_hid_printer_t));
    if (!self) return NULL;
    self->device_path = strdup(device_path);
#ifdef __WIN32__
    HANDLE handle;
    handle = CreateFile(device_path,
                        0,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        NULL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
    if (handle != INVALID_HANDLE_VALUE) {
        PHIDP_PREPARSED_DATA preparsed_data;
        if (HidD_GetPreparsedData(handle, &preparsed_data)) {
            HIDP_CAPS capabilities;
            NTSTATUS ret = HidP_GetCaps(preparsed_data, &capabilities);
            if (ret == HIDP_STATUS_SUCCESS) {
                self->input_length = capabilities.InputReportByteLength;
                self->output_length = capabilities.OutputReportByteLength;
                self->feature_length = capabilities.FeatureReportByteLength;
                zsys_info("hid printer: input length %d output length %d feature length %d", self->input_length,
                          self->output_length, self->feature_length);
            } else {
                zsys_warning("hid printer: can not get hid printer capabilities.");
            }
        } else {
            zsys_warning("hid printer: can not get hid prepared data");
        }
        CloseHandle(handle);
    } else {
        zsys_warning("hid printer: can not open hid device code %d", GetLastError());
    }
#endif
    self->device = hid_open_path(self->device_path);
    if (self->device == NULL) {
        zsys_error("hid printer: could not create device from path %s", device_path);
        boca_hid_destroy(&self);
        return NULL;
    }
    return self;
}
Beispiel #24
0
int initializeDevice() {

  struct hid_device_info *devs, *cur_dev;
  const wchar_t targetManufacturer[] = L"Wincor Nixdorf";

  hid_init();
  /* Auto-detection du périphérique */
  //Wincor Nixdorf

	devs = hid_enumerate(0x0, 0x0);
	cur_dev = devs;

	while (cur_dev) {
    if (DEBUG) fprintf(stdout, "<Debug> Périphérique trouvé: %04hx %04hx - %ls - %s\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->manufacturer_string ,cur_dev->path);

    #if defined(__APPLE__)
      if (!wcscmp(targetManufacturer, cur_dev->manufacturer_string) ) {
        fprintf(stdout, "<Pilote> Afficheur USB %04hx %04hx en cours d\'ouverture sur %s..\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path);
        display = hid_open(cur_dev->vendor_id, cur_dev->product_id, NULL);
        break;
      }
    #elif defined(linux)
      if (!wcscmp(targetManufacturer, cur_dev->manufacturer_string) &&  !strcmp(cur_dev->path+(strlen(cur_dev->path)-2), "01")) {
        fprintf(stdout, "<Pilote> Afficheur USB %04hx %04hx en cours d\'ouverture sur %s..\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path);
        display = hid_open_path(cur_dev->path);
        break;
      }
    #else
      fprintf(stderr, "<Fatal> Ce système n'est pas (encore) supporté pour l'instant!\n");
      exit(-1);
    #endif

		cur_dev = cur_dev->next;
	}

	hid_free_enumeration(devs);
  if (!display) return 0;

  hid_get_product_string(display, moduleName, MAX_STR);
  if (DEBUG) fprintf(stdout, "<Info> Connected to \"%ls\" display.\n", moduleName);
  return display!=NULL;
}
Beispiel #25
0
int DAPLUGCALL Daplug_getDongleById(Dongle_info* di,DaplugDongle *dpd){

    if(di->type == HID_DEVICE){
        if((di->handle = (hid_device *)hid_open_path(di->path)) == NULL){
            fprintf(stderr,"\ngetDongleById(): Cannot open hid dongle !\n");
            return 0;
        }
    }

    if(di->type == WINUSB_DEVICE){
        if(initWinusbDevice(di->handle) == 0){
            fprintf(stderr,"\ngetDongleById(): Cannot open winusb dongle !\n");
            return 0;
        }
    }

    initDongle(dpd);
    dpd->di = (Dongle_info) *di;

    return 1;
}
Beispiel #26
0
ambit_object_t * libambit_new(const ambit_device_info_t *device)
{
    ambit_object_t *object = NULL;
    const ambit_known_device_t *known_device = NULL;
    const char *path = NULL;

    if (!device || !device->path) {
        LOG_ERROR("%s", strerror(EINVAL));
        return NULL;
    }

    path = strdup (device->path);
    if (!path) return NULL;

    if (0 == device->access_status && device->is_supported) {
        // Note, this should never fail if device was properly received with libambit_enumerate
        known_device = libambit_device_support_find(device->vendor_id, device->product_id, device->model, device->fw_version);
        if (known_device != NULL) {
            object = calloc(1, sizeof(*object));
            if (object) {
                object->handle = hid_open_path(path);
                memcpy(&object->device_info, device, sizeof(*device));
                object->device_info.path = path;
                object->driver = known_device->driver;

                if (object->handle) {
                    hid_set_nonblocking(object->handle, true);
                }

                // Initialize driver
                object->driver->init(object, known_device->driver_param);
            }
        }
    }
    if (!object) {
        free((char *) path);
    }

    return object;
}
Beispiel #27
0
static bool IsDeviceUsable(const std::string& device_path)
{
  hid_device* handle = hid_open_path(device_path.c_str());
  if (handle == nullptr)
  {
    ERROR_LOG(WIIMOTE, "Could not connect to Wii Remote at \"%s\". "
                       "Do you have permission to access the device?",
              device_path.c_str());
    return false;
  }
  // Some third-party adapters (DolphinBar) always expose all four Wii Remotes as HIDs
  // even when they are not connected, which causes an endless error loop when we try to use them.
  // Try to write a report to the device to see if this Wii Remote is really usable.
  static const u8 report[] = {WR_SET_REPORT | BT_OUTPUT, RT_REQUEST_STATUS, 0};
  const int result = hid_write(handle, report, sizeof(report));
  // The DolphinBar uses EPIPE to signal the absence of a Wii Remote connected to this HID.
  if (result == -1 && errno != EPIPE)
    ERROR_LOG(WIIMOTE, "Couldn't write to Wii Remote at \"%s\".", device_path.c_str());

  hid_close(handle);
  return result != -1;
}
LPCUSBSIO_API LPC_HANDLE I2C_Open(uint32_t index)
{
    hid_device *pHid = NULL;
    LPCUSBSIO_I2C_Ctrl_t *dev = NULL;
    struct hid_device_info *cur_dev;

    cur_dev = GetDevAtIndex(index);

    if (cur_dev) 
    {
        pHid = hid_open_path(cur_dev->path);

        if (pHid) 
        {
            dev = framework_AllocMem(sizeof(LPCUSBSIO_I2C_Ctrl_t));
            memset(dev, 0, sizeof(LPCUSBSIO_I2C_Ctrl_t));
            dev->hidDev = pHid;
            dev->hidInfo = cur_dev;
            dev->sesionId = rand();
            map_create(&dev->request_map);
            memcpy(&dev->fwVersion[0], g_fwInitVer, strlen(g_fwInitVer));

            /* insert at top */
            dev->next = g_Ctrl.devList;
            g_Ctrl.devList = dev;
            /* Set all calls to this hid device as blocking. */
            // hid_set_nonblocking(dev->hidDev, 0);
            framework_CreateMutex(&dev->SendLock);
            framework_CreateMutex(&dev->RequestMapLock);
            framework_CreateMutex(&dev->NotifierContainerLock);
            dev->thread_exit = 0x00;
            framework_CreateThread(&dev->ResponsethreadHandle , WaitRequestResponse, dev);

        }
    }
    
    return (LPC_HANDLE) dev;
}
Beispiel #29
0
bool tempered_type_hid_open( tempered_device* device )
{
	struct tempered_type_hid_device_data *device_data = malloc(
		sizeof( struct tempered_type_hid_device_data )
	);
	if ( device_data == NULL )
	{
		tempered_set_error(
			device, strdup( "Failed to allocate memory for the device data." )
		);
		return false;
	}
	device_data->group_data = NULL;
	device_data->hid_dev = hid_open_path( device->path );
	if ( device_data->hid_dev == NULL )
	{
		free( device_data );
		tempered_set_error( device, strdup( "Failed to open HID device." ) );
		return false;
	}
	device->data = device_data;
	return true;
}
//-----------------------------------------------------------------------------
bool HIDDevice::openDevice(const char* device_path)
{
    // First fill out the device descriptor
    if (!HIDManager->GetDescriptorFromPath(device_path, &DevDesc))
    {
        return false;
    }

    DeviceHandle = hid_open_path(device_path);

    if(!DeviceHandle)
    {
    	LogError("Could not open %s error: %s", device_path, strerror(errno));
    	return false;
    }

    hid_set_nonblocking(DeviceHandle,0);

    HIDManager->DevManager->pThread->AddSelectFd(this, -1); //set this up to be polled
    

    return true;
}