@@ -1039,33 +1039,24 @@ int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const u
1039
1039
return (int ) length ;
1040
1040
}
1041
1041
1042
-
1043
- int HID_API_EXPORT HID_API_CALL hid_get_feature_report (hid_device * dev , unsigned char * data , size_t length )
1042
+ static int hid_get_report (hid_device * dev , DWORD report_type , unsigned char * data , size_t length )
1044
1043
{
1045
1044
BOOL res ;
1046
- #if 0
1047
- res = HidD_GetFeature (dev -> device_handle , data , length );
1048
- if (!res ) {
1049
- register_error (dev , "HidD_GetFeature" );
1050
- return -1 ;
1051
- }
1052
- return 0 ; /* HidD_GetFeature() doesn't give us an actual length, unfortunately */
1053
- #else
1054
- DWORD bytes_returned ;
1045
+ DWORD bytes_returned = 0 ;
1055
1046
1056
1047
OVERLAPPED ol ;
1057
1048
memset (& ol , 0 , sizeof (ol ));
1058
1049
1059
1050
res = DeviceIoControl (dev -> device_handle ,
1060
- IOCTL_HID_GET_FEATURE ,
1051
+ report_type ,
1061
1052
data , (DWORD ) length ,
1062
1053
data , (DWORD ) length ,
1063
1054
& bytes_returned , & ol );
1064
1055
1065
1056
if (!res ) {
1066
1057
if (GetLastError () != ERROR_IO_PENDING ) {
1067
1058
/* DeviceIoControl() failed. Return error. */
1068
- register_error (dev , "Send Feature Report DeviceIoControl" );
1059
+ register_error (dev , "Get Input/ Feature Report DeviceIoControl" );
1069
1060
return -1 ;
1070
1061
}
1071
1062
}
@@ -1075,56 +1066,30 @@ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned
1075
1066
res = GetOverlappedResult (dev -> device_handle , & ol , & bytes_returned , TRUE/*wait*/ );
1076
1067
if (!res ) {
1077
1068
/* The operation failed. */
1078
- register_error (dev , "Send Feature Report GetOverLappedResult" );
1069
+ register_error (dev , "Get Input/ Feature Report GetOverLappedResult" );
1079
1070
return -1 ;
1080
1071
}
1081
1072
1073
+ /* When numbered reports aren't used,
1074
+ bytes_returned seem to include only what is actually received from the device
1075
+ (not including the first byte with 0, as an indication "no numbered reports"). */
1076
+ if (data [0 ] == 0x0 ) {
1077
+ bytes_returned ++ ;
1078
+ }
1079
+
1082
1080
return bytes_returned ;
1083
- #endif
1084
1081
}
1085
1082
1083
+ int HID_API_EXPORT HID_API_CALL hid_get_feature_report (hid_device * dev , unsigned char * data , size_t length )
1084
+ {
1085
+ /* We could use HidD_GetFeature() instead, but it doesn't give us an actual length, unfortunately */
1086
+ return hid_get_report (dev , IOCTL_HID_GET_FEATURE , data , length );
1087
+ }
1086
1088
1087
1089
int HID_API_EXPORT HID_API_CALL hid_get_input_report (hid_device * dev , unsigned char * data , size_t length )
1088
1090
{
1089
- BOOL res ;
1090
- #if 0
1091
- res = HidD_GetInputReport (dev -> device_handle , data , length );
1092
- if (!res ) {
1093
- register_error (dev , "HidD_GetInputReport" );
1094
- return -1 ;
1095
- }
1096
- return length ;
1097
- #else
1098
- DWORD bytes_returned ;
1099
-
1100
- OVERLAPPED ol ;
1101
- memset (& ol , 0 , sizeof (ol ));
1102
-
1103
- res = DeviceIoControl (dev -> device_handle ,
1104
- IOCTL_HID_GET_INPUT_REPORT ,
1105
- data , (DWORD ) length ,
1106
- data , (DWORD ) length ,
1107
- & bytes_returned , & ol );
1108
-
1109
- if (!res ) {
1110
- if (GetLastError () != ERROR_IO_PENDING ) {
1111
- /* DeviceIoControl() failed. Return error. */
1112
- register_error (dev , "Send Input Report DeviceIoControl" );
1113
- return -1 ;
1114
- }
1115
- }
1116
-
1117
- /* Wait here until the write is done. This makes
1118
- hid_get_feature_report() synchronous. */
1119
- res = GetOverlappedResult (dev -> device_handle , & ol , & bytes_returned , TRUE/*wait*/ );
1120
- if (!res ) {
1121
- /* The operation failed. */
1122
- register_error (dev , "Send Input Report GetOverLappedResult" );
1123
- return -1 ;
1124
- }
1125
-
1126
- return bytes_returned ;
1127
- #endif
1091
+ /* We could use HidD_GetInputReport() instead, but it doesn't give us an actual length, unfortunately */
1092
+ return hid_get_report (dev , IOCTL_HID_GET_INPUT_REPORT , data , length );
1128
1093
}
1129
1094
1130
1095
void HID_API_EXPORT HID_API_CALL hid_close (hid_device * dev )
0 commit comments