|
|
@ -20,7 +20,6 @@ void DeviceFinder::addDevice(const char *path) |
|
|
|
// Asynchronously scan device
|
|
|
|
// Asynchronously scan device
|
|
|
|
std::thread{[=]() |
|
|
|
std::thread{[=]() |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<Device*> _devs; |
|
|
|
|
|
|
|
const int max_tries = 10; |
|
|
|
const int max_tries = 10; |
|
|
|
const int try_delay = 250000; |
|
|
|
const int try_delay = 250000; |
|
|
|
|
|
|
|
|
|
|
@ -50,7 +49,16 @@ void DeviceFinder::addDevice(const char *path) |
|
|
|
if(major > 1) // HID++ 2.0 devices only
|
|
|
|
if(major > 1) // HID++ 2.0 devices only
|
|
|
|
{ |
|
|
|
{ |
|
|
|
auto dev = new Device(string_path, index); |
|
|
|
auto dev = new Device(string_path, index); |
|
|
|
_devs.push_back(dev); |
|
|
|
|
|
|
|
|
|
|
|
this->devicesMutex.lock(); |
|
|
|
|
|
|
|
this->devices.insert({ |
|
|
|
|
|
|
|
dev, |
|
|
|
|
|
|
|
std::thread{[dev]() { |
|
|
|
|
|
|
|
dev->start(); |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this->devicesMutex.unlock(); |
|
|
|
|
|
|
|
|
|
|
|
log_printf(INFO, "%s detected: device %d on %s", d.name().c_str(), index, string_path.c_str()); |
|
|
|
log_printf(INFO, "%s detected: device %d on %s", d.name().c_str(), index, string_path.c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -93,17 +101,14 @@ void DeviceFinder::addDevice(const char *path) |
|
|
|
catch(HIDPP::Dispatcher::NoHIDPPReportException &e) { } |
|
|
|
catch(HIDPP::Dispatcher::NoHIDPPReportException &e) { } |
|
|
|
catch(std::system_error &e) { log_printf(WARN, "Failed to open %s: %s", string_path.c_str(), e.what()); } |
|
|
|
catch(std::system_error &e) { log_printf(WARN, "Failed to open %s: %s", string_path.c_str(), e.what()); } |
|
|
|
|
|
|
|
|
|
|
|
for(auto dev : _devs) |
|
|
|
|
|
|
|
devices.insert({dev, std::thread{[dev]() { dev->start(); }}}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}.detach(); |
|
|
|
}}.detach(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DeviceFinder::removeDevice(const char* path) |
|
|
|
void DeviceFinder::removeDevice(const char* path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
devicesMutex.lock(); |
|
|
|
// Iterate through Devices, stop all in path
|
|
|
|
// Iterate through Devices, stop all in path
|
|
|
|
auto it = devices.begin(); |
|
|
|
for (auto it = devices.begin(); it != devices.end(); it++) |
|
|
|
while (it != devices.end()) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if(it->first->path == path) |
|
|
|
if(it->first->path == path) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -112,9 +117,7 @@ void DeviceFinder::removeDevice(const char* path) |
|
|
|
it->second.join(); |
|
|
|
it->second.join(); |
|
|
|
delete(it->first); |
|
|
|
delete(it->first); |
|
|
|
devices.erase(it); |
|
|
|
devices.erase(it); |
|
|
|
it++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
it++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
devicesMutex.unlock(); |
|
|
|
} |
|
|
|
} |