@@ -278,8 +278,11 @@ void CALLBACK XboxController::OnVigemNotification(PVIGEM_CLIENT Client, PVIGEM_T
278
278
controller.output_prev_ .Rumble .wLeftMotorSpeed = _byteswap_ushort (LargeMotor); // why do these need to be byteswapped???
279
279
controller.output_prev_ .Rumble .wRightMotorSpeed = _byteswap_ushort (SmallMotor);
280
280
281
- libusb_control_transfer (controller.usb_handle_ , LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
282
- HID_SET_REPORT, (HID_REPORT_TYPE_OUTPUT << 8 ) | 0x00 , 0 , (unsigned char *)&controller.output_prev_ , sizeof (XboxOutputReport), 1000 );
281
+ {
282
+ std::lock_guard<std::mutex> guard (usb_mutex_);
283
+ libusb_control_transfer (controller.usb_handle_ , LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
284
+ HID_SET_REPORT, (HID_REPORT_TYPE_OUTPUT << 8 ) | 0x00 , 0 , (unsigned char *)&controller.output_prev_ , sizeof (XboxOutputReport), 1000 );
285
+ }
283
286
284
287
break ;
285
288
}
@@ -325,15 +328,18 @@ bool XboxController::update()
325
328
326
329
// if we have interrupt endpoints use those for better compatibility, otherwise fallback to control transfers
327
330
memset (&input_prev_, 0 , sizeof (XboxInputReport));
328
- std::lock_guard<std::mutex> guard (usb_mutex_);
329
331
int length = 0 ;
330
332
int ret = -1 ;
333
+
331
334
if (endpoint_in_)
332
335
ret = libusb_interrupt_transfer (usb_handle_, endpoint_in_, (unsigned char *)&input_prev_, sizeof (XboxInputReport), &length, 0 );
333
336
334
337
if (ret < 0 )
338
+ {
339
+ std::lock_guard<std::mutex> guard (usb_mutex_);
335
340
ret = libusb_control_transfer (usb_handle_, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
336
341
HID_GET_REPORT, (HID_REPORT_TYPE_INPUT << 8 ) | 0x00 , 0 , (unsigned char *)&input_prev_, sizeof (XboxInputReport), 1000 );
342
+ }
337
343
338
344
if (ret < 0 )
339
345
{
0 commit comments