Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,6 @@ add_library(Common STATIC
Common/SysError.cpp
Common/TimeUtil.cpp
Common/TimeUtil.h
Common/Battery/Battery.h
)

include_directories(Common)
Expand Down
7 changes: 4 additions & 3 deletions Common/Battery/AppleBatteryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// Created by Serena on 24/01/2023.
//

#include "Battery.h"
#include "ppsspp_config.h"

#import <Foundation/Foundation.h>

#if PPSSPP_PLATFORM(MAC)
Expand Down Expand Up @@ -90,7 +91,7 @@ - (void)setNeedsToUpdateLevel {

@end


int getCurrentBatteryCapacity() {
// TODO: Move this.
int Apple_GetCurrentBatteryCapacity() {
return [[AppleBatteryClient sharedClient] batteryLevel];
}
32 changes: 0 additions & 32 deletions Common/Battery/Battery.h

This file was deleted.

3 changes: 3 additions & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 21 additions & 2 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
}
}

#if PPSSPP_PLATFORM(MAC)
extern "C" {
int Apple_GetCurrentBatteryCapacity();
}
#endif

int64_t System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
Expand Down Expand Up @@ -543,6 +549,18 @@ int64_t System_GetPropertyInt(SystemProperty prop) {
return g_DesktopWidth;
case SYSPROP_DISPLAY_YRES:
return g_DesktopHeight;
case SYSPROP_BATTERY_PERCENTAGE:
#if PPSSPP_PLATFORM(MAC)
// Let's keep using the old code on Mac for safety. Evaluate later if to be deleted.
return Apple_GetCurrentBatteryCapacity();
#else
{
int seconds = 0;
int percentage = 0;
SDL_GetPowerInfo(&seconds, &percentage);
return percentage;
}
#endif
default:
return -1;
}
Expand Down Expand Up @@ -604,15 +622,16 @@ bool System_GetPropertyBool(SystemProperty prop) {
#if PPSSPP_PLATFORM(MAC)
case SYSPROP_HAS_FOLDER_BROWSER:
case SYSPROP_HAS_FILE_BROWSER:
return true;
#endif
case SYSPROP_HAS_ACCELEROMETER:
#if defined(MOBILE_DEVICE)
return true;
#else
return false;
#endif
default:
case SYSPROP_CAN_READ_BATTERY_PERCENTAGE:
return true;
default:
return false;
}
}
Expand Down
13 changes: 7 additions & 6 deletions UI/DebugOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 5 additions & 6 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}

Expand Down
9 changes: 9 additions & 0 deletions ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ bool jb_enable_ptrace_hack(void) {
}
}

extern "C" {
int Apple_GetCurrentBatteryCapacity();
}

int64_t System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
Expand All @@ -324,6 +328,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;
}
Expand Down Expand Up @@ -381,6 +387,9 @@ bool System_GetPropertyBool(SystemProperty prop) {
case SYSPROP_SUPPORTS_HTTPS:
return true;
#endif
case SYSPROP_CAN_READ_BATTERY_PERCENTAGE:
return true;

default:
return false;
}
Expand Down
Loading