Tidy reporting of USB errors.

This commit is contained in:
David Given
2023-08-19 20:46:41 +02:00
parent 688061397b
commit 95b703b1ea
2 changed files with 26 additions and 21 deletions

View File

@@ -32,8 +32,6 @@ endif
ifeq ($(shell uname),FreeBSD)
PLATFORM = FreeBSD
#WX_CONFIG=/usr/local/bin/wxgtk3u-3.2-config
#WX_CONFIG=/usr/local/bin/wxgtk3u-3.0-config
CFLAGS += -I/usr/local/include
endif

View File

@@ -26,32 +26,39 @@ static const std::string get_serial_number(const libusbp::device& device)
std::vector<std::shared_ptr<CandidateDevice>> findUsbDevices()
{
std::vector<std::shared_ptr<CandidateDevice>> candidates;
for (const auto& it : libusbp::list_connected_devices())
try
{
auto candidate = std::make_unique<CandidateDevice>();
candidate->device = it;
uint32_t id = (it.get_vendor_id() << 16) | it.get_product_id();
if (VALID_DEVICES.find(id) != VALID_DEVICES.end())
std::vector<std::shared_ptr<CandidateDevice>> candidates;
for (const auto& it : libusbp::list_connected_devices())
{
candidate->id = id;
candidate->serial = get_serial_number(it);
auto candidate = std::make_unique<CandidateDevice>();
candidate->device = it;
if (id == GREASEWEAZLE_ID)
uint32_t id = (it.get_vendor_id() << 16) | it.get_product_id();
if (VALID_DEVICES.find(id) != VALID_DEVICES.end())
{
libusbp::serial_port port(candidate->device);
candidate->serialPort = port.get_name();
candidate->type = DEVICE_GREASEWEAZLE;
candidate->id = id;
candidate->serial = get_serial_number(it);
if (id == GREASEWEAZLE_ID)
{
libusbp::serial_port port(candidate->device);
candidate->serialPort = port.get_name();
candidate->type = DEVICE_GREASEWEAZLE;
}
else if (id == FLUXENGINE_ID)
candidate->type = DEVICE_FLUXENGINE;
candidates.push_back(std::move(candidate));
}
else if (id == FLUXENGINE_ID)
candidate->type = DEVICE_FLUXENGINE;
candidates.push_back(std::move(candidate));
}
}
return candidates;
return candidates;
}
catch (const libusbp::error& e)
{
error("USB error: {}", e.message());
}
}
std::string getDeviceName(DeviceType type)