joy-con: Fix hiddbgGetFirmwareVersion

This commit is contained in:
joel16 2023-06-18 00:20:06 -04:00
parent f01352a931
commit 3e44a00637
4 changed files with 33 additions and 43 deletions

View File

@ -22,6 +22,14 @@ typedef struct {
u32 charge_method;
} BatteryChargeInfoFields;
typedef struct {
u8 major;
u8 minor;
u8 micro;
u8 rev;
u8 device_identifier[0xC];
} HIDFirmwareVersion;
namespace SwitchIdent {
// Kernel
const char *GetDramDesc(void);
@ -77,7 +85,7 @@ namespace SwitchIdent {
u32 GetWlanRSSI(void);
// Joycon
u128 GetJoyconFirmwareVersion(HidsysUniquePadId unique_pad_id);
Result GetJoyconFirmwareVersion(HidDeviceTypeBits deviceType, HIDFirmwareVersion *version);
HidPowerInfo GetJoyconPowerInfo(HidNpadIdType id);
HidPowerInfo GetJoyconPowerInfoL(HidNpadIdType id);
HidPowerInfo GetJoyconPowerInfoR(HidNpadIdType id);

View File

@ -3,30 +3,22 @@
#include "common.hpp"
namespace SwitchIdent {
// TODO: Fix this
static Result hiddbgGetFirmwareVersion(HidsysUniquePadId unique_pad_id, u128 *out) {
if (hosversionBefore(6,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
static Result hiddbgGetFirmwareVersion(HidNpadIdType id, u8 deviceType, HIDFirmwareVersion *version) {
const struct {
HidNpadIdType a;
u8 b;
} in = { id, deviceType };
u128 temp = 0;
Result ret = serviceDispatchInOut(hiddbgGetServiceSession(), 205, unique_pad_id.id, temp);
if (R_SUCCEEDED(ret) && out) {
*out = temp;
}
else
std::printf("serviceDispatchInOut failed: 0x%x\n", ret);
return ret;
return serviceDispatchInOut(hiddbgGetServiceSession(), 205, in, *version);
}
u128 GetJoyconFirmwareVersion(HidsysUniquePadId unique_pad_id) {
Result GetJoyconFirmwareVersion(HidDeviceTypeBits deviceType, HIDFirmwareVersion *version) {
Result ret = 0;
u128 version = 0;
if (R_FAILED(ret = hiddbgGetFirmwareVersion(unique_pad_id, &version)))
if (R_FAILED(ret = hiddbgGetFirmwareVersion(HidNpadIdType_No1, deviceType, version)))
std::printf("hiddbgGetFirmwareVersion() failed: 0x%x.\n\n", ret);
return version;
return ret;
}
HidPowerInfo GetJoyconPowerInfo(HidNpadIdType id) {

View File

@ -6,8 +6,7 @@
namespace Services {
void Exit(void) {
// hiddbgExit();
// hidsysExit();
hiddbgExit();
tsExit();
wlaninfExit();
@ -101,11 +100,9 @@ namespace Services {
std::printf("tsInitialize() failed: 0x%x.\n\n", ret);
}
// if (R_FAILED(ret = hidsysInitialize()))
// std::printf("hidsysInitialize() failed: 0x%x.\n\n", ret);
// if (R_FAILED(ret = hiddbgInitialize()))
// std::printf("hiddbgInitialize() failed: 0x%x.\n\n", ret);
if (R_FAILED(ret = hiddbgInitialize())) {
std::printf("hiddbgInitialize() failed: 0x%x.\n\n", ret);
}
GUI::Init();
}

View File

@ -9,7 +9,6 @@ namespace Menus {
// Globals
static int g_item_height = 0;
static bool g_is_sd_inserted = false, g_is_gamecard_inserted = false;
static HidsysUniquePadId g_unique_pad_ids[2] = {0};
static PadState g_pad;
static const int g_item_dist = 67;
static const int g_start_x = 450;
@ -173,14 +172,19 @@ namespace Menus {
}
void JoyconInfo(void) {
// TODO: account for HidNpadIdType_Other;
// Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "JC fw:", "%llu", SwitchIdent::GetJoyconFirmwareVersion(g_unique_pad_ids[0]));
// TODO: Get info on other connected controllers
HidPowerInfo info_left = SwitchIdent::GetJoyconPowerInfoL(padIsHandheld(&g_pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1);
HidPowerInfo info_right = SwitchIdent::GetJoyconPowerInfoR(padIsHandheld(&g_pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1);
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "Left Joycon battery:", "%lu %% (%s)", (info_left.battery_level * 25), info_left.is_charging? "charging" : "not charging");
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "Right Joycon battery:", "%lu %% (%s)", (info_right.battery_level * 25), info_right.is_charging? "charging" : "not charging");
HIDFirmwareVersion version_left;
HIDFirmwareVersion version_right;
SwitchIdent::GetJoyconFirmwareVersion(padIsHandheld(&g_pad) ? HidDeviceTypeBits_HandheldLeft : HidDeviceTypeBits_JoyLeft, &version_left);
SwitchIdent::GetJoyconFirmwareVersion(padIsHandheld(&g_pad) ? HidDeviceTypeBits_HandheldRight : HidDeviceTypeBits_JoyRight, &version_right);
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "Left Joy-con battery:", "%lu %% (%s)", (info_left.battery_level * 25), info_left.is_charging? "charging" : "not charging");
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "Right Joy-con battery:", "%lu %% (%s)", (info_right.battery_level * 25), info_right.is_charging? "charging" : "not charging");
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 180, "Left Joy-con firmware:", "%d.%d.%d", version_left.major, version_left.minor, version_left.micro);
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 240, "Right Joy-con firmware:", "%d.%d.%d", version_right.major, version_right.minor, version_right.micro);
}
void MiscInfo(void) {
@ -223,23 +227,12 @@ namespace Menus {
padInitializeDefault(&g_pad);
padUpdate(&g_pad);
// For SwitchIdent::GetJoyconFirmwareVersion()
// memset(g_unique_pad_ids, 0, sizeof(g_unique_pad_ids));
// s32 total_entries = 0;
// if (R_FAILED(ret = hidsysGetUniquePadsFromNpad(padIsHandheld(&g_pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1, g_unique_pad_ids, 2, &total_entries)))
// std::printf("hidsysGetUniquePadsFromNpad(): 0x%x.\n\n", ret);
// if (R_SUCCEEDED(ret))
// std::printf("hidsysGetUniquePadsFromNpad: total_entries (%d)\n", total_entries);
const char *items[] = {
"Kernel",
"System",
"Battery",
"Storage",
"Joycon",
"Joy-con",
"Misc",
"Exit"
};