Skip to content

Commit

Permalink
HID Devices: add connect() with pre-opened devices
Browse files Browse the repository at this point in the history
Signed-off-by: Norbert Takacs <[email protected]>
  • Loading branch information
norberttak committed Mar 30, 2024
1 parent c4ff75f commit b7a7085
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,26 @@ 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;
}
}
}

int ArduinoHomeCockpit::connect()
{
return UsbHidDevice::connect();
Expand Down
1 change: 1 addition & 0 deletions src/devices/arduino-homecockpit/ArduinoHomeCockpit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/devices/saitek-multi/SaitekMultiPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ 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;
}
}
}

int SaitekMultiPanel::connect()
{
unsigned char buff[WRITE_BUFFER_SIZE];
Expand Down
1 change: 1 addition & 0 deletions src/devices/saitek-multi/SaitekMultiPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SaitekMultiPanel : public UsbHidDevice
std::vector<PanelDisplay> multi_displays;
public:
SaitekMultiPanel(DeviceConfiguration &config);
int connect(hid_device* _device_handle);
int connect();
void start();
void stop(int timeout);
Expand Down
22 changes: 19 additions & 3 deletions src/devices/saitek-radio/SaitekRadioPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/devices/saitek-radio/SaitekRadioPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
20 changes: 20 additions & 0 deletions src/devices/saitek-switch/SaitekSwitchPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ 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;
}
}
}

int SaitekSwitchPanel::connect()
{
unsigned char buff[WRITE_BUFFER_SIZE];
Expand Down
1 change: 1 addition & 0 deletions src/devices/saitek-switch/SaitekSwitchPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SaitekSwitchPanel : public UsbHidDevice
std::vector<PanelLight> switch_lights;
public:
SaitekSwitchPanel(DeviceConfiguration& config);
int connect(hid_device* _device_handle);
int connect();
void start();
void stop(int timeout);
Expand Down
20 changes: 20 additions & 0 deletions src/devices/trc-1000/TRC1000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ 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;
}
}
}

int TRC1000::connect()
{
if (UsbHidDevice::connect() != EXIT_SUCCESS)
Expand Down
1 change: 1 addition & 0 deletions src/devices/trc-1000/TRC1000.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b7a7085

Please sign in to comment.