diff --git a/src/core/UsbHidDevice.cpp b/src/core/UsbHidDevice.cpp index e629894..e04a41b 100644 --- a/src/core/UsbHidDevice.cpp +++ b/src/core/UsbHidDevice.cpp @@ -137,16 +137,25 @@ int UsbHidDevice::connect() ref_count++; if (dev_info->next) { - Logger(TLogLevel::logWARNING) << "found more than one device with vid=" << vid << " pid=" << pid << " Only the first device is used now. serial=" << dev_info->serial_number << std::endl; + Logger(TLogLevel::logWARNING) << "found more than one device with vid=" << vid << " pid=" << pid << " Only the first device is used now" << std::endl; } - Logger(TLogLevel::logDEBUG) << "device opened: vid=" << vid << " pid=" << pid << " product=" << dev_info->product_string << " serial=" << dev_info->serial_number << std::endl; + Logger(TLogLevel::logDEBUG) << "device opened: vid=" << vid << " pid=" << pid << std::endl; hid_free_enumeration(dev_info); return EXIT_SUCCESS; } +int UsbHidDevice::connect(hid_device* _device_handle) +{ + ref_count++; + device_handle = _device_handle; + Logger(TLogLevel::logDEBUG) << "device connect: vid=" << vid << " pid=" << pid << std::endl; + + return EXIT_SUCCESS; +} + void UsbHidDevice::start() { Logger(TLogLevel::logDEBUG) << "UsbHidDevice::start" << std::endl; diff --git a/src/core/UsbHidDevice.h b/src/core/UsbHidDevice.h index f409d58..bce2fdf 100644 --- a/src/core/UsbHidDevice.h +++ b/src/core/UsbHidDevice.h @@ -31,6 +31,7 @@ class UsbHidDevice : public Device unsigned short vid = 0; unsigned short pid = 0; int connect(); + int connect(hid_device* _device_handle); virtual void start(); virtual void stop(int time_out); void release(); diff --git a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp index 95f5a35..d6c1c32 100644 --- a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp +++ b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp @@ -148,6 +148,27 @@ int ArduinoHomeCockpit::read_board_configuration(std::string file_name, unsigned return exit_status; } +int ArduinoHomeCockpit::connect(hid_device* _device_handle) +{ + if (_device_handle == NULL) + { + if (UsbHidDevice::connect() != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "Arduin Home Cockpit connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + else + { + if (UsbHidDevice::connect(_device_handle) != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "Arduin Home Cockpit connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; +} + int ArduinoHomeCockpit::connect() { return UsbHidDevice::connect(); diff --git a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h index 1e04dfa..dfa5869 100644 --- a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h +++ b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h @@ -24,6 +24,7 @@ class ArduinoHomeCockpit :public UsbHidDevice const std::string TOKEN_DISPLAY = "display:id=\"([a-zA-Z0-9_-]+)\",width=([0-9]+)"; public: ArduinoHomeCockpit(DeviceConfiguration& config); + int connect(hid_device* _device_handle); int connect(); void start(); void stop(int timeout); diff --git a/src/devices/saitek-multi/SaitekMultiPanel.cpp b/src/devices/saitek-multi/SaitekMultiPanel.cpp index dcdb002..b220318 100644 --- a/src/devices/saitek-multi/SaitekMultiPanel.cpp +++ b/src/devices/saitek-multi/SaitekMultiPanel.cpp @@ -67,6 +67,27 @@ SaitekMultiPanel::SaitekMultiPanel(DeviceConfiguration& config) :UsbHidDevice(co } } +int SaitekMultiPanel::connect(hid_device* _device_handle) +{ + if (_device_handle == NULL) + { + if (UsbHidDevice::connect() != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "SaitekMultiPanel connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + else + { + if (UsbHidDevice::connect(_device_handle) != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "SaitekMultiPanel connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; +} + int SaitekMultiPanel::connect() { unsigned char buff[WRITE_BUFFER_SIZE]; diff --git a/src/devices/saitek-multi/SaitekMultiPanel.h b/src/devices/saitek-multi/SaitekMultiPanel.h index 9df2017..edcbbab 100644 --- a/src/devices/saitek-multi/SaitekMultiPanel.h +++ b/src/devices/saitek-multi/SaitekMultiPanel.h @@ -19,6 +19,7 @@ class SaitekMultiPanel : public UsbHidDevice std::vector multi_displays; public: SaitekMultiPanel(DeviceConfiguration &config); + int connect(hid_device* _device_handle); int connect(); void start(); void stop(int timeout); diff --git a/src/devices/saitek-radio/SaitekRadioPanel.cpp b/src/devices/saitek-radio/SaitekRadioPanel.cpp index b807b35..36424d9 100644 --- a/src/devices/saitek-radio/SaitekRadioPanel.cpp +++ b/src/devices/saitek-radio/SaitekRadioPanel.cpp @@ -64,10 +64,26 @@ SaitekRadioPanel::SaitekRadioPanel(DeviceConfiguration& config) :UsbHidDevice(co int SaitekRadioPanel::connect() { - if (UsbHidDevice::connect() != EXIT_SUCCESS) + return connect(NULL); +} + +int SaitekRadioPanel::connect(hid_device* _device_handle) +{ + if (_device_handle == NULL) { - Logger(TLogLevel::logERROR) << "SaitekRadioPanel connect. Error during connect" << std::endl; - return EXIT_FAILURE; + if (UsbHidDevice::connect() != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "SaitekRadioPanel connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + else + { + if (UsbHidDevice::connect(_device_handle) != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "SaitekRadioPanel connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } } read_device(read_buffer, read_buffer_size); diff --git a/src/devices/saitek-radio/SaitekRadioPanel.h b/src/devices/saitek-radio/SaitekRadioPanel.h index a5f6bc8..f530bd3 100644 --- a/src/devices/saitek-radio/SaitekRadioPanel.h +++ b/src/devices/saitek-radio/SaitekRadioPanel.h @@ -19,6 +19,7 @@ class SaitekRadioPanel : public UsbHidDevice public: SaitekRadioPanel(DeviceConfiguration& config); int connect(); + int connect(hid_device* _device_handle); void start(); void stop(int timeout); }; diff --git a/src/devices/saitek-switch/SaitekSwitchPanel.cpp b/src/devices/saitek-switch/SaitekSwitchPanel.cpp index a6826f1..2e720b8 100644 --- a/src/devices/saitek-switch/SaitekSwitchPanel.cpp +++ b/src/devices/saitek-switch/SaitekSwitchPanel.cpp @@ -53,6 +53,27 @@ SaitekSwitchPanel::SaitekSwitchPanel(DeviceConfiguration& config) :UsbHidDevice( register_lights(switch_lights); } +int SaitekSwitchPanel::connect(hid_device* _device_handle) +{ + if (_device_handle == NULL) + { + if (UsbHidDevice::connect() != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "SaitekSwitchPanel connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + else + { + if (UsbHidDevice::connect(_device_handle) != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "SaitekSwitchPanel connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; +} + int SaitekSwitchPanel::connect() { unsigned char buff[WRITE_BUFFER_SIZE]; diff --git a/src/devices/saitek-switch/SaitekSwitchPanel.h b/src/devices/saitek-switch/SaitekSwitchPanel.h index 3af8ce4..f64dcff 100644 --- a/src/devices/saitek-switch/SaitekSwitchPanel.h +++ b/src/devices/saitek-switch/SaitekSwitchPanel.h @@ -17,6 +17,7 @@ class SaitekSwitchPanel : public UsbHidDevice std::vector switch_lights; public: SaitekSwitchPanel(DeviceConfiguration& config); + int connect(hid_device* _device_handle); int connect(); void start(); void stop(int timeout); diff --git a/src/devices/trc-1000/TRC1000.cpp b/src/devices/trc-1000/TRC1000.cpp index 82602b3..e94dc88 100644 --- a/src/devices/trc-1000/TRC1000.cpp +++ b/src/devices/trc-1000/TRC1000.cpp @@ -121,6 +121,27 @@ void TRC1000::thread_func() Logger(TLogLevel::logDEBUG) << "TRC1000 thread_func: exit vid=" << vid << " pid=" << pid << std::endl; } +int TRC1000::connect(hid_device* _device_handle) +{ + if (_device_handle == NULL) + { + if (UsbHidDevice::connect() != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "TRC1000 connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + else + { + if (UsbHidDevice::connect(_device_handle) != EXIT_SUCCESS) + { + Logger(TLogLevel::logERROR) << "TRC1000 connect. Error during connect" << std::endl; + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; +} + int TRC1000::connect() { if (UsbHidDevice::connect() != EXIT_SUCCESS) diff --git a/src/devices/trc-1000/TRC1000.h b/src/devices/trc-1000/TRC1000.h index 3ada98c..87460da 100644 --- a/src/devices/trc-1000/TRC1000.h +++ b/src/devices/trc-1000/TRC1000.h @@ -34,6 +34,7 @@ class TRC1000 : public UsbHidDevice TRC1000(DeviceConfiguration& config, int _read_buffer_size, int _write_buffer_size); ~TRC1000(); virtual void thread_func(); + int connect(hid_device* _device_handle); int connect(); void start(); void stop(int timeout);