1 /* 2 ******************************************************************************************* 3 * Dgame (a D game framework) - Copyright (c) Randy Schütt 4 * 5 * This software is provided 'as-is', without any express or implied warranty. 6 * In no event will the authors be held liable for any damages arising from 7 * 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 claim 14 * that you wrote the original software. If you use this software in a product, 15 * an acknowledgment in the product documentation would be appreciated but is 16 * not required. 17 * 18 * 2. Altered source versions must be plainly marked as such, and must not be 19 * misrepresented as being the original software. 20 * 21 * 3. This notice may not be removed or altered from any source distribution. 22 ******************************************************************************************* 23 */ 24 module Dgame.System.Battery; 25 26 private import derelict.sdl2.sdl; 27 28 /** 29 * This structure provide support for battery lifetime if you are on a laptop etc. 30 */ 31 struct Battery { 32 /** 33 * The Power States 34 */ 35 enum State { 36 Unknown = SDL_POWERSTATE_UNKNOWN, /// Cannot determine power status 37 OnBattery = SDL_POWERSTATE_ON_BATTERY, /// Not plugged in, running on the battery 38 NoBattery = SDL_POWERSTATE_NO_BATTERY, /// plugged in, no battery available 39 Charging = SDL_POWERSTATE_CHARGING, /// plugged in, charging battery 40 Charged = SDL_POWERSTATE_CHARGED, /// plugged in, battery charged 41 } 42 43 /** 44 * Remaining time in seconds, or -1 if cannot determine power status 45 */ 46 int seconds; 47 /** 48 * Remaining battery percent, or -1 if cannot determine power status 49 */ 50 byte percent; 51 /** 52 * Battery state 53 */ 54 State state; 55 } 56 57 /** 58 * The System struct contains the Power struct, 59 * which give information about your current battery 60 * and several other informations about your system, like the available RAM. 61 * 62 * Author: Randy Schuett (rswhite4@googlemail.com)k 63 */ 64 interface System { 65 /** 66 * Returns the PowerInfo structure with the currently power informations 67 * 68 * See: PowerInfo struct 69 */ 70 @nogc 71 static Battery getBatteryInfo() nothrow { 72 int secs, pct; 73 SDL_PowerState state = SDL_GetPowerInfo(&secs, &pct); 74 75 return Battery(secs, cast(byte) pct, cast(Battery.State) state); 76 } 77 78 /** 79 * Returns the available RAM 80 */ 81 @nogc 82 static int getRAM() nothrow { 83 return SDL_GetSystemRAM(); 84 } 85 }