Add battery level PowerSyscal interface and to system infos.
Current iOS is supporting this new feature.
<string id="12392">Hours</string>
<string id="12393">Days</string>
<string id="12394">Total uptime</string>
+ <string id="12395">Battery level</string>
<string id="12600">Weather</string>
case SYSTEM_INTERNET_STATE:
case SYSTEM_UPTIME:
case SYSTEM_TOTALUPTIME:
+ case SYSTEM_BATTERY_LEVEL:
return g_sysinfo.GetInfo(info);
break;
#define SYSTEM_HAS_ADDON 711
#define SYSTEM_ADDON_TITLE 712
#define SYSTEM_ADDON_ICON 713
+#define SYSTEM_BATTERY_LEVEL 714
#define LIBRARY_HAS_MUSIC 720
#define LIBRARY_HAS_VIDEO 721
extern "C"
{
#endif
- bool DarwinIsAppleTV2(void);
- float GetIOSVersion(void);
- int GetDarwinFrameworkPath(bool forPython, char* path, uint32_t *pathsize);
- int GetDarwinExecutablePath(char* path, uint32_t *pathsize);
-
- bool DarwinHasVideoToolboxDecoder(void);
+ bool DarwinIsAppleTV2(void);
+ float GetIOSVersion(void);
+ int GetDarwinFrameworkPath(bool forPython, char* path, uint32_t *pathsize);
+ int GetDarwinExecutablePath(char* path, uint32_t *pathsize);
+ bool DarwinHasVideoToolboxDecoder(void);
+ int DarwinBatteryLevel(void);
#ifdef __cplusplus
}
#endif
#import <sys/sysctl.h>
#else
#import <Cocoa/Cocoa.h>
+ #import <IOKit/ps/IOPowerSources.h>
+ #import <IOKit/ps/IOPSKeys.h>
#endif
#import "AutoPool.h"
return bDecoderAvailable;
}
+int DarwinBatteryLevel(void)
+{
+ float batteryLevel = 0;
+#if defined(TARGET_DARWIN_IOS)
+ if(!DarwinIsAppleTV2())
+ batteryLevel = [[UIDevice currentDevice] batteryLevel];
+#else
+ CFTypeRef powerSourceInfo = IOPSCopyPowerSourcesInfo();
+ CFArrayRef powerSources = IOPSCopyPowerSourcesList(powerSourceInfo);
+
+ CFDictionaryRef powerSource = NULL;
+ const void *powerSourceVal;
+
+ for (int i = 0 ; i < CFArrayGetCount(powerSources) ; i++)
+ {
+ powerSource = IOPSGetPowerSourceDescription(powerSourceInfo, CFArrayGetValueAtIndex(powerSources, i));
+ if (!powerSource) break;
+
+ powerSourceVal = (CFStringRef)CFDictionaryGetValue(powerSource, CFSTR(kIOPSNameKey));
+
+ int curLevel = 0;
+ int maxLevel = 0;
+
+ powerSourceVal = CFDictionaryGetValue(powerSource, CFSTR(kIOPSCurrentCapacityKey));
+ CFNumberGetValue((CFNumberRef)powerSourceVal, kCFNumberSInt32Type, &curLevel);
+
+ powerSourceVal = CFDictionaryGetValue(powerSource, CFSTR(kIOPSMaxCapacityKey));
+ CFNumberGetValue((CFNumberRef)powerSourceVal, kCFNumberSInt32Type, &maxLevel);
+
+ batteryLevel = (int)((double)curLevel/(double)maxLevel);
+
+ }
+#endif
+ return batteryLevel * 100;
+}
+
#endif
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
+ [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
+
m_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
/* Turn off autoresizing */
virtual bool CanSuspend() = 0;
virtual bool CanHibernate() = 0;
virtual bool CanReboot() = 0;
+
+// Battery related functions
+ virtual int BatteryLevel() = 0;
/*!
\brief Pump power related events back to xbmc.
{
return m_instance->CanReboot();
}
-
+int CPowerManager::BatteryLevel()
+{
+ return m_instance->BatteryLevel();
+}
void CPowerManager::ProcessEvents()
{
m_instance->PumpPowerEvents(this);
virtual bool CanHibernate() { return true; }
virtual bool CanReboot() { return true; }
+ virtual int BatteryLevel() { return 0; }
+
+
virtual bool PumpPowerEvents(IPowerEventsCallback *callback) { return false; }
};
bool CanSuspend();
bool CanHibernate();
bool CanReboot();
+
+ int BatteryLevel();
void ProcessEvents();
private:
return m_CanReboot;
}
+int CConsoleDeviceKitPowerSyscall::BatteryLevel()
+{
+ return 0;
+}
+
bool CConsoleDeviceKitPowerSyscall::HasDeviceConsoleKit()
{
bool hasConsoleKitManager = false;
virtual bool CanSuspend();
virtual bool CanHibernate();
virtual bool CanReboot();
+ virtual int BatteryLevel();
static bool HasDeviceConsoleKit();
private:
return m_CanReboot;
}
+int CConsoleUPowerSyscall::BatteryLevel()
+{
+ return 0;
+}
+
bool CConsoleUPowerSyscall::HasDeviceConsoleKit()
{
bool hasConsoleKitManager = false;
virtual bool CanSuspend();
virtual bool CanHibernate();
virtual bool CanReboot();
+ virtual int BatteryLevel();
virtual bool PumpPowerEvents(IPowerEventsCallback *callback);
return m_CanReboot;
}
+int CHALPowerSyscall::BatteryLevel()
+{
+ return 0;
+}
+
bool CHALPowerSyscall::doPowerCall(const char *powerstate)
{
DBusMessage* msg;
virtual bool CanSuspend();
virtual bool CanHibernate();
virtual bool CanReboot();
+ virtual int BatteryLevel();
private:
bool QueryCapability(const char *capability);
#include <IOKit/ps/IOPSKeys.h>
#endif
+#include "osx/DarwinUtils.h"
+
// missing in 10.4/10.5 SDKs.
#if (MAC_OS_X_VERSION_MAX_ALLOWED < 1060)
#define kIOPSNotifyLowBattery "com.apple.system.powersources.lowbattery"
return result;
}
+int CCocoaPowerSyscall::BatteryLevel(void)
+{
+ return DarwinBatteryLevel();
+}
+
bool CCocoaPowerSyscall::PumpPowerEvents(IPowerEventsCallback *callback)
{
if (m_OnSuspend)
virtual bool CanHibernate(void);
virtual bool CanReboot(void);
bool HasBattery(void);
+ virtual int BatteryLevel(void);
virtual bool PumpPowerEvents(IPowerEventsCallback *callback);
private:
return true;
}
+int CWin32PowerSyscall::BatteryLevel()
+{
+ return CWIN32Util::BatteryLevel();
+}
+
bool CWin32PowerSyscall::PumpPowerEvents(IPowerEventsCallback *callback)
{
if (m_OnSuspend)
virtual bool CanSuspend();
virtual bool CanHibernate();
virtual bool CanReboot();
+ virtual int BatteryLevel();
virtual bool PumpPowerEvents(IPowerEventsCallback *callback);
#include "osx/DarwinUtils.h"
#include "osx/CocoaInterface.h"
#endif
+#include "powermanagement/PowerManager.h"
CSysInfo g_sysinfo;
m_info.cpuFrequency = GetCPUFreqInfo();
m_info.kernelVersion = CSysInfo::GetKernelVersion();
m_info.macAddress = GetMACAddress();
+ m_info.batteryLevel = GetBatteryLevel();
return true;
}
return "GPU: " + g_Windowing.GetRenderRenderer();
}
+CStdString CSysInfoJob::GetBatteryLevel()
+{
+ CStdString strVal;
+ strVal.Format("%d%%", g_powerManager.BatteryLevel());
+ return strVal;
+}
+
double CSysInfoJob::GetCPUFrequency()
{
#if defined (_LINUX) || defined(_WIN32)
return g_localizeStrings.Get(13274);
else
return g_localizeStrings.Get(13297);
+ case SYSTEM_BATTERY_LEVEL:
+ return m_info.batteryLevel;
default:
return "";
}
CStdString cpuFrequency;
CStdString kernelVersion;
CStdString macAddress;
+ CStdString batteryLevel;
};
class CSysInfoJob : public CJob
CStdString GetCPUFreqInfo();
CStdString GetMACAddress();
CStdString GetVideoEncoder();
+ CStdString GetBatteryLevel();
CSysData m_info;
};
#endif
}
+int CWIN32Util::BatteryLevel()
+{
+ SYSTEM_POWER_STATUS SystemPowerStatus;
+
+ if (GetSystemPowerStatus(&SystemPowerStatus) && SystemPowerStatus.BatteryLifePercent != 255)
+ return SystemPowerStatus.BatteryLifePercent;
+
+ return 0;
+}
+
bool CWIN32Util::XBMCShellExecute(const CStdString &strPath, bool bWaitForScriptExit)
{
CStdString strCommand = strPath;
static char FirstDriveFromMask (ULONG unitmask);
static int GetDriveStatus(const CStdString &strPath);
static bool PowerManagement(PowerState State);
+ static int BatteryLevel();
static bool XBMCShellExecute(const CStdString &strPath, bool bWaitForScriptExit=false);
static std::vector<CStdString> GetDiskUsage();
static CStdString GetResInfoString();
{
public:
void StartZero();
-};
\ No newline at end of file
+};
#endif
SetControlLabel(i++, "%s: %s", 12390, SYSTEM_UPTIME);
SetControlLabel(i++, "%s: %s", 12394, SYSTEM_TOTALUPTIME);
+ SetControlLabel(i++, "%s: %s", 12395, SYSTEM_BATTERY_LEVEL);
}
else if (m_section == CONTROL_BT_STORAGE)
{