Input: init pads as disconnected

inlcudes simpsons "hack" as comment
This commit is contained in:
Megamouse 2018-01-13 00:55:51 +01:00 committed by Ivan
parent c951601fa4
commit 9b4868f017
6 changed files with 32 additions and 29 deletions

View File

@ -789,7 +789,7 @@ bool ds4_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::strin
pad->Init
(
CELL_PAD_STATUS_CONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES,
CELL_PAD_STATUS_DISCONNECTED,
CELL_PAD_SETTING_PRESS_OFF | CELL_PAD_SETTING_SENSOR_OFF,
CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_HP_ANALOG_STICK | CELL_PAD_CAPABILITY_ACTUATOR | CELL_PAD_CAPABILITY_SENSOR_MODE,
CELL_PAD_DEV_TYPE_STANDARD
@ -855,7 +855,7 @@ void ds4_pad_handler::ThreadProc()
}
hid_set_nonblocking(dev, 1);
m_dev->hidDevice = dev;
thepad->m_port_status = CELL_PAD_STATUS_CONNECTED|CELL_PAD_STATUS_ASSIGN_CHANGES;
thepad->m_port_status = CELL_PAD_STATUS_CONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES;
if (!m_dev->hasCalibData)
m_dev->hasCalibData = GetCalibrationData(m_dev);
}
@ -868,13 +868,14 @@ void ds4_pad_handler::ThreadProc()
last_connection_status[i] = false;
connected--;
}
thepad->m_port_status = CELL_PAD_STATUS_DISCONNECTED|CELL_PAD_STATUS_ASSIGN_CHANGES;
thepad->m_port_status = CELL_PAD_STATUS_DISCONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES;
continue;
}
}
else if (last_connection_status[i] == false)
{
LOG_NOTICE(HLE, "DS4 device %d connected", i);
thepad->m_port_status = CELL_PAD_STATUS_CONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES;
last_connection_status[i] = true;
connected++;
}

View File

