test/testpower.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 07 Jun 2009 06:06:35 +0000
changeset 3170 b7a48f533966
child 3186 51750b7a966f
permissions -rw-r--r--
Initial work on power subsystem for SDL 1.3.
icculus@3170
     1
/* Simple test of power subsystem. */
icculus@3170
     2
icculus@3170
     3
#include <stdio.h>
icculus@3170
     4
#include "SDL.h"
icculus@3170
     5
icculus@3170
     6
static void report_power(void)
icculus@3170
     7
{
icculus@3170
     8
    int seconds, percent;
icculus@3170
     9
    const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
icculus@3170
    10
    char *statestr = NULL;
icculus@3170
    11
icculus@3170
    12
    printf("SDL-reported power info...\n");
icculus@3170
    13
    switch(state)
icculus@3170
    14
    {
icculus@3170
    15
        case SDL_POWERSTATE_UNKNOWN:
icculus@3170
    16
            statestr = "Unknown";
icculus@3170
    17
            break;
icculus@3170
    18
        case SDL_POWERSTATE_ON_BATTERY:
icculus@3170
    19
            statestr = "On battery";
icculus@3170
    20
            break;
icculus@3170
    21
        case SDL_POWERSTATE_NO_BATTERY:
icculus@3170
    22
            statestr = "No battery";
icculus@3170
    23
            break;
icculus@3170
    24
        case SDL_POWERSTATE_CHARGING:
icculus@3170
    25
            statestr = "Charging";
icculus@3170
    26
            break;
icculus@3170
    27
        case SDL_POWERSTATE_CHARGED:
icculus@3170
    28
            statestr = "Charged";
icculus@3170
    29
            break;
icculus@3170
    30
        default:
icculus@3170
    31
            statestr = "!!API ERROR!!";
icculus@3170
    32
            break;
icculus@3170
    33
    }
icculus@3170
    34
icculus@3170
    35
    printf("State: %s\n", statestr);
icculus@3170
    36
icculus@3170
    37
    if (percent == -1) {
icculus@3170
    38
        printf("Percent left: unknown\n");
icculus@3170
    39
    } else {
icculus@3170
    40
        printf("Percent left: %d%%\n", percent);
icculus@3170
    41
    }
icculus@3170
    42
icculus@3170
    43
    if (seconds == -1) {
icculus@3170
    44
        printf("Time left: unknown\n");
icculus@3170
    45
    } else {
icculus@3170
    46
        printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60), (int) (seconds % 60));
icculus@3170
    47
    }
icculus@3170
    48
}
icculus@3170
    49
icculus@3170
    50
icculus@3170
    51
int main(int argc, char *argv[])
icculus@3170
    52
{
icculus@3170
    53
    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
icculus@3170
    54
        fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
icculus@3170
    55
        return 1;
icculus@3170
    56
    }
icculus@3170
    57
icculus@3170
    58
    report_power();
icculus@3170
    59
icculus@3170
    60
    SDL_Quit();
icculus@3170
    61
    return 0;
icculus@3170
    62
}
icculus@3170
    63
icculus@3170
    64
/* end of testpower.c ... */
icculus@3170
    65