wugren 3 роки тому
батько
коміт
c806626b03
3 змінених файлів з 35 додано та 25 видалено
  1. 3 1
      hidapi/hidapi/hidapi.h
  2. 10 11
      hidapi/windows/hid.c
  3. 22 13
      src/HID.cc

+ 3 - 1
hidapi/hidapi/hidapi.h

@@ -73,7 +73,9 @@ extern "C" {
 			    in all cases, and valid on the Windows implementation
 			    only if the device contains more than one interface. */
 			int interface_number;
-
+			
+			char* hardware_id;
+			
 			/** Pointer to the next device */
 			struct hid_device_info *next;
 		};

+ 10 - 11
hidapi/windows/hid.c

@@ -410,17 +410,6 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
 			}
 			cur_dev = tmp;
 
-			/* Get the Usage Page and Usage for this device. */
-			res = HidD_GetPreparsedData(write_handle, &pp_data);
-			if (res) {
-				nt_res = HidP_GetCaps(pp_data, &caps);
-				if (nt_res == HIDP_STATUS_SUCCESS) {
-					cur_dev->usage_page = caps.UsagePage;
-					cur_dev->usage = caps.Usage;
-				}
-
-				HidD_FreePreparsedData(pp_data);
-			}
 
 			/* Fill out the record */
 			cur_dev->next = NULL;
@@ -434,6 +423,16 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
 			else
 				cur_dev->path = NULL;
 
+			str = driverkey;
+			if (str) {
+				len = strlen(str);
+				cur_dev->hardware_id = (char*)calloc(len + 1, sizeof(char));
+				strncpy(cur_dev->hardware_id, str, len + 1);
+				cur_dev->hardware_id[len] = '\0';
+			}
+			else {
+				cur_dev->hardware_id = NULL;
+			}
 			/* Serial Number */
 			res = HidD_GetSerialNumberString(write_handle, wstr, sizeof(wstr));
 			wstr[WSTR_LEN-1] = 0x0000;

+ 22 - 13
src/HID.cc

@@ -58,6 +58,17 @@ protected:
   string _message;
 };
 
+static string
+narrow(wchar_t* wide)
+{
+  wstring ws(wide);
+  ostringstream os;
+  for (size_t i = 0; i < ws.size(); i++) {
+    os << os.narrow(ws[i], '?');
+  }
+  return os.str();
+}
+
 class HID
   : public Nan::ObjectWrap
 {
@@ -167,7 +178,10 @@ HID::write(const databuf_t& message)
   throw(JSException)
 {
   if(!_hidHandle) {
-    throw JSException("Cannot write to closed device");
+	char buf[1024];
+	memset(buf, 0, sizeof(buf));
+	sprintf(buf, "Cannot write to closed device. size:%d", message.size());
+    throw JSException(buf);
   }
   //unsigned char buf[message.size()];
   unsigned char* buf = new unsigned char[message.size()];
@@ -179,7 +193,10 @@ HID::write(const databuf_t& message)
   res = hid_write(_hidHandle, buf, message.size());
   delete[] buf;
   if (res < 0) {
-    throw JSException("Cannot write to HID device");
+	char buf[1024];
+	memset(buf, 0, sizeof(buf));
+	sprintf(buf, "Cannot write to HID device.error:%d", GetLastError());
+    throw JSException(buf);
   }
   return res;  // return actual number of bytes written
 }
@@ -490,17 +507,6 @@ NAN_METHOD(HID::write)
   }
 }
 
-static string
-narrow(wchar_t* wide)
-{
-  wstring ws(wide);
-  ostringstream os;
-  for (size_t i = 0; i < ws.size(); i++) {
-    os << os.narrow(ws[i], '?');
-  }
-  return os.str();
-}
-
 NAN_METHOD(HID::getDeviceInfo)
 {
   Nan::HandleScope scope;
@@ -561,6 +567,9 @@ NAN_METHOD(HID::devices)
     Local<Object> deviceInfo = Nan::New<Object>();
     Nan::Set(deviceInfo, Nan::New<String>("vendorId").ToLocalChecked(), Nan::New<Integer>(dev->vendor_id));
     Nan::Set(deviceInfo, Nan::New<String>("productId").ToLocalChecked(), Nan::New<Integer>(dev->product_id));
+	if (dev->hardware_id) {
+		Nan::Set(deviceInfo, Nan::New<String>("hardwareId").ToLocalChecked(), Nan::New<String>(dev->hardware_id).ToLocalChecked());
+	}
     if (dev->path) {
       Nan::Set(deviceInfo, Nan::New<String>("path").ToLocalChecked(), Nan::New<String>(dev->path).ToLocalChecked());
     }