app: Minor style changes and cleanup

This commit is contained in:
joel16 2023-06-18 15:17:59 -04:00
parent 3e44a00637
commit 8892836e58
11 changed files with 83 additions and 61 deletions

View File

@ -58,7 +58,7 @@ APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := `$(PREFIX)pkg-config --cflags sdl2 SDL2_image` -Wall -O2 -ffunction-sections \
CFLAGS := `$(PREFIX)pkg-config --cflags sdl2 SDL2_image` -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__

View File

@ -1,5 +1,4 @@
#ifndef _SWITCHIDENT_COMMON_H_
#define _SWITCHIDENT_COMMON_H_
#pragma once
#include <switch.h>
@ -41,7 +40,6 @@ namespace SwitchIdent {
u64 GetDeviceID(void);
SetSysSerialNumber GetSerialNumber(void);
// Misc
const char *GetOperationMode(void);
bool GetWirelessLanEnableFlag(void);
@ -90,5 +88,3 @@ namespace SwitchIdent {
HidPowerInfo GetJoyconPowerInfoL(HidNpadIdType id);
HidPowerInfo GetJoyconPowerInfoR(HidNpadIdType id);
}
#endif

View File

@ -1,5 +1,4 @@
#ifndef _SWITCHIDENT_GUI_H_
#define _SWITCHIDENT_GUI_H_
#pragma once
#include <switch.h>
#include <SDL2/SDL.h>
@ -17,5 +16,3 @@ namespace GUI {
void DrawImage(SDL_Texture *texture, int x, int y);
void Render(void);
}
#endif

View File

@ -1,8 +1,5 @@
#ifndef _SWITCHIDENT_MENUS_H_
#define _SWITCHIDENT_MENUS_H_
#pragma once
namespace Menus {
void Main(void);
}
#endif

View File

@ -15,8 +15,9 @@ namespace SwitchIdent {
Result GetJoyconFirmwareVersion(HidDeviceTypeBits deviceType, HIDFirmwareVersion *version) {
Result ret = 0;
if (R_FAILED(ret = hiddbgGetFirmwareVersion(HidNpadIdType_No1, deviceType, version)))
if (R_FAILED(ret = hiddbgGetFirmwareVersion(HidNpadIdType_No1, deviceType, version))) {
std::printf("hiddbgGetFirmwareVersion() failed: 0x%x.\n\n", ret);
}
return ret;
}

View File

@ -41,11 +41,13 @@ namespace SwitchIdent {
"Unknown"
};
if (R_FAILED(ret = splGetConfig(SplConfigItem_DramId, &id)))
if (R_FAILED(ret = splGetConfig(SplConfigItem_DramId, &id))) {
std::printf("splGetConfig(SplConfigItem_DramId) failed: 0x%x.\n\n", ret);
}
if (id >= 30)
if (id >= 30) {
return dram_desc[30];
}
return dram_desc[id];
}
@ -54,8 +56,9 @@ namespace SwitchIdent {
Result ret = 0;
SetSysFirmwareVersion version;
if (R_FAILED(ret = setsysGetFirmwareVersion(&version)))
if (R_FAILED(ret = setsysGetFirmwareVersion(&version))) {
std::printf("setsysGetFirmwareVersion() failed: 0x%x.\n\n", ret);
}
return version;
}
@ -74,11 +77,13 @@ namespace SwitchIdent {
"Unknown"
};
if (R_FAILED(ret = splGetConfig(SplConfigItem_HardwareType, &hardware_type)))
if (R_FAILED(ret = splGetConfig(SplConfigItem_HardwareType, &hardware_type))) {
std::printf("splGetConfig(SplConfigItem_HardwareType) failed: 0x%x.\n\n", ret);
}
if (hardware_type >= 6)
if (hardware_type >= 6) {
return hardware_string[6];
}
return hardware_string[hardware_type];
}
@ -88,8 +93,9 @@ namespace SwitchIdent {
u64 is_kiosk_mode = 0;
Result ret = 0;
if (R_FAILED(ret = splGetConfig(SplConfigItem_IsKiosk , &is_kiosk_mode)))
if (R_FAILED(ret = splGetConfig(SplConfigItem_IsKiosk , &is_kiosk_mode))) {
std::printf("splGetConfig(SplConfigItem_IsKiosk) failed: 0x%x.\n\n", ret);
}
return is_kiosk_mode? true : false;
}
@ -116,21 +122,20 @@ namespace SwitchIdent {
Result ret = 0;
u64 safemode = 0;
if (R_FAILED(ret = splGetConfig(SplConfigItem_IsRecoveryBoot, &safemode)))
if (R_FAILED(ret = splGetConfig(SplConfigItem_IsRecoveryBoot, &safemode))) {
std::printf("splGetConfig(SplConfigItem_IsRecoveryBoot) failed: 0x%x.\n\n", ret);
if (safemode)
return true;
}
return false;
return safemode? true : false;
}
u64 GetDeviceID(void) {
Result ret = 0;
u64 id = 0;
if (R_FAILED(ret = splGetConfig(SplConfigItem_DeviceId, &id)))
if (R_FAILED(ret = splGetConfig(SplConfigItem_DeviceId, &id))) {
std::printf("splGetConfig(SplConfigItem_DeviceId) failed: 0x%x.\n\n", ret);
}
return id;
}
@ -139,8 +144,9 @@ namespace SwitchIdent {
Result ret = 0;
SetSysSerialNumber serial;
if (R_FAILED(ret = setsysGetSerialNumber(&serial)))
if (R_FAILED(ret = setsysGetSerialNumber(&serial))) {
std::printf("setsysGetSerialNumber() failed: 0x%x.\n\n", ret);
}
return serial;
}

