Improved FTDI device finding logic

pull/4/head
Paul Hollinsky 2018-12-10 14:58:28 -05:00
parent 3488e36f2a
commit 837ca29ac8
1 changed files with 6 additions and 1 deletions

View File

@ -101,15 +101,20 @@ std::vector<neodevice_t> VCP::FindByProduct(int product, std::vector<std::wstrin
} }
bool alreadyFound = false; bool alreadyFound = false;
neodevice_t* shouldReplace = nullptr;
for(auto& foundDev : found) { for(auto& foundDev : found) {
if(foundDev.handle == device.handle && serial == foundDev.serial) { if((foundDev.handle == device.handle || foundDev.handle == 0 || device.handle == 0) && serial == foundDev.serial) {
alreadyFound = true; alreadyFound = true;
if(foundDev.handle == 0)
shouldReplace = &foundDev;
break; break;
} }
} }
if(!alreadyFound) if(!alreadyFound)
found.push_back(device); found.push_back(device);
else if(shouldReplace != nullptr)
*shouldReplace = device;
} }
} }