* @brief Returns (lazily creating) a driver instance for editing source @p deviceId. */
| 297 | * @brief Returns (lazily creating) a driver instance for editing source @p deviceId. |
| 298 | */ |
| 299 | IO::HAL_Driver* IO::ConnectionManager::driverForEditing(int deviceId) |
| 300 | { |
| 301 | const auto& sources = DataModel::ProjectModel::instance().sources(); |
| 302 | const DataModel::Source* srcPtr = nullptr; |
| 303 | for (const auto& src : sources) { |
| 304 | if (src.sourceId == deviceId) { |
| 305 | srcPtr = &src; |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | if (!srcPtr) |
| 311 | return nullptr; |
| 312 | |
| 313 | const auto busType = static_cast<SerialStudio::BusType>(srcPtr->busType); |
| 314 | HAL_Driver* uiDrv = uiDriverForBusType(busType); |
| 315 | if (!uiDrv) |
| 316 | return nullptr; |
| 317 | |
| 318 | if (!srcPtr->connectionSettings.isEmpty()) { |
| 319 | m_syncingFromProject = true; |
| 320 | uiDrv->applyConnectionSettings(srcPtr->connectionSettings); |
| 321 | m_syncingFromProject = false; |
| 322 | } |
| 323 | |
| 324 | if (busType == SerialStudio::BusType::BluetoothLE) { |
| 325 | auto* ble = qobject_cast<IO::Drivers::BluetoothLE*>(uiDrv); |
| 326 | if (ble && ble->deviceCount() == 0) |
| 327 | ble->startDiscovery(); |
| 328 | } |
| 329 | |
| 330 | return uiDrv; |
| 331 | } |
| 332 | |
| 333 | //-------------------------------------------------------------------------------------------------- |
| 334 | // UI driver accessors |
no test coverage detected