mirror of
https://github.com/joel16/SwitchIdent.git
synced 2024-11-23 11:49:43 +00:00
Update for compatibility with libnx v4.2.0 (#15)
This commit is contained in:
parent
26f850f334
commit
c574b8987e
@ -48,33 +48,25 @@ char *SwitchIdent_GetFirmwareVersion(void) {
|
||||
|
||||
char *SwitchIdent_GetHardwareType(void) {
|
||||
Result ret = 0;
|
||||
u64 hardware_type = 4;
|
||||
u64 hardware_type;
|
||||
|
||||
char *hardware_300[] = {
|
||||
char *hardware_string[] = {
|
||||
"Icosa",
|
||||
"Copper",
|
||||
"Hoag",
|
||||
"Unknown"
|
||||
};
|
||||
|
||||
char *hardware_400[] = {
|
||||
"Icosa",
|
||||
"Copper",
|
||||
"Hoag",
|
||||
"Mariko",
|
||||
"Iowa",
|
||||
"Calcio",
|
||||
"Aula",
|
||||
"Unknown"
|
||||
};
|
||||
|
||||
if (R_FAILED(ret = splGetConfig(SplConfigItem_HardwareType, &hardware_type)))
|
||||
printf("splGetConfig(SplConfigItem_HardwareType) failed: 0x%x.\n\n", ret);
|
||||
else {
|
||||
if (kernelAbove400())
|
||||
return hardware_400[hardware_type];
|
||||
else
|
||||
return hardware_300[hardware_type];
|
||||
}
|
||||
|
||||
return hardware_400[4];
|
||||
if (hardware_type >= 6)
|
||||
return hardware_string[6];
|
||||
|
||||
return hardware_string[hardware_type];
|
||||
}
|
||||
|
||||
// [4.0.0+] Kiosk mode (0 = retail; 1 = kiosk)
|
||||
@ -134,10 +126,10 @@ u64 SwitchIdent_GetDeviceID(void) {
|
||||
|
||||
char *SwitchIdent_GetSerialNumber(void) {
|
||||
Result ret = 0;
|
||||
static char serial[0x19];
|
||||
static SetSysSerialNumber serial;
|
||||
|
||||
if (R_FAILED(ret = setsysGetSerialNumber(serial)))
|
||||
if (R_FAILED(ret = setsysGetSerialNumber(&serial)))
|
||||
printf("setsysGetSerialNumber() failed: 0x%x.\n\n", ret);
|
||||
|
||||
return serial;
|
||||
return serial.number;
|
||||
}
|
||||
|
@ -8,12 +8,52 @@ char *SwitchIdent_GetOperationMode(void) {
|
||||
return "Docked";
|
||||
}
|
||||
|
||||
bool SwitchIdent_GetFlag(SetSysFlag flag) {
|
||||
bool SwitchIdent_GetWirelessLanEnableFlag() {
|
||||
Result ret = 0;
|
||||
bool out = false;
|
||||
|
||||
if (R_FAILED(ret = setsysGetFlag(flag, &out)))
|
||||
printf("setsysGetFlag() failed: 0x%x.\n\n", ret);
|
||||
if (R_FAILED(ret = setsysGetWirelessLanEnableFlag(&out)))
|
||||
printf("setsysGetWirelessLanEnableFlag() failed: 0x%x.\n\n", ret);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool SwitchIdent_GetBluetoothEnableFlag() {
|
||||
Result ret = 0;
|
||||
bool out = false;
|
||||
|
||||
if (R_FAILED(ret = setsysGetBluetoothEnableFlag(&out)))
|
||||
printf("setsysGetBluetoothEnableFlag() failed: 0x%x.\n\n", ret);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool SwitchIdent_GetNfcEnableFlag() {
|
||||
Result ret = 0;
|
||||
bool out = false;
|
||||
|
||||
if (R_FAILED(ret = setsysGetNfcEnableFlag(&out)))
|
||||
printf("setsysGetNfcEnableFlag() failed: 0x%x.\n\n", ret);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool SwitchIdent_GetAutoUpdateEnableFlag() {
|
||||
Result ret = 0;
|
||||
bool out = false;
|
||||
|
||||
if (R_FAILED(ret = setsysGetAutoUpdateEnableFlag(&out)))
|
||||
printf("setsysGetAutoUpdateEnableFlag() failed: 0x%x.\n\n", ret);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool SwitchIdent_GetConsoleInformationUploadFlag() {
|
||||
Result ret = 0;
|
||||
bool out = false;
|
||||
|
||||
if (R_FAILED(ret = setsysGetConsoleInformationUploadFlag(&out)))
|
||||
printf("setsysGetConsoleInformationUploadFlag() failed: 0x%x.\n\n", ret);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
@ -2,7 +2,11 @@
|
||||
#define _SWITCHIDENT_MISC_H_
|
||||
|
||||
char *SwitchIdent_GetOperationMode(void);
|
||||
bool SwitchIdent_GetFlag(SetSysFlag flag);
|
||||
bool SwitchIdent_GetWirelessLanEnableFlag();
|
||||
bool SwitchIdent_GetBluetoothEnableFlag();
|
||||
bool SwitchIdent_GetNfcEnableFlag();
|
||||
bool SwitchIdent_GetAutoUpdateEnableFlag();
|
||||
bool SwitchIdent_GetConsoleInformationUploadFlag();
|
||||
bool SwitchIdent_IsSDCardInserted(FsDeviceOperator *fsDeviceOperator);
|
||||
bool SwitchIdent_IsGameCardInserted(FsDeviceOperator *fsDeviceOperator);
|
||||
|
||||
|
178
common/power.c
178
common/power.c
@ -1,150 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "setcal.h"
|
||||
static Result _psmCmdNoInOutBool(Service* srv, bool *out, u32 cmd_id) {
|
||||
u8 outval = 0;
|
||||
Result rc = serviceDispatchOut(srv, cmd_id, outval);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (out) *out = outval & 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result psmIsBatteryChargingEnabled(bool *out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 4;
|
||||
|
||||
Result rc = serviceIpcDispatch(psmGetServiceSession());
|
||||
|
||||
if(R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u8 enable;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = resp->enable;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result psmGetRawBatteryChargePercentage(u64 *out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 13;
|
||||
|
||||
Result rc = serviceIpcDispatch(psmGetServiceSession());
|
||||
|
||||
if(R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 age_percentage;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = resp->age_percentage;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result psmIsEnoughPowerSupplied(bool *out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 14;
|
||||
|
||||
Result rc = serviceIpcDispatch(psmGetServiceSession());
|
||||
|
||||
if(R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u8 power_supplied;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = resp->power_supplied;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result psmGetBatteryAgePercentage(u64 *out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 15;
|
||||
|
||||
Result rc = serviceIpcDispatch(psmGetServiceSession());
|
||||
|
||||
if(R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 age_percentage;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = resp->age_percentage;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
return _psmCmdNoInOutBool(psmGetServiceSession(), out, 4);
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetBatteryPercent(void) {
|
||||
@ -159,14 +26,14 @@ u32 SwitchIdent_GetBatteryPercent(void) {
|
||||
|
||||
char *SwitchIdent_GetChargerType(void) {
|
||||
Result ret = 0;
|
||||
ChargerType charger_type;
|
||||
PsmChargerType charger_type;
|
||||
|
||||
if (R_FAILED(ret = psmGetChargerType(&charger_type)))
|
||||
return NULL;
|
||||
|
||||
if (charger_type == ChargerType_Charger)
|
||||
if (charger_type == PsmChargerType_EnoughPower)
|
||||
return "Official charger or dock";
|
||||
else if (charger_type == ChargerType_Usb)
|
||||
else if (charger_type == PsmChargerType_LowPower)
|
||||
return "USB-C charger";
|
||||
else
|
||||
return "No charger connected";
|
||||
@ -176,15 +43,12 @@ char *SwitchIdent_GetChargerType(void) {
|
||||
|
||||
bool SwitchIdent_IsCharging(void) {
|
||||
Result ret = 0;
|
||||
ChargerType charger_type;
|
||||
PsmChargerType charger_type;
|
||||
|
||||
if (R_FAILED(ret = psmGetChargerType(&charger_type)))
|
||||
return false;
|
||||
|
||||
if ((charger_type == ChargerType_Charger) || (charger_type == ChargerType_Usb))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return charger_type != PsmChargerType_Unconnected;
|
||||
}
|
||||
|
||||
bool SwitchIdent_IsChargingEnabled(void) {
|
||||
@ -219,9 +83,9 @@ char *SwitchIdent_GetVoltageState(void) {
|
||||
return states[4];
|
||||
}
|
||||
|
||||
u64 SwitchIdent_GetRawBatteryChargePercentage(void) {
|
||||
double SwitchIdent_GetRawBatteryChargePercentage(void) {
|
||||
Result ret = 0;
|
||||
u64 out = 0;
|
||||
double out = 0;
|
||||
|
||||
if (R_FAILED(ret = psmGetRawBatteryChargePercentage(&out)))
|
||||
return -1;
|
||||
@ -239,9 +103,9 @@ bool SwitchIdent_IsEnoughPowerSupplied(void) {
|
||||
return out;
|
||||
}
|
||||
|
||||
u64 SwitchIdent_GetBatteryAgePercent(void) {
|
||||
double SwitchIdent_GetBatteryAgePercent(void) {
|
||||
Result ret = 0;
|
||||
u64 out = 0;
|
||||
double out = 0;
|
||||
|
||||
if (R_FAILED(ret = psmGetBatteryAgePercentage(&out)))
|
||||
return -1;
|
||||
@ -251,12 +115,12 @@ u64 SwitchIdent_GetBatteryAgePercent(void) {
|
||||
|
||||
char *SwitchIdent_GetBatteryLot(void) {
|
||||
Result ret = 0;
|
||||
static char battery_lot[0x13];
|
||||
static SetBatteryLot battery_lot;
|
||||
|
||||
if (R_FAILED(ret = setcalGetBatteryLot(battery_lot))) {
|
||||
if (R_FAILED(ret = setcalGetBatteryLot(&battery_lot))) {
|
||||
printf("setcalGetBatteryLot() failed: 0x%x.\n\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return battery_lot;
|
||||
return battery_lot.lot;
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ char *SwitchIdent_GetChargerType(void);
|
||||
bool SwitchIdent_IsCharging(void);
|
||||
bool SwitchIdent_IsChargingEnabled(void);
|
||||
char *SwitchIdent_GetVoltageState(void);
|
||||
u64 SwitchIdent_GetRawBatteryChargePercentage(void);
|
||||
double SwitchIdent_GetRawBatteryChargePercentage(void);
|
||||
bool SwitchIdent_IsEnoughPowerSupplied(void);
|
||||
u64 SwitchIdent_GetBatteryAgePercent(void);
|
||||
double SwitchIdent_GetBatteryAgePercent(void);
|
||||
char *SwitchIdent_GetBatteryLot(void);
|
||||
|
||||
#endif
|
||||
|
128
common/setcal.c
128
common/setcal.c
@ -1,128 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <switch.h>
|
||||
|
||||
static Service setcal_service;
|
||||
|
||||
Result setcalInitialize(void) {
|
||||
return smGetService(&setcal_service, "set:cal");
|
||||
}
|
||||
|
||||
void setcalExit(void) {
|
||||
serviceClose(&setcal_service);
|
||||
}
|
||||
|
||||
Result setcalGetBluetoothBdAddress(char *address) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
if (address) memset(address, 0, 0x13);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 0;
|
||||
|
||||
Result rc = serviceIpcDispatch(&setcal_service);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
char address[0x6];
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && address) {
|
||||
snprintf(address, 0x12, "%02X:%02X:%02X:%02X:%02X:%02X", *resp->address, *(resp->address + 0x1), *(resp->address + 0x2), *(resp->address + 0x3),
|
||||
*(resp->address + 0x4), *(resp->address + 0x5));
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result setcalGetWirelessLanMacAddress(char *address) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
if (address) memset(address, 0, 0x13);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 6;
|
||||
|
||||
Result rc = serviceIpcDispatch(&setcal_service);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
char address[0x6];
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && address) {
|
||||
snprintf(address, 0x12, "%02X:%02X:%02X:%02X:%02X:%02X", *resp->address, *(resp->address + 0x1), *(resp->address + 0x2), *(resp->address + 0x3),
|
||||
*(resp->address + 0x4), *(resp->address + 0x5));
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result setcalGetBatteryLot(char *out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
if (out) memset(out, 0, 0x19);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 12;
|
||||
|
||||
Result rc = serviceIpcDispatch(&setcal_service);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
char battery_lot[0x18];
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && out)
|
||||
memcpy(out, resp->battery_lot, 0x18);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
#ifndef _SWITCHIDENT_SETCAL_H_
|
||||
#define _SWITCHIDENT_SETCAL_H_
|
||||
|
||||
Result setcalInitialize(void);
|
||||
void setcalExit(void);
|
||||
Result setcalGetBluetoothBdAddress(char *address);
|
||||
Result setcalGetWirelessLanMacAddress(char *address);
|
||||
Result setcalGetBatteryLot(char *out);
|
||||
|
||||
#endif
|
@ -2,9 +2,9 @@
|
||||
|
||||
#include "storage.h"
|
||||
|
||||
u64 SwitchIdent_GetTotalStorage(FsStorageId storage_id) {
|
||||
s64 SwitchIdent_GetTotalStorage(NcmStorageId storage_id) {
|
||||
Result ret = 0;
|
||||
u64 total = 0;
|
||||
s64 total = 0;
|
||||
|
||||
if (R_FAILED(ret = nsGetTotalSpaceSize(storage_id, &total)))
|
||||
printf("nsGetFreeSpaceSize() failed: 0x%x.\n\n", ret);
|
||||
@ -12,9 +12,9 @@ u64 SwitchIdent_GetTotalStorage(FsStorageId storage_id) {
|
||||
return total;
|
||||
}
|
||||
|
||||
u64 SwitchIdent_GetFreeStorage(FsStorageId storage_id) {
|
||||
s64 SwitchIdent_GetFreeStorage(NcmStorageId storage_id) {
|
||||
Result ret = 0;
|
||||
u64 free = 0;
|
||||
s64 free = 0;
|
||||
|
||||
if (R_FAILED(ret = nsGetFreeSpaceSize(storage_id, &free)))
|
||||
printf("nsGetFreeSpaceSize() failed: 0x%x.\n\n", ret);
|
||||
@ -22,6 +22,6 @@ u64 SwitchIdent_GetFreeStorage(FsStorageId storage_id) {
|
||||
return free;
|
||||
}
|
||||
|
||||
u64 SwitchIdent_GetUsedStorage(FsStorageId storage_id) {
|
||||
s64 SwitchIdent_GetUsedStorage(NcmStorageId storage_id) {
|
||||
return (SwitchIdent_GetTotalStorage(storage_id) - SwitchIdent_GetFreeStorage(storage_id));
|
||||
}
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
u64 SwitchIdent_GetTotalStorage(FsStorageId storage_id);
|
||||
u64 SwitchIdent_GetFreeStorage(FsStorageId storage_id);
|
||||
u64 SwitchIdent_GetUsedStorage(FsStorageId storage_id);
|
||||
s64 SwitchIdent_GetTotalStorage(NcmStorageId storage_id);
|
||||
s64 SwitchIdent_GetFreeStorage(NcmStorageId storage_id);
|
||||
s64 SwitchIdent_GetUsedStorage(NcmStorageId storage_id);
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <switch.h>
|
||||
|
||||
#include "misc.h"
|
||||
#include "setcal.h"
|
||||
|
||||
char *SwitchIdent_GetLanguage(void) {
|
||||
Result ret = 0;
|
||||
@ -40,56 +39,56 @@ char *SwitchIdent_GetRegion(void) {
|
||||
return regions[regionCode];
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetCPUClock(void) {
|
||||
u32 SwitchIdent_GetClock(PcvModule module) {
|
||||
Result ret = 0;
|
||||
u32 out = 0;
|
||||
|
||||
if (R_FAILED(ret = pcvGetClockRate(PcvModule_CpuBus, &out)))
|
||||
printf("pcvGetClockRate(PcvModule_CpuBus) failed: 0x%x.\n\n", ret);
|
||||
if (hosversionAtLeast(8, 0, 0)) {
|
||||
ClkrstSession session = {0};
|
||||
PcvModuleId module_id;
|
||||
|
||||
return out/1000000;
|
||||
if (R_FAILED(ret = pcvGetModuleId(&module_id, module)))
|
||||
printf("pcvGetModuleId() failed: 0x%x.\n\n", ret);
|
||||
else if (R_FAILED(ret = clkrstOpenSession(&session, module_id, 3)))
|
||||
printf("clkrstOpenSession() failed: 0x%x.\n\n", ret);
|
||||
else if (R_FAILED(ret = clkrstGetClockRate(&session, &out)))
|
||||
printf("clkrstGetClockRate() failed: 0x%x.\n\n", ret);
|
||||
else
|
||||
clkrstCloseSession(&session);
|
||||
} else {
|
||||
if (R_FAILED(ret = pcvGetClockRate(module, &out)))
|
||||
printf("pcvGetClockRate() failed: 0x%x.\n\n", ret);
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetGPUClock(void) {
|
||||
Result ret = 0;
|
||||
u32 out = 0;
|
||||
|
||||
if (R_FAILED(ret = pcvGetClockRate(PcvModule_GPU, &out)))
|
||||
printf("pcvGetClockRate(PcvModule_GPU) failed: 0x%x.\n\n", ret);
|
||||
|
||||
return out/1000000;
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetEMCClock(void) {
|
||||
Result ret = 0;
|
||||
u32 out = 0;
|
||||
|
||||
if (R_FAILED(ret = pcvGetClockRate(PcvModule_EMC , &out)))
|
||||
printf("pcvGetClockRate(PcvModule_EMC ) failed: 0x%x.\n\n", ret);
|
||||
|
||||
return out/1000000;
|
||||
}
|
||||
|
||||
char *SwitchIdent_GetBluetoothBdAddress(void) {
|
||||
Result ret = 0;
|
||||
static char bd_addr[0x13];
|
||||
static char bd_addr_string[0x13];
|
||||
SetCalBdAddress bd_addr;
|
||||
|
||||
if (R_FAILED(ret = setcalGetBluetoothBdAddress(bd_addr))) {
|
||||
printf("setcalGetBluetoothBdAddress() failed: 0x%x.\n\n", ret);
|
||||
if (R_FAILED(ret = setcalGetBdAddress(&bd_addr))) {
|
||||
printf("setcalGetBdAddress() failed: 0x%x.\n\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bd_addr;
|
||||
snprintf(bd_addr_string, 0x12, "%02X:%02X:%02X:%02X:%02X:%02X", bd_addr.bd_addr[0], bd_addr.bd_addr[1], bd_addr.bd_addr[2], bd_addr.bd_addr[3], bd_addr.bd_addr[4], bd_addr.bd_addr[5]);
|
||||
|
||||
return bd_addr_string;
|
||||
}
|
||||
|
||||
char *SwitchIdent_GetWirelessLanMacAddress(void) {
|
||||
Result ret = 0;
|
||||
static char mac_addr[0x13];
|
||||
static char mac_addr_string[0x13];
|
||||
SetCalMacAddress mac_addr;
|
||||
|
||||
if (R_FAILED(ret = setcalGetWirelessLanMacAddress(mac_addr))) {
|
||||
if (R_FAILED(ret = setcalGetWirelessLanMacAddress(&mac_addr))) {
|
||||
printf("setcalGetWirelessLanMacAddress() failed: 0x%x.\n\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mac_addr;
|
||||
snprintf(mac_addr_string, 0x12, "%02X:%02X:%02X:%02X:%02X:%02X", mac_addr.addr[0], mac_addr.addr[1], mac_addr.addr[2], mac_addr.addr[3], mac_addr.addr[4], mac_addr.addr[5]);
|
||||
|
||||
return mac_addr_string;
|
||||
}
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
char *SwitchIdent_GetLanguage(void);
|
||||
char *SwitchIdent_GetRegion(void);
|
||||
u32 SwitchIdent_GetCPUClock(void);
|
||||
u32 SwitchIdent_GetGPUClock(void);
|
||||
u32 SwitchIdent_GetEMCClock(void);
|
||||
u32 SwitchIdent_GetClock(PcvModule module);
|
||||
char *SwitchIdent_GetBluetoothBdAddress(void);
|
||||
char *SwitchIdent_GetWirelessLanMacAddress(void);
|
||||
|
||||
|
@ -2,12 +2,14 @@
|
||||
|
||||
#include "menus.h"
|
||||
#include "power.h"
|
||||
#include "setcal.h"
|
||||
#include "SDL_helper.h"
|
||||
#include "wlan.h"
|
||||
|
||||
static void Term_Services(void) {
|
||||
wlaninfExit();
|
||||
if (hosversionAtLeast(8, 0, 0))
|
||||
clkrstExit();
|
||||
else
|
||||
pcvExit();
|
||||
psmExit();
|
||||
nsExit();
|
||||
@ -41,7 +43,7 @@ static void Init_Services(void) {
|
||||
if (R_FAILED(ret = splInitialize()))
|
||||
printf("splInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (R_FAILED(ret = nifmInitialize()))
|
||||
if (R_FAILED(ret = nifmInitialize(NifmServiceType_User)))
|
||||
printf("nifmInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (R_FAILED(ret = socketInitializeDefault()))
|
||||
@ -59,8 +61,13 @@ static void Init_Services(void) {
|
||||
if (R_FAILED(ret = psmInitialize()))
|
||||
printf("psmInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (hosversionAtLeast(8, 0, 0)) {
|
||||
if (R_FAILED(ret = clkrstInitialize()))
|
||||
printf("clkrstInitialize() failed: 0x%x.\n\n", ret);
|
||||
} else {
|
||||
if (R_FAILED(ret = pcvInitialize()))
|
||||
printf("pcvInitialize() failed: 0x%x.\n\n", ret);
|
||||
}
|
||||
|
||||
if (R_FAILED(ret = wlaninfInitialize()))
|
||||
printf("wlaninfInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
@ -41,12 +41,12 @@ static void Menu_Kernel(void) {
|
||||
|
||||
static void Menu_System(void) {
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 50, "Region:", SwitchIdent_GetRegion());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 100, "CPU clock:", "%lu MHz", SwitchIdent_GetCPUClock());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "GPU clock:", "%lu MHz", SwitchIdent_GetGPUClock());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "EMC clock:", "%lu MHz", SwitchIdent_GetEMCClock());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 250, "Wireless LAN:", "%s (RSSI: %d) (Quality: %lu)", SwitchIdent_GetFlag(SetSysFlag_WirelessLanEnable)? "Enabled" : "Disabled", SwitchIdent_GetWlanRSSI(), SwitchIdent_GetWlanQuality(SwitchIdent_GetWlanRSSI()));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 300, "Bluetooth:", "%s", SwitchIdent_GetFlag(SetSysFlag_BluetoothEnable)? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 350, "NFC:", SwitchIdent_GetFlag(SetSysFlag_NfcEnable)? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 100, "CPU clock:", "%lu MHz", SwitchIdent_GetClock(PcvModule_CpuBus));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "GPU clock:", "%lu MHz", SwitchIdent_GetClock(PcvModule_GPU));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "EMC clock:", "%lu MHz", SwitchIdent_GetClock(PcvModule_EMC));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 250, "Wireless LAN:", "%s (RSSI: %d) (Quality: %lu)", SwitchIdent_GetWirelessLanEnableFlag()? "Enabled" : "Disabled", SwitchIdent_GetWlanRSSI(), SwitchIdent_GetWlanQuality(SwitchIdent_GetWlanRSSI()));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 300, "Bluetooth:", "%s", SwitchIdent_GetBluetoothEnableFlag()? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 350, "NFC:", SwitchIdent_GetNfcEnableFlag()? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
static void Menu_Power(void) {
|
||||
@ -59,28 +59,28 @@ static void Menu_Power(void) {
|
||||
}
|
||||
|
||||
static void Menu_Storage(void) {
|
||||
u64 sd_used = SwitchIdent_GetUsedStorage(FsStorageId_SdCard);
|
||||
u64 sd_total = SwitchIdent_GetTotalStorage(FsStorageId_SdCard);
|
||||
u64 sd_used = SwitchIdent_GetUsedStorage(NcmStorageId_SdCard);
|
||||
u64 sd_total = SwitchIdent_GetTotalStorage(NcmStorageId_SdCard);
|
||||
|
||||
u64 nand_u_used = SwitchIdent_GetUsedStorage(FsStorageId_NandUser);
|
||||
u64 nand_u_total = SwitchIdent_GetTotalStorage(FsStorageId_NandUser);
|
||||
u64 nand_u_used = SwitchIdent_GetUsedStorage(NcmStorageId_BuiltInUser);
|
||||
u64 nand_u_total = SwitchIdent_GetTotalStorage(NcmStorageId_BuiltInUser);
|
||||
|
||||
u64 nand_s_used = SwitchIdent_GetUsedStorage(FsStorageId_NandSystem);
|
||||
u64 nand_s_total = SwitchIdent_GetTotalStorage(FsStorageId_NandSystem);
|
||||
u64 nand_s_used = SwitchIdent_GetUsedStorage(NcmStorageId_BuiltInSystem);
|
||||
u64 nand_s_total = SwitchIdent_GetTotalStorage(NcmStorageId_BuiltInSystem);
|
||||
|
||||
char sd_total_str[16], sd_free_str[16], sd_used_str[16];
|
||||
Utils_GetSizeString(sd_total_str, sd_total);
|
||||
Utils_GetSizeString(sd_free_str, SwitchIdent_GetFreeStorage(FsStorageId_SdCard));
|
||||
Utils_GetSizeString(sd_free_str, SwitchIdent_GetFreeStorage(NcmStorageId_SdCard));
|
||||
Utils_GetSizeString(sd_used_str, sd_used);
|
||||
|
||||
char nand_u_total_str[16], nand_u_free_str[16], nand_u_used_str[16];
|
||||
Utils_GetSizeString(nand_u_total_str, nand_u_total);
|
||||
Utils_GetSizeString(nand_u_free_str, SwitchIdent_GetFreeStorage(FsStorageId_NandUser));
|
||||
Utils_GetSizeString(nand_u_free_str, SwitchIdent_GetFreeStorage(NcmStorageId_BuiltInUser));
|
||||
Utils_GetSizeString(nand_u_used_str, nand_u_used);
|
||||
|
||||
char nand_s_total_str[16], nand_s_free_str[16], nand_s_used_str[16];
|
||||
Utils_GetSizeString(nand_s_total_str, nand_s_total);
|
||||
Utils_GetSizeString(nand_s_free_str, SwitchIdent_GetFreeStorage(FsStorageId_NandSystem));
|
||||
Utils_GetSizeString(nand_s_free_str, SwitchIdent_GetFreeStorage(NcmStorageId_BuiltInSystem));
|
||||
Utils_GetSizeString(nand_s_used_str, nand_s_used);
|
||||
|
||||
SDL_DrawRect(400, 50, 880, 670, BACKGROUND_COLOUR);
|
||||
@ -121,8 +121,8 @@ static void Menu_Misc(void) {
|
||||
Result ret = gethostname(hostname, sizeof(hostname));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 50, "IP:", R_SUCCEEDED(ret)? hostname : NULL);
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 100, "State:", SwitchIdent_GetOperationMode());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "Automatic update:", SwitchIdent_GetFlag(SetSysFlag_AutoUpdateEnable)? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "Console information upload:", SwitchIdent_GetFlag(SetSysFlag_ConsoleInformationUpload)? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "Automatic update:", SwitchIdent_GetAutoUpdateEnableFlag()? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "Console information upload:", SwitchIdent_GetConsoleInformationUploadFlag()? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 250, "SD card status:", isSDInserted? "Inserted" : "Not inserted");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 300, "Game card status:", isGameCardInserted? "Inserted" : "Not inserted");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 350, "BT address:", SwitchIdent_GetBluetoothBdAddress());
|
||||
@ -147,6 +147,11 @@ void Menu_Main(void) {
|
||||
|
||||
fsDeviceOperatorClose(&fsDeviceOperator);
|
||||
|
||||
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
||||
|
||||
PadState pad;
|
||||
padInitializeDefault(&pad);
|
||||
|
||||
while(appletMainLoop()) {
|
||||
SDL_ClearScreen(BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(0, 0, 1280, 50, STATUS_BAR_COLOUR);
|
||||
@ -165,12 +170,12 @@ void Menu_Main(void) {
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 4), 25, selection == 4? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Misc");
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 5), 25, selection == 5? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Exit");
|
||||
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
padUpdate(&pad);
|
||||
u32 kDown = padGetButtonsDown(&pad);
|
||||
|
||||
if (kDown & KEY_DDOWN)
|
||||
if (kDown & HidNpadButton_AnyDown)
|
||||
selection++;
|
||||
else if (kDown & KEY_DUP)
|
||||
else if (kDown & HidNpadButton_AnyUp)
|
||||
selection--;
|
||||
|
||||
if (selection > MAX_MENU_ITEMS)
|
||||
@ -198,7 +203,7 @@ void Menu_Main(void) {
|
||||
|
||||
SDL_Renderdisplay();
|
||||
|
||||
if ((kDown & KEY_PLUS) || ((kDown & KEY_A) && (selection == MAX_MENU_ITEMS)))
|
||||
if ((kDown & HidNpadButton_Plus) || ((kDown & HidNpadButton_A) && (selection == MAX_MENU_ITEMS)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user