Skip to content

Commit

Permalink
Bugfixes for 3.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Electronicks committed Sep 20, 2023
1 parent a502e76 commit 0894736
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 54 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ This is a summary of new features and bugfixes. Read the README to learn how to
## Known issues
* SDL always merges joycons behind the scene into a single controller. JSM is not able to split them. Use legacy-JSL version to use this feature.

## 3.5.1

Nick fixes everything he broke with his "improvements"

### Bugfixes
* Restore digital binding of virtual gamepad trigggers X_LT, X_RT, PS_L2 AND PS_R2.
* Fix turbo binding of virtual controller buttons. Use Toggle as well for 50-50 press time instead of 40ms.
* Fix Dualsense Edge new button bindings (left buttons were inverted: LSL and RSR are grips)
* Add VIRTUAL_CONTROLLER and HIDE_MINIMIZED as settings exempted from resetting on RESET_BINDINGS
* Restore scroll stick mode
* Fix Ds4 virtual controller connect with UP stuck
* Fix Ds4 virtual controller touch adding a second ghost touch at 0,0
* Fix Ds4 virtual controller HOME and CAPTURE buttons
* Robustness fix at cleanup
* Fix Armor X Pro PS mode's M2 button

## 3.5.0

Nick updates C++ standard to C++20, Add Setting Manager, Create Stick and Autoload objects, Update ViGEm, SDL2 and JSL dependencies to latest,
Expand Down
26 changes: 4 additions & 22 deletions JoyShockMapper/src/DigitalButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,12 @@ struct DigitalButtonImpl : public pocket_fsm::PimplBase, public EventActionIf

