Renamed hidInitializeVibrationDevice() to hidInitializeVibrationDevices(), and added support for optionally returning 2 handles + other changes.

This commit is contained in:
yellows8 2018-03-07 01:16:35 -05:00
parent cbaa0e359b
commit d1cefabd12
2 changed files with 38 additions and 8 deletions

View File

@ -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);

View File

@ -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<total_handles; i++) {
rc = _hidCreateActiveVibrationDeviceList(&srv);
if (R_FAILED(rc))
break;
rc = _hidActivateVibrationDevice(&srv, VibrationDeviceHandles[i]);
serviceClose(&srv);
if (R_FAILED(rc))
break;
}
rc = _hidActivateVibrationDevice(&srv, *VibrationDeviceHandle);
serviceClose(&srv);
return rc;
}