mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 10:42:36 +01:00
input: implement HidDevice::close
Preparing for further ps move additions down the line.
This commit is contained in:
parent
eab1c1260c
commit
289b70d276
@ -519,8 +519,7 @@ PadHandlerBase::connection ds3_pad_handler::update_connection(const std::shared_
|
||||
if (get_data(dev) == DataStatus::ReadError)
|
||||
{
|
||||
// this also can mean disconnected, either way deal with it on next loop and reconnect
|
||||
hid_close(dev->hidDevice);
|
||||
dev->hidDevice = nullptr;
|
||||
dev->close();
|
||||
|
||||
return connection::no_data;
|
||||
}
|
||||
|
@ -527,8 +527,7 @@ void ds4_pad_handler::check_add_device(hid_device* hidDevice, std::string_view p
|
||||
if (!GetCalibrationData(device))
|
||||
{
|
||||
ds4_log.error("check_add_device: GetCalibrationData failed!");
|
||||
hid_close(hidDevice);
|
||||
device->hidDevice = nullptr;
|
||||
device->close();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -553,8 +552,7 @@ void ds4_pad_handler::check_add_device(hid_device* hidDevice, std::string_view p
|
||||
if (hid_set_nonblocking(hidDevice, 1) == -1)
|
||||
{
|
||||
ds4_log.error("check_add_device: hid_set_nonblocking failed! Reason: %s", hid_error(hidDevice));
|
||||
hid_close(hidDevice);
|
||||
device->hidDevice = nullptr;
|
||||
device->close();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -790,8 +788,7 @@ PadHandlerBase::connection ds4_pad_handler::update_connection(const std::shared_
|
||||
if (get_data(ds4_dev) == DataStatus::ReadError)
|
||||
{
|
||||
// this also can mean disconnected, either way deal with it on next loop and reconnect
|
||||
hid_close(ds4_dev->hidDevice);
|
||||
ds4_dev->hidDevice = nullptr;
|
||||
ds4_dev->close();
|
||||
|
||||
return connection::no_data;
|
||||
}
|
||||
|
@ -155,8 +155,7 @@ void dualsense_pad_handler::check_add_device(hid_device* hidDevice, std::string_
|
||||
if (!get_calibration_data(device))
|
||||
{
|
||||
dualsense_log.error("check_add_device: get_calibration_data failed!");
|
||||
hid_close(hidDevice);
|
||||
device->hidDevice = nullptr;
|
||||
device->close();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -182,8 +181,7 @@ void dualsense_pad_handler::check_add_device(hid_device* hidDevice, std::string_
|
||||
if (hid_set_nonblocking(hidDevice, 1) == -1)
|
||||
{
|
||||
dualsense_log.error("check_add_device: hid_set_nonblocking failed! Reason: %s", hid_error(hidDevice));
|
||||
hid_close(hidDevice);
|
||||
device->hidDevice = nullptr;
|
||||
device->close();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -569,8 +567,7 @@ PadHandlerBase::connection dualsense_pad_handler::update_connection(const std::s
|
||||
if (get_data(dualsense_dev) == DataStatus::ReadError)
|
||||
{
|
||||
// this also can mean disconnected, either way deal with it on next loop and reconnect
|
||||
hid_close(dualsense_dev->hidDevice);
|
||||
dualsense_dev->hidDevice = nullptr;
|
||||
dualsense_dev->close();
|
||||
|
||||
return connection::no_data;
|
||||
}
|
||||
|
@ -20,6 +20,15 @@ LOG_CHANNEL(hid_log, "HID");
|
||||
static std::mutex s_hid_mutex; // hid_pad_handler is created by pad_thread and pad_settings_dialog
|
||||
static u8 s_hid_instances{0};
|
||||
|
||||
void HidDevice::close()
|
||||
{
|
||||
if (hidDevice)
|
||||
{
|
||||
hid_close(hidDevice);
|
||||
hidDevice = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Device>
|
||||
hid_pad_handler<Device>::hid_pad_handler(pad_handler type, std::vector<id_pair> ids)
|
||||
: PadHandlerBase(type), m_ids(std::move(ids))
|
||||
@ -40,9 +49,9 @@ hid_pad_handler<Device>::~hid_pad_handler()
|
||||
|
||||
for (auto& controller : m_controllers)
|
||||
{
|
||||
if (controller.second && controller.second->hidDevice)
|
||||
if (controller.second)
|
||||
{
|
||||
hid_close(controller.second->hidDevice);
|
||||
controller.second->close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,7 +179,7 @@ void hid_pad_handler<Device>::update_devices()
|
||||
{
|
||||
if (controller.second && !controller.second->path.empty() && !m_new_enumerated_devices.contains(controller.second->path))
|
||||
{
|
||||
hid_close(controller.second->hidDevice);
|
||||
controller.second->close();
|
||||
cfg_pad* config = controller.second->config;
|
||||
controller.second.reset(new Device());
|
||||
controller.second->config = config;
|
||||
|
@ -30,6 +30,8 @@ enum CalibIndex
|
||||
class HidDevice : public PadDevice
|
||||
{
|
||||
public:
|
||||
void close();
|
||||
|
||||
hid_device* hidDevice{nullptr};
|
||||
std::string path;
|
||||
bool new_output_data{true};
|
||||
|
@ -204,7 +204,7 @@ skateboard_pad_handler::DataStatus skateboard_pad_handler::get_data(skateboard_d
|
||||
if (res == -1)
|
||||
{
|
||||
// looks like controller disconnected or read error
|
||||
skateboard_log.error("get_data ReadError", device->path);
|
||||
skateboard_log.error("get_data ReadError: %s", hid_error(device->hidDevice));
|
||||
return DataStatus::ReadError;
|
||||
}
|
||||
|
||||
@ -254,8 +254,7 @@ PadHandlerBase::connection skateboard_pad_handler::update_connection(const std::
|
||||
if (get_data(skateboard_dev) == DataStatus::ReadError)
|
||||
{
|
||||
// this also can mean disconnected, either way deal with it on next loop and reconnect
|
||||
hid_close(skateboard_dev->hidDevice);
|
||||
skateboard_dev->hidDevice = nullptr;
|
||||
skateboard_dev->close();
|
||||
|
||||
return connection::no_data;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user