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 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_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_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 CELL_PAD_DEV_TYPE_STANDARD
@ -875,6 +875,7 @@ void ds4_pad_handler::ThreadProc()
else if (last_connection_status[i] == false) else if (last_connection_status[i] == false)
{ {
LOG_NOTICE(HLE, "DS4 device %d connected", i); 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; last_connection_status[i] = true;
connected++; connected++;
} }

View file

@ -113,7 +113,7 @@ bool evdev_joystick_handler::Init()
return true; 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; std::shared_ptr<Pad> pad = device.pad;
const auto& path = device.path; const auto& path = device.path;
@ -125,19 +125,12 @@ bool evdev_joystick_handler::update_device(EvdevDevice& device, bool use_cell)
{ {
if (was_connected) if (was_connected)
{ {
// It was disconnected.
if (use_cell)
pad->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
int fd = libevdev_get_fd(dev); int fd = libevdev_get_fd(dev);
libevdev_free(dev); libevdev_free(dev);
close(fd); close(fd);
dev = nullptr; 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); LOG_ERROR(GENERAL, "Joystick %s is not present or accessible [previous status: %d]", path.c_str(), was_connected ? 1 : 0);
return false; 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); 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; return true;
} }
void evdev_joystick_handler::update_devs(bool use_cell) void evdev_joystick_handler::update_devs()
{ {
for (auto& device : devices) 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]; EvdevDevice& dev = devices[m_pad_index];
// Check if our device is connected // Check if our device is connected
if (!update_device(dev, false)) if (!update_device(dev))
return nullptr; return nullptr;
return &dev; return &dev;
@ -692,7 +677,10 @@ void evdev_joystick_handler::ThreadProc()
{ {
if (last_connection_status[padnum] == true) if (last_connection_status[padnum] == true)
{ {
// It was disconnected.
LOG_ERROR(HLE, "evdev device %d disconnected", padnum); 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; last_connection_status[padnum] = false;
connected--; connected--;
} }
@ -702,7 +690,10 @@ void evdev_joystick_handler::ThreadProc()
if (last_connection_status[padnum] == false) if (last_connection_status[padnum] == false)
{ {
// Connection status changed from disconnected to connected.
LOG_ERROR(HLE, "evdev device %d reconnected", padnum); 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; last_connection_status[padnum] = true;
connected++; connected++;
} }
@ -915,7 +906,7 @@ bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std
pad->Init 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_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_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 CELL_PAD_DEV_TYPE_STANDARD

View file

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

View file

@ -1,6 +1,7 @@
#include "keyboard_pad_handler.h" #include "keyboard_pad_handler.h"
#include <QApplication> #include <QApplication>
#include <QThread>
inline std::string sstr(const QString& _in) { return _in.toStdString(); } inline std::string sstr(const QString& _in) { return _in.toStdString(); }
constexpr auto qstr = QString::fromStdString; 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 //Fixed assign change, default is both sensor and press off
pad->Init 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_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_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 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); pad->m_vibrateMotors.emplace_back(false, 0);
bindings.push_back(pad); bindings.push_back(pad);
connected++;
return true; return true;
} }
void keyboard_pad_handler::ThreadProc() 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 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_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_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 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 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_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_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 CELL_PAD_DEV_TYPE_STANDARD