Compare commits
1 Commits
sdl_who
...
ring_proto
Author | SHA1 | Date | |
---|---|---|---|
0495a13e31 |
@ -388,6 +388,32 @@ enum class ExternalDeviceId : u16 {
|
|||||||
Starlink = 0x2800,
|
Starlink = 0x2800,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Most missing command names are leftovers from other firmware versions
|
||||||
|
enum class RingConCommand : u32 {
|
||||||
|
GetFirmwareVersion = 0x00020000,
|
||||||
|
ReadId = 0x00020100,
|
||||||
|
JoyPolling = 0x00020101,
|
||||||
|
Unknown1 = 0x00020104,
|
||||||
|
c20105 = 0x00020105,
|
||||||
|
Unknown2 = 0x00020204,
|
||||||
|
Unknown3 = 0x00020304,
|
||||||
|
Unknown4 = 0x00020404,
|
||||||
|
ReadUnkCal = 0x00020504,
|
||||||
|
ReadFactoryCal = 0x00020A04,
|
||||||
|
Unknown5 = 0x00021104,
|
||||||
|
Unknown6 = 0x00021204,
|
||||||
|
Unknown7 = 0x00021304,
|
||||||
|
ReadUserCal = 0x00021A04,
|
||||||
|
ReadRepCount = 0x00023104,
|
||||||
|
ReadTotalPushCount = 0x00023204,
|
||||||
|
ResetRepCount = 0x04013104,
|
||||||
|
Unknown8 = 0x04011104,
|
||||||
|
Unknown9 = 0x04011204,
|
||||||
|
Unknown10 = 0x04011304,
|
||||||
|
SaveCalData = 0x10011A04,
|
||||||
|
Error = 0xFFFFFFFF,
|
||||||
|
};
|
||||||
|
|
||||||
enum class DriverResult {
|
enum class DriverResult {
|
||||||
Success,
|
Success,
|
||||||
WrongReply,
|
WrongReply,
|
||||||
@ -687,6 +713,57 @@ struct RingStatus {
|
|||||||
s16 min_value;
|
s16 min_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
struct RingCommandData {
|
||||||
|
u8 data_type;
|
||||||
|
RingConCommand command;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingCommandData) == 0x5, "RingCommandData is an invalid size");
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
struct RingFactoryCalibration {
|
||||||
|
s32_le os_max;
|
||||||
|
s32_le hk_max;
|
||||||
|
s32_le zero_min;
|
||||||
|
s32_le zero_max;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingFactoryCalibration) == 0x10, "RingFactoryCalibration is an invalid size");
|
||||||
|
|
||||||
|
struct RingCalibrationValue {
|
||||||
|
s16 value;
|
||||||
|
u16 crc;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingCalibrationValue) == 0x4, "RingCalibrationValue is an invalid size");
|
||||||
|
|
||||||
|
struct RingUserCalibration {
|
||||||
|
RingCalibrationValue os_max;
|
||||||
|
RingCalibrationValue hk_max;
|
||||||
|
RingCalibrationValue zero;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingUserCalibration) == 0xC, "RingUserCalibration is an invalid size");
|
||||||
|
|
||||||
|
struct RingReadId {
|
||||||
|
u16 id_l_x0;
|
||||||
|
u16 id_l_x0_2;
|
||||||
|
u16 id_l_x4;
|
||||||
|
u16 id_h_x0;
|
||||||
|
u16 id_h_x0_2;
|
||||||
|
u16 id_h_x4;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingReadId) == 0xC, "RingReadId is an invalid size");
|
||||||
|
|
||||||
|
struct RingCommandReply {
|
||||||
|
DriverResult result;
|
||||||
|
RingConCommand command;
|
||||||
|
FirmwareVersion firmware;
|
||||||
|
RingFactoryCalibration factory_calibration;
|
||||||
|
RingUserCalibration user_calibration;
|
||||||
|
RingReadId read_id;
|
||||||
|
u8 c20105;
|
||||||
|
u8 total_push_count;
|
||||||
|
u8 total_rep_count;
|
||||||
|
};
|
||||||
|
|
||||||
struct VibrationPacket {
|
struct VibrationPacket {
|
||||||
OutputReport output_report;
|
OutputReport output_report;
|
||||||
u8 packet_counter;
|
u8 packet_counter;
|
||||||
|
@ -108,6 +108,65 @@ DriverResult RingConProtocol::ConfigureRing() {
|
|||||||
return SendSubCommand(SubCommand::ENABLE_EXTERNAL_POLLING, ringcon_data);
|
return SendSubCommand(SubCommand::ENABLE_EXTERNAL_POLLING, ringcon_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DriverResult RingConProtocol::SendCommand(RingConCommand command) {
|
||||||
|
SubCommandResponce output{};
|
||||||
|
RingCommandData data{
|
||||||
|
.data_type = 0x04, // This seems to be always 4 for this command
|
||||||
|
.command = command,
|
||||||
|
};
|
||||||
|
RingCommandReply reply{
|
||||||
|
.result = DriverResult::Success,
|
||||||
|
.command = command,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<u8, sizeof(RingCommandData)> raw_data{};
|
||||||
|
memcpy(raw_data.data(), &data, sizeof(RingCommandData));
|
||||||
|
const DriverResult result = SendSubCommand(SubCommand::SET_EXTERNAL_CONFIG, raw_data, output);
|
||||||
|
|
||||||
|
if (result != DriverResult::Success) {
|
||||||
|
reply.result = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case RingConCommand::GetFirmwareVersion:
|
||||||
|
memcpy(&reply.firmware, output.command_data.data() + 6, sizeof(FirmwareVersion));
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadId:
|
||||||
|
memcpy(&reply.read_id, output.command_data.data() + 6,
|
||||||
|
sizeof(RingReadId));
|
||||||
|
break;
|
||||||
|
case RingConCommand::c20105:
|
||||||
|
reply.c20105 = output.command_data[6];
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadUnkCal:
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadFactoryCal:
|
||||||
|
memcpy(&reply.factory_calibration, output.command_data.data() + 6,
|
||||||
|
sizeof(RingFactoryCalibration));
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadUserCal:
|
||||||
|
memcpy(&reply.user_calibration, output.command_data.data() + 6, sizeof(RingUserCalibration));
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadRepCount:
|
||||||
|
reply.total_rep_count = output.command_data[6];
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadTotalPushCount:
|
||||||
|
reply.total_push_count = output.command_data[6];
|
||||||
|
break;
|
||||||
|
case RingConCommand::ResetRepCount:
|
||||||
|
break;
|
||||||
|
case RingConCommand::SaveCalData:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
reply.result = DriverResult::NotSupported;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool RingConProtocol::IsEnabled() const {
|
bool RingConProtocol::IsEnabled() const {
|
||||||
return is_enabled;
|
return is_enabled;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,9 @@ public:
|
|||||||
|
|
||||||
DriverResult StartRingconPolling();
|
DriverResult StartRingconPolling();
|
||||||
|
|
||||||
|
// Hidbus can send individual commands to the ring each one with an unique reply
|
||||||
|
DriverResult SendCommand(RingConCommand command);
|
||||||
|
|
||||||
bool IsEnabled() const;
|
bool IsEnabled() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user