Implement IHidServer Functions

Add GetVibrationDeviceInfo and StartSixAxisSensor
This commit is contained in:
kaikecarlos 2022-03-27 08:06:14 -03:00 committed by PixelyIon
parent 9f51664b1d
commit e8cc760b10
5 changed files with 81 additions and 1 deletions

View File

@ -134,7 +134,7 @@ namespace skyline::input {
section.header.singleColorStatus = NpadColorReadStatus::Success; // Single color is also written for dual controllers section.header.singleColorStatus = NpadColorReadStatus::Success; // Single color is also written for dual controllers
section.header.singleColor = section.header.leftColor; // and is set to the color of the left JC section.header.singleColor = section.header.leftColor; // and is set to the color of the left JC
break; break;
case NpadControllerType::Gamecube:
case NpadControllerType::None: case NpadControllerType::None:
break; break;
} }

View File

@ -83,12 +83,23 @@ namespace skyline::input {
return NpadControllerType::JoyconLeft; return NpadControllerType::JoyconLeft;
case 7: case 7:
return NpadControllerType::JoyconRight; return NpadControllerType::JoyconRight;
case 8:
return NpadControllerType::Gamecube;
default: default:
return NpadControllerType::None; return NpadControllerType::None;
} }
} }
}; };
/**
* @url https://switchbrew.org/wiki/HID_services#VibrationDeviceInfo
*/
struct NpadVibrationDeviceInfo {
NpadVibrationDeviceType deviceType;
NpadVibrationDevicePosition position;
};
static_assert(sizeof(NpadVibrationDeviceInfo) == 0x8);
/** /**
* @brief The parameters to produce a vibration using an LRA * @brief The parameters to produce a vibration using an LRA
* @note The vibration is broken into a frequency band with the lower and high range supplied * @note The vibration is broken into a frequency band with the lower and high range supplied

View File

@ -14,6 +14,7 @@ namespace skyline::input {
JoyconDual = 0b100, JoyconDual = 0b100,
JoyconLeft = 0b1000, JoyconLeft = 0b1000,
JoyconRight = 0b10000, JoyconRight = 0b10000,
Gamecube = 0b100000,
}; };
// @fmt:on // @fmt:on
@ -187,6 +188,26 @@ namespace skyline::input {
}; };
static_assert(sizeof(NpadDeviceType) == 0x4); static_assert(sizeof(NpadDeviceType) == 0x4);
/**
* @url https://switchbrew.org/wiki/HID_services#VibrationDeviceType
*/
enum class NpadVibrationDeviceType : u32 {
Unknown,
LinearResonantActuator, //!< LRAs are used on devices that support HD Rumble functionality such as Joy-Cons and the Pro Controller
EccentricRotatingMass, //!< ERMs are mainly used in the old GameCube controllers and offer more crude rumble
};
static_assert(sizeof(NpadVibrationDeviceType) == 0x4);
/**
* @url https://switchbrew.org/wiki/HID_services#VibrationDevicePosition
*/
enum class NpadVibrationDevicePosition : u32 {
None,
Left,
Right
};
static_assert(sizeof(NpadVibrationDevicePosition) == 0x4);
/** /**
* @url https://switchbrew.org/wiki/HID_Shared_Memory#NpadSystemProperties * @url https://switchbrew.org/wiki/HID_Shared_Memory#NpadSystemProperties
*/ */

View File

@ -179,4 +179,34 @@ namespace skyline::service::hid {
return {}; return {};
} }
Result IHidServer::StartSixAxisSensor(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
return {};
}
Result IHidServer::GetVibrationDeviceInfo(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto deviceHandle{request.Pop<NpadDeviceHandle>()};
auto id{deviceHandle.id};
if (id > NpadId::Player8 && id != NpadId::Handheld && id != NpadId::Unknown)
return result::InvalidNpadId;
auto vibrationDeviceType{NpadVibrationDeviceType::Unknown};
auto vibrationDevicePosition{NpadVibrationDevicePosition::None};
if (deviceHandle.GetType() == NpadControllerType::Gamecube)
vibrationDeviceType = NpadVibrationDeviceType::EccentricRotatingMass;
else
vibrationDeviceType = NpadVibrationDeviceType::LinearResonantActuator;
if (vibrationDeviceType == NpadVibrationDeviceType::LinearResonantActuator)
if (deviceHandle.isRight)
vibrationDevicePosition = NpadVibrationDevicePosition::Right;
else
vibrationDevicePosition = NpadVibrationDevicePosition::Left;
response.Push(NpadVibrationDeviceInfo{vibrationDeviceType, vibrationDevicePosition});
return {};
}
} }

