mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 03:18:13 +00:00
joystick: Report battery on GIP controllers
This commit is contained in:
@@ -1412,17 +1412,71 @@ static bool GIP_HandleCommandStatusDevice(
|
|||||||
const Uint8 *bytes,
|
const Uint8 *bytes,
|
||||||
int num_bytes)
|
int num_bytes)
|
||||||
{
|
{
|
||||||
GIP_ExtendedStatus status = {{0}};
|
GIP_ExtendedStatus status;
|
||||||
|
SDL_Joystick *joystick = NULL;
|
||||||
|
SDL_PowerState power_state;
|
||||||
|
int power_percent = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (num_bytes < 1) {
|
if (num_bytes < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SDL_zero(status);
|
||||||
status.base.battery_level = bytes[0] & 3;
|
status.base.battery_level = bytes[0] & 3;
|
||||||
status.base.battery_type = (bytes[0] >> 2) & 3;
|
status.base.battery_type = (bytes[0] >> 2) & 3;
|
||||||
status.base.charge = (bytes[0] >> 4) & 3;
|
status.base.charge = (bytes[0] >> 4) & 3;
|
||||||
status.base.power_level = (bytes[0] >> 6) & 3;
|
status.base.power_level = (bytes[0] >> 6) & 3;
|
||||||
|
|
||||||
|
if (attachment->joystick) {
|
||||||
|
joystick = SDL_GetJoystickFromID(attachment->joystick);
|
||||||
|
}
|
||||||
|
if (joystick) {
|
||||||
|
switch (status.base.battery_level) {
|
||||||
|
case GIP_BATTERY_CRITICAL:
|
||||||
|
power_percent = 1;
|
||||||
|
break;
|
||||||
|
case GIP_BATTERY_LOW:
|
||||||
|
power_percent = 25;
|
||||||
|
break;
|
||||||
|
case GIP_BATTERY_MEDIUM:
|
||||||
|
power_percent = 50;
|
||||||
|
break;
|
||||||
|
case GIP_BATTERY_FULL:
|
||||||
|
power_percent = 100;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (status.base.charge) {
|
||||||
|
case GIP_CHARGING:
|
||||||
|
if (status.base.battery_level == GIP_BATTERY_FULL) {
|
||||||
|
power_state = SDL_POWERSTATE_CHARGED;
|
||||||
|
} else {
|
||||||
|
power_state = SDL_POWERSTATE_CHARGING;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GIP_NOT_CHARGING:
|
||||||
|
power_state = SDL_POWERSTATE_ON_BATTERY;
|
||||||
|
break;
|
||||||
|
case GIP_CHARGE_ERROR:
|
||||||
|
default:
|
||||||
|
power_state = SDL_POWERSTATE_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (status.base.battery_type) {
|
||||||
|
case GIP_BATTERY_ABSENT:
|
||||||
|
power_state = SDL_POWERSTATE_NO_BATTERY;
|
||||||
|
break;
|
||||||
|
case GIP_BATTERY_STANDARD:
|
||||||
|
case GIP_BATTERY_RECHARGEABLE:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
power_state = SDL_POWERSTATE_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SendJoystickPowerInfo(joystick, power_state, power_percent);
|
||||||
|
}
|
||||||
|
|
||||||
if (num_bytes >= 4) {
|
if (num_bytes >= 4) {
|
||||||
status.device_active = bytes[1] & 1;
|
status.device_active = bytes[1] & 1;
|
||||||
if (bytes[1] & 2) {
|
if (bytes[1] & 2) {
|
||||||
|
Reference in New Issue
Block a user