SDL  2.0
testpower.c File Reference
#include <stdio.h>
#include "SDL.h"
+ Include dependency graph for testpower.c:

Go to the source code of this file.

Functions

static void report_power (void)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 64 of file testpower.c.

References report_power(), SDL_GetError, SDL_Init, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, and SDL_Quit.

65 {
66  /* Enable standard application logging */
68 
69  if (SDL_Init(0) == -1) {
70  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
71  return 1;
72  }
73 
74  report_power();
75 
76  SDL_Quit();
77  return 0;
78 }
#define SDL_GetError
#define SDL_LogError
static void report_power(void)
Definition: testpower.c:18
#define SDL_Quit
#define SDL_LogSetPriority
#define SDL_Init

◆ report_power()

static void report_power ( void  )
static

Definition at line 18 of file testpower.c.

References NULL, SDL_GetPowerInfo, SDL_Log, SDL_POWERSTATE_CHARGED, SDL_POWERSTATE_CHARGING, SDL_POWERSTATE_NO_BATTERY, SDL_POWERSTATE_ON_BATTERY, SDL_POWERSTATE_UNKNOWN, and state.

Referenced by main().

19 {
20  int seconds, percent;
21  const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
22  char *statestr = NULL;
23 
24  SDL_Log("SDL-reported power info...\n");
25  switch (state) {
27  statestr = "Unknown";
28  break;
30  statestr = "On battery";
31  break;
33  statestr = "No battery";
34  break;
36  statestr = "Charging";
37  break;
39  statestr = "Charged";
40  break;
41  default:
42  statestr = "!!API ERROR!!";
43  break;
44  }
45 
46  SDL_Log("State: %s\n", statestr);
47 
48  if (percent == -1) {
49  SDL_Log("Percent left: unknown\n");
50  } else {
51  SDL_Log("Percent left: %d%%\n", percent);
52  }
53 
54  if (seconds == -1) {
55  SDL_Log("Time left: unknown\n");
56  } else {
57  SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
58  (int) (seconds % 60));
59  }
60 }
struct xkb_state * state
#define SDL_Log
#define SDL_GetPowerInfo
#define NULL
Definition: begin_code.h:164
SDL_PowerState
The basic state for the system&#39;s power supply.
Definition: SDL_power.h:42