hid: Use structs for vibration/SixAxis handles.

Various internal improvements, andpass vibration handles by value where needed.
This commit is contained in:
yellows8 2020-11-18 19:06:04 -05:00 committed by fincs
parent c0ef14fcaa
commit 16ff35faea
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
2 changed files with 194 additions and 110 deletions

View File

@ -808,6 +808,28 @@ typedef struct {
HidSevenSixAxisSensorStateEntry entries[0x21]; HidSevenSixAxisSensorStateEntry entries[0x21];
} HidSevenSixAxisSensorStates; } HidSevenSixAxisSensorStates;
/// HidSixAxisSensorHandle
typedef union HidSixAxisSensorHandle {
u32 type_value; ///< TypeValue
struct {
u32 npad_style_index : 8; ///< NpadStyleIndex
u32 npad_id_type : 8; ///< PlayerNumber / NpadIdType
u32 idx : 8; ///< Idx
u32 pad : 8; ///< Padding
};
} HidSixAxisSensorHandle;
/// HidVibrationDeviceHandle
typedef union HidVibrationDeviceHandle {
u32 type_value; ///< TypeValue
struct {
u32 npad_style_index : 8; ///< NpadStyleIndex
u32 player_number : 8; ///< PlayerNumber
u32 device_idx : 8; ///< DeviceIdx
u32 pad : 8; ///< Padding
};
} HidVibrationDeviceHandle;
/// HidVibrationDeviceInfo /// HidVibrationDeviceInfo
typedef struct HidVibrationDeviceInfo { typedef struct HidVibrationDeviceInfo {
u32 unk_x0; u32 unk_x0;
@ -929,22 +951,22 @@ u32 hidSixAxisSensorValuesRead(SixAxisSensorValues *values, HidControllerID id,
bool hidGetHandheldMode(void); bool hidGetHandheldMode(void);
/// SetSixAxisSensorFusionParameters. unk0 must be 0.0f-1.0f. /// SetSixAxisSensorFusionParameters. unk0 must be 0.0f-1.0f.
Result hidSetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float unk0, float unk1); Result hidSetSixAxisSensorFusionParameters(HidSixAxisSensorHandle handle, float unk0, float unk1);
/// GetSixAxisSensorFusionParameters /// GetSixAxisSensorFusionParameters
Result hidGetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float *unk0, float *unk1); Result hidGetSixAxisSensorFusionParameters(HidSixAxisSensorHandle handle, float *unk0, float *unk1);
/// ResetSixAxisSensorFusionParameters /// ResetSixAxisSensorFusionParameters
Result hidResetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle); Result hidResetSixAxisSensorFusionParameters(HidSixAxisSensorHandle handle);
/// Sets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle. /// Sets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle.
Result hidSetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode mode); Result hidSetGyroscopeZeroDriftMode(HidSixAxisSensorHandle handle, HidGyroscopeZeroDriftMode mode);
/// Gets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle. /// Gets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle.
Result hidGetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode *mode); Result hidGetGyroscopeZeroDriftMode(HidSixAxisSensorHandle handle, HidGyroscopeZeroDriftMode *mode);
/// Resets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle to ::HidGyroscopeZeroDriftMode_Standard. /// Resets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle to ::HidGyroscopeZeroDriftMode_Standard.
Result hidResetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle); Result hidResetGyroscopeZeroDriftMode(HidSixAxisSensorHandle handle);
/// Sets which controller styles are supported, bitfield of \ref HidNpadStyleTag. This is automatically called with all styles in \ref hidInitialize. /// Sets which controller styles are supported, bitfield of \ref HidNpadStyleTag. This is automatically called with all styles in \ref hidInitialize.
Result hidSetSupportedNpadStyleSet(u32 style_set); Result hidSetSupportedNpadStyleSet(u32 style_set);
@ -983,16 +1005,16 @@ Result hidSetNpadJoyAssignmentModeDual(HidNpadIdType id);
/// If successful, the id of the resulting dual controller is set to id0. /// If successful, the id of the resulting dual controller is set to id0.
Result hidMergeSingleJoyAsDualJoy(HidNpadIdType id0, HidNpadIdType id1); Result hidMergeSingleJoyAsDualJoy(HidNpadIdType id0, HidNpadIdType id1);
Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style); Result hidInitializeVibrationDevices(HidVibrationDeviceHandle *handles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style);
/// Gets HidVibrationDeviceInfo for the specified VibrationDeviceHandle. /// Gets HidVibrationDeviceInfo for the specified device.
Result hidGetVibrationDeviceInfo(const u32 *VibrationDeviceHandle, HidVibrationDeviceInfo *VibrationDeviceInfo); Result hidGetVibrationDeviceInfo(HidVibrationDeviceHandle handle, HidVibrationDeviceInfo *VibrationDeviceInfo);
/// Send the VibrationValue to the specified VibrationDeviceHandle. /// Send the VibrationValue to the specified device.
Result hidSendVibrationValue(const u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue); Result hidSendVibrationValue(HidVibrationDeviceHandle handle, HidVibrationValue *VibrationValue);
/// Gets the current HidVibrationValue for the specified VibrationDeviceHandle. /// Gets the current HidVibrationValue for the specified device.
Result hidGetActualVibrationValue(const u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue); Result hidGetActualVibrationValue(HidVibrationDeviceHandle handle, HidVibrationValue *VibrationValue);
/// Sets whether vibration is allowed, this also affects the config displayed by System Settings. /// Sets whether vibration is allowed, this also affects the config displayed by System Settings.
Result hidPermitVibration(bool flag); Result hidPermitVibration(bool flag);
@ -1000,20 +1022,20 @@ Result hidPermitVibration(bool flag);
/// Gets whether vibration is allowed. /// Gets whether vibration is allowed.
Result hidIsVibrationPermitted(bool *flag); Result hidIsVibrationPermitted(bool *flag);
/// Send VibrationValues[index] to VibrationDeviceHandles[index], where count is the number of entries in the VibrationDeviceHandles/VibrationValues arrays. /// Send VibrationValues[index] to handles[index], where count is the number of entries in the handles/VibrationValues arrays.
Result hidSendVibrationValues(const u32 *VibrationDeviceHandles, HidVibrationValue *VibrationValues, s32 count); Result hidSendVibrationValues(const HidVibrationDeviceHandle *handles, HidVibrationValue *VibrationValues, s32 count);
/// Gets whether vibration is available with the specified device. Only available on [7.0.0+]. /// Gets whether vibration is available with the specified device. Only available on [7.0.0+].
Result hidIsVibrationDeviceMounted(const u32 *VibrationDeviceHandle, bool *flag); Result hidIsVibrationDeviceMounted(HidVibrationDeviceHandle handle, bool *flag);
/// Gets SixAxisSensorHandles. total_handles==2 can only be used with ::HidNpadStyleTag_NpadJoyDual. /// Gets SixAxisSensorHandles. total_handles==2 can only be used with ::HidNpadStyleTag_NpadJoyDual.
Result hidGetSixAxisSensorHandles(u32 *SixAxisSensorHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style); Result hidGetSixAxisSensorHandles(HidSixAxisSensorHandle *handles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style);
/// Starts the SixAxisSensor for the specified handle. /// Starts the SixAxisSensor for the specified handle.
Result hidStartSixAxisSensor(u32 SixAxisSensorHandle); Result hidStartSixAxisSensor(HidSixAxisSensorHandle handle);
/// Stops the SixAxisSensor for the specified handle. /// Stops the SixAxisSensor for the specified handle.
Result hidStopSixAxisSensor(u32 SixAxisSensorHandle); Result hidStopSixAxisSensor(HidSixAxisSensorHandle handle);
/// Starts the SevenSixAxisSensor. Only available on [5.0.0+]. /// Starts the SevenSixAxisSensor. Only available on [5.0.0+].
Result hidStartSevenSixAxisSensor(void); Result hidStartSevenSixAxisSensor(void);