View File

@ -216,8 +216,9 @@ namespace Menus {
Result ret = 0;
FsDeviceOperator fsDeviceOperator;
if (R_FAILED(ret = fsOpenDeviceOperator(&fsDeviceOperator)))
if (R_FAILED(ret = fsOpenDeviceOperator(&fsDeviceOperator))) {
std::printf("fsOpenDeviceOperator() failed: 0x%x.\n\n", ret);
}
g_is_sd_inserted = SwitchIdent::IsSDCardInserted(&fsDeviceOperator);
g_is_gamecard_inserted = SwitchIdent::IsGameCardInserted(&fsDeviceOperator);
@ -255,16 +256,20 @@ namespace Menus {
padUpdate(&g_pad);
u32 kDown = padGetButtonsDown(&g_pad);
if (kDown & HidNpadButton_AnyDown)
if (kDown & HidNpadButton_AnyDown) {
selection++;
else if (kDown & HidNpadButton_AnyUp)
}
else if (kDown & HidNpadButton_AnyUp) {
selection--;
}
if (selection > STATE_EXIT)
if (selection > STATE_EXIT) {
selection = 0;
if (selection < 0)
}
if (selection < 0) {
selection = STATE_EXIT;
}
switch (selection) {
case STATE_KERNEL_INFO:
Menus::KernelInfo();
@ -296,8 +301,9 @@ namespace Menus {
GUI::Render();
if ((kDown & HidNpadButton_Plus) || ((kDown & HidNpadButton_A) && (selection == STATE_EXIT)))
if ((kDown & HidNpadButton_Plus) || ((kDown & HidNpadButton_A) && (selection == STATE_EXIT))) {
break;
}
}
}
}

View File

@ -4,18 +4,16 @@
namespace SwitchIdent {
const char *GetOperationMode(void) {
if (appletGetOperationMode() == AppletOperationMode_Handheld)
return "Handheld";
return "Docked";
return (appletGetOperationMode() == AppletOperationMode_Handheld)? "Handheld" : "Docked";
}
bool GetWirelessLanEnableFlag(void) {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = setsysGetWirelessLanEnableFlag(&out)))
if (R_FAILED(ret = setsysGetWirelessLanEnableFlag(&out))) {
std::printf("setsysGetWirelessLanEnableFlag() failed: 0x%x.\n\n", ret);
}
return out;
}
@ -24,8 +22,9 @@ namespace SwitchIdent {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = setsysGetBluetoothEnableFlag(&out)))
if (R_FAILED(ret = setsysGetBluetoothEnableFlag(&out))) {
std::printf("setsysGetBluetoothEnableFlag() failed: 0x%x.\n\n", ret);
}
return out;
}
@ -34,8 +33,9 @@ namespace SwitchIdent {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = setsysGetNfcEnableFlag(&out)))
if (R_FAILED(ret = setsysGetNfcEnableFlag(&out))) {
std::printf("setsysGetNfcEnableFlag() failed: 0x%x.\n\n", ret);
}
return out;
}
@ -44,8 +44,9 @@ namespace SwitchIdent {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = setsysGetAutoUpdateEnableFlag(&out)))
if (R_FAILED(ret = setsysGetAutoUpdateEnableFlag(&out))) {
std::printf("setsysGetAutoUpdateEnableFlag() failed: 0x%x.\n\n", ret);
}
return out;
}
@ -54,8 +55,9 @@ namespace SwitchIdent {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = setsysGetConsoleInformationUploadFlag(&out)))
if (R_FAILED(ret = setsysGetConsoleInformationUploadFlag(&out))) {
std::printf("setsysGetConsoleInformationUploadFlag() failed: 0x%x.\n\n", ret);
}
return out;
}
@ -64,8 +66,9 @@ namespace SwitchIdent {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = fsDeviceOperatorIsSdCardInserted(fsDeviceOperator, &out)))
if (R_FAILED(ret = fsDeviceOperatorIsSdCardInserted(fsDeviceOperator, &out))) {
std::printf("fsDeviceOperatorIsSdCardInserted() failed: 0x%x.\n\n", ret);
}
return out;
}
@ -74,8 +77,9 @@ namespace SwitchIdent {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = fsDeviceOperatorIsGameCardInserted(fsDeviceOperator, &out)))
if (R_FAILED(ret = fsDeviceOperatorIsGameCardInserted(fsDeviceOperator, &out))) {
std::printf("fsDeviceOperatorIsGameCardInserted() failed: 0x%x.\n\n", ret);
}
return out;
}

