Properly display SD and gamecard slot status

Also fixed console version duplicating the CPU clock info
This commit is contained in:
Joel16 2018-11-22 23:49:42 -06:00
parent 8b36cc1b54
commit 919f7d0f32
7 changed files with 56 additions and 91 deletions

View File

@ -1,62 +0,0 @@
#include <stdio.h>
#include "fs.h"
static Result fsDeviceOperatorIsGameCardInserted(FsDeviceOperator *d, 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 = 200;
Result rc = serviceIpcDispatch(&d->s);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
ipcParse(&r);
struct {
u64 magic;
u64 result;
u8 is_inserted;
} *resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc)) {
*out = resp->is_inserted != 0;
}
}
return rc;
}
bool SwitchIdent_IsSDCardInserted(FsDeviceOperator *fsDeviceOperator) {
bool inserted;
Result ret = 0;
if (R_FAILED(ret = fsDeviceOperatorIsSdCardInserted(fsDeviceOperator, &inserted))) {
printf("fsDeviceOperatorIsSdCardInserted() failed: 0x%x.\n\n", ret);
return false;
}
return inserted;
}
bool SwitchIdent_IsGameCardInserted(FsDeviceOperator *fsDeviceOperator) {
bool inserted;
Result ret = 0;
if (R_FAILED(ret = fsDeviceOperatorIsGameCardInserted(fsDeviceOperator, &inserted))) {
printf("fsDeviceOperatorIsGameCardInserted() failed: 0x%x.\n\n", ret);
return false;
}
return inserted;
}

View File

@ -1,9 +0,0 @@
#ifndef _SWITCHIDENT_FS_H_
#define _SWITCHIDENT_FS_H_
#include <switch.h>
bool SwitchIdent_IsSDCardInserted(FsDeviceOperator *fsDeviceOperator);
bool SwitchIdent_IsGameCardInserted(FsDeviceOperator *fsDeviceOperator);
#endif

View File

@ -16,4 +16,24 @@ bool SwitchIdent_GetFlag(SetSysFlag flag) {
printf("setsysGetFlag() failed: 0x%x.\n\n", ret);
return out;
}
}
bool SwitchIdent_IsSDCardInserted(FsDeviceOperator *fsDeviceOperator) {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = fsDeviceOperatorIsSdCardInserted(fsDeviceOperator, &out)))
printf("fsDeviceOperatorIsSdCardInserted() failed: 0x%x.\n\n", ret);
return out;
}
bool SwitchIdent_IsGameCardInserted(FsDeviceOperator *fsDeviceOperator) {
Result ret = 0;
bool out = false;
if (R_FAILED(ret = fsDeviceOperatorIsGameCardInserted(fsDeviceOperator, &out)))
printf("fsDeviceOperatorIsGameCardInserted() failed: 0x%x.\n\n", ret);
return out;
}

View File

@ -3,5 +3,7 @@
char *SwitchIdent_GetOperationMode(void);
bool SwitchIdent_GetFlag(SetSysFlag flag);
bool SwitchIdent_IsSDCardInserted(FsDeviceOperator *fsDeviceOperator);
bool SwitchIdent_IsGameCardInserted(FsDeviceOperator *fsDeviceOperator);
#endif

View File