View File

@ -7,6 +7,10 @@
#include "IAppletResource.h" #include "IAppletResource.h"
namespace skyline::service::hid { namespace skyline::service::hid {
namespace result {
constexpr Result InvalidNpadId(202, 709);
}
/** /**
* @brief IHidServer or hid service is used to access input devices * @brief IHidServer or hid service is used to access input devices
* @url https://switchbrew.org/wiki/HID_services#hid * @url https://switchbrew.org/wiki/HID_services#hid
@ -31,6 +35,12 @@ namespace skyline::service::hid {
*/ */
Result ActivateTouchScreen(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); Result ActivateTouchScreen(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief Starts the Six Axis Sensor given an PID
* @url https://switchbrew.org/wiki/HID_services#CreateAppletResource
*/
Result StartSixAxisSensor(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/** /**
* @brief Sets the style of controllers supported * @brief Sets the style of controllers supported
* @url https://switchbrew.org/wiki/HID_services#SetSupportedNpadStyleSet * @url https://switchbrew.org/wiki/HID_services#SetSupportedNpadStyleSet
@ -114,6 +124,12 @@ namespace skyline::service::hid {
*/ */
Result CreateActiveVibrationDeviceList(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); Result CreateActiveVibrationDeviceList(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief Returns the current vibration state of a device
* @url https://switchbrew.org/wiki/HID_services#GetVibrationDeviceInfo
*/
Result GetVibrationDeviceInfo(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/** /**
* @brief Send a single vibration value to a HID device * @brief Send a single vibration value to a HID device
* @url https://switchbrew.org/wiki/HID_services#SendVibrationValue * @url https://switchbrew.org/wiki/HID_services#SendVibrationValue
@ -130,6 +146,7 @@ namespace skyline::service::hid {
SFUNC(0x0, IHidServer, CreateAppletResource), SFUNC(0x0, IHidServer, CreateAppletResource),
SFUNC(0x1, IHidServer, ActivateDebugPad), SFUNC(0x1, IHidServer, ActivateDebugPad),
SFUNC(0xB, IHidServer, ActivateTouchScreen), SFUNC(0xB, IHidServer, ActivateTouchScreen),
SFUNC(0x42, IHidServer, StartSixAxisSensor),
SFUNC(0x64, IHidServer, SetSupportedNpadStyleSet), SFUNC(0x64, IHidServer, SetSupportedNpadStyleSet),
SFUNC(0x65, IHidServer, GetSupportedNpadStyleSet), SFUNC(0x65, IHidServer, GetSupportedNpadStyleSet),
SFUNC(0x66, IHidServer, SetSupportedNpadIdType), SFUNC(0x66, IHidServer, SetSupportedNpadIdType),
@ -144,6 +161,7 @@ namespace skyline::service::hid {
SFUNC(0x7B, IHidServer, SetNpadJoyAssignmentModeSingle), SFUNC(0x7B, IHidServer, SetNpadJoyAssignmentModeSingle),
SFUNC(0x7C, IHidServer, SetNpadJoyAssignmentModeDual), SFUNC(0x7C, IHidServer, SetNpadJoyAssignmentModeDual),
SFUNC(0xCB, IHidServer, CreateActiveVibrationDeviceList), SFUNC(0xCB, IHidServer, CreateActiveVibrationDeviceList),
SFUNC(0xC8, IHidServer, GetVibrationDeviceInfo),
SFUNC(0xC9, IHidServer, SendVibrationValue), SFUNC(0xC9, IHidServer, SendVibrationValue),
SFUNC(0xCE, IHidServer, SendVibrationValues) SFUNC(0xCE, IHidServer, SendVibrationValues)
) )