Skip to content

Commit

Permalink
power: Linux /sys/class testing should skip "device" scopes.
Browse files Browse the repository at this point in the history
(the PS4 game controllers report their batteries through this interface, which
is cool, but not helpful for powering the rest of the system.  :)   )
  • Loading branch information
icculus committed Jul 3, 2017
1 parent 9f99b3d commit c27dc51
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/power/linux/SDL_syspower.c
Expand Up @@ -460,6 +460,16 @@ SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, int *second
continue; /* we don't care about UPS and such. */
}

/* if the scope is "device," it might be something like a PS4
controller reporting its own battery, and not something that powers
the system. Most system batteries don't list a scope at all; we
assume it's a system battery if not specified. */
if (read_power_file(base, name, "scope", str, sizeof (str))) {
if (SDL_strcmp(str, "device\n") != 0) {
continue; /* skip external devices with their own batteries. */
}
}

/* some drivers don't offer this, so if it's not explicitly reported assume it's present. */
if (read_power_file(base, name, "present", str, sizeof (str)) && (SDL_strcmp(str, "0\n") == 0)) {
st = SDL_POWERSTATE_NO_BATTERY;
Expand Down

0 comments on commit c27dc51

Please sign in to comment.