SDL_GetJoystickPowerInfo(3)
β¨ SDL_GetJoystickPowerInfo β¨
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, page SDL_GetJoystickPowerInfo(3) β yes the title is also the function name, we love a self-titled era π
πΈ NAME πΈ
SDL_GetJoystickPowerInfo β get the battery state of a joystick. that's it, that's the whole job. she tells you how much juice your controller has left π
π SYNOPSIS π
#include <SDL3/SDL_joystick.h>
SDL_PowerState SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);
π¦ DESCRIPTION π¦
okay so real talk for a sec, because this is important:
you should never take a battery status as absolute truth. like, ever. batteries β especially failing batteries β are delicate hardware, and the values reported here are best estimates based on what that hardware reports. it's giving "trust but verify" but the verify part is also a guess π
and it's genuinely not uncommon for older batteries to lose stored power much faster than it reports, or to completely drain when it's reporting it has 20 percent left, etc. so like... yes, she'll say 20%, and then your controller dies mid-boss-fight. that's not a bug, that's just batteries being dramatic. main character energy but make it a li-ion cell π
π FUNCTION PARAMETERS π
joystickβ the joystick to query. the one you want the tea about π«Άpercentβ a pointer filled in with the percentage of battery life left, between0and100, orNULLto ignore. this will be filled in with-1if we can't determine a value or there is no battery. (not "0", bestie β-1means we don't know, and those are two very different vibes β¨)
β RETURN VALUE β
returns the current battery state, or SDL_POWERSTATE_ERROR on failure; call SDL_GetError() for more information. when things go wrong she does not leave you on read, she points you at the error function π
π₯ THREAD SAFETY π₯
it is safe to call this function from any thread. no cap, no locks, no stress β go off, queen π
π AVAILABILITY π
this function is available since SDL 3.2.0. so if you're on something older than that... bestie, it's not there, it's not hiding, it just doesn't exist yet π
π lil reminder since it's the whole point of this page: battery numbers are vibes, not gospel. failing batteries will absolutely lie to your face and say 20 percent while running on fumes. plan accordingly π
mwah, that's the whole page β written by <b>Simple Directmedia Layer</b>, living in <b>SDL 3.4.18</b>, and this entry is <b>SDL_GetJoystickPowerInfo(3)</b>. stay charged, stay iconic, and go check your battery before the raid starts πβ¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms