src/power/psp/SDL_syspower.c
author Captain Lex <kimonline@126.com>
Sun, 17 Mar 2013 20:07:02 +0800
changeset 7009 161b7b6a5303
child 7191 75360622e65f
permissions -rw-r--r--
Add PSP support
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 #include "SDL_config.h"
    23 
    24 #ifndef SDL_POWER_DISABLED
    25 #if SDL_POWER_PSP
    26 
    27 #include "SDL_power.h"
    28 #include <psppower.h> 
    29 
    30 
    31 SDL_bool
    32 SDL_GetPowerInfo_PSP(SDL_PowerState * state, int *seconds,
    33                             int *percent)
    34 {
    35     int battery = scePowerIsBatteryExist();
    36     int plugged = scePowerIsPowerOnline();
    37 	int charging = scePowerIsBatteryCharging();
    38 
    39     *state = SDL_POWERSTATE_UNKNOWN;
    40 	*seconds = -1;
    41 	*percent = -1;
    42 	
    43 	if (!battery) {
    44 		*state = SDL_POWERSTATE_NO_BATTERY;
    45 		*seconds = -1;
    46     	*percent = -1;
    47     } else if (charging) {
    48         *state = SDL_POWERSTATE_CHARGING;
    49     	*percent = scePowerGetBatteryLifePercent();
    50 		*seconds = scePowerGetBatteryLifeTime()*60;
    51     } else if (plugged) {
    52         *state = SDL_POWERSTATE_CHARGED;
    53     	*percent = scePowerGetBatteryLifePercent();
    54 		*seconds = scePowerGetBatteryLifeTime()*60;        
    55     } else {
    56         *state = SDL_POWERSTATE_ON_BATTERY;
    57     	*percent = scePowerGetBatteryLifePercent();
    58 		*seconds = scePowerGetBatteryLifeTime()*60;
    59     }
    60 
    61 	
    62     return SDL_TRUE;            /* always the definitive answer on PSP. */
    63 }
    64 
    65 #endif /* SDL_POWER_PSP */
    66 #endif /* SDL_POWER_DISABLED */
    67 
    68 /* vi: set ts=4 sw=4 expandtab: */