ptm_u.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/logging/log.h"
  5. #include "core/hle/hle.h"
  6. #include "core/hle/service/ptm/ptm.h"
  7. #include "core/hle/service/ptm/ptm_u.h"
  8. namespace Service {
  9. namespace PTM {
  10. /**
  11. * PTM_U::GetAdapterState service function
  12. * Outputs:
  13. * 1 : Result of function, 0 on success, otherwise error code
  14. * 2 : Output of function, 0 = not charging, 1 = charging.
  15. */
  16. static void GetAdapterState(Service::Interface* self) {
  17. u32* cmd_buff = Kernel::GetCommandBuffer();
  18. cmd_buff[1] = RESULT_SUCCESS.raw;
  19. cmd_buff[2] = GetAdapterState();
  20. LOG_WARNING(Service_PTM, "(STUBBED) called");
  21. }
  22. /*
  23. * PTM_User::GetShellState service function.
  24. * Outputs:
  25. * 1 : Result of function, 0 on success, otherwise error code
  26. * 2 : Whether the 3DS's physical shell casing is open (1) or closed (0)
  27. */
  28. static void GetShellState(Service::Interface* self) {
  29. u32* cmd_buff = Kernel::GetCommandBuffer();
  30. cmd_buff[1] = RESULT_SUCCESS.raw;
  31. cmd_buff[2] = GetShellState();
  32. }
  33. /**
  34. * PTM_U::GetBatteryLevel service function
  35. * Outputs:
  36. * 1 : Result of function, 0 on success, otherwise error code
  37. * 2 : Battery level, 5 = completely full battery, 4 = mostly full battery,
  38. * 3 = half full battery, 2 = low battery, 1 = critical battery.
  39. */
  40. static void GetBatteryLevel(Service::Interface* self) {
  41. u32* cmd_buff = Kernel::GetCommandBuffer();
  42. cmd_buff[1] = RESULT_SUCCESS.raw;
  43. cmd_buff[2] = static_cast<u32>(GetBatteryLevel());
  44. LOG_WARNING(Service_PTM, "(STUBBED) called");
  45. }
  46. /**
  47. * PTM_U::GetBatteryChargeState service function
  48. * Outputs:
  49. * 1 : Result of function, 0 on success, otherwise error code
  50. * 2 : Output of function, 0 = not charging, 1 = charging.
  51. */
  52. static void GetBatteryChargeState(Service::Interface* self) {
  53. u32* cmd_buff = Kernel::GetCommandBuffer();
  54. // TODO(purpasmart96): This function is only a stub,
  55. // it returns a valid result without implementing full functionality.
  56. cmd_buff[1] = RESULT_SUCCESS.raw;
  57. cmd_buff[2] = GetAdapterState();
  58. LOG_WARNING(Service_PTM, "(STUBBED) called");
  59. }
  60. const Interface::FunctionInfo FunctionTable[] = {
  61. {0x00010002, nullptr, "RegisterAlarmClient"},
  62. {0x00020080, nullptr, "SetRtcAlarm"},
  63. {0x00030000, nullptr, "GetRtcAlarm"},
  64. {0x00040000, nullptr, "CancelRtcAlarm"},
  65. {0x00050000, GetAdapterState, "GetAdapterState"},
  66. {0x00060000, GetShellState, "GetShellState"},
  67. {0x00070000, GetBatteryLevel, "GetBatteryLevel"},
  68. {0x00080000, GetBatteryChargeState, "GetBatteryChargeState"},
  69. {0x00090000, nullptr, "GetPedometerState"},
  70. {0x000A0042, nullptr, "GetStepHistoryEntry"},
  71. {0x000B00C2, nullptr, "GetStepHistory"},
  72. {0x000C0000, nullptr, "GetTotalStepCount"},
  73. {0x000D0040, nullptr, "SetPedometerRecordingMode"},
  74. {0x000E0000, nullptr, "GetPedometerRecordingMode"},
  75. {0x000F0084, nullptr, "GetStepHistoryAll"},
  76. };
  77. PTM_U_Interface::PTM_U_Interface() {
  78. Register(FunctionTable);
  79. }
  80. } // namespace PTM
  81. } // namespace Service