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, between 0 and 100, or NULL to ignore. this will be filled in with -1 if we can't determine a value or there is no battery. (not "0", bestie β€” -1 means 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