Wait for devices to be ready before adding them.

This commit is contained in:
pixl 2023-04-28 21:05:47 -04:00
parent adcb173e4c
commit 0115aaa804
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
3 changed files with 12 additions and 2 deletions

View File

@ -30,7 +30,7 @@
namespace logid {
namespace defaults {
static constexpr double io_timeout = 1000;
static constexpr double io_timeout = 500;
static constexpr int gesture_threshold = 50;
}

View File

@ -95,7 +95,15 @@ void DeviceMonitor::ready() {
std::string dev_node = udev_device_get_devnode(device);
if (action == "add")
spawn_task([this, dev_node]() { _addHandler(dev_node); });
spawn_task([this, dev_node]() {
/* Device was just connected, may not be ready yet.
* Sleep for 2 seconds to ensure device is ready before attempting to add.
* This is a bit of a hack and this time was determined through a bit of
* experimentation.
*/
std::this_thread::sleep_for(std::chrono::milliseconds(ready_wait));
_addHandler(dev_node);
});
else if (action == "remove")
spawn_task([this, dev_node]() { _removeHandler(dev_node); });

View File

@ -32,6 +32,8 @@ struct udev_monitor;
}
namespace logid::backend::raw {
static constexpr int ready_wait = 2000;
class DeviceMonitor {
public:
virtual ~DeviceMonitor();