void ApplyBtnPress(KeyCode key) override
{
if (key.code >= X_UP && key.code <= X_START || key.code == PS_HOME || key.code == PS_PAD_CLICK)
if (key.code >= X_UP && key.code <= X_START || key.code == PS_HOME ||
key.code == PS_PAD_CLICK || key.code == X_LT || key.code == X_RT)
{
if (_context->_vigemController)
_context->_vigemController->setButton(key, true);
}
else if (key.code == X_LT)
{
if (_context->_vigemController)
_context->_vigemController->setLeftTrigger(1.f);
}
else if (key.code == X_RT)
{
if (_context->_vigemController)
_context->_vigemController->setRightTrigger(1.f);
}
else if (key.code == VK_NONAME)
{
if (_context->nn == 0)
Expand All @@ -201,24 +192,15 @@ struct DigitalButtonImpl : public pocket_fsm::PimplBase, public EventActionIf

void ApplyBtnRelease(KeyCode key) override
{
if (key.code >= X_UP && key.code <= X_START || key.code == PS_HOME || key.code == PS_PAD_CLICK)
if (key.code >= X_UP && key.code <= X_START || key.code == PS_HOME ||
key.code == PS_PAD_CLICK || key.code == X_LT || key.code == X_RT)
{
if (_context->_vigemController)
{
_context->_vigemController->setButton(key, false);
ClearAllActiveToggle(key);
}
}
else if (key.code == X_LT)
{
if (_context->_vigemController)
_context->_vigemController->setLeftTrigger(0.f);
}
else if (key.code == X_RT)
{
if (_context->_vigemController)
_context->_vigemController->setRightTrigger(0.f);
}
else if (key.code != NO_HOLD_MAPPED)
{
// DEBUG_LOG << "Releasing key " << key.name << endl;
Expand Down
6 changes: 4 additions & 2 deletions JoyShockMapper/src/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
{
case ActionModifier::Toggle:
apply = bind(&EventActionIf::ApplyButtonToggle, placeholders::_1, key, apply, release);
release = EventActionIf::Callback();
break;
case ActionModifier::Instant:
{
Expand All @@ -232,13 +231,16 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
}

// Insert release first because in turbo's case apply and release are the same but we want release to apply first
InsertEventMapping(releaseEvt, release);
InsertEventMapping(applyEvt, apply);
if (evtMod == EventModifier::TurboPress)
{
// On turbo you also always need to clear the turbo on release
InsertEventMapping(BtnEvent::OnRelease, release);
}
else
{
InsertEventMapping(releaseEvt, release);
}

stringstream ss;
// Update Description
Expand Down
6 changes: 3 additions & 3 deletions JoyShockMapper/src/SDL2Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct ControllerDevice
}
if (vid == 0x24c6) // PowerA
{
_ctrlr_type = JS_TYPE_XBOX_SERIES;
_ctrlr_type = JS_TYPE_XBOX_SERIES;
}
if (vid == 0x045e) // Microsoft Vendor ID
{
Expand Down Expand Up @@ -472,9 +472,9 @@ struct SdlInstance : public JslWrapper
case JS_TYPE_DS:
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_MISC1) > 0 ? 1 << JSOFFSET_MIC : 0;
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_PADDLE1) > 0 ? 1 << JSOFFSET_SR : 0;
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_PADDLE2) > 0 ? 1 << JSOFFSET_FNL : 0;
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_PADDLE2) > 0 ? 1 << JSOFFSET_SL : 0;
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_PADDLE3) > 0 ? 1 << JSOFFSET_FNR : 0;
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_PADDLE4) > 0 ? 1 << JSOFFSET_SL : 0;
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_PADDLE4) > 0 ? 1 << JSOFFSET_FNL : 0;
// Intentional fall through to the next case
case JS_TYPE_DS4:
buttons |= SDL_GameControllerGetButton(_controllerMap[deviceId]->_sdlController, SDL_CONTROLLER_BUTTON_TOUCHPAD) > 0 ? 1 << JSOFFSET_CAPTURE : 0;
Expand Down
4 changes: 3 additions & 1 deletion JoyShockMapper/src/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ void SettingsManager::resetAllSettings()
static std::set<SettingID> exceptions = {
SettingID::AUTOLOAD,
SettingID::JSM_DIRECTORY,
SettingID::HIDE_MINIMIZED,
SettingID::VIRTUAL_CONTROLLER,
};
return exceptions.find(kvPair.first) == exceptions.end();
};
ranges::for_each(_settings | views::filter(exceptions), callReset);
}
}
42 changes: 25 additions & 17 deletions JoyShockMapper/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class JoyShock
{
touchpads.push_back(TouchStick(i, _context, handle));
}
left_stick.scroll.init(buttons[int(ButtonID::LLEFT)], buttons[int(ButtonID::LRIGHT)]);
right_stick.scroll.init(buttons[int(ButtonID::RLEFT)], buttons[int(ButtonID::RRIGHT)]);
motion_stick.scroll.init(buttons[int(ButtonID::MLEFT)], buttons[int(ButtonID::MRIGHT)]);
touch_scroll_x.init(touchpads[0].buttons.find(ButtonID::TLEFT)->second, touchpads[0].buttons.find(ButtonID::TRIGHT)->second);
touch_scroll_y.init(touchpads[0].buttons.find(ButtonID::TUP)->second, touchpads[0].buttons.find(ButtonID::TDOWN)->second);
updateGridSize();
Expand Down Expand Up @@ -1722,6 +1725,10 @@ void JoyShock::processStick(float stickX, float stickY, Stick &stick, float mous
stick.scroll.processScroll(angle - lastAngle, getSetting<FloatXY>(SettingID::SCROLL_SENS).x(), time_now);
}
}
else
{
CERR << "Scroll object for stick " << stick._stickMode << " was not initialized!\n";
}
}
else if (stickMode == StickMode::NO_MOUSE || stickMode == StickMode::INNER_RING || stickMode == StickMode::OUTER_RING)
{ // Do not do if invalid
Expand Down Expand Up @@ -2097,20 +2104,19 @@ void DisplayTouchInfo(int id, optional<FloatXY> xy, optional<FloatXY> prevXY = n

void TouchCallback(int jcHandle, TOUCH_STATE newState, TOUCH_STATE prevState, float delta_time)
{

// if (current.t0Down || previous.t0Down)
//if (newState.t0Down || prevState.t0Down)
//{
// DisplayTouchInfo(current.t0Down ? current.t0Id : previous.t0Id,
// current.t0Down ? optional<FloatXY>({ current.t0X, current.t0Y }) : nullopt,
// previous.t0Down ? optional<FloatXY>({ previous.t0X, previous.t0Y }) : nullopt);
// }
// DisplayTouchInfo(newState.t0Down ? newState.t0Id : prevState.t0Id,
// newState.t0Down ? optional<FloatXY>({ newState.t0X, newState.t0Y }) : nullopt,
// prevState.t0Down ? optional<FloatXY>({ prevState.t0X, prevState.t0Y }) : nullopt);
//}

// if (current.t1Down || previous.t1Down)
//if (newState.t1Down || prevState.t1Down)
//{
// DisplayTouchInfo(current.t1Down ? current.t1Id : previous.t1Id,
// current.t1Down ? optional<FloatXY>({ current.t1X, current.t1Y }) : nullopt,
// previous.t1Down ? optional<FloatXY>({ previous.t1X, previous.t1Y }) : nullopt);
// }
// DisplayTouchInfo(newState.t1Down ? newState.t1Id : prevState.t1Id,
// newState.t1Down ? optional<FloatXY>({ newState.t1X, newState.t1Y }) : nullopt,
// prevState.t1Down ? optional<FloatXY>({ prevState.t1X, prevState.t1Y }) : nullopt);
//}

shared_ptr<JoyShock> js = handle_to_joyshock[jcHandle];
int tpSizeX, tpSizeY;
Expand Down Expand Up @@ -2154,17 +2160,17 @@ void TouchCallback(int jcHandle, TOUCH_STATE newState, TOUCH_STATE prevState, fl
int index0 = -1, index1 = -1;
if (point0.isDown())
{
float row = floorf(point0.posY * grid_size.value().y());
float col = floorf(point0.posX * grid_size.value().x());
// cout << "I should be in button " << row << " " << col << endl;
float row = ceilf(point0.posY * grid_size.value().y()) - 1.f;
float col = ceilf(point0.posX * grid_size.value().x()) - 1.f;
// COUT << "I should be in button " << row << " " << col << endl;
index0 = int(row * grid_size.value().x() + col);
}

if (point1.isDown())
{
float row = floorf(point1.posY * grid_size.value().y());
float col = floorf(point1.posX * grid_size.value().x());
// cout << "I should be in button " << row << " " << col << endl;
float row = ceilf(point1.posY * grid_size.value().y()) - 1.f;
float col = ceilf(point1.posX * grid_size.value().x()) - 1.f;
// COUT << "I should be in button " << row << " " << col << endl;
index1 = int(row * grid_size.value().x() + col);
}

Expand Down Expand Up @@ -3490,11 +3496,13 @@ void OnVirtualControllerChange(const ControllerScheme &newScheme)
for (auto &js : handle_to_joyshock)
{
// Display an error message if any vigem is no good.
lock_guard guard(js.second->_context->callback_lock);
if (!js.second->CheckVigemState())
{
break;
}
}
// TODO: on NONE clear mappings with vigem commands?
}

void RefreshAutoLoadHelp(JSMAssignment<Switch> *autoloadCmd)
Expand Down
67 changes: 58 additions & 9 deletions JoyShockMapper/src/win32/Gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sstream>
#include <iostream>
#include <thread>
#include <mutex>

//
// Link against SetupAPI
Expand Down Expand Up @@ -55,13 +56,18 @@ union UDs4OutputBuffer
inline void DS4_REPORT_EX_INIT(DS4_REPORT_EX* ds4reportEx)
{
// Preserve button state
auto buttons = ds4reportEx->Report.wButtons;
memset(ds4reportEx, 0, (sizeof(DS4_REPORT_EX)));
ds4reportEx->Report.wButtons = buttons;
ds4reportEx->Report.bThumbLX = 0x7F;
ds4reportEx->Report.bThumbLY = 0x7F;
ds4reportEx->Report.bThumbRX = 0x7F;
ds4reportEx->Report.bThumbRY = 0x7F;
ds4reportEx->Report.bThumbLX = 0x80;
ds4reportEx->Report.bThumbLY = 0x80;
ds4reportEx->Report.bThumbRX = 0x80;
ds4reportEx->Report.bThumbRY = 0x80;

//DS4_SET_DPAD(ds4reportEx, DS4_BUTTON_DPAD_NONE);
ds4reportEx->Report.wButtons &= ~0xF;
ds4reportEx->Report.wButtons |= (USHORT)DS4_BUTTON_DPAD_NONE;

ds4reportEx->Report.sCurrentTouch.bIsUpTrackingNum1 = 0x80;
ds4reportEx->Report.sCurrentTouch.bIsUpTrackingNum2 = 0x80;
}

template<typename T>
Expand Down Expand Up @@ -237,6 +243,8 @@ class VigemGamepad : public Gamepad
}

PVIGEM_TARGET _gamepad = nullptr;
bool isLeftTriggerPressedDigitally = false;
bool isRightTriggerPressedDigitally = false;

private :
Callback _notification = nullptr;
Expand Down Expand Up @@ -308,6 +316,16 @@ class XboxGamepad : public VigemGamepad
{
op(_stateX360.wButtons, found->second);
}
else if (btn.code == X_LT)
{
isLeftTriggerPressedDigitally = pressed;
setLeftTrigger(1.0f);
}
else if (btn.code == X_RT)
{
isRightTriggerPressedDigitally = pressed;
setRightTrigger(1.0f);
}
}
void setLeftStick(float x, float y) override
{
Expand All @@ -332,6 +350,11 @@ class XboxGamepad : public VigemGamepad
{
if (isInitialized())
{
if (isLeftTriggerPressedDigitally)
setLeftTrigger(1.0f);
if (isRightTriggerPressedDigitally)
setRightTrigger(1.0f);

vigem_target_x360_update(VigemClient::get(), _gamepad, _stateX360);
auto buttons = _stateX360.wButtons;
XUSB_REPORT_INIT(&_stateX360);
Expand Down Expand Up @@ -377,6 +400,7 @@ class Ds4Gamepad : public VigemGamepad

if (_errorMsg.empty())
{
lock_guard guard(_gamepadLock);
// Allocate handle to identify new pad
_gamepad = vigem_target_ds4_alloc();

Expand All @@ -396,6 +420,7 @@ class Ds4Gamepad : public VigemGamepad
{
if (isInitialized())
{
lock_guard guard(_gamepadLock);
// We're done with this pad, free resources (this disconnects the virtual device)
if (PVIGEM_CLIENT client = VigemClient::get(); client != nullptr)
{
Expand All @@ -406,13 +431,19 @@ class Ds4Gamepad : public VigemGamepad
_pollDs4Thread.join();
}

VIGEM_ERROR awaitOutputReportTimeout(UDs4OutputBuffer &out)
{
lock_guard guard(_gamepadLock);
return vigem_target_ds4_await_output_report_timeout(VigemClient::get(), _gamepad, 1000, &out.buffer);
}

void pollDs4()
{
UDs4OutputBuffer out;
Indicator ind;
for (auto result = vigem_target_ds4_await_output_report_timeout(VigemClient::get(), _gamepad, 1000, &out.buffer);
for (auto result = awaitOutputReportTimeout(out);
result == VIGEM_ERROR_NONE || result == VIGEM_ERROR_TIMED_OUT;
result = vigem_target_ds4_await_output_report_timeout(VigemClient::get(), _gamepad, 1000, &out.buffer))
result = awaitOutputReportTimeout(out))
{
if (result == VIGEM_ERROR_NONE)
{
Expand Down Expand Up @@ -518,8 +549,17 @@ class Ds4Gamepad : public VigemGamepad
{
if (isInitialized())
{
if (isLeftTriggerPressedDigitally)
setLeftTrigger(1.0f);
if (isRightTriggerPressedDigitally)
setRightTrigger(1.0f);

vigem_target_ds4_update_ex(VigemClient::get(), _gamepad, _stateDS4);
auto buttons = _stateDS4.Report.wButtons;
auto special = _stateDS4.Report.bSpecial;
DS4_REPORT_EX_INIT(&_stateDS4);
_stateDS4.Report.wButtons = buttons;
_stateDS4.Report.bSpecial = special;
}
}

Expand All @@ -535,6 +575,7 @@ class Ds4Gamepad : public VigemGamepad
std::optional<uint8_t> _touchId1 = 0;
std::optional<uint8_t> _touchId2 = 0;
std::thread _pollDs4Thread;
std::mutex _gamepadLock;
};

class PSHat
Expand Down Expand Up @@ -812,7 +853,15 @@ void Ds4Gamepad::setButton(KeyCode btn, bool pressed)
case PS_R3:
op_w(_stateDS4.Report.wButtons, DS4_BUTTON_THUMB_RIGHT);
break;
default:
case PS_L2:
isLeftTriggerPressedDigitally = pressed;
op_w(_stateDS4.Report.wButtons, DS4_BUTTON_TRIGGER_LEFT);
setLeftTrigger(pressed ? 1.0f : 0.f);
break;
case PS_R2:
isRightTriggerPressedDigitally = pressed;
op_w(_stateDS4.Report.wButtons, DS4_BUTTON_TRIGGER_RIGHT);
setRightTrigger(pressed ? 1.0f : 0.f);
break;
}
}
Expand Down

0 comments on commit 0894736

Please sign in to comment.