| 26 | } |
| 27 | |
| 28 | std::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 | |
| 69 | std::string getDeviceName(DeviceType type) |
| 70 | { |