MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / findUsbDevices

Function findUsbDevices

lib/usb/usbfinder.cc:28–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28std::vector<std::shared_ptr<CandidateDevice>> findUsbDevices()
29{
30 try
31 {
32 std::vector<std::shared_ptr<CandidateDevice>> candidates;
33 for (const auto& it : libusbp::list_connected_devices())
34 {
35 auto candidate = std::make_unique<CandidateDevice>();
36 candidate->device = it;
37
38 uint32_t id = (it.get_vendor_id() << 16) | it.get_product_id();
39 if (VALID_DEVICES.find(id) != VALID_DEVICES.end())
40 {
41 candidate->id = id;
42 candidate->serial = get_serial_number(it);
43
44 if (id == GREASEWEAZLE_ID)
45 candidate->type = DEVICE_GREASEWEAZLE;
46 else if (id == APPLESAUCE_ID)
47 candidate->type = DEVICE_APPLESAUCE;
48 else if (id == FLUXENGINE_ID)
49 candidate->type = DEVICE_FLUXENGINE;
50
51 if ((id == GREASEWEAZLE_ID) || (id == APPLESAUCE_ID))
52 {
53 libusbp::serial_port port(candidate->device);
54 candidate->serialPort = port.get_name();
55 }
56
57 candidates.push_back(std::move(candidate));
58 }
59 }
60
61 return candidates;
62 }
63 catch (const libusbp::error& e)
64 {
65 error("USB error: {}", e.message());
66 }
67}
68
69std::string getDeviceName(DeviceType type)
70{

Callers 4

selectDeviceFunction · 0.85
mainTestDevicesFunction · 0.85
probeDevicesMethod · 0.85
UpdateDevicesMethod · 0.85

Calls 5

get_serial_numberFunction · 0.85
errorFunction · 0.85
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by 1

mainTestDevicesFunction · 0.68