Skip to content

Commit

Permalink
Input: finish work on remapping evdev
Browse files Browse the repository at this point in the history
and some more crap
  • Loading branch information
Megamouse committed Oct 25, 2017
1 parent 72418b0 commit 3f0fc05
Show file tree
Hide file tree
Showing 14 changed files with 528 additions and 536 deletions.
4 changes: 2 additions & 2 deletions rpcs3/Emu/Io/PadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ class PadHandlerBase
bool has_config() { return b_has_config; };
bool has_rumble() { return b_has_rumble; };
bool has_deadzones() { return b_has_deadzones; };
pad_config* GetConfig() { return &m_pad_config; };
//Sets window to config the controller(optional)
virtual void ConfigController(const std::string& device) {};
virtual void GetNextButtonPress(const std::string& padId, const std::function<void(std::string)>& callback) {};
virtual void GetNextButtonPress(const std::string& padId, const std::vector<int>& deadzones, const std::function<void(std::string)>& callback) {};
virtual void TranslateButtonPress(u32 keyCode, bool& pressed, u16& value, bool ignore_threshold = false) {};
virtual void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) {};
//Return list of devices for that handler
Expand Down
37 changes: 23 additions & 14 deletions rpcs3/ds4_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,24 @@ ds4_pad_handler::ds4_pad_handler() : is_init(false)
b_has_deadzones = true;
}

void ds4_pad_handler::ConfigController(const std::string& device)
{
pad_settings_dialog dlg(&m_pad_config, device, *this);
dlg.exec();
}

void ds4_pad_handler::GetNextButtonPress(const std::string& padid, const std::function<void(std::string)>& callback)
void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::vector<int>& deadzones, const std::function<void(std::string)>& callback)
{
if (!Init())
{
return;
}

int ltriggerthreshold = deadzones[0];
int rtriggerthreshold = deadzones[1];
int lstickdeadzone = deadzones[2];
int rstickdeadzone = deadzones[3];

// Get the DS4 Device or return if none found
size_t pos = padid.find("Ds4 Pad #");
size_t pos = padId.find("Ds4 Pad #");

if (pos == std::string::npos) return;

std::string pad_serial = padid.substr(pos + 9);
std::string pad_serial = padId.substr(pos + 9);

std::shared_ptr<DS4Device> device = nullptr;

Expand Down Expand Up @@ -207,20 +206,30 @@ void ds4_pad_handler::GetNextButtonPress(const std::string& padid, const std::fu

// Check for each button in our list if its corresponding (maybe remapped) button or axis was pressed.
// Return the new value if the button was pressed (aka. its value was bigger than 0 or the defined threshold)
// Use a pair to get all the legally pressed buttons and use the one with highest value (prioritize first)
std::pair<u16, std::string> pressed_button = { 0, "" };
for (const auto& button : button_list)
{
u32 keycode = button.first;
u16 value = data[keycode];

if (((keycode < DS4KeyCodes::L2) && (value > 0))
|| ((keycode == DS4KeyCodes::L2) && (value > m_pad_config.ltriggerthreshold))
|| ((keycode == DS4KeyCodes::R2) && (value > m_pad_config.rtriggerthreshold))
|| ((keycode >= DS4KeyCodes::LSXNeg && keycode <= DS4KeyCodes::LSYPos) && (value > m_pad_config.lstickdeadzone))
|| ((keycode >= DS4KeyCodes::RSXNeg && keycode <= DS4KeyCodes::RSYPos) && (value > m_pad_config.rstickdeadzone)))
|| ((keycode == DS4KeyCodes::L2) && (value > ltriggerthreshold))
|| ((keycode == DS4KeyCodes::R2) && (value > rtriggerthreshold))
|| ((keycode >= DS4KeyCodes::LSXNeg && keycode <= DS4KeyCodes::LSYPos) && (value > lstickdeadzone))
|| ((keycode >= DS4KeyCodes::RSXNeg && keycode <= DS4KeyCodes::RSYPos) && (value > rstickdeadzone)))
{
return callback(button.second);
if (value > pressed_button.first)
{
pressed_button = { value, button.second};
}
}
}
if (pressed_button.first > 0)
{
LOG_NOTICE(HLE, "GetNextButtonPress: %s button %s pressed with value %d", m_pad_config.cfg_type, pressed_button.second, pressed_button.first);
return callback(pressed_button.second);
}
}

void ds4_pad_handler::TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor)
Expand Down
11 changes: 5 additions & 6 deletions rpcs3/ds4_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class ds4_pad_handler final : public PadHandlerBase
Up,
Down,
R1,
R2,
R3,
L1,
L2,
L3,
Share,
Options,
PSButton,
TouchPad,

L3,
R3,
L2,
R2,

LSXNeg,
LSXPos,
Expand Down Expand Up @@ -135,8 +135,7 @@ 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 ConfigController(const std::string& device) override;
void GetNextButtonPress(const std::string& padid, const std::function<void(std::string)>& buttonCallback) override;
void GetNextButtonPress(const std::string& padId, const std::vector<int>& deadzones, const std::function<void(std::string)>& buttonCallback) override;
void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override;
void TranslateButtonPress(u32 keyCode, bool& pressed, u16& value, bool ignore_threshold = false) override;

Expand Down
Loading

0 comments on commit 3f0fc05

Please sign in to comment.