MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / hid_write

Function hid_write

dependencies/hidapi/hidapi.c:872–920  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

870
871
872int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
873{
874 int res;
875 int report_number = data[0];
876 int skipped_report_id = 0;
877
878 if (report_number == 0x0) {
879 data++;
880 length--;
881 skipped_report_id = 1;
882 }
883
884
885 if (dev->output_endpoint <= 0) {
886 /* No interrupt out endpoint. Use the Control Endpoint */
887 res = libusb_control_transfer(dev->device_handle,
888 LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT,
889 0x09/*HID Set_Report*/,
890 (2/*HID output*/ << 8) | report_number,
891 dev->interface,
892 (unsigned char *)data, length,
893 1000/*timeout millis*/);
894
895 if (res < 0)
896 return -1;
897
898 if (skipped_report_id)
899 length++;
900
901 return length;
902 }
903 else {
904 /* Use the interrupt out endpoint */
905 int actual_length;
906 res = libusb_interrupt_transfer(dev->device_handle,
907 dev->output_endpoint,
908 (unsigned char*)data,
909 length,
910 &actual_length, 1000);
911
912 if (res < 0)
913 return -1;
914
915 if (skipped_report_id)
916 actual_length++;
917
918 return actual_length;
919 }
920}
921
922/* Helper function, to simplify hid_read().
923 This should be called with dev->mutex locked. */

Callers 15

SetZoneColorMethod · 0.85
SetModeMethod · 0.85
SetLedsDirectMethod · 0.85
SaveMethod · 0.85
SendProfileMethod · 0.85
SendEnableCommandMethod · 0.85
SendApplyCommandMethod · 0.85
SendDirectPacketMethod · 0.85
SendZoneUpdateMethod · 0.85
SendInitializeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected