From 8892836e586585311ae3ceea9d27e3bd2f08dab6 Mon Sep 17 00:00:00 2001 From: joel16 Date: Sun, 18 Jun 2023 15:17:59 -0400 Subject: [PATCH] app: Minor style changes and cleanup --- Makefile | 2 +- include/common.hpp | 6 +----- include/gui.hpp | 5 +---- include/menus.hpp | 5 +---- source/joycon.cpp | 3 ++- source/kernel.cpp | 32 +++++++++++++++++++------------- source/menus.cpp | 20 +++++++++++++------- source/misc.cpp | 26 +++++++++++++++----------- source/storage.cpp | 6 ++++-- source/system.cpp | 24 ++++++++++++++++-------- source/wlan.cpp | 15 ++++++++++----- 11 files changed, 83 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index a9fa1e6..2d185e5 100644 --- a/Makefile +++ b/Makefile @@ -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__ diff --git a/include/common.hpp b/include/common.hpp index 2bff805..e77c53f 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -1,5 +1,4 @@ -#ifndef _SWITCHIDENT_COMMON_H_ -#define _SWITCHIDENT_COMMON_H_ +#pragma once #include @@ -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 diff --git a/include/gui.hpp b/include/gui.hpp index e87d977..2645da4 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -1,5 +1,4 @@ -#ifndef _SWITCHIDENT_GUI_H_ -#define _SWITCHIDENT_GUI_H_ +#pragma once #include #include @@ -17,5 +16,3 @@ namespace GUI { void DrawImage(SDL_Texture *texture, int x, int y); void Render(void); } - -#endif diff --git a/include/menus.hpp b/include/menus.hpp index c13c1dd..8dad8ad 100644 --- a/include/menus.hpp +++ b/include/menus.hpp @@ -1,8 +1,5 @@ -#ifndef _SWITCHIDENT_MENUS_H_ -#define _SWITCHIDENT_MENUS_H_ +#pragma once namespace Menus { void Main(void); } - -#endif diff --git a/source/joycon.cpp b/source/joycon.cpp index 0621c74..2804e0e 100644 --- a/source/joycon.cpp +++ b/source/joycon.cpp @@ -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; } diff --git a/source/kernel.cpp b/source/kernel.cpp index 23a669b..cca0aa0 100644 --- a/source/kernel.cpp +++ b/source/kernel.cpp @@ -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; } diff --git a/source/menus.cpp b/source/menus.cpp index e83ce09..0e66fef 100644 --- a/source/menus.cpp +++ b/source/menus.cpp @@ -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; + } } } } diff --git a/source/misc.cpp b/source/misc.cpp index eed0484..2f26073 100644 --- a/source/misc.cpp +++ b/source/misc.cpp @@ -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; } diff --git a/source/storage.cpp b/source/storage.cpp index fedc970..556ef6c 100644 --- a/source/storage.cpp +++ b/source/storage.cpp @@ -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; } diff --git a/source/system.cpp b/source/system.cpp index d1a8c2d..dbff305 100644 --- a/source/system.cpp +++ b/source/system.cpp @@ -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; } diff --git a/source/wlan.cpp b/source/wlan.cpp index da255a4..3694ccc 100644 --- a/source/wlan.cpp +++ b/source/wlan.cpp @@ -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; }