diff options
Diffstat (limited to 'device.cc')
-rw-r--r-- | device.cc | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -20,6 +20,7 @@ */ #include <chrono> +#include <iostream> #include <thread> #include <cstddef> #include <stdexcept> @@ -92,12 +93,20 @@ bool Device::_connect() { LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); // hid_init(); // done automatically on hid_open - mp_devhandle = hid_open(m_vid, m_pid, nullptr); + if (m_path.empty()){ + mp_devhandle = hid_open(m_vid, m_pid, nullptr); + } else { + mp_devhandle = hid_open_path(m_path.c_str()); + } const bool success = mp_devhandle != nullptr; LOG(std::string("Connection success: ") + std::to_string(success), Loglevel::DEBUG_L2); return success; } +void Device::set_path(const std::string path){ + m_path = path; +} + int Device::send(const void *packet) { LOG(__FUNCTION__, Loglevel::DEBUG_L2); std::lock_guard<std::mutex> lock(mex_dev_com); @@ -160,6 +169,24 @@ int Device::recv(void *packet) { return status; } +std::vector<std::string> Device::enumerate(){ + //TODO make static + auto pInfo = hid_enumerate(m_vid, m_pid); + auto pInfo_ = pInfo; + std::vector<std::string> res; + while (pInfo != nullptr){ + std::string a (pInfo->path); + res.push_back(a); + pInfo = pInfo->next; + } + + if (pInfo_ != nullptr){ + hid_free_enumeration(pInfo_); + } + + return res; +} + bool Device::could_be_enumerated() { LOG(__FUNCTION__, Loglevel::DEBUG_L2); std::lock_guard<std::mutex> lock(mex_dev_com); |