This commit is contained in:
Anon 2016-07-30 10:21:23 -05:00
parent e4237e0378
commit 9535169577

View File

@ -21,27 +21,27 @@
#include "video_core/video_core.h" #include "video_core/video_core.h"
namespace Service { namespace Service {
namespace HID { namespace HID {
// Handle to shared memory region designated to HID_User service // Handle to shared memory region designated to HID_User service
static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem;
// Event handles // Event handles
static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_1; static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_1;
static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_2; static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_2;
static Kernel::SharedPtr<Kernel::Event> event_accelerometer; static Kernel::SharedPtr<Kernel::Event> event_accelerometer;
static Kernel::SharedPtr<Kernel::Event> event_gyroscope; static Kernel::SharedPtr<Kernel::Event> event_gyroscope;
static Kernel::SharedPtr<Kernel::Event> event_debug_pad; static Kernel::SharedPtr<Kernel::Event> event_debug_pad;
static u32 next_pad_index; static u32 next_pad_index;
static u32 next_touch_index; static u32 next_touch_index;
static u32 next_accelerometer_index; static u32 next_accelerometer_index;
static u32 next_gyroscope_index; static u32 next_gyroscope_index;
static int enable_accelerometer_count = 0; // positive means enabled static int enable_accelerometer_count = 0; // positive means enabled
static int enable_gyroscope_count = 0; // positive means enabled static int enable_gyroscope_count = 0; // positive means enabled
static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) { static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
constexpr float TAN30 = 0.577350269, TAN60 = 1 / TAN30; // 30 degree and 60 degree are angular thresholds for directions constexpr float TAN30 = 0.577350269, TAN60 = 1 / TAN30; // 30 degree and 60 degree are angular thresholds for directions
constexpr int CIRCLE_PAD_THRESHOLD_SQUARE = 40 * 40; // a circle pad radius greater than 40 will trigger circle pad direction constexpr int CIRCLE_PAD_THRESHOLD_SQUARE = 40 * 40; // a circle pad radius greater than 40 will trigger circle pad direction
PadState state; PadState state;
@ -66,9 +66,9 @@ namespace Service {
} }
return state; return state;
} }
void Update() { void Update() {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer()); SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
if (mem == nullptr) { if (mem == nullptr) {
@ -77,7 +77,6 @@ namespace Service {
} }
PadState state = InputCore::pad_state; PadState state = InputCore::pad_state;
// Get current circle pad position and update circle pad direction // Get current circle pad position and update circle pad direction
s16 circle_pad_x, circle_pad_y; s16 circle_pad_x, circle_pad_y;
std::tie(circle_pad_x, circle_pad_y) = InputCore::circle_pad; std::tie(circle_pad_x, circle_pad_y) = InputCore::circle_pad;
@ -185,9 +184,9 @@ namespace Service {
event_gyroscope->Signal(); event_gyroscope->Signal();
} }
} }
void GetIPCHandles(Service::Interface* self) { void GetIPCHandles(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = 0; // No error cmd_buff[1] = 0; // No error
@ -199,9 +198,9 @@ namespace Service {
cmd_buff[6] = Kernel::g_handle_table.Create(Service::HID::event_accelerometer).MoveFrom(); cmd_buff[6] = Kernel::g_handle_table.Create(Service::HID::event_accelerometer).MoveFrom();
cmd_buff[7] = Kernel::g_handle_table.Create(Service::HID::event_gyroscope).MoveFrom(); cmd_buff[7] = Kernel::g_handle_table.Create(Service::HID::event_gyroscope).MoveFrom();
cmd_buff[8] = Kernel::g_handle_table.Create(Service::HID::event_debug_pad).MoveFrom(); cmd_buff[8] = Kernel::g_handle_table.Create(Service::HID::event_debug_pad).MoveFrom();
} }
void EnableAccelerometer(Service::Interface* self) { void EnableAccelerometer(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
++enable_accelerometer_count; ++enable_accelerometer_count;
@ -210,9 +209,9 @@ namespace Service {
cmd_buff[1] = RESULT_SUCCESS.raw; cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_HID, "called"); LOG_DEBUG(Service_HID, "called");
} }
void DisableAccelerometer(Service::Interface* self) { void DisableAccelerometer(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
--enable_accelerometer_count; --enable_accelerometer_count;
@ -221,9 +220,9 @@ namespace Service {
cmd_buff[1] = RESULT_SUCCESS.raw; cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_HID, "called"); LOG_DEBUG(Service_HID, "called");
} }
void EnableGyroscopeLow(Service::Interface* self) { void EnableGyroscopeLow(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
++enable_gyroscope_count; ++enable_gyroscope_count;
@ -232,9 +231,9 @@ namespace Service {
cmd_buff[1] = RESULT_SUCCESS.raw; cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_HID, "called"); LOG_DEBUG(Service_HID, "called");
} }
void DisableGyroscopeLow(Service::Interface* self) { void DisableGyroscopeLow(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
--enable_gyroscope_count; --enable_gyroscope_count;
@ -243,18 +242,18 @@ namespace Service {
cmd_buff[1] = RESULT_SUCCESS.raw; cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_HID, "called"); LOG_DEBUG(Service_HID, "called");
} }
void GetGyroscopeLowRawToDpsCoefficient(Service::Interface* self) { void GetGyroscopeLowRawToDpsCoefficient(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw; cmd_buff[1] = RESULT_SUCCESS.raw;
f32 coef = VideoCore::g_emu_window->GetGyroscopeRawToDpsCoefficient(); f32 coef = VideoCore::g_emu_window->GetGyroscopeRawToDpsCoefficient();
memcpy(&cmd_buff[2], &coef, 4); memcpy(&cmd_buff[2], &coef, 4);
} }
void GetGyroscopeLowCalibrateParam(Service::Interface* self) { void GetGyroscopeLowCalibrateParam(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw; cmd_buff[1] = RESULT_SUCCESS.raw;
@ -268,9 +267,9 @@ namespace Service {
memcpy(&cmd_buff[2], &param, sizeof(param)); memcpy(&cmd_buff[2], &param, sizeof(param));
LOG_WARNING(Service_HID, "(STUBBED) called"); LOG_WARNING(Service_HID, "(STUBBED) called");
} }
void GetSoundVolume(Service::Interface* self) { void GetSoundVolume(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
const u8 volume = 0x3F; // TODO(purpasmart): Find out if this is the max value for the volume const u8 volume = 0x3F; // TODO(purpasmart): Find out if this is the max value for the volume
@ -279,9 +278,9 @@ namespace Service {
cmd_buff[2] = volume; cmd_buff[2] = volume;
LOG_WARNING(Service_HID, "(STUBBED) called"); LOG_WARNING(Service_HID, "(STUBBED) called");
} }
void Init() { void Init() {
using namespace Kernel; using namespace Kernel;
AddService(new HID_U_Interface); AddService(new HID_U_Interface);
@ -301,17 +300,17 @@ namespace Service {
event_accelerometer = Event::Create(ResetType::OneShot, "HID:EventAccelerometer"); event_accelerometer = Event::Create(ResetType::OneShot, "HID:EventAccelerometer");
event_gyroscope = Event::Create(ResetType::OneShot, "HID:EventGyroscope"); event_gyroscope = Event::Create(ResetType::OneShot, "HID:EventGyroscope");
event_debug_pad = Event::Create(ResetType::OneShot, "HID:EventDebugPad"); event_debug_pad = Event::Create(ResetType::OneShot, "HID:EventDebugPad");
} }
void Shutdown() { void Shutdown() {
shared_mem = nullptr; shared_mem = nullptr;
event_pad_or_touch_1 = nullptr; event_pad_or_touch_1 = nullptr;
event_pad_or_touch_2 = nullptr; event_pad_or_touch_2 = nullptr;
event_accelerometer = nullptr; event_accelerometer = nullptr;
event_gyroscope = nullptr; event_gyroscope = nullptr;
event_debug_pad = nullptr; event_debug_pad = nullptr;
} }
} // namespace HID } // namespace HID
} // namespace Service } // namespace Service