Correct GetNpadIrCameraHandle return value

This commit is contained in:
Billy Laws 2023-01-08 21:07:58 +00:00
parent a8b32c3cef
commit fd5c141dbf
2 changed files with 28 additions and 18 deletions

View File

@ -26,22 +26,6 @@ namespace skyline::input {
friend NpadDevice; friend NpadDevice;
/**
* @brief Translates an NPad's ID into its index in the array
* @param id The ID of the NPad to translate
* @return The corresponding index of the NPad in the array
*/
static constexpr size_t Translate(NpadId id) {
switch (id) {
case NpadId::Handheld:
return 8;
case NpadId::Unknown:
return 9;
default:
return static_cast<size_t>(id);
}
}
public: public:
std::recursive_mutex mutex; //!< This mutex must be locked before any modifications to class members std::recursive_mutex mutex; //!< This mutex must be locked before any modifications to class members
std::array<NpadDevice, constant::NpadCount> npads; std::array<NpadDevice, constant::NpadCount> npads;
@ -56,18 +40,33 @@ namespace skyline::input {
*/ */
NpadManager(const DeviceState &state, input::HidSharedMemory *hid); NpadManager(const DeviceState &state, input::HidSharedMemory *hid);
/**
* @brief Translates an NPad's ID into its index in the npad array
* @param id The ID of the NPad to translate
*/
static constexpr size_t NpadIdToIndex(NpadId id) {
switch (id) {
case NpadId::Handheld:
return 8;
case NpadId::Unknown:
return 9;
default:
return static_cast<size_t>(id);
}
}
/** /**
* @return A reference to the NPad with the specified ID * @return A reference to the NPad with the specified ID
*/ */
constexpr NpadDevice &at(NpadId id) { constexpr NpadDevice &at(NpadId id) {
return npads.at(Translate(id)); return npads.at(NpadIdToIndex(id));
} }
/** /**
* @return A reference to the NPad with the specified ID * @return A reference to the NPad with the specified ID
*/ */
constexpr NpadDevice &operator[](NpadId id) noexcept { constexpr NpadDevice &operator[](NpadId id) noexcept {
return npads.operator[](Translate(id)); return npads.operator[](NpadIdToIndex(id));
} }
/** /**

View File

@ -13,6 +13,17 @@ namespace skyline::service::irs {
auto id{request.Pop<NpadId>()}; auto id{request.Pop<NpadId>()};
if (id > NpadId::Player8 && id != NpadId::Handheld && id != NpadId::Unknown) if (id > NpadId::Player8 && id != NpadId::Handheld && id != NpadId::Unknown)
return result::InvalidNpadId; return result::InvalidNpadId;
struct IrCameraHandle {
u8 npadIndex;
u8 npadType;
u8 _pad0_[2];
} handle{
.npadIndex = static_cast<u8>(state.input->npad.NpadIdToIndex(id)),
};
response.Push(handle);
return {}; return {};
} }