diff --git a/CMakeLists.txt b/CMakeLists.txt index d7fd06a0c4..885f24bd0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -926,7 +926,6 @@ add_library(Common STATIC Common/SysError.cpp Common/TimeUtil.cpp Common/TimeUtil.h - Common/Battery/Battery.h ) include_directories(Common) diff --git a/Common/Battery/AppleBatteryClient.m b/Common/Battery/AppleBatteryClient.m index 6fbb29e8d5..8645fdcab4 100644 --- a/Common/Battery/AppleBatteryClient.m +++ b/Common/Battery/AppleBatteryClient.m @@ -5,7 +5,6 @@ // Created by Serena on 24/01/2023. // -#include "Battery.h" #import #if PPSSPP_PLATFORM(MAC) @@ -90,7 +89,7 @@ void _powerSourceRunLoopCallback(void * __unused ctx) { @end - -int getCurrentBatteryCapacity() { +// TODO: Move this. +int Apple_GetCurrentBatteryCapacity() { return [[AppleBatteryClient sharedClient] batteryLevel]; } diff --git a/Common/Battery/Battery.h b/Common/Battery/Battery.h deleted file mode 100644 index aa90d60f29..0000000000 --- a/Common/Battery/Battery.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// Battery.h -// PPSSPP -// -// Created by Serena on 24/01/2023. -// - -// NOTE: Though this is a general purpose header file, -// though the implementation right now is Darwin specific -// In case any future platform implementations are made for other platforms, -// define the function below in their own file - -#ifndef BATTERY_H -#define BATTERY_H -#include "ppsspp_config.h" -//#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC) -#define CAN_DISPLAY_CURRENT_BATTERY_CAPACITY -/// Get the current battery %. -int getCurrentBatteryCapacity(); -#endif /* PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC) */ - -#ifdef __cplusplus -} -#endif - -#endif /* BATTERY_H */ diff --git a/Common/System/System.h b/Common/System/System.h index 03826f4468..078edda8af 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -213,6 +213,9 @@ enum SystemProperty { SYSPROP_OK_BUTTON_LEFT, SYSPROP_MAIN_WINDOW_HANDLE, + + SYSPROP_CAN_READ_BATTERY_PERCENTAGE, + SYSPROP_BATTERY_PERCENTAGE, }; enum class SystemNotification { diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index f3bfd6cb45..808f218eb6 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -513,6 +513,10 @@ std::vector System_GetPropertyStringVec(SystemProperty prop) { } } +#if PPSSPP_PLATFORM(MAC) +int Apple_GetCurrentBatteryCapacity(); +#endif + int64_t System_GetPropertyInt(SystemProperty prop) { switch (prop) { case SYSPROP_AUDIO_SAMPLE_RATE: @@ -543,6 +547,10 @@ int64_t System_GetPropertyInt(SystemProperty prop) { return g_DesktopWidth; case SYSPROP_DISPLAY_YRES: return g_DesktopHeight; +#if PPSSPP_PLATFORM(MAC) + case SYSPROP_BATTERY_PERCENTAGE: + return Apple_GetCurrentBatteryCapacity(); +#endif default: return -1; } @@ -604,6 +612,7 @@ bool System_GetPropertyBool(SystemProperty prop) { #if PPSSPP_PLATFORM(MAC) case SYSPROP_HAS_FOLDER_BROWSER: case SYSPROP_HAS_FILE_BROWSER: + case SYSPROP_CAN_READ_BATTERY_PERCENTAGE: return true; #endif case SYSPROP_HAS_ACCELEROMETER: diff --git a/UI/DebugOverlay.cpp b/UI/DebugOverlay.cpp index 090db6ab59..d2e0e419b5 100644 --- a/UI/DebugOverlay.cpp +++ b/UI/DebugOverlay.cpp @@ -453,13 +453,14 @@ void DrawFPS(UIContext *ctx, const Bounds &bounds) { } } -#ifdef CAN_DISPLAY_CURRENT_BATTERY_CAPACITY - if (g_Config.iShowStatusFlags & (int)ShowStatusFlags::BATTERY_PERCENT) { - char temp[256]; - snprintf(temp, sizeof(temp), "%s Battery: %d%%", fpsbuf, getCurrentBatteryCapacity()); - snprintf(fpsbuf, sizeof(fpsbuf), "%s", temp); + if (System_GetPropertyBool(SYSPROP_CAN_READ_BATTERY_PERCENTAGE)) { + if (g_Config.iShowStatusFlags & (int)ShowStatusFlags::BATTERY_PERCENT) { + char temp[256]; + const int percentage = System_GetPropertyInt(SYSPROP_BATTERY_PERCENTAGE); + snprintf(temp, sizeof(temp), "%s Battery: %d%%", fpsbuf, percentage); + snprintf(fpsbuf, sizeof(fpsbuf), "%s", temp); + } } -#endif ctx->Flush(); ctx->BindFontTexture(); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 430790ceb1..dc4080f0fc 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -33,7 +33,6 @@ #include "Common/System/Display.h" // Only to check screen aspect ratio with pixel_yres/pixel_xres #include "Common/System/Request.h" #include "Common/System/OSD.h" -#include "Common/Battery/Battery.h" #include "Common/System/NativeApp.h" #include "Common/Data/Color/RGBAUtil.h" #include "Common/Math/curves.h" @@ -622,11 +621,11 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings) }); graphicsSettings->Add(new ItemHeader(gr->T("Overlay Information"))); - BitCheckBox *showFPSCtr = graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::FPS_COUNTER, gr->T("Show FPS Counter"))); - BitCheckBox *showSpeed = graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::SPEED_COUNTER, gr->T("Show Speed"))); -#ifdef CAN_DISPLAY_CURRENT_BATTERY_CAPACITY - BitCheckBox *showBattery = graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::BATTERY_PERCENT, gr->T("Show Battery %"))); -#endif + graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::FPS_COUNTER, gr->T("Show FPS Counter"))); + graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::SPEED_COUNTER, gr->T("Show Speed"))); + if (System_GetPropertyBool(SYSPROP_CAN_READ_BATTERY_PERCENTAGE)) { + graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::BATTERY_PERCENT, gr->T("Show Battery %"))); + } AddOverlayList(graphicsSettings, screenManager()); } diff --git a/ios/main.mm b/ios/main.mm index bef02d0a26..d2f1be2908 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -316,6 +316,8 @@ std::vector System_GetPropertyStringVec(SystemProperty prop) { } } +int Apple_GetCurrentBatteryCapacity(); + int64_t System_GetPropertyInt(SystemProperty prop) { switch (prop) { case SYSPROP_AUDIO_SAMPLE_RATE: @@ -324,6 +326,8 @@ int64_t System_GetPropertyInt(SystemProperty prop) { return DEVICE_TYPE_MOBILE; case SYSPROP_SYSTEMVERSION: return g_iosVersionMajor; + case SYSPROP_BATTERY_PERCENTAGE: + return Apple_GetCurrentBatteryCapacity(); default: return -1; } @@ -381,6 +385,9 @@ bool System_GetPropertyBool(SystemProperty prop) { case SYSPROP_SUPPORTS_HTTPS: return true; #endif + case SYSPROP_CAN_READ_BATTERY_PERCENTAGE: + return true; + default: return false; }