@ -3,7 +3,6 @@
#include <inttypes.h>
#include <switch.h>
#include "fs.h"
#include "kernel.h"
#include "misc.h"
#include "power.h"
@ -13,7 +12,7 @@
#include "wlan.h"
static Service psm_service, wlaninf_service;
//static FsDeviceOperator fsDeviceOperator;
static bool isSDInserted = false, isGameCardInserted = false;
static void SwitchIdent_InitServices(void) {
Result ret = 0;
@ -45,20 +44,29 @@ static void SwitchIdent_InitServices(void) {
if (R_FAILED(ret = psmInitialize()))
printf("psmInitialize() failed: 0x%x.\n\n", ret);
if (R_FAILED(ret = pcvInitialize()))
printf("pcvInitialize() failed: 0x%x.\n\n", ret);
if (R_FAILED(ret = smGetService(&psm_service, "psm")))
printf("psmInitialize() failed: 0x%x.\n\n", ret);
if (R_FAILED(ret = smGetService(&wlaninf_service, "wlan:inf")))
printf("wlaninfInitialize() failed: 0x%x.\n\n", ret);
/*if (R_FAILED(ret = fsOpenDeviceOperator(&fsDeviceOperator)))
printf("fsOpenDeviceOperator() failed: 0x%x.\n\n", ret);*/
FsDeviceOperator fsDeviceOperator;
if (R_FAILED(ret = fsOpenDeviceOperator(&fsDeviceOperator)))
printf("fsOpenDeviceOperator() failed: 0x%x.\n\n", ret);
isSDInserted = SwitchIdent_IsSDCardInserted(&fsDeviceOperator);
isGameCardInserted = SwitchIdent_IsGameCardInserted(&fsDeviceOperator);
fsDeviceOperatorClose(&fsDeviceOperator);
}
static void SwitchIdent_TermServices(void) {
//fsDeviceOperatorClose(&fsDeviceOperator);
serviceClose(&wlaninf_service);
serviceClose(&psm_service);
pcvExit();
psmExit();
nsExit();
apmExit();
@ -123,7 +131,7 @@ int main(int argc, char **argv) {
Utils_GetSizeString(nand_s_free_str, SwitchIdent_GetFreeStorage(FsStorageId_NandSystem));
Utils_GetSizeString(nand_s_used_str, SwitchIdent_GetUsedStorage(FsStorageId_NandSystem));
printf("\x1b[28;0H");
printf("\x1b[30;0H");
printf("\x1b[35;1m*\x1b[0m Total SD Capacity: \x1b[35;1m%s\n", sd_total_str);
printf("\x1b[35;1m*\x1b[0m Free SD Capacity: \x1b[35;1m%s\n", sd_free_str);
printf("\x1b[35;1m*\x1b[0m Used storage: \x1b[35;1m%s\n", sd_used_str);
@ -144,7 +152,7 @@ int main(int argc, char **argv) {
*/
printf("\x1b[11;0H");
printf("\x1b[33;1m*\x1b[0m CPU clock: \x1b[33;1m%lu\x1b[0m MHz \n", SwitchIdent_GetCPUClock());
printf("\x1b[33;1m*\x1b[0m CPU clock: \x1b[33;1m%lu\x1b[0m MHz \n", SwitchIdent_GetCPUClock());
printf("\x1b[33;1m*\x1b[0m GPU clock: \x1b[33;1m%lu\x1b[0m MHz \n", SwitchIdent_GetGPUClock());
printf("\x1b[33;1m*\x1b[0m Wireless LAN: \x1b[33;1m%s\x1b[0m (RSSI: \x1b[33;1m%d\x1b[0m) (Quality: \x1b[33;1m%lu\x1b[0m) \n\n", SwitchIdent_GetFlag(SetSysFlag_WirelessLanEnable)? "Enabled" : "Disabled", SwitchIdent_GetWlanRSSI(&wlaninf_service), SwitchIdent_GetWlanQuality(SwitchIdent_GetWlanRSSI(&wlaninf_service)));
/*
@ -159,10 +167,9 @@ int main(int argc, char **argv) {
printf("\x1b[94;1m*\x1b[0m Battery ample power supplied: \x1b[94;1m%s \n\n", SwitchIdent_IsEnoughPowerSupplied(&psm_service)? "Yes" : "No");
printf("\x1b[26;0H");
printf("\x1b[36;1m*\x1b[0m State: \x1b[36;1m%s \n\n", SwitchIdent_GetOperationMode());
// The following aren't working
//printf("\x1b[36;1m*\x1b[0m SD card status: \x1b[36;1m%s \n", SwitchIdent_IsSDCardInserted(&fsDeviceOperator)? "Inserted" : "Not inserted");
//printf("\x1b[36;1m*\x1b[0m Game card status: \x1b[36;1m%s \n\n", SwitchIdent_IsGameCardInserted(&fsDeviceOperator)? "Inserted" : "Not inserted");
printf("\x1b[36;1m*\x1b[0m State: \x1b[36;1m%s \n", SwitchIdent_GetOperationMode());
printf("\x1b[36;1m*\x1b[0m SD card status: \x1b[36;1m%s \n", isSDInserted? "Inserted" : "Not inserted");
printf("\x1b[36;1m*\x1b[0m Game card status: \x1b[36;1m%s \n\n", isGameCardInserted? "Inserted" : "Not inserted");
//Scan all the inputs. This should be done once for each frame
hidScanInput();

View File

@ -4,6 +4,7 @@
#include "SDL_helper.h"
static void Term_Services(void) {
pcvExit();
psmExit();
nsExit();
apmExit();
@ -56,6 +57,9 @@ static void Init_Services(void) {
if (R_FAILED(ret = psmInitialize()))
printf("psmInitialize() failed: 0x%x.\n\n", ret);
if (R_FAILED(ret = pcvInitialize()))
printf("pcvInitialize() failed: 0x%x.\n\n", ret);
}
int main(int argc, char **argv) {

View File

@ -1,7 +1,6 @@
#include <unistd.h>
#include <switch.h>
#include "fs.h"
#include "kernel.h"
#include "menus.h"
#include "misc.h"
@ -16,9 +15,8 @@
#define MAX_MENU_ITEMS 5
static u32 item_height = 0;
static Service setcal_service, psm_service, wlaninf_service;
//static FsDeviceOperator fsDeviceOperator;
static bool isSDInserted = false, isGameCardInserted = false;
static void Menu_DrawItem(int x, int y, char *item_title, const char *text, ...) {
u32 title_width = 0;
@ -125,8 +123,8 @@ static void Menu_Misc(void) {
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) + 250, "SD card status:", SwitchIdent_IsSDCardInserted(&fsDeviceOperator)? "Inserted" : "Not inserted");
//Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 300, "Game card status:", SwitchIdent_IsGameCardInserted(&fsDeviceOperator)? "Inserted" : "Not inserted");
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");
}
void Menu_Main(void) {
@ -147,8 +145,14 @@ void Menu_Main(void) {
if (R_FAILED(ret = smGetService(&wlaninf_service, "wlan:inf")))
printf("wlaninfInitialize() failed: 0x%x.\n\n", ret);
/*if (R_FAILED(ret = fsOpenDeviceOperator(&fsDeviceOperator)))
printf("fsOpenDeviceOperator() failed: 0x%x.\n\n", ret);*/
FsDeviceOperator fsDeviceOperator;
if (R_FAILED(ret = fsOpenDeviceOperator(&fsDeviceOperator)))
printf("fsOpenDeviceOperator() failed: 0x%x.\n\n", ret);
isSDInserted = SwitchIdent_IsSDCardInserted(&fsDeviceOperator);
isGameCardInserted = SwitchIdent_IsGameCardInserted(&fsDeviceOperator);
fsDeviceOperatorClose(&fsDeviceOperator);
while(appletMainLoop()) {
SDL_ClearScreen(BACKGROUND_COLOUR);
@ -205,7 +209,6 @@ void Menu_Main(void) {
break;
}
//fsDeviceOperatorClose(&fsDeviceOperator);
serviceClose(&wlaninf_service);
serviceClose(&psm_service);
serviceClose(&setcal_service);