MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / open

Method open

app/src/IO/Drivers/HID.cpp:160–201  ·  view source on GitHub ↗

* @brief Opens the selected HID device and starts the read thread. */

Source from the content-addressed store, hash-verified

158 * @brief Opens the selected HID device and starts the read thread.
159 */
160bool 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

Callers

nothing calls this directly

Calls 4

hid_errorFunction · 0.50
hid_set_nonblockingFunction · 0.50
valueMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected