git-svn-id: http://bladebattles.com/kurok/SVN@11 20cd92bb-ff49-0410-b73e-96a06e42c3b9
[kurok.git] / psp / battery.cpp
blobda742837950fd5d4d7f1b26ae5fb4376e3140394
1 /*
2 Copyright (C) 2007 Peter Mackay and Chris Swindle.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <psppower.h>
23 extern "C"
25 #include "../quakedef.h"
28 #include "battery.hpp"
30 namespace quake
32 namespace battery
34 // The previous battery level.
35 static int lastLevel = scePowerGetBatteryLifePercent();
36 static bool lastCharging = scePowerGetBatteryChargingStatus();
38 void check()
40 // No battery?
41 if (!scePowerIsBatteryExist())
43 // Don't report anything.
44 return;
47 // Get the new battery status.
48 const int level = scePowerGetBatteryLifePercent();
49 const bool charging = scePowerGetBatteryChargingStatus();
51 // Is the level not sensible?
52 if ((level < 0) || (level > 100))
54 // Hopefully it will be sensible soon.
55 return;
58 // Has the battery status changed?
59 if ((level != lastLevel) || (charging != lastCharging))
61 // Charging?
62 if (charging)
64 // Inform the player.
65 Con_Printf("Battery %d%% (charging)\n",
66 level);
68 else
70 // How much time is left?
71 const int timeLeft = scePowerGetBatteryLifeTime();
73 // Is the time sensible?
74 if (timeLeft > 0)
76 // Convert the time to something readable.
77 const int hoursLeft = timeLeft / 60;
78 const int minutesLeft = timeLeft % 60;
80 // Inform the player.
81 Con_Printf("Battery %d%% (%d hour%s %d minute%s)\n",
82 level,
83 hoursLeft,
84 (hoursLeft == 1) ? "" : "s", // Handle pluralisation of hour(s).
85 minutesLeft,
86 (minutesLeft == 1) ? "" : "s"); // Handle pluralisation of minute(s).
88 else
90 // It's a silly time, just report the battery level.
91 Con_Printf("Battery %d%%\n",
92 level);
96 // Remember the status for next frame.
97 lastLevel = level;
98 lastCharging = charging;