* @brief Opens the selected HID device and starts the read thread. */
| 158 | * @brief Opens the selected HID device and starts the read thread. |
| 159 | */ |
| 160 | bool IO::Drivers::HID::open(const QIODevice::OpenMode mode) |
| 161 | { |
| 162 | (void)mode; |
| 163 | |
| 164 | if (!configurationOk()) |
| 165 | return false; |
| 166 | |
| 167 | const QString path = m_devicePaths.at(m_deviceIndex); |
| 168 | |
| 169 | m_handle = hid_open_path(path.toUtf8().constData()); |
| 170 | if (!m_handle) { |
| 171 | const wchar_t* err = hid_error(nullptr); |
| 172 | const QString detail = |
| 173 | (err && err[0] != L'\0') ? QString::fromWCharArray(err) : tr("Unknown error"); |
| 174 | QString info = detail; |
| 175 | #ifdef Q_OS_LINUX |
| 176 | info += tr("\n\nCheck that your user is in the 'plugdev' group " |
| 177 | "or that a udev rule grants access to this device."); |
| 178 | #endif |
| 179 | Misc::Utilities::showMessageBox( |
| 180 | tr("Failed to open \"%1\"").arg(m_deviceLabels.value(m_deviceIndex)), |
| 181 | info, |
| 182 | QMessageBox::Warning); |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | hid_set_nonblocking(m_handle, 0); |
| 187 | |
| 188 | const uint16_t up = m_deviceUsagePages.value(m_deviceIndex, 0); |
| 189 | const uint16_t u = m_deviceUsages.value(m_deviceIndex, 0); |
| 190 | m_usagePage = up |
| 191 | ? QStringLiteral("0x") + QString::number(up, 16).rightJustified(4, QLatin1Char('0')) |
| 192 | : QString(); |
| 193 | m_usage = u ? QStringLiteral("0x") + QString::number(u, 16).rightJustified(4, QLatin1Char('0')) |
| 194 | : QString(); |
| 195 | Q_EMIT deviceInfoChanged(); |
| 196 | |
| 197 | m_running = true; |
| 198 | m_readThread.start(); |
| 199 | |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | //-------------------------------------------------------------------------------------------------- |
| 204 | // Property accessors |
nothing calls this directly
no test coverage detected