fix(linux/input): don't pass unknown battery values (#2820)

This commit is contained in:
Cameron Gutman 2024-07-14 13:11:29 -05:00 committed by GitHub
parent d57c66fa9c
commit 5f715d66cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<inputtino::PS5Joypad>(*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<inputtino::PS5Joypad>(*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<inputtino::PS5Joypad>(*gamepad->joypad).set_battery(state, battery.percentage / 2.55);
}
}