View File

@ -6,8 +6,9 @@ namespace SwitchIdent {
Result ret = 0;
s64 total = 0;
if (R_FAILED(ret = nsGetTotalSpaceSize(storage_id, &total)))
if (R_FAILED(ret = nsGetTotalSpaceSize(storage_id, &total))) {
std::printf("nsGetFreeSpaceSize() failed: 0x%x.\n\n", ret);
}
return total;
}
@ -16,8 +17,9 @@ namespace SwitchIdent {
Result ret = 0;
s64 free = 0;
if (R_FAILED(ret = nsGetFreeSpaceSize(storage_id, &free)))
if (R_FAILED(ret = nsGetFreeSpaceSize(storage_id, &free))) {
std::printf("nsGetFreeSpaceSize() failed: 0x%x.\n\n", ret);
}
return free;
}

View File

@ -7,8 +7,9 @@ namespace SwitchIdent {
Result ret = 0;
u64 language = 0;
if (R_FAILED(ret = setGetSystemLanguage(&language)))
if (R_FAILED(ret = setGetSystemLanguage(&language))) {
std::printf("setGetSystemLanguage() failed: 0x%x.\n\n", ret);
}
return language;
}
@ -43,18 +44,23 @@ namespace SwitchIdent {
ClkrstSession session = {0};
PcvModuleId module_id;
if (R_FAILED(ret = pcvGetModuleId(&module_id, module)))
if (R_FAILED(ret = pcvGetModuleId(&module_id, module))) {
std::printf("pcvGetModuleId() failed: 0x%x.\n\n", ret);
else if (R_FAILED(ret = clkrstOpenSession(&session, module_id, 3)))
}
else if (R_FAILED(ret = clkrstOpenSession(&session, module_id, 3))) {
std::printf("clkrstOpenSession() failed: 0x%x.\n\n", ret);
else if (R_FAILED(ret = clkrstGetClockRate(&session, &out)))
}
else if (R_FAILED(ret = clkrstGetClockRate(&session, &out))) {
std::printf("clkrstGetClockRate() failed: 0x%x.\n\n", ret);
else
}
else {
clkrstCloseSession(&session);
}
}
else {
if (R_FAILED(ret = pcvGetClockRate(module, &out)))
if (R_FAILED(ret = pcvGetClockRate(module, &out))) {
std::printf("pcvGetClockRate() failed: 0x%x.\n\n", ret);
}
}
return out/1000000;
@ -64,8 +70,9 @@ namespace SwitchIdent {
Result ret = 0;
SetCalBdAddress bd_addr;
if (R_FAILED(ret = setcalGetBdAddress(&bd_addr)))
if (R_FAILED(ret = setcalGetBdAddress(&bd_addr))) {
std::printf("setcalGetBdAddress() failed: 0x%x.\n\n", ret);
}
return bd_addr;
}
@ -74,8 +81,9 @@ namespace SwitchIdent {
Result ret = 0;
SetCalMacAddress mac_addr;
if (R_FAILED(ret = setcalGetWirelessLanMacAddress(&mac_addr)))
if (R_FAILED(ret = setcalGetWirelessLanMacAddress(&mac_addr))) {
std::printf("setcalGetWirelessLanMacAddress() failed: 0x%x.\n\n", ret);
}
return mac_addr;
}

View File

@ -6,8 +6,9 @@ namespace SwitchIdent {
Result ret = 0;
WlanInfState state;
if (R_FAILED(ret = wlaninfGetState(&state)))
if (R_FAILED(ret = wlaninfGetState(&state))) {
return -1;
}
return state;
}
@ -15,12 +16,15 @@ namespace SwitchIdent {
s32 GetWlanQuality(s32 dBm) {
u32 quality = 0;
if (dBm <= -100)
if (dBm <= -100) {
quality = 0;
else if (dBm >= -50)
}
else if (dBm >= -50) {
quality = 100;
else
}
else {
quality = 2 * (dBm + 100);
}
return quality;
}
@ -29,8 +33,9 @@ namespace SwitchIdent {
Result ret = 0;
s32 rssi = 0;
if (R_FAILED(ret = wlaninfGetRSSI(&rssi)))
if (R_FAILED(ret = wlaninfGetRSSI(&rssi))) {
return -1;
}
return rssi;
}