Skip to content

Commit

Permalink
Add method for checking is the device listed as connected in OS
Browse files Browse the repository at this point in the history
Signed-off-by: Szczepan Zalega <[email protected]>
  • Loading branch information
szszszsz committed Mar 11, 2017
1 parent 0503db5 commit d69cf0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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)
{}
Expand Down
2 changes: 2 additions & 0 deletions include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Device {
*/
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; };
Expand Down

0 comments on commit d69cf0b

Please sign in to comment.