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

Function selectDevice

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

Source from the content-addressed store, hash-verified

18USB::~USB() {}
19
20static std::shared_ptr<CandidateDevice> selectDevice()
21{
22 auto candidates = findUsbDevices();
23 if (candidates.size() == 0)
24 error(
25 "no devices found (is one plugged in? Do you have the "
26 "appropriate permissions?");
27
28 if (globalConfig()->usb().has_serial())
29 {
30 auto wantedSerial = globalConfig()->usb().serial();
31 for (auto& c : candidates)
32 {
33 if (c->serial == wantedSerial)
34 return c;
35 }
36 error(
37 "serial number not found (try without one to list or "
38 "autodetect devices)");
39 }
40
41 if (candidates.size() == 1)
42 return candidates[0];
43
44 std::cerr << "More than one device detected; use --usb.serial=<serial> to "
45 "select one:\n";
46 for (const auto& c : candidates)
47 {
48 std::cerr << " ";
49 switch (c->id)
50 {
51 case FLUXENGINE_ID:
52 std::cerr << fmt::format("FluxEngine: {}\n", c->serial);
53 break;
54
55 case GREASEWEAZLE_ID:
56 std::cerr << fmt::format(
57 "Greaseweazle: {} on {}\n", c->serial, c->serialPort);
58 break;
59
60 case APPLESAUCE_ID:
61 std::cerr << fmt::format(
62 "Applesauce: {} on {}\n", c->serial, c->serialPort);
63 break;
64 }
65 }
66 exit(1);
67}
68
69USB* get_usb_impl()
70{

Callers 1

get_usb_implFunction · 0.85

Calls 3

findUsbDevicesFunction · 0.85
errorFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected