Add poll interval to libScePad (#1415)

This commit is contained in:
Vladislav Mikhalin 2024-10-19 15:57:01 +03:00 committed by GitHub
parent 87f8fea4de
commit c38e3f77f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 2 deletions

View file

@ -1,10 +1,13 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <SDL3/SDL.h>
#include "controller.h"
#include "common/assert.h"
#include "core/libraries/kernel/time_management.h"
#include "core/libraries/pad/pad.h"
#include "input/controller.h"
#include <SDL3/SDL.h>
namespace Input {
@ -157,4 +160,23 @@ void GameController::TryOpenSDLController() {
}
}
u32 GameController::Poll() {
if (m_connected) {
auto time = Libraries::Kernel::sceKernelGetProcessTime();
if (m_states_num == 0) {
auto diff = (time - m_last_state.time) / 1000;
if (diff >= 100) {
AddState(GetLastState());
}
} else {
auto index = (m_first_state - 1 + m_states_num) % MAX_STATES;
auto diff = (time - m_states[index].time) / 1000;
if (m_private[index].obtained && diff >= 100) {
AddState(GetLastState());
}
}
}
return 100;
}
} // namespace Input

View file

@ -56,6 +56,7 @@ public:
bool SetVibration(u8 smallMotor, u8 largeMotor);
void SetTouchpadState(int touchIndex, bool touchDown, float x, float y);
void TryOpenSDLController();
u32 Poll();
private:
struct StateInternal {