hbehrens
(Heiko Behrens)
1
Via the C SDK, I would like to detect if the Playdate is currently charging. In the Lua SDK, I can see the Lua function getPowerStatus() and based on this related forum discussion here, it seems that this is exactly what I need.
Unfortunately, I cannot find the equivalent in the C SDK. When looking at pd_api_sys.h
, all I can see is the pair of
struct playdate_sys
{
// ...
// 1.4
float (*getBatteryPercentage)(void);
float (*getBatteryVoltage)(void);
Am I missing something? Is there a way to access the same information from C (without going through playdate->lua->callFunction
)?
If not, I would like to request the addition of
typedef enum
{
kPDPowerStatusCharging = (1<<0),
kPDPowerStatusUsb = (1<<1),
kPDPowerStatusScrews = (1<<2),
} PDPowerStatus;
// ...
struct playdate_sys
{
// ...
PDPowerStatus (*getPowerStatus)(void);
Thank you!
1 Like
Nino
(Gravity Express)
2
In your proposal the function would return a bitmask so that screws and usb could both be active, right? And 0 is battery power?
hbehrens
(Heiko Behrens)
3
Yes, that was my intention. I tried to model this after PDButtons
typedef enum
{
kButtonLeft = (1<<0),
kButtonRight = (1<<1),
kButtonUp = (1<<2),
kButtonDown = (1<<3),
kButtonB = (1<<4),
kButtonA = (1<<5)
} PDButtons;
// ..
struct playdate_sys
{
// ...
void (*getButtonState)(PDButtons* current, PDButtons* pushed, PDButtons* released);
and how I interpret the Lua documentation for playdate.getPowerPowerStatus():
playdate.getPowerStatus()
Returns a table holding booleans with the following keys:
- charging: The battery is actively being charged
- USB: There is a powered USB cable connected
- screws: There is 5V being applied to the corner screws (via the dock, for example)