void DeviceDescriptor::SetConfig(const DeviceConfig &_config) { ResetFailureCounter(); config = _config; if (config.UsesDriver()) { driver = FindDriverByName(config.driver_name); assert(driver != nullptr); } else driver = nullptr; }
bool DeviceDescriptor::DoOpen(OperationEnvironment &env) { assert(config.IsAvailable()); if (config.port_type == DeviceConfig::PortType::INTERNAL) return OpenInternalSensors(); if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2) return OpenDroidSoarV2(); if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR) return OpenI2Cbaro(); if (config.port_type == DeviceConfig::PortType::NUNCHUCK) return OpenNunchuck(); if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE) return OpenVoltage(); reopen_clock.Update(); Port *port = OpenPort(config, port_listener, *this); if (port == nullptr) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); StaticString<256> msg; msg.Format(_T("%s: %s."), _("Unable to open port"), name); env.SetErrorMessage(msg); return false; } DumpPort *dump_port = new DumpPort(port); dump_port->Disable(); if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) { if (!env.IsCancelled()) ++n_failures; delete dump_port; return false; } ResetFailureCounter(); return true; }
void DeviceDescriptor::SetConfig(const DeviceConfig &_config) { ResetFailureCounter(); config = _config; if (config.UsesDriver()) { driver = FindDriverByName(config.driver_name); assert(driver != nullptr); second_driver = nullptr; if (driver->HasPassThrough() && config.use_second_device){ second_driver = FindDriverByName(config.driver2_name); assert(second_driver != nullptr); } } else{ driver = nullptr; second_driver = nullptr; } }
bool DeviceDescriptor::DoOpen(OperationEnvironment &env) { assert(config.IsAvailable()); { ScopeLock protect(mutex); error_message.clear(); } if (config.port_type == DeviceConfig::PortType::INTERNAL) return OpenInternalSensors(); if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2) return OpenDroidSoarV2(); if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR) return OpenI2Cbaro(); if (config.port_type == DeviceConfig::PortType::NUNCHUCK) return OpenNunchuck(); if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE) return OpenVoltage(); reopen_clock.Update(); Port *port; try { port = OpenPort(io_service, config, this, *this); } catch (const std::runtime_error &e) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); LogError(WideToUTF8Converter(name), e); StaticString<256> msg; const UTF8ToWideConverter what(e.what()); if (what.IsValid()) { ScopeLock protect(mutex); error_message = what; } msg.Format(_T("%s: %s (%s)"), _("Unable to open port"), name, (const TCHAR *)what); env.SetErrorMessage(msg); return false; } if (port == nullptr) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); StaticString<256> msg; msg.Format(_T("%s: %s."), _("Unable to open port"), name); env.SetErrorMessage(msg); return false; } DumpPort *dump_port = new DumpPort(port); dump_port->Disable(); if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) { if (!env.IsCancelled()) ++n_failures; delete dump_port; return false; } ResetFailureCounter(); return true; }