Merge pull request #8908 from jordan-woyak/wiimote-battery-hax
WiimoteCommon: Tweak battery level math.
This commit is contained in:
commit
4c50eadf34
|
@ -10,10 +10,6 @@ namespace WiimoteCommon
|
||||||
{
|
{
|
||||||
constexpr u8 MAX_PAYLOAD = 23;
|
constexpr u8 MAX_PAYLOAD = 23;
|
||||||
|
|
||||||
// Based on testing, old WiiLi.org docs, and WiiUse library:
|
|
||||||
// Max battery level seems to be 0xc8 (decimal 200)
|
|
||||||
constexpr u8 MAX_BATTERY_LEVEL = 0xc8;
|
|
||||||
|
|
||||||
enum class InputReportID : u8
|
enum class InputReportID : u8
|
||||||
{
|
{
|
||||||
Status = 0x20,
|
Status = 0x20,
|
||||||
|
|
|
@ -207,6 +207,22 @@ struct InputReportStatus
|
||||||
u8 leds : 4;
|
u8 leds : 4;
|
||||||
u8 padding2[2];
|
u8 padding2[2];
|
||||||
u8 battery;
|
u8 battery;
|
||||||
|
|
||||||
|
constexpr float GetEstimatedCharge() const
|
||||||
|
{
|
||||||
|
return battery * BATTERY_LEVEL_M / BATTERY_MAX + BATTERY_LEVEL_B;
|
||||||
|
}
|
||||||
|
void SetEstimatedCharge(float charge)
|
||||||
|
{
|
||||||
|
battery = u8(std::lround((charge - BATTERY_LEVEL_B) / BATTERY_LEVEL_M * BATTERY_MAX));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr auto BATTERY_MAX = std::numeric_limits<decltype(battery)>::max();
|
||||||
|
|
||||||
|
// Linear fit of battery level mid-point for charge bars in home menu.
|
||||||
|
static constexpr float BATTERY_LEVEL_M = 2.46f;
|
||||||
|
static constexpr float BATTERY_LEVEL_B = -0.013f;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(InputReportStatus) == 6, "Wrong size");
|
static_assert(sizeof(InputReportStatus) == 6, "Wrong size");
|
||||||
|
|
||||||
|
|
|
@ -235,13 +235,12 @@ void Wiimote::HandleRequestStatus(const OutputReportRequestStatus&)
|
||||||
|
|
||||||
// Update status struct
|
// Update status struct
|
||||||
m_status.extension = m_extension_port.IsDeviceConnected();
|
m_status.extension = m_extension_port.IsDeviceConnected();
|
||||||
|
m_status.SetEstimatedCharge(m_battery_setting.GetValue() / ciface::BATTERY_INPUT_MAX_VALUE);
|
||||||
m_status.battery = u8(std::lround(m_battery_setting.GetValue() / 100 * MAX_BATTERY_LEVEL));
|
|
||||||
|
|
||||||
if (Core::WantsDeterminism())
|
if (Core::WantsDeterminism())
|
||||||
{
|
{
|
||||||
// One less thing to break determinism:
|
// One less thing to break determinism:
|
||||||
m_status.battery = MAX_BATTERY_LEVEL;
|
m_status.SetEstimatedCharge(1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Less than 0x20 triggers the low-battery flag:
|
// Less than 0x20 triggers the low-battery flag:
|
||||||
|
|
|
@ -288,8 +288,7 @@ Device::Device(std::unique_ptr<WiimoteReal::Wiimote> wiimote) : m_wiimote(std::m
|
||||||
AddInput(new AnalogInput<float>(&m_classic_state.triggers[1], classic_prefix + "R-Analog", 1.f));
|
AddInput(new AnalogInput<float>(&m_classic_state.triggers[1], classic_prefix + "R-Analog", 1.f));
|
||||||
|
|
||||||
// Specialty inputs:
|
// Specialty inputs:
|
||||||
AddInput(new UndetectableAnalogInput<u8>(
|
AddInput(new UndetectableAnalogInput<float>(&m_battery, "Battery", 1.f));
|
||||||
&m_battery, "Battery", WiimoteCommon::MAX_BATTERY_LEVEL / ciface::BATTERY_INPUT_MAX_VALUE));
|
|
||||||
AddInput(new UndetectableAnalogInput<WiimoteEmu::ExtensionNumber>(
|
AddInput(new UndetectableAnalogInput<WiimoteEmu::ExtensionNumber>(
|
||||||
&m_extension_number_input, "Attached Extension", WiimoteEmu::ExtensionNumber(1)));
|
&m_extension_number_input, "Attached Extension", WiimoteEmu::ExtensionNumber(1)));
|
||||||
AddInput(new UndetectableAnalogInput<bool>(&m_mplus_attached_input, "Attached MotionPlus", 1));
|
AddInput(new UndetectableAnalogInput<bool>(&m_mplus_attached_input, "Attached MotionPlus", 1));
|
||||||
|
@ -1550,7 +1549,7 @@ void Device::ProcessStatusReport(const InputReportStatus& status)
|
||||||
// Update status periodically to keep battery level value up to date.
|
// Update status periodically to keep battery level value up to date.
|
||||||
m_status_outdated_time = Clock::now() + std::chrono::seconds(10);
|
m_status_outdated_time = Clock::now() + std::chrono::seconds(10);
|
||||||
|
|
||||||
m_battery = status.battery;
|
m_battery = status.GetEstimatedCharge() * BATTERY_INPUT_MAX_VALUE;
|
||||||
m_leds = status.leds;
|
m_leds = status.leds;
|
||||||
|
|
||||||
if (!status.ir)
|
if (!status.ir)
|
||||||
|
|
|
@ -233,7 +233,7 @@ private:
|
||||||
|
|
||||||
// Status report is requested every so often to update the battery level.
|
// Status report is requested every so often to update the battery level.
|
||||||
Clock::time_point m_status_outdated_time = Clock::now();
|
Clock::time_point m_status_outdated_time = Clock::now();
|
||||||
u8 m_battery = 0;
|
float m_battery = 0;
|
||||||
u8 m_leds = 0;
|
u8 m_leds = 0;
|
||||||
|
|
||||||
bool m_speaker_configured = false;
|
bool m_speaker_configured = false;
|
||||||
|
|
Loading…
Reference in New Issue