Problem or limitation
Currently Godot doesn't provide a way to check a joypad's battery (full, charging, discharging, no battery, and battery percentage) and connection (wireless via Bluetooth or wired via USB) information. This might be limiting for games that might want to, for example, warn the player that they need to charge their controller if the battery is low, or display an in-game message if the game can't use a specific joypad feature (for example, vibration) if it's connected via Bluetooth (see also godotengine/godot#114918 ).
Proposed improvement
Using SDL_GetGamepadPowerInfo, SDL_GetGamepadConnectionState and SDL_JoyBatteryEvent it's possible to create new enums and Input class methods that describe battery and connection states:
// See SDL_PowerState. SDL_POWERSTATE_ERROR equivalent was omitted for simplicity.
enum class JoyPowerState {
UNKNOWN = 0,
ON_BATTERY = 1,
NO_BATTERY = 2,
CHARGING = 3,
FULL_BATTERY = 4,
};
// See SDL_JoystickConnectionState. SDL_JOYSTICK_CONNECTION_INVALID equivalent was omitted for simplicity.
enum class JoyConnectionState {
UNKNOWN = 0,
WIRED = 1,
WIRELESS = 2,
};
JoyPowerState get_joy_power_state(int p_device) const;
int get_joy_battery_percent(int p_device) const;
JoyConnectionState get_joy_connection_state(int p_device) const;
Proposal review
Problem or limitation
Currently Godot doesn't provide a way to check a joypad's battery (full, charging, discharging, no battery, and battery percentage) and connection (wireless via Bluetooth or wired via USB) information. This might be limiting for games that might want to, for example, warn the player that they need to charge their controller if the battery is low, or display an in-game message if the game can't use a specific joypad feature (for example, vibration) if it's connected via Bluetooth (see also godotengine/godot#114918 ).
Proposed improvement
Using SDL_GetGamepadPowerInfo, SDL_GetGamepadConnectionState and SDL_JoyBatteryEvent it's possible to create new enums and
Inputclass methods that describe battery and connection states:Proposal review