MCPcopy Create free account
hub / github.com/andybarry/makerscanner / SetConfig

Function SetConfig

SetConfig.c:32–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30// -2: Unable to send SET_CONFIGURATION request
31
32int SetConfig() {
33 struct usb_bus *bus;
34 struct usb_device *dev;
35 usb_dev_handle *udev;
36 int dev_found, ret;
37 char buffer[8];
38
39 usb_init();
40
41 usb_find_busses();
42 usb_find_devices();
43
44 udev = NULL;
45 dev_found = FALSE;
46 for (bus = usb_get_busses(); bus && !dev_found; bus = bus->next) {
47 for (dev = bus->devices; dev && !dev_found; dev = dev->next) {
48 if ((dev->descriptor.idVendor == 0x6666) && (dev->descriptor.idProduct == 0x0003)) {
49 dev_found = TRUE;
50 udev = usb_open(dev);
51 }
52 }
53 }
54 if (!dev_found) {
55 printf("No matching device found...\n");
56 return -1;
57 }
58 if (udev) {
59 ret = usb_control_msg(udev, USB_TYPE_STANDARD | USB_RECIP_DEVICE, USB_REQ_SET_CONFIGURATION, 1, 0, buffer, 0, 100);
60 if (ret < 0) {
61 printf("Unable to send SET_CONFIGURATION standard request, ret = %d...\n", ret);
62 return -2;
63 }
64 usb_close(udev);
65 }
66 return 0;
67}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected