mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(libScePad): implement scePadSetTiltCorrectionState
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bn7CrhG7pTPR6DT13tN6Me
This commit is contained in:
@@ -191,10 +191,9 @@ int APS5_VABI scePadSetMotionSensorState(int handle, bool enable) {
|
||||
}
|
||||
|
||||
int APS5_VABI scePadSetTiltCorrectionState(int handle, bool enabled) {
|
||||
(void)handle;
|
||||
(void)enabled;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
if (handle != PAD_HANDLE) return PAD_ERROR_INVALID_HANDLE;
|
||||
Pad::SetTiltCorrection(enabled);
|
||||
return PAD_OK;
|
||||
}
|
||||
|
||||
int APS5_VABI scePadSetTriggerEffect(int handle, const void* param) {
|
||||
|
||||
@@ -57,6 +57,7 @@ void SetLightBar(bool valid, std::uint8_t r, std::uint8_t g, std::uint8_t b);
|
||||
void SetTriggerCommand(int trigger, const std::uint8_t* command);
|
||||
void ResetOrientation();
|
||||
void SetMotionEnabled(bool enabled);
|
||||
void SetTiltCorrection(bool enabled);
|
||||
}
|
||||
|
||||
extern "C" void PadPublishInput_nid_postfix(const PadInputState& input);
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace {
|
||||
Quat orientation;
|
||||
std::uint64_t lastFuseTime = 0;
|
||||
float biasIntegral[3] = {0.0f, 0.0f, 0.0f};
|
||||
bool tiltCorrection = true;
|
||||
std::uint8_t nextTouchId = 0;
|
||||
bool prevTouchActive[2] = {false, false};
|
||||
std::uint8_t touchIds[2] = {0, 0};
|
||||
@@ -32,7 +33,7 @@ namespace {
|
||||
void fuse(float dt, const std::array<float, 3>& accel, const std::array<float, 3>& gyro) {
|
||||
float gx = gyro[0], gy = gyro[1], gz = gyro[2];
|
||||
const float an = std::sqrt(accel[0] * accel[0] + accel[1] * accel[1] + accel[2] * accel[2]);
|
||||
if (an > 1.0f) {
|
||||
if (tiltCorrection && an > 1.0f) {
|
||||
const float ax = accel[0] / an, ay = accel[1] / an, az = accel[2] / an;
|
||||
const float vx = 2.0f * (orientation.x * orientation.y + orientation.w * orientation.z);
|
||||
const float vy = orientation.w * orientation.w - orientation.x * orientation.x + orientation.y * orientation.y - orientation.z * orientation.z;
|
||||
@@ -256,6 +257,12 @@ void Pad::ResetOrientation() {
|
||||
biasIntegral[0] = biasIntegral[1] = biasIntegral[2] = 0.0f;
|
||||
}
|
||||
|
||||
void Pad::SetTiltCorrection(bool enabled) {
|
||||
std::lock_guard lock(stateMutex);
|
||||
tiltCorrection = enabled;
|
||||
biasIntegral[0] = biasIntegral[1] = biasIntegral[2] = 0.0f;
|
||||
}
|
||||
|
||||
void Pad::SetMotionEnabled(bool enabled) {
|
||||
std::lock_guard lock(stateMutex);
|
||||
if (output.motionEnabled == enabled) return;
|
||||
|
||||
@@ -1,16 +1,46 @@
|
||||
#include "prx/libScePad/include/Pad.hpp"
|
||||
#include "prx/libScePad/include/PadState.hpp"
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
|
||||
extern "C" {
|
||||
int APS5_VABI scePadOpen_nid_postfix(int, int, int, const void*);
|
||||
int APS5_VABI scePadClose_nid_postfix(int);
|
||||
int APS5_VABI scePadGetHandle(int, int, int);
|
||||
int APS5_VABI scePadSetVibrationTriggerEffectWeakWhileEmbeddedMicInUse(bool);
|
||||
int APS5_VABI scePadInit_nid_postfix(void);
|
||||
int APS5_VABI scePadSetTiltCorrectionState(int, bool);
|
||||
int APS5_VABI scePadResetOrientation(int);
|
||||
}
|
||||
|
||||
static void Require(bool value) { if (!value) std::abort(); }
|
||||
|
||||
static float SettleOrientationW() {
|
||||
float w = 1.0f;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
w = Pad::ReadState().orientation_w;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
static void CheckTiltCorrection(int handle) {
|
||||
Require(scePadInit_nid_postfix() == 0);
|
||||
PadInputState tilted;
|
||||
tilted.hasMotion = true;
|
||||
tilted.accel = {9.80665f, 0.0f, 0.0f};
|
||||
PadPublishInput_nid_postfix(tilted);
|
||||
Require(scePadSetTiltCorrectionState(handle + 1, false) == PAD_ERROR_INVALID_HANDLE);
|
||||
Require(scePadSetTiltCorrectionState(handle, false) == PAD_OK);
|
||||
Require(scePadResetOrientation(handle) == PAD_OK);
|
||||
Require(SettleOrientationW() == 1.0f);
|
||||
Require(scePadSetTiltCorrectionState(handle, true) == PAD_OK);
|
||||
Require(SettleOrientationW() < 0.999f);
|
||||
PadPublishInput_nid_postfix(PadInputState{});
|
||||
}
|
||||
|
||||
int main() {
|
||||
constexpr int noHandle = static_cast<int>(0x80920008);
|
||||
constexpr int user = 0x10000000;
|
||||
@@ -23,6 +53,7 @@ int main() {
|
||||
Require(handle > 0);
|
||||
Require(scePadGetHandle(user, 0, 0) == handle);
|
||||
Require(scePadGetHandle(user, 2, 0) == handle);
|
||||
CheckTiltCorrection(handle);
|
||||
Require(scePadGetHandle(0xff, 16, 0) == handle);
|
||||
Require(scePadGetHandle(user, 16, 0) == noHandle);
|
||||
Require(scePadGetHandle(user, 0, 1) == noHandle);
|
||||
|
||||
Reference in New Issue
Block a user