From d69cf0b866fa3cc5afda2bb1a321a900520fbcc1 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 31 Jan 2017 18:15:48 +0100 Subject: Add method for checking is the device listed as connected in OS Signed-off-by: Szczepan Zalega --- device.cc | 18 ++++++++++++++++++ include/device.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/device.cc b/device.cc index 532ba2e..42c6883 100644 --- a/device.cc +++ b/device.cc @@ -106,6 +106,24 @@ int Device::recv(void *packet) { return status; } +bool Device::is_connected() { + Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + std::lock_guard lock(mex_dev_com); + if (mp_devhandle==nullptr){ + return false; + } + auto pInfo = hid_enumerate(m_vid, m_pid); + if (pInfo != nullptr){ + hid_free_enumeration(pInfo); + return true; + } + return false; + +// alternative: +// unsigned char buf[1]; +// return hid_read_timeout(mp_devhandle, buf, sizeof(buf), 20) != -1; +} + Stick10::Stick10(): Device(0x20a0, 0x4108, DeviceModel::PRO, 100ms, 20, 100ms) {} diff --git a/include/device.h b/include/device.h index 4001d45..5965f99 100644 --- a/include/device.h +++ b/include/device.h @@ -52,6 +52,8 @@ public: */ virtual int recv(void *packet); + bool is_connected(); + int get_retry_receiving_count() const { return m_retry_receiving_count; }; int get_retry_sending_count() const { return m_retry_sending_count; }; std::chrono::milliseconds get_retry_timeout() const { return m_retry_timeout; }; -- cgit v1.2.3