1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-18 18:06:40 +00:00

strat/hid: Update for new libnx HID interface

This commit is contained in:
fincs 2020-12-02 00:42:13 +01:00 committed by SciresM
parent 8b2ed36698
commit a03ee7b148

View file

@ -23,12 +23,30 @@ namespace ams::hid {
os::Mutex g_hid_lock(false); os::Mutex g_hid_lock(false);
bool g_initialized_hid = false; bool g_initialized_hid = false;
/* Set of supported NpadIds (we want to read from any connected controllers). */
constexpr const HidNpadIdType NpadIdTypes[] = {
HidNpadIdType_No1,
HidNpadIdType_No2,
HidNpadIdType_No3,
HidNpadIdType_No4,
HidNpadIdType_No5,
HidNpadIdType_No6,
HidNpadIdType_No7,
HidNpadIdType_No8,
HidNpadIdType_Handheld,
};
constexpr const size_t NumNpadIdTypes = util::size(NpadIdTypes);
/* Helper. */ /* Helper. */
void InitializeHid() { void InitializeHid() {
R_ABORT_UNLESS(smInitialize()); R_ABORT_UNLESS(smInitialize());
ON_SCOPE_EXIT { smExit(); }; ON_SCOPE_EXIT { smExit(); };
{ {
R_ABORT_UNLESS(hidInitialize()); R_ABORT_UNLESS(hidInitialize());
hidInitializeNpad();
R_ABORT_UNLESS(hidSetSupportedNpadIdType(NpadIdTypes, NumNpadIdTypes));
R_ABORT_UNLESS(hidSetSupportedNpadStyleSet(HidNpadStyleSet_NpadStandard | HidNpadStyleTag_NpadSystemExt));
} }
} }
@ -46,6 +64,17 @@ namespace ams::hid {
return ResultSuccess(); return ResultSuccess();
} }
u64 ReadHidNpad(HidNpadIdType id) {
HidNpadSystemExtState state;
size_t count = hidGetNpadStatesSystemExt(id, std::addressof(state), 1);
if (count != 0 && (state.attributes & HidNpadAttribute_IsConnected)) {
return state.buttons;
}
return 0;
}
} }
Result GetKeysHeld(u64 *out) { Result GetKeysHeld(u64 *out) {
@ -53,11 +82,10 @@ namespace ams::hid {
R_TRY(EnsureHidInitialized()); R_TRY(EnsureHidInitialized());
hidScanInput(); *out = ReadHidNpad(HidNpadIdType_Handheld);
*out = 0;
for (size_t controller = 0; controller < 10; controller++) { for (size_t controller = 0; controller < 8; controller++) {
*out |= hidKeysHeld(static_cast<HidControllerID>(controller)); *out |= ReadHidNpad(static_cast<HidNpadIdType>(controller));
} }
return ResultSuccess(); return ResultSuccess();