@ -113,7 +113,7 @@ bool evdev_joystick_handler::Init()
return true;
}
bool evdev_joystick_handler::update_device(EvdevDevice& device, bool use_cell)
bool evdev_joystick_handler::update_device(EvdevDevice& device)
{
std::shared_ptr<Pad> pad = device.pad;
const auto& path = device.path;
@ -125,19 +125,12 @@ bool evdev_joystick_handler::update_device(EvdevDevice& device, bool use_cell)
{
if (was_connected)
{
// It was disconnected.
if (use_cell)
pad->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
int fd = libevdev_get_fd(dev);
libevdev_free(dev);
close(fd);
dev = nullptr;
}
if (use_cell)
pad->m_port_status &= ~CELL_PAD_STATUS_CONNECTED;
LOG_ERROR(GENERAL, "Joystick %s is not present or accessible [previous status: %d]", path.c_str(), was_connected ? 1 : 0);
return false;
}
@ -161,22 +154,14 @@ bool evdev_joystick_handler::update_device(EvdevDevice& device, bool use_cell)
}
LOG_NOTICE(GENERAL, "Opened joystick: '%s' at %s (fd %d)", libevdev_get_name(dev), path, fd);
if (use_cell)
{
// Connection status changed from disconnected to connected.
pad->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
pad->m_port_status |= CELL_PAD_STATUS_CONNECTED;
}
return true;
}
void evdev_joystick_handler::update_devs(bool use_cell)
void evdev_joystick_handler::update_devs()
{
for (auto& device : devices)
{
update_device(device, use_cell);
update_device(device);
}
}
@ -252,7 +237,7 @@ evdev_joystick_handler::EvdevDevice* evdev_joystick_handler::get_device(const st
EvdevDevice& dev = devices[m_pad_index];
// Check if our device is connected
if (!update_device(dev, false))
if (!update_device(dev))
return nullptr;
return &dev;
@ -692,7 +677,10 @@ void evdev_joystick_handler::ThreadProc()
{
if (last_connection_status[padnum] == true)
{
// It was disconnected.
LOG_ERROR(HLE, "evdev device %d disconnected", padnum);
pad->m_port_status &= ~CELL_PAD_STATUS_CONNECTED;
pad->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
last_connection_status[padnum] = false;
connected--;
}
@ -702,7 +690,10 @@ void evdev_joystick_handler::ThreadProc()
if (last_connection_status[padnum] == false)
{
// Connection status changed from disconnected to connected.
LOG_ERROR(HLE, "evdev device %d reconnected", padnum);
pad->m_port_status |= CELL_PAD_STATUS_CONNECTED;
pad->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
last_connection_status[padnum] = true;
connected++;
}
@ -915,7 +906,7 @@ bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std
pad->Init
(
CELL_PAD_STATUS_CONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES,
CELL_PAD_STATUS_DISCONNECTED,
CELL_PAD_SETTING_PRESS_OFF | CELL_PAD_SETTING_SENSOR_OFF,
CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_HP_ANALOG_STICK | CELL_PAD_CAPABILITY_ACTUATOR | CELL_PAD_CAPABILITY_SENSOR_MODE,
CELL_PAD_DEV_TYPE_STANDARD

View File

@ -341,8 +341,8 @@ public:
private:
void TranslateButtonPress(u64 keyCode, bool& pressed, u16& value, bool ignore_threshold = false) override;
EvdevDevice* get_device(const std::string& device);
bool update_device(EvdevDevice& device, bool use_cell = true);
void update_devs(bool use_cell = true);
bool update_device(EvdevDevice& device);
void update_devs();
int add_device(const std::string& device, bool in_settings = false);
int GetButtonInfo(const input_event& evt, const EvdevDevice& device, int& button_code);
std::unordered_map<u64, std::pair<u16, bool>> GetButtonValues(const EvdevDevice& device);

View File

@ -1,6 +1,7 @@
#include "keyboard_pad_handler.h"
#include <QApplication>
#include <QThread>
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
constexpr auto qstr = QString::fromStdString;
@ -398,7 +399,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::
//Fixed assign change, default is both sensor and press off
pad->Init
(
CELL_PAD_STATUS_CONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES,
CELL_PAD_STATUS_DISCONNECTED,
CELL_PAD_SETTING_PRESS_OFF | CELL_PAD_SETTING_SENSOR_OFF,
CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_HP_ANALOG_STICK | CELL_PAD_CAPABILITY_ACTUATOR | CELL_PAD_CAPABILITY_SENSOR_MODE,
CELL_PAD_DEV_TYPE_STANDARD
@ -437,11 +438,21 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::
pad->m_vibrateMotors.emplace_back(false, 0);
bindings.push_back(pad);
connected++;
return true;
}
void keyboard_pad_handler::ThreadProc()
{
for (int i = 0; i < bindings.size(); i++)
{
if (last_connection_status[i] == false)
{
//QThread::msleep(100); // Hack Simpsons. It calls a seemingly useless cellPadGetInfo at boot that would swallow the first CELL_PAD_STATUS_ASSIGN_CHANGES otherwise
bindings[i]->m_port_status |= CELL_PAD_STATUS_CONNECTED;
bindings[i]->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
last_connection_status[i] = true;
connected++;
}
}
}

View File

@ -144,7 +144,7 @@ bool mm_joystick_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::s
pad->Init
(
CELL_PAD_STATUS_CONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES,
CELL_PAD_STATUS_DISCONNECTED,
CELL_PAD_SETTING_PRESS_OFF | CELL_PAD_SETTING_SENSOR_OFF,
CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_HP_ANALOG_STICK | CELL_PAD_CAPABILITY_ACTUATOR | CELL_PAD_CAPABILITY_SENSOR_MODE,
CELL_PAD_DEV_TYPE_STANDARD

View File

@ -475,7 +475,7 @@ bool xinput_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::st
pad->Init
(
CELL_PAD_STATUS_CONNECTED | CELL_PAD_STATUS_ASSIGN_CHANGES,
CELL_PAD_STATUS_DISCONNECTED,
CELL_PAD_SETTING_PRESS_OFF | CELL_PAD_SETTING_SENSOR_OFF,
CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_HP_ANALOG_STICK | CELL_PAD_CAPABILITY_ACTUATOR | CELL_PAD_CAPABILITY_SENSOR_MODE,
CELL_PAD_DEV_TYPE_STANDARD