From 3e7e3b10ed837fcd202b9d5f26403d5b9cf34fa9 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 27 Nov 2024 22:16:04 +0100 Subject: [PATCH] cellGem: try to map accelerometer and gyro --- rpcs3/Emu/Cell/Modules/cellGem.cpp | 13 ++++++++++++- rpcs3/Emu/Io/pad_types.h | 12 ++++++------ rpcs3/Input/pad_thread.h | 2 +- rpcs3/Input/ps_move_handler.cpp | 22 +++++++++++----------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index f04864852a..d94c4dbd70 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -1109,6 +1109,11 @@ static void ps_move_pos_to_gem_state(u32 gem_num, const gem_config::gem_controll if constexpr (std::is_same_v>) { + gem_state->temperature = pad->move_data.temperature; + gem_state->accel[0] = pad->move_data.accelerometer_x * 1000; // linear velocity in mm/s² + gem_state->accel[1] = pad->move_data.accelerometer_y * 1000; // linear velocity in mm/s² + gem_state->accel[2] = pad->move_data.accelerometer_z * 1000; // linear velocity in mm/s² + pos_to_gem_state(gem_num, controller, gem_state, info.x_pos, info.y_pos, info.x_max, info.y_max); } else if constexpr (std::is_same_v>) @@ -1866,7 +1871,7 @@ error_code cellGemGetInertialState(u32 gem_num, u32 state_flag, u64 timestamp, v { case move_handler::real: { - // Get temperature + // Get temperature and sensor data { std::lock_guard lock(pad::g_pad_mutex); @@ -1876,6 +1881,12 @@ error_code cellGemGetInertialState(u32 gem_num, u32 state_flag, u64 timestamp, v if (pad && pad->m_pad_handler == pad_handler::move && (pad->m_port_status & CELL_PAD_STATUS_CONNECTED)) { inertial_state->temperature = pad->move_data.temperature; + inertial_state->accelerometer[0] = pad->move_data.accelerometer_x; + inertial_state->accelerometer[1] = pad->move_data.accelerometer_y; + inertial_state->accelerometer[2] = pad->move_data.accelerometer_z; + inertial_state->gyro[0] = pad->move_data.gyro_x; + inertial_state->gyro[1] = pad->move_data.gyro_y; + inertial_state->gyro[2] = pad->move_data.gyro_z; } } diff --git a/rpcs3/Emu/Io/pad_types.h b/rpcs3/Emu/Io/pad_types.h index d048c65651..631e9d6c4e 100644 --- a/rpcs3/Emu/Io/pad_types.h +++ b/rpcs3/Emu/Io/pad_types.h @@ -466,12 +466,12 @@ struct ps_move_data bool external_device_read_requested = false; bool external_device_write_requested = false; - s16 accelerometer_x = 0; - s16 accelerometer_y = 0; - s16 accelerometer_z = 0; - s16 gyro_x = 0; - s16 gyro_y = 0; - s16 gyro_z = 0; + f32 accelerometer_x = 0; // linear velocity in m/s² + f32 accelerometer_y = 0; // linear velocity in m/s² + f32 accelerometer_z = 0; // linear velocity in m/s² + f32 gyro_x = 0; // linear velocity in m/s² + f32 gyro_y = 0; // linear velocity in m/s² + f32 gyro_z = 0; // linear velocity in m/s² s16 temperature = 0; }; diff --git a/rpcs3/Input/pad_thread.h b/rpcs3/Input/pad_thread.h index d1f63b5fdb..fe9fa015c5 100644 --- a/rpcs3/Input/pad_thread.h +++ b/rpcs3/Input/pad_thread.h @@ -25,7 +25,7 @@ public: void operator()(); PadInfo& GetInfo() { return m_info; } - auto& GetPads() { return m_pads; } + std::array, CELL_PAD_MAX_PORT_NUM>& GetPads() { return m_pads; } void SetRumble(const u32 pad, u8 large_motor, bool small_motor); void SetIntercepted(bool intercepted); diff --git a/rpcs3/Input/ps_move_handler.cpp b/rpcs3/Input/ps_move_handler.cpp index 376ce72cd9..cee24d208f 100644 --- a/rpcs3/Input/ps_move_handler.cpp +++ b/rpcs3/Input/ps_move_handler.cpp @@ -642,19 +642,19 @@ void ps_move_handler::get_extended_info(const pad_ensemble& binding) gyro_z -= zero_shift; } - pad->m_sensors[0].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * (accel_x / MOVE_ONE_G) * -1.0f)); - pad->m_sensors[1].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * (accel_z / MOVE_ONE_G) * -1.0f)); - pad->m_sensors[2].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * (accel_y / MOVE_ONE_G))); - pad->m_sensors[3].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * (gyro_z / MOVE_ONE_G) * -1.0f)); - - pad->move_data.accelerometer_x = accel_x; - pad->move_data.accelerometer_y = accel_y; - pad->move_data.accelerometer_z = accel_z; - pad->move_data.gyro_x = gyro_x; - pad->move_data.gyro_y = gyro_y; - pad->move_data.gyro_z = gyro_z; + pad->move_data.accelerometer_x = accel_x / MOVE_ONE_G; + pad->move_data.accelerometer_y = accel_y / MOVE_ONE_G; + pad->move_data.accelerometer_z = accel_z / MOVE_ONE_G; + pad->move_data.gyro_x = accel_x / MOVE_ONE_G; + pad->move_data.gyro_y = accel_y / MOVE_ONE_G; + pad->move_data.gyro_z = accel_z / MOVE_ONE_G; pad->move_data.temperature = ((input.temperature << 4) | ((input.magnetometer_x & 0xF0) >> 4)); + pad->m_sensors[0].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * pad->move_data.accelerometer_x * -1.0f)); + pad->m_sensors[1].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * pad->move_data.accelerometer_y * -1.0f)); + pad->m_sensors[2].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * pad->move_data.accelerometer_z)); + pad->m_sensors[3].m_value = Clamp0To1023(512.0f + (MOTION_ONE_G * pad->move_data.gyro_z * -1.0f)); + handle_external_device(binding); }