Skip to content

[REQUEST] Expose controller battery/power level via love.joystick (SDL_JoystickCurrentPowerLevel) #2223

@JamesVanBoxtel

Description

@JamesVanBoxtel

Requesting an API to query a gamepad/joystick’s power level (Unknown/Empty/Low/Medium/Full/Wired).

Useful for showing “controller low battery” UI and for diagnostics in games that support long sessions and multiple local players.

Motivation / Use cases

Alert player when a wireless pad is about to die.
Prefer wired pads in tournaments or when recording replays.
Telemetry/debug overlays (e.g., per-player status in local multiplayer).
Parity with SDL, which LÖVE already uses.
Proposed API (Lua)

local level = joystick:getPowerLevel() -- "unknown" | "empty" | "low" | "medium" | "full" | "wired"

-- Optional convenience:
local seconds = joystick:getEstimatedBatterySeconds() -- if available; else nil

Behavior / Details

Values mirror SDL’s SDL_JoystickPowerLevel: Unknown, Empty, Low, Medium, Full, Wired.
For devices without a battery or with OS restrictions, return "unknown" (or enum Unknown).
Should not allocate or block; callable every frame.

SDL reference

SDL_JoystickCurrentPowerLevel(SDL_Joystick*) returns SDL_JoystickPowerLevel (Unknown/Empty/Low/Medium/Full/Wired).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions