diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index f024480d..8c417d79 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -587,7 +587,7 @@ Result hidSetNpadJoyAssignmentModeSingleByDefault(HidControllerID id); /// id must be CONTROLLER_PLAYER_*. Result hidSetNpadJoyAssignmentModeDual(HidControllerID id); -Result hidInitializeVibrationDevice(u32 *VibrationDeviceHandle, HidControllerID id, HidControllerLayoutType type); +Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, size_t total_handles, HidControllerID id, HidControllerLayoutType type); Result hidSendVibrationValue(u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue); diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index 818b8a42..e1c821c8 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -722,19 +722,49 @@ Result hidIsVibrationPermitted(bool *flag) { return rc; } -Result hidInitializeVibrationDevice(u32 *VibrationDeviceHandle, HidControllerID id, HidControllerLayoutType type) { +Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, size_t total_handles, HidControllerID id, HidControllerLayoutType type) { Result rc=0; Service srv; + u32 tmp_type = type & 0xff; + size_t i; + + if (total_handles == 0 || total_handles > 2) + return MAKERESULT(Module_Libnx, LibnxError_BadInput); + + if (tmp_type < 5) { + if (tmp_type == 4) tmp_type |= 0x010000; + tmp_type+= 3; + } + else { + if (tmp_type == 5) tmp_type = 0x20; + if (tmp_type == 6) tmp_type = 0x21; + } //TODO: Is type correct? - *VibrationDeviceHandle = (type & 0xff) | (id & 0xff)<<8; + VibrationDeviceHandles[0] = tmp_type | (id & 0xff)<<8; - rc = _hidCreateActiveVibrationDeviceList(&srv); - if (R_FAILED(rc)) - return rc; + if (total_handles > 1) { + tmp_type &= 0xff; + if (tmp_type!=6 && tmp_type!=7) { + VibrationDeviceHandles[1] = VibrationDeviceHandles[0] | 0x010000; + } + else { + return MAKERESULT(Module_Libnx, LibnxError_BadInput); + } + } + + for (i=0; i