Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Input] Final Fixes (MMJOY + evdev) #3817

Merged
merged 8 commits into from
Dec 21, 2017
41 changes: 40 additions & 1 deletion rpcs3/Emu/Io/PadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ class PadHandlerBase
protected:
static const u32 MAX_GAMEPADS = 7;

std::array<bool, MAX_GAMEPADS> last_connection_status{{ false, false, false, false, false, false, false }};
Copy link
Contributor

@elad335 elad335 Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use bitset instead?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 7 boolean values? Seriously?


int m_trigger_threshold = 0;
int m_thumb_threshold = 0;

Expand Down Expand Up @@ -383,6 +385,42 @@ class PadHandlerBase
return def_code;
};

// Search an unordered map for a string value and return found keycode
int FindKeyCodeByString(std::unordered_map<u32, std::string> map, const std::string& name, bool fallback = true)
{
for (auto it = map.begin(); it != map.end(); ++it)
{
if (it->second == name)
return it->first;
}

if (fallback)
{
LOG_ERROR(HLE, "long FindKeyCodeByString fohr [name = %s] returned with 0", name);
return 0;
}

return -1;
};

// Search an unordered map for a string value and return found keycode
long FindKeyCodeByString(std::unordered_map<u64, std::string> map, const std::string& name, bool fallback = true)
{
for (auto it = map.begin(); it != map.end(); ++it)
{
if (it->second == name)
return it->first;
}

if (fallback)
{
LOG_ERROR(HLE, "long FindKeyCodeByString fohr [name = %s] returned with 0", name);
return 0;
}

return -1;
};

// Get normalized trigger value based on the range defined by a threshold
u16 NormalizeTriggerInput(u16 value, int threshold)
{
Expand Down Expand Up @@ -544,6 +582,7 @@ class PadHandlerBase
s32 trigger_max = 255;
s32 vibration_min = 0;
s32 vibration_max = 255;
u32 connected = 0;

virtual bool Init() { return true; };
virtual ~PadHandlerBase() = default;
Expand All @@ -554,7 +593,7 @@ class PadHandlerBase
bool has_deadzones() { return b_has_deadzones; };
pad_config* GetConfig() { return &m_pad_config; };
//Sets window to config the controller(optional)
virtual void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist = false) {};
virtual void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) {};
virtual void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) {};
//Return list of devices for that handler
virtual std::vector<std::string> ListDevices() = 0;
Expand Down
20 changes: 16 additions & 4 deletions rpcs3/ds4_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ ds4_pad_handler::ds4_pad_handler() : is_init(false)
m_thumb_threshold = thumb_max / 2;
}

void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist)
void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist, std::vector<std::string> buttons)
{
if (get_blacklist)
blacklist.clear();
Expand Down Expand Up @@ -809,17 +809,23 @@ bool ds4_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::strin

void ds4_pad_handler::ThreadProc()
{
for (auto &bind : bindings)
for (int i = 0; i < static_cast<int>(bindings.size()); i++)
{
std::shared_ptr<DS4Device> device = bind.first;
auto thepad = bind.second;
std::shared_ptr<DS4Device> device = bindings[i].first;
auto thepad = bindings[i].second;

if (device->hidDevice == nullptr)
{
// try to reconnect
hid_device* dev = hid_open_path(device->path.c_str());
if (dev)
{
if (last_connection_status[i] == false)
{
LOG_ERROR(HLE, "DS4 device %d reconnected", i);
last_connection_status[i] = true;
connected++;
}
hid_set_nonblocking(dev, 1);
device->hidDevice = dev;
thepad->m_port_status = CELL_PAD_STATUS_CONNECTED|CELL_PAD_STATUS_ASSIGN_CHANGES;
Expand All @@ -829,6 +835,12 @@ void ds4_pad_handler::ThreadProc()
else
{
// nope, not there
if (last_connection_status[i] == true)
{
LOG_ERROR(HLE, "DS4 device %d disconnected", i);
last_connection_status[i] = false;
connected--;
}
thepad->m_port_status = CELL_PAD_STATUS_DISCONNECTED|CELL_PAD_STATUS_ASSIGN_CHANGES;
continue;
}
Expand Down
4 changes: 1 addition & 3 deletions rpcs3/ds4_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ class ds4_pad_handler final : public PadHandlerBase
std::vector<std::string> ListDevices() override;
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& buttonCallback, bool get_blacklist = false) override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& buttonCallback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override;
void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override;

private:
bool is_init;

// holds internal controller state change
std::array<bool, MAX_GAMEPADS> last_connection_status = {};
std::vector<u32> blacklist;
std::vector<std::pair<std::shared_ptr<DS4Device>, std::shared_ptr<Pad>>> bindings;

Expand Down
Loading