summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/sdl_driver.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2022-02-24 11:42:51 -0800
committerGravatar GitHub2022-02-24 11:42:51 -0800
commit1079215871cc15452e58aea59630871ea183feeb (patch)
treeac74f8005fc0f98ebdc3206037a83dc55db5ce1b /src/input_common/drivers/sdl_driver.cpp
parentMerge pull request #7933 from german77/am_update (diff)
parentinput_common: Remove battery duplicated struct and update every button press (diff)
downloadyuzu-1079215871cc15452e58aea59630871ea183feeb.tar.gz
yuzu-1079215871cc15452e58aea59630871ea183feeb.tar.xz
yuzu-1079215871cc15452e58aea59630871ea183feeb.zip
Merge pull request #7859 from german77/battery_again
input_common: Remove battery duplicated struct and update every button press
Diffstat (limited to 'src/input_common/drivers/sdl_driver.cpp')
-rw-r--r--src/input_common/drivers/sdl_driver.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index 5cf1987ad..c17ea305e 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -175,22 +175,23 @@ public:
175 return false; 175 return false;
176 } 176 }
177 177
178 BatteryLevel GetBatteryLevel() { 178 Common::Input::BatteryLevel GetBatteryLevel() {
179 const auto level = SDL_JoystickCurrentPowerLevel(sdl_joystick.get()); 179 const auto level = SDL_JoystickCurrentPowerLevel(sdl_joystick.get());
180 switch (level) { 180 switch (level) {
181 case SDL_JOYSTICK_POWER_EMPTY: 181 case SDL_JOYSTICK_POWER_EMPTY:
182 return BatteryLevel::Empty; 182 return Common::Input::BatteryLevel::Empty;
183 case SDL_JOYSTICK_POWER_LOW: 183 case SDL_JOYSTICK_POWER_LOW:
184 return BatteryLevel::Low; 184 return Common::Input::BatteryLevel::Low;
185 case SDL_JOYSTICK_POWER_MEDIUM: 185 case SDL_JOYSTICK_POWER_MEDIUM:
186 return BatteryLevel::Medium; 186 return Common::Input::BatteryLevel::Medium;
187 case SDL_JOYSTICK_POWER_FULL: 187 case SDL_JOYSTICK_POWER_FULL:
188 case SDL_JOYSTICK_POWER_MAX: 188 case SDL_JOYSTICK_POWER_MAX:
189 return BatteryLevel::Full; 189 return Common::Input::BatteryLevel::Full;
190 case SDL_JOYSTICK_POWER_UNKNOWN:
191 case SDL_JOYSTICK_POWER_WIRED: 190 case SDL_JOYSTICK_POWER_WIRED:
191 return Common::Input::BatteryLevel::Charging;
192 case SDL_JOYSTICK_POWER_UNKNOWN:
192 default: 193 default:
193 return BatteryLevel::Charging; 194 return Common::Input::BatteryLevel::None;
194 } 195 }
195 } 196 }
196 197
@@ -351,6 +352,8 @@ void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) {
351 if (const auto joystick = GetSDLJoystickBySDLID(event.jbutton.which)) { 352 if (const auto joystick = GetSDLJoystickBySDLID(event.jbutton.which)) {
352 const PadIdentifier identifier = joystick->GetPadIdentifier(); 353 const PadIdentifier identifier = joystick->GetPadIdentifier();
353 SetButton(identifier, event.jbutton.button, true); 354 SetButton(identifier, event.jbutton.button, true);
355 // Battery doesn't trigger an event so just update every button press
356 SetBattery(identifier, joystick->GetBatteryLevel());
354 } 357 }
355 break; 358 break;
356 } 359 }