mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 02:22:15 +02:00
ringcon: Various fixes, and updated func names/docs.
This commit is contained in:
parent
3710f17f94
commit
6ccea704dc
@ -8,7 +8,7 @@
|
||||
#include "../types.h"
|
||||
#include "../services/hidbus.h"
|
||||
|
||||
#define RINGCON_CAL_MAGIC 0xCAFE
|
||||
#define RINGCON_CAL_MAGIC -0x3502 // 0xCAFE
|
||||
|
||||
/// Whether the output data is valid.
|
||||
typedef enum {
|
||||
@ -149,6 +149,7 @@ NX_CONSTEXPR void ringconGetManuCal(RingCon *c, RingConManuCal *out) {
|
||||
|
||||
/**
|
||||
* @brief Gets the \ref RingConUserCal previously loaded by \ref ringconCreate.
|
||||
* @note The Ring-Con UserCal doesn't seem to be calibrated normally?
|
||||
* @param c \ref RingCon
|
||||
* @param[out] out \ref RingConUserCal
|
||||
*/
|
||||
@ -159,6 +160,7 @@ NX_CONSTEXPR void ringconGetUserCal(RingCon *c, RingConUserCal *out) {
|
||||
/**
|
||||
* @brief Updates the \ref RingConUserCal.
|
||||
* @note The input \ref RingConUserCal is used with \ref ringconWriteUserCal, and the output from \ref ringconReadUserCal is verified with the input \ref RingConUserCal. This does not update the \ref RingConUserCal returned by \ref ringconGetUserCal.
|
||||
* @note The Ring-Con UserCal doesn't seem to be calibrated normally?
|
||||
* @param c \ref RingCon
|
||||
* @param[in] cal \ref RingConUserCal
|
||||
*/
|
||||
@ -223,15 +225,15 @@ Result ringconReadUnkCal(RingCon *c, s16 *out);
|
||||
Result ringconReadUserCal(RingCon *c, RingConUserCal *out);
|
||||
|
||||
/**
|
||||
* @brief Uses cmd 0x00023104.
|
||||
* @brief Reads the rep-count for Multitask Mode.
|
||||
* @param c \ref RingCon
|
||||
* @param[out] out Output value. Official sw using this clamps the output to range 0-500.
|
||||
* @param[out] data_valid \ref RingConDataValid
|
||||
*/
|
||||
Result ringconCmdx00023104(RingCon *c, s32 *out, RingConDataValid *data_valid);
|
||||
Result ringconReadRepCount(RingCon *c, s32 *out, RingConDataValid *data_valid);
|
||||
|
||||
/**
|
||||
* @brief Gets the total-push-count.
|
||||
* @brief Reads the total-push-count, for Multitask Mode.
|
||||
* @note Used internally by \ref ringconCreate. Normally \ref ringconGetTotalPushCount should be used instead.
|
||||
* @param c \ref RingCon
|
||||
* @param[out] out Output value.
|
||||
@ -240,10 +242,10 @@ Result ringconCmdx00023104(RingCon *c, s32 *out, RingConDataValid *data_valid);
|
||||
Result ringconReadTotalPushCount(RingCon *c, s32 *out, RingConDataValid *data_valid);
|
||||
|
||||
/**
|
||||
* @brief Uses cmd 0x04013104.
|
||||
* @brief This resets the value returned by \ref ringconReadRepCount to 0.
|
||||
* @param c \ref RingCon
|
||||
*/
|
||||
Result ringconCmdx04013104(RingCon *c);
|
||||
Result ringconResetRepCount(RingCon *c);
|
||||
|
||||
/**
|
||||
* @brief Writes the \ref RingConUserCal.
|
||||
|
@ -71,7 +71,7 @@ Result ringconCreate(RingCon *c, HidControllerID id) {
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (type & TYPE_JOYCON_LEFT)
|
||||
bus_type = HidbusBusType_JoyLeftRail;
|
||||
else if (type & TYPE_JOYCON_RIGHT)
|
||||
else if (type & (TYPE_JOYCON_RIGHT | TYPE_JOYCON_PAIR))
|
||||
bus_type = HidbusBusType_JoyRightRail;
|
||||
else
|
||||
rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
@ -101,7 +101,7 @@ void ringconClose(RingCon *c) {
|
||||
}
|
||||
|
||||
free(c->workbuf);
|
||||
memset(c, 0, sizeof(*c));
|
||||
c->workbuf = 0;
|
||||
}
|
||||
|
||||
static Result _ringconSetup(RingCon *c) {
|
||||
@ -491,6 +491,7 @@ Result ringconReadUserCal(RingCon *c, RingConUserCal *out) {
|
||||
static Result _ringconGet3ByteOut(RingCon *c, u32 cmd, s32 *out, RingConDataValid *data_valid) {
|
||||
Result rc=0;
|
||||
u64 out_size=0;
|
||||
u8 data[0x4]={0};
|
||||
|
||||
struct {
|
||||
u8 status;
|
||||
@ -502,17 +503,18 @@ static Result _ringconGet3ByteOut(RingCon *c, u32 cmd, s32 *out, RingConDataVali
|
||||
rc = hidbusSendAndReceive(c->handle, &cmd, sizeof(cmd), &reply, sizeof(reply), &out_size);
|
||||
if (R_SUCCEEDED(rc) && (out_size != sizeof(reply) || reply.status != 0)) rc = MAKERESULT(218, 7);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (crc_update(0, &reply.data, sizeof(reply.data)) != reply.crc) *data_valid = RingConDataValid_CRC; // Official sw has this field value inverted with this func, but whatever.
|
||||
memcpy(data, reply.data, sizeof(reply.data));
|
||||
if (crc_update(0, data, sizeof(data)) != reply.crc) *data_valid = RingConDataValid_CRC; // Official sw has this field value inverted with this func, but whatever.
|
||||
else {
|
||||
*data_valid = RingConDataValid_Ok;
|
||||
*out = reply.data[0x0] | (reply.data[0x1]<<8) | (reply.data[0x2]<<16);
|
||||
*out = data[0x0] | (data[0x1]<<8) | (data[0x2]<<16);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result ringconCmdx00023104(RingCon *c, s32 *out, RingConDataValid *data_valid) {
|
||||
Result ringconReadRepCount(RingCon *c, s32 *out, RingConDataValid *data_valid) {
|
||||
return _ringconGet3ByteOut(c, 0x00023104, out, data_valid);
|
||||
}
|
||||
|
||||
@ -520,7 +522,7 @@ Result ringconReadTotalPushCount(RingCon *c, s32 *out, RingConDataValid *data_va
|
||||
return _ringconGet3ByteOut(c, 0x00023204, out, data_valid);
|
||||
}
|
||||
|
||||
Result ringconCmdx04013104(RingCon *c) {
|
||||
Result ringconResetRepCount(RingCon *c) {
|
||||
Result rc=0;
|
||||
u64 cmd = 0x04013104;
|
||||
u64 out_size=0;
|
||||
|
Loading…
Reference in New Issue
Block a user