View File

@ -999,31 +999,31 @@ static Result _hidGetSharedMemoryHandle(Service* srv, Handle* handle_out) {
return _hidCmdGetHandle(srv, handle_out, 0); return _hidCmdGetHandle(srv, handle_out, 0);
} }
Result hidSetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float unk0, float unk1) { Result hidSetSixAxisSensorFusionParameters(HidSixAxisSensorHandle handle, float unk0, float unk1) {
if (unk0 < 0.0f || unk0 > 1.0f) if (unk0 < 0.0f || unk0 > 1.0f)
return MAKERESULT(Module_Libnx, LibnxError_BadInput); return MAKERESULT(Module_Libnx, LibnxError_BadInput);
const struct { const struct {
u32 SixAxisSensorHandle; HidSixAxisSensorHandle handle;
float unk0; float unk0;
float unk1; float unk1;
u32 pad; u32 pad;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { SixAxisSensorHandle, unk0, unk1, 0, appletGetAppletResourceUserId() }; } in = { handle, unk0, unk1, 0, appletGetAppletResourceUserId() };
return serviceDispatchIn(&g_hidSrv, 70, in, return serviceDispatchIn(&g_hidSrv, 70, in,
.in_send_pid = true, .in_send_pid = true,
); );
} }
Result hidGetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float *unk0, float *unk1) { Result hidGetSixAxisSensorFusionParameters(HidSixAxisSensorHandle handle, float *unk0, float *unk1) {
Result rc; Result rc;
const struct { const struct {
u32 SixAxisSensorHandle; HidSixAxisSensorHandle handle;
u32 pad; u32 pad;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { SixAxisSensorHandle, 0, appletGetAppletResourceUserId() }; } in = { handle, 0, appletGetAppletResourceUserId() };
struct { struct {
float unk0; float unk0;
@ -1038,30 +1038,30 @@ Result hidGetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float *unk0,
return rc; return rc;
} }
Result hidResetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle) { Result hidResetSixAxisSensorFusionParameters(HidSixAxisSensorHandle handle) {
return _hidCmdWithInputU32(SixAxisSensorHandle, 72); return _hidCmdWithInputU32(handle.type_value, 72);
} }
Result hidSetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode mode) { Result hidSetGyroscopeZeroDriftMode(HidSixAxisSensorHandle handle, HidGyroscopeZeroDriftMode mode) {
const struct { const struct {
u32 SixAxisSensorHandle; HidSixAxisSensorHandle handle;
u32 mode; u32 mode;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { SixAxisSensorHandle, mode, appletGetAppletResourceUserId() }; } in = { handle, mode, appletGetAppletResourceUserId() };
return serviceDispatchIn(&g_hidSrv, 79, in, return serviceDispatchIn(&g_hidSrv, 79, in,
.in_send_pid = true, .in_send_pid = true,
); );
} }
Result hidGetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode *mode) { Result hidGetGyroscopeZeroDriftMode(HidSixAxisSensorHandle handle, HidGyroscopeZeroDriftMode *mode) {
Result rc; Result rc;
const struct { const struct {
u32 SixAxisSensorHandle; HidSixAxisSensorHandle handle;
u32 pad; u32 pad;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { SixAxisSensorHandle, 0, appletGetAppletResourceUserId() }; } in = { handle, 0, appletGetAppletResourceUserId() };
u32 tmp=0; u32 tmp=0;
rc = serviceDispatchInOut(&g_hidSrv, 80, in, tmp, rc = serviceDispatchInOut(&g_hidSrv, 80, in, tmp,
@ -1071,8 +1071,8 @@ Result hidGetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDri
return rc; return rc;
} }
Result hidResetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle) { Result hidResetGyroscopeZeroDriftMode(HidSixAxisSensorHandle handle) {
return _hidCmdWithInputU32(SixAxisSensorHandle, 81); return _hidCmdWithInputU32(handle.type_value, 81);
} }
Result hidSetSupportedNpadStyleSet(u32 style_set) { Result hidSetSupportedNpadStyleSet(u32 style_set) {
@ -1169,32 +1169,32 @@ static Result _hidCreateActiveVibrationDeviceList(Service* srv_out) {
return _hidCmdGetSession(srv_out, 203); return _hidCmdGetSession(srv_out, 203);
} }
static Result _hidActivateVibrationDevice(Service* srv, u32 VibrationDeviceHandle) { static Result _hidActivateVibrationDevice(Service* srv, HidVibrationDeviceHandle handle) {
return _hidCmdInU32NoOut(srv, VibrationDeviceHandle, 0); return _hidCmdInU32NoOut(srv, handle.type_value, 0);
} }
Result hidGetVibrationDeviceInfo(const u32 *VibrationDeviceHandle, HidVibrationDeviceInfo *VibrationDeviceInfo) { Result hidGetVibrationDeviceInfo(HidVibrationDeviceHandle handle, HidVibrationDeviceInfo *VibrationDeviceInfo) {
return serviceDispatchInOut(&g_hidSrv, 200, *VibrationDeviceHandle, *VibrationDeviceInfo); return serviceDispatchInOut(&g_hidSrv, 200, handle, *VibrationDeviceInfo);
} }
Result hidSendVibrationValue(const u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue) { Result hidSendVibrationValue(HidVibrationDeviceHandle handle, HidVibrationValue *VibrationValue) {
const struct { const struct {
u32 VibrationDeviceHandle; HidVibrationDeviceHandle handle;
HidVibrationValue VibrationValue; HidVibrationValue VibrationValue;
u32 pad; u32 pad;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { *VibrationDeviceHandle, *VibrationValue, 0, appletGetAppletResourceUserId() }; } in = { handle, *VibrationValue, 0, appletGetAppletResourceUserId() };
return serviceDispatchIn(&g_hidSrv, 201, in, return serviceDispatchIn(&g_hidSrv, 201, in,
.in_send_pid = true, .in_send_pid = true,
); );
} }
Result hidGetActualVibrationValue(const u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue) { Result hidGetActualVibrationValue(HidVibrationDeviceHandle handle, HidVibrationValue *VibrationValue) {
const struct { const struct {
u32 VibrationDeviceHandle; HidVibrationDeviceHandle handle;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { *VibrationDeviceHandle, appletGetAppletResourceUserId() }; } in = { handle, appletGetAppletResourceUserId() };
return serviceDispatchInOut(&g_hidSrv, 202, in, *VibrationValue, return serviceDispatchInOut(&g_hidSrv, 202, in, *VibrationValue,
.in_send_pid = true, .in_send_pid = true,
@ -1209,7 +1209,7 @@ Result hidIsVibrationPermitted(bool *flag) {
return _hidCmdNoInOutBool(flag, 205); return _hidCmdNoInOutBool(flag, 205);
} }
Result hidSendVibrationValues(const u32 *VibrationDeviceHandles, HidVibrationValue *VibrationValues, s32 count) { Result hidSendVibrationValues(const HidVibrationDeviceHandle *handles, HidVibrationValue *VibrationValues, s32 count) {
u64 AppletResourceUserId = appletGetAppletResourceUserId(); u64 AppletResourceUserId = appletGetAppletResourceUserId();
return serviceDispatchIn(&g_hidSrv, 206, AppletResourceUserId, return serviceDispatchIn(&g_hidSrv, 206, AppletResourceUserId,
@ -1218,22 +1218,22 @@ Result hidSendVibrationValues(const u32 *VibrationDeviceHandles, HidVibrationVal
SfBufferAttr_HipcPointer | SfBufferAttr_In, SfBufferAttr_HipcPointer | SfBufferAttr_In,
}, },
.buffers = { .buffers = {
{ VibrationDeviceHandles, count*sizeof(u32) }, { handles, count*sizeof(HidVibrationDeviceHandle) },
{ VibrationValues, count*sizeof(HidVibrationValue) }, { VibrationValues, count*sizeof(HidVibrationValue) },
}, },
); );
} }
Result hidIsVibrationDeviceMounted(const u32 *VibrationDeviceHandle, bool *flag) { Result hidIsVibrationDeviceMounted(HidVibrationDeviceHandle handle, bool *flag) {
if (hosversionBefore(7,0,0)) if (hosversionBefore(7,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
Result rc; Result rc;
const struct { const struct {
u32 VibrationDeviceHandle; HidVibrationDeviceHandle handle;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { *VibrationDeviceHandle, appletGetAppletResourceUserId() }; } in = { handle, appletGetAppletResourceUserId() };
u8 tmp=0; u8 tmp=0;
rc = serviceDispatchInOut(&g_hidSrv, 211, in, tmp, rc = serviceDispatchInOut(&g_hidSrv, 211, in, tmp,
@ -1243,75 +1243,75 @@ Result hidIsVibrationDeviceMounted(const u32 *VibrationDeviceHandle, bool *flag)
return rc; return rc;
} }
static Result _hidGetDeviceHandles(u32 devicetype, u32 *DeviceHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) { static HidVibrationDeviceHandle _hidMakeVibrationDeviceHandle(u8 npad_style_index, u8 npad_id_type, u8 device_idx) {
Result rc=0; return (HidVibrationDeviceHandle){.npad_style_index = npad_style_index, .player_number = npad_id_type, .device_idx = device_idx, .pad = 0};
u32 tmp_type=0; }
if (total_handles <= 0 || total_handles > 2 || devicetype > 1) static HidSixAxisSensorHandle _hidMakeSixAxisSensorHandle(u8 npad_style_index, u8 npad_id_type, u8 idx) {
return (HidSixAxisSensorHandle){.npad_style_index = npad_style_index, .npad_id_type = npad_id_type, .idx = idx, .pad = 0};
}
static Result _hidGetVibrationDeviceHandles(HidVibrationDeviceHandle *handles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) {
Result rc=0;
s32 max_handles=1;
u32 style_index=0;
u8 idx=0;
if (total_handles <= 0 || total_handles > 2)
return MAKERESULT(Module_Libnx, LibnxError_BadInput); return MAKERESULT(Module_Libnx, LibnxError_BadInput);
if (style & HidNpadStyleTag_NpadFullKey) { if (style & HidNpadStyleTag_NpadFullKey) {
tmp_type = 3; style_index = 3;
max_handles = 2;
} }
else if (style & HidNpadStyleTag_NpadHandheld) { else if (style & HidNpadStyleTag_NpadHandheld) {
tmp_type = 4; style_index = 4;
max_handles = 2;
} }
else if (style & HidNpadStyleTag_NpadJoyDual) { else if (style & HidNpadStyleTag_NpadJoyDual) {
tmp_type = 5; style_index = 5;
max_handles = 2;
} }
else if (style & HidNpadStyleTag_NpadJoyLeft) { else if (style & HidNpadStyleTag_NpadJoyLeft) {
tmp_type = 6; style_index = 6;
} }
else if (style & HidNpadStyleTag_NpadJoyRight) { else if (style & HidNpadStyleTag_NpadJoyRight) {
tmp_type = 7; style_index = 7;
tmp_type |= 0x010000; idx = 0x1;
} }
else if (style & HidNpadStyleTag_NpadGc) { else if (style & HidNpadStyleTag_NpadGc) {
if (devicetype==0) style_index = 8;
tmp_type = 8;
else
tmp_type = 3;
} }
else if (style & HidNpadStyleTag_Npad10) { else if (style & HidNpadStyleTag_Npad10) {
if (devicetype==0) style_index = 0xd;
tmp_type = 0xd;
else
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
} }
else if (style & (HidNpadStyleTag_NpadLark | HidNpadStyleTag_NpadLucia)) { else if (style & (HidNpadStyleTag_NpadLark | HidNpadStyleTag_NpadLucia)) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles. return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
} }
else if (style & HidNpadStyleTag_NpadHandheldLark) { else if (style & HidNpadStyleTag_NpadHandheldLark) {
tmp_type = 4; style_index = 4;
max_handles = 2;
} }
else if (style & HidNpadStyleTag_NpadSystem) { else if (style & HidNpadStyleTag_NpadSystem) {
if (devicetype==1) return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles. style_index = 0x21;
tmp_type = 0x21; max_handles = 2;
} }
else if (style & HidNpadStyleTag_NpadSystemExt) { else if (style & HidNpadStyleTag_NpadSystemExt) {
if (devicetype==1) return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles. style_index = 0x20;
tmp_type = 0x20; max_handles = 2;
} }
else if (style & HidNpadStyleTag_NpadPalma) { else if (style & HidNpadStyleTag_NpadPalma) {
if (devicetype==0) return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles. return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
tmp_type = 3;
} }
else { else {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); return MAKERESULT(Module_Libnx, LibnxError_BadInput);
} }
DeviceHandles[0] = tmp_type | (id & 0xff)<<8; handles[0] = _hidMakeVibrationDeviceHandle(style_index, id, idx);
if (devicetype==1 && (tmp_type==3 || tmp_type==4))
DeviceHandles[0] |= 0x020000;
if (total_handles > 1) { if (total_handles > 1) {
tmp_type &= 0xff; if (max_handles > 1) {
if (devicetype==0 && (tmp_type!=6 && tmp_type!=7 && tmp_type!=8 && tmp_type!=0xd)) { handles[1] = _hidMakeVibrationDeviceHandle(style_index, id, 0x1);
DeviceHandles[1] = DeviceHandles[0] | 0x010000;
}
else if (devicetype==1 && tmp_type==5) {
DeviceHandles[1] = DeviceHandles[0] | 0x010000;
} }
else { else {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would just return 0 here. return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would just return 0 here.
@ -1321,11 +1321,81 @@ static Result _hidGetDeviceHandles(u32 devicetype, u32 *DeviceHandles, s32 total
return rc; return rc;
} }
Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) { static Result _hidGetSixAxisSensorHandles(HidSixAxisSensorHandle *handles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) {
Result rc=0;
s32 max_handles=1;
u32 style_index=0;
u8 idx=0;
if (total_handles <= 0 || total_handles > 2)
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
if (style & HidNpadStyleTag_NpadFullKey) {
style_index = 3;
idx = 0x2;
}
else if (style & HidNpadStyleTag_NpadHandheld) {
style_index = 4;
idx = 0x2;
}
else if (style & HidNpadStyleTag_NpadJoyDual) {
style_index = 5;
max_handles = 2;
}
else if (style & HidNpadStyleTag_NpadJoyLeft) {
style_index = 6;
}
else if (style & HidNpadStyleTag_NpadJoyRight) {
style_index = 7;
idx = 0x1;
}
else if (style & HidNpadStyleTag_NpadGc) {
style_index = 3;
idx = 0x2;
}
else if (style & HidNpadStyleTag_Npad10) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
}
else if (style & (HidNpadStyleTag_NpadLark | HidNpadStyleTag_NpadLucia)) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
}
else if (style & HidNpadStyleTag_NpadHandheldLark) {
style_index = 4;
idx = 0x2;
}
else if (style & HidNpadStyleTag_NpadSystem) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
}
else if (style & HidNpadStyleTag_NpadSystemExt) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
}
else if (style & HidNpadStyleTag_NpadPalma) {
style_index = 3;
idx = 0x2;
}
else {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would return 0, and return no handles.
}
handles[0] = _hidMakeSixAxisSensorHandle(style_index, id, idx);
if (total_handles > 1) {
if (max_handles > 1) {
handles[1] = _hidMakeSixAxisSensorHandle(style_index, id, 0x1);
}
else {
return MAKERESULT(Module_Libnx, LibnxError_BadInput); // sdknso would just return 0 here.
}
}
return rc;
}
Result hidInitializeVibrationDevices(HidVibrationDeviceHandle *handles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) {
Result rc=0; Result rc=0;
s32 i; s32 i;
rc = _hidGetDeviceHandles(0, VibrationDeviceHandles, total_handles, id, style); rc = _hidGetVibrationDeviceHandles(handles, total_handles, id, style);
if (R_FAILED(rc)) return rc; if (R_FAILED(rc)) return rc;
rwlockWriteLock(&g_hidLock); rwlockWriteLock(&g_hidLock);
@ -1336,7 +1406,7 @@ Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_hand
rwlockWriteUnlock(&g_hidLock); rwlockWriteUnlock(&g_hidLock);
for (i=0; i<total_handles; i++) { for (i=0; i<total_handles; i++) {
rc = _hidActivateVibrationDevice(&g_hidIActiveVibrationDeviceList, VibrationDeviceHandles[i]); rc = _hidActivateVibrationDevice(&g_hidIActiveVibrationDeviceList, handles[i]);
if (R_FAILED(rc)) if (R_FAILED(rc))
break; break;
@ -1345,36 +1415,28 @@ Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_hand
return rc; return rc;
} }
Result hidGetSixAxisSensorHandles(u32 *SixAxisSensorHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) { Result hidGetSixAxisSensorHandles(HidSixAxisSensorHandle *handles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) {
return _hidGetDeviceHandles(1, SixAxisSensorHandles, total_handles, id, style); return _hidGetSixAxisSensorHandles(handles, total_handles, id, style);
} }
Result hidStartSixAxisSensor(u32 SixAxisSensorHandle) { Result hidStartSixAxisSensor(HidSixAxisSensorHandle handle) {
u32 rc = _hidCmdWithInputU32(SixAxisSensorHandle, 66); Result rc = _hidCmdWithInputU32(handle.type_value, 66);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
int controller = (SixAxisSensorHandle >> 8) & 0xff; HidControllerID controller = hidControllerIDFromNpadIdType(handle.npad_id_type);
if (controller == 0x20) rwlockWriteLock(&g_hidLock);
controller = CONTROLLER_HANDHELD; g_sixaxisEnabled[controller] = true;
if (controller < 10) { rwlockWriteUnlock(&g_hidLock);
rwlockWriteLock(&g_hidLock);
g_sixaxisEnabled[controller] = true;
rwlockWriteUnlock(&g_hidLock);
}
} }
return rc; return rc;
} }
Result hidStopSixAxisSensor(u32 SixAxisSensorHandle) { Result hidStopSixAxisSensor(HidSixAxisSensorHandle handle) {
u32 rc = _hidCmdWithInputU32(SixAxisSensorHandle, 67); Result rc = _hidCmdWithInputU32(handle.type_value, 67);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
int controller = (SixAxisSensorHandle >> 8) & 0xff; HidControllerID controller = hidControllerIDFromNpadIdType(handle.npad_id_type);
if (controller == 0x20) rwlockWriteLock(&g_hidLock);
controller = CONTROLLER_HANDHELD; g_sixaxisEnabled[controller] = false;
if (controller < 10) { rwlockWriteUnlock(&g_hidLock);
rwlockWriteLock(&g_hidLock);
g_sixaxisEnabled[controller] = false;
rwlockWriteUnlock(&g_hidLock);
}
} }
return rc; return rc;
} }