From 5f715d66cd4950afe803026e86128442ac371a5c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 14 Jul 2024 13:11:29 -0500 Subject: [PATCH] fix(linux/input): don't pass unknown battery values (#2820) --- src/platform/linux/input/inputtino_gamepad.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/platform/linux/input/inputtino_gamepad.cpp b/src/platform/linux/input/inputtino_gamepad.cpp index 7dfc7bae..15fbfcaf 100644 --- a/src/platform/linux/input/inputtino_gamepad.cpp +++ b/src/platform/linux/input/inputtino_gamepad.cpp @@ -248,9 +248,9 @@ namespace platf::gamepad { if (!gamepad) { return; } - // Only the PS5 controller supports motion + // Only the PS5 controller supports battery reports if (std::holds_alternative(*gamepad->joypad)) { - inputtino::PS5Joypad::BATTERY_STATE state = inputtino::PS5Joypad::CHARGHING_ERROR; + inputtino::PS5Joypad::BATTERY_STATE state; switch (battery.state) { case LI_BATTERY_STATE_CHARGING: state = inputtino::PS5Joypad::BATTERY_CHARGHING; @@ -261,10 +261,14 @@ namespace platf::gamepad { case LI_BATTERY_STATE_FULL: state = inputtino::PS5Joypad::BATTERY_FULL; break; + case LI_BATTERY_STATE_UNKNOWN: + case LI_BATTERY_STATE_NOT_PRESENT: + default: + return; + } + if (battery.percentage != LI_BATTERY_PERCENTAGE_UNKNOWN) { + std::get(*gamepad->joypad).set_battery(state, battery.percentage); } - // Battery values in Moonlight are in the range [0, 0xFF (255)] - // Inputtino expects them as a percentage [0, 100] - std::get(*gamepad->joypad).set_battery(state, battery.percentage / 2.55); } }