From 51eb25387d603b2864002a736361334caaff9cf2 Mon Sep 17 00:00:00 2001 From: JibbSmart Date: Tue, 6 Oct 2020 22:53:14 +0800 Subject: [PATCH] Untested fix for motion data not being updated if no callback is set --- JoyShockLibrary/JoyShockLibrary.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/JoyShockLibrary/JoyShockLibrary.cpp b/JoyShockLibrary/JoyShockLibrary.cpp index c156494..d91afdd 100644 --- a/JoyShockLibrary/JoyShockLibrary.cpp +++ b/JoyShockLibrary/JoyShockLibrary.cpp @@ -97,7 +97,7 @@ void pollIndividualLoop(JoyShock *jc) { numTimeOuts = 0; // we want to be able to do these check-and-calls without fear of interruption by another thread. there could be many threads (as many as connected controllers), // and the callback could be time-consuming (up to the user), so we use a readers-writer-lock. - if (handle_input(jc, buf, 64, hasIMU) && (_pollCallback != nullptr || (jc->is_ds4 && _pollTouchCallback != nullptr))) { // but the user won't necessarily have a callback at all, so we'll skip the lock altogether in that case + if (handle_input(jc, buf, 64, hasIMU)) { // but the user won't necessarily have a callback at all, so we'll skip the lock altogether in that case if (hasIMU) { if (jc->cue_motion_reset) @@ -120,15 +120,18 @@ void pollIndividualLoop(JoyShock *jc) { { //printf("No IMU input detected\n"); } - _callbackLock.lock_shared(); - if (_pollCallback != nullptr) { - _pollCallback(jc->intHandle, jc->simple_state, jc->last_simple_state, jc->imu_state, jc->last_imu_state, jc->delta_time); - } - // touchpad will have its own callback so that it doesn't change the existing api - if (jc->is_ds4 && _pollTouchCallback != nullptr) { - _pollTouchCallback(jc->intHandle, jc->touch_state, jc->last_touch_state, jc->delta_time); + if (_pollCallback != nullptr || _pollTouchCallback != nullptr) + { + _callbackLock.lock_shared(); + if (_pollCallback != nullptr) { + _pollCallback(jc->intHandle, jc->simple_state, jc->last_simple_state, jc->imu_state, jc->last_imu_state, jc->delta_time); + } + // touchpad will have its own callback so that it doesn't change the existing api + if (jc->is_ds4 && _pollTouchCallback != nullptr) { + _pollTouchCallback(jc->intHandle, jc->touch_state, jc->last_touch_state, jc->delta_time); + } + _callbackLock.unlock_shared(); } - _callbackLock.unlock_shared(); // count how many have no IMU result. We want to periodically attempt to enable IMU if it's not present if (!hasIMU) {