Skip to content

Commit 4a326f1

Browse files
committed
USB HID initialization: add error handling
Signed-off-by: Norbert Takacs <norberttak@gmail.com>
1 parent 14a9576 commit 4a326f1

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/core/XPanel.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,21 @@ int enumerate_and_add_hid_devices(ClassConfiguration& it)
278278
do
279279
{
280280
Logger(TLogLevel::logDEBUG) << "add new panel device. vid =" << it.vid << " pid = " << it.pid << std::endl;
281+
hid_device* hid_dev = hid_open_path(dev_info->path);
282+
if (hid_dev == NULL)
283+
{
284+
Logger(TLogLevel::logERROR) << "error opening hid device with vid=" << it.vid << " pid=" << it.pid << std::endl;
285+
continue;
286+
}
287+
288+
if (hid_set_nonblocking(hid_dev, 1) != 0)
289+
{
290+
Logger(TLogLevel::logERROR) << "error hid_set_nonblocking with vid=" << it.vid << " pid=" << it.pid << std::endl;
291+
continue;
292+
}
293+
281294
device = new T(it);
282295
devices.push_back(device);
283-
284-
hid_device* hid_dev = hid_open_path(dev_info->path);
285-
hid_set_nonblocking(hid_dev, 1);
286296
((T*)device)->connect(hid_dev);
287297
device->start();
288298
device->thread_handle = new std::thread(&T::thread_func, (T*)device);

0 commit comments

Comments
 (0)