Implement ptm:u:GetBatteryLevel

This commit is contained in:
Andrea Pascal 2017-05-12 18:15:35 -04:00
parent bf97bac8dc
commit 23ed5932ba

View File

@ -13,6 +13,7 @@
#include "core/hle/service/ptm/ptm_u.h"
#include "core/hle/service/service.h"
#include "core/settings.h"
#include <SDL_power.h>
namespace Service {
namespace PTM {
@ -49,22 +50,38 @@ void GetShellState(Service::Interface* self) {
void GetBatteryLevel(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
// TODO(purpasmart96): This function is only a stub,
// it returns a valid result without implementing full functionality.
int* battery_percentage;
SDL_PowerState power_status = SDL_GetPowerInfo(NULL, battery_percentage);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] =
static_cast<u32>(ChargeLevels::CompletelyFull); // Set to a completely full battery
LOG_WARNING(Service_PTM, "(STUBBED) called");
ChargeLevels PowerPercentageToChargeLevel = [](int* percentage) {
if (percentage <= 100 && percentage >= 61) return ChargeLevels::CompletelyFull;
if (percentage <= 60 && percentage >= 31) return ChargeLevels::MostlyFull;
if (percentage <= 30 && percentage >= 11) return ChargeLevels::HalfFull;
if (percentage <= 10 && percentage >= 5) return ChargeLevels::LowBattery;
if (percentage <= 5 && percentage >= 1) return ChargeLevels::CriticalBattery;
if (percentage == 0) return ChargeLevels::EmptyBattery;
return ChargeLevels::CompletelyFull;
// Return full battery since it's obvious the battery is NOT empty.
}
// Deal with exceptional cases
if (power_status == SDL_POWERSTATE_CHARGED ||
power_status == SDL_POWERSTATE_NO_BATTERY ||
power_status == SDL_POWERSTATE_UNKNOWN) {
cmd_buff[2] = ChargeLevels::CompletelyFull;
return;
}
cmd_buff[2] = PowerPercentageToChargeLevel(battery_percentage);
}
void GetBatteryChargeState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
// TODO(purpasmart96): This function is only a stub,
// it returns a valid result without implementing full functionality.
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = battery_is_charging ? 1 : 0;