use IPCHelper for PTM services

This commit is contained in:
emmaus 2017-05-17 21:12:59 +00:00
parent 8d558777a6
commit b2e82d16c8
3 changed files with 45 additions and 31 deletions

View file

@ -27,67 +27,72 @@ static bool shell_open;
static bool battery_is_charging; static bool battery_is_charging;
static bool pedometer_is_counting;
void GetAdapterState(Service::Interface* self) { void GetAdapterState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x5, 0, 0);
// TODO(purpasmart96): This function is only a stub, IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
// it returns a valid result without implementing full functionality. rb.Push(RESULT_SUCCESS);
rb.Push(battery_is_charging);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = battery_is_charging ? 1 : 0;
LOG_WARNING(Service_PTM, "(STUBBED) called"); LOG_WARNING(Service_PTM, "(STUBBED) called");
} }
void GetShellState(Service::Interface* self) { void GetShellState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x6, 0, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
cmd_buff[2] = shell_open ? 1 : 0; rb.Push(RESULT_SUCCESS);
rb.Push(shell_open);
} }
void GetBatteryLevel(Service::Interface* self) { void GetBatteryLevel(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x7, 0, 0);
// TODO(purpasmart96): This function is only a stub, IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
// it returns a valid result without implementing full functionality. rb.Push(RESULT_SUCCESS);
rb.Push(static_cast<u32>(ChargeLevels::CompletelyFull)); // Set to a completely full battery
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"); LOG_WARNING(Service_PTM, "(STUBBED) called");
} }
void GetBatteryChargeState(Service::Interface* self) { void GetBatteryChargeState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x8, 0, 0);
// TODO(purpasmart96): This function is only a stub, IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
// it returns a valid result without implementing full functionality. rb.Push(RESULT_SUCCESS);
rb.Push(battery_is_charging);
cmd_buff[1] = RESULT_SUCCESS.raw; LOG_WARNING(Service_PTM, "(STUBBED) called");
cmd_buff[2] = battery_is_charging ? 1 : 0; }
void GetPedometerState(Service::Interface* self) {
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x9, 0, 0);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
rb.Push(pedometer_is_counting);
LOG_WARNING(Service_PTM, "(STUBBED) called"); LOG_WARNING(Service_PTM, "(STUBBED) called");
} }
void GetTotalStepCount(Service::Interface* self) { void GetTotalStepCount(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0xC, 0, 0);
// TODO: This function is only a stub, IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
// it returns 0 as the total step count rb.Push(RESULT_SUCCESS);
rb.Push<u32>(0);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = 0;
LOG_WARNING(Service_PTM, "(STUBBED) called"); LOG_WARNING(Service_PTM, "(STUBBED) called");
} }
void GetSoftwareClosedFlag(Service::Interface* self) { void GetSoftwareClosedFlag(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x80F, 0, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
cmd_buff[2] = 0; rb.Push(RESULT_SUCCESS);
rb.Push(false);
LOG_WARNING(Service_PTM, "(STUBBED) called"); LOG_WARNING(Service_PTM, "(STUBBED) called");
} }
@ -121,6 +126,7 @@ void Init() {
shell_open = true; shell_open = true;
battery_is_charging = true; battery_is_charging = true;
pedometer_is_counting = false;
// Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't // Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't
// exist // exist

View file

@ -74,6 +74,14 @@ void GetBatteryLevel(Interface* self);
*/ */
void GetBatteryChargeState(Interface* self); void GetBatteryChargeState(Interface* self);
/**
* PTM::GetPedometerState service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output of function, 0 = not counting steps, 1 = counting steps.
*/
void GetPedometerState(Interface* self);
/** /**
* PTM::GetTotalStepCount service function * PTM::GetTotalStepCount service function
* Outputs: * Outputs:

View file

@ -17,7 +17,7 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x00060000, GetShellState, "GetShellState"}, {0x00060000, GetShellState, "GetShellState"},
{0x00070000, GetBatteryLevel, "GetBatteryLevel"}, {0x00070000, GetBatteryLevel, "GetBatteryLevel"},
{0x00080000, GetBatteryChargeState, "GetBatteryChargeState"}, {0x00080000, GetBatteryChargeState, "GetBatteryChargeState"},
{0x00090000, nullptr, "GetPedometerState"}, {0x00090000, GetPedometerState, "GetPedometerState"},
{0x000A0042, nullptr, "GetStepHistoryEntry"}, {0x000A0042, nullptr, "GetStepHistoryEntry"},
{0x000B00C2, nullptr, "GetStepHistory"}, {0x000B00C2, nullptr, "GetStepHistory"},
{0x000C0000, GetTotalStepCount, "GetTotalStepCount"}, {0x000C0000, GetTotalStepCount, "GetTotalStepCount"},