From 5331a48b0c64608c742cd54e1988d4ce829dbcb4 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 14 Aug 2019 15:27:03 -0700 Subject: [PATCH] Publicly expose ConvertToSensorWeight; add ConvertToKilograms --- .../Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp | 15 ++++++++++++--- .../Core/HW/WiimoteEmu/Extension/BalanceBoard.h | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp index eed194fff2..3662e6d6a6 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp @@ -141,9 +141,6 @@ void BalanceBoardExt::LoadDefaults(const ControllerInterface& ciface) u16 BalanceBoardExt::ConvertToSensorWeight(double weight_in_kilos) { - constexpr u16 LOW_WEIGHT_DELTA = WEIGHT_17_KG - WEIGHT_0_KG; - constexpr u16 HIGH_WEIGHT_DELTA = WEIGHT_34_KG - WEIGHT_17_KG; - // Note: this is the weight on a single sensor, so these ranges make more sense // (if all sensors read 34 kilos, then the overall weight would be 136 kilos or 300 pounds...) if (weight_in_kilos < 17) @@ -156,6 +153,18 @@ u16 BalanceBoardExt::ConvertToSensorWeight(double weight_in_kilos) } } +double BalanceBoardExt::ConvertToKilograms(u16 sensor_weight) +{ + if (sensor_weight < WEIGHT_17_KG) + { + return (sensor_weight - WEIGHT_0_KG) * 17. / LOW_WEIGHT_DELTA; + } + else + { + return (sensor_weight - WEIGHT_17_KG) * 17. / HIGH_WEIGHT_DELTA + 17.; + } +} + void BalanceBoardExt::ComputeCalibrationChecksum() { std::array data; diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h index 69935f1a75..4273074a18 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h @@ -52,6 +52,9 @@ public: void LoadDefaults(const ControllerInterface& ciface) override; + static u16 ConvertToSensorWeight(double weight_in_kilos); + static double ConvertToKilograms(u16 sensor_weight); + // Use the same calibration data for all sensors. // Wii Fit internally converts to grams, but using grams for the actual values leads to // overflowing values, and also underflowing values when a sensor gets negative if balance is @@ -65,9 +68,11 @@ public: static constexpr u8 TEMPERATURE = 0x19; private: - u16 ConvertToSensorWeight(double weight_in_kilos); void ComputeCalibrationChecksum(); + static constexpr u16 LOW_WEIGHT_DELTA = WEIGHT_17_KG - WEIGHT_0_KG; + static constexpr u16 HIGH_WEIGHT_DELTA = WEIGHT_34_KG - WEIGHT_17_KG; + ControllerEmu::AnalogStick* m_balance; ControllerEmu::Triggers* m_weight; };