Skip to content

Commit

Permalink
Add LED indicators
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Rohloff <[email protected]>
  • Loading branch information
V10lator authored and GaryOderNichts committed Mar 1, 2024
1 parent 997ec86 commit 9ec6108
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 167 deletions.
39 changes: 27 additions & 12 deletions ios_mcp/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "netconf.h"
#include "mcp_misc.h"

#include <stdarg.h>
#include <string.h>
#include <unistd.h>

Expand Down Expand Up @@ -212,6 +213,28 @@ void waitButtonInput(void)
}
}

void print_error(int index, const char *msg)
{
gfx_set_font_color(COLOR_ERROR);
gfx_print(16, index, GfxPrintFlag_ClearBG, msg);
setNotificationLED(NOTIF_LED_RED, 0);
waitButtonInput();
setNotificationLED(NOTIF_LED_PURPLE, 0);
}

void printf_error(int index, const char *format, ...)
{
va_list args;
va_start(args, format);

char buffer[0x100];

vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);

print_error(index, buffer);
}

/**
* Initialize the network configuration.
* @param index [in/out] Starting (and ending) Y position.
Expand All @@ -224,9 +247,7 @@ int initNetconf(uint32_t* index)

int res = netconf_init();
if (res <= 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, *index, 0, "Failed to initialize netconf: %x", res);
waitButtonInput();
printf_error(*index, "Failed to initialize netconf: %x", res);
return res;
}

Expand All @@ -251,9 +272,7 @@ int initNetconf(uint32_t* index)
*index += CHAR_SIZE_DRC_Y;

if (interface == 0xff) {
gfx_set_font_color(COLOR_ERROR);
gfx_print(16, *index, 0, "No network connection!");
waitButtonInput();
print_error(*index, "No network connection!");
return 1;
}

Expand All @@ -263,9 +282,7 @@ int initNetconf(uint32_t* index)
uint8_t ip_address[4];
res = netconf_get_assigned_address(interface, (uint32_t*) ip_address);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, *index, 0, "Failed to get IP address: %x", res);
waitButtonInput();
printf_error(*index, "Failed to get IP address: %x", res);
return res;
}

Expand All @@ -275,9 +292,7 @@ int initNetconf(uint32_t* index)

res = socketInit();
if (res <= 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, *index, 0, "Failed to initialize socketlib: %x", res);
waitButtonInput();
printf_error(*index, "Failed to initialize socketlib: %x", res);
return res;
}

Expand Down
6 changes: 6 additions & 0 deletions ios_mcp/source/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ int drawMenu(const char* title, const Menu* menu, size_t count,
*/
void waitButtonInput(void);

/**
* Print an error message in red and indicate it on the LED
*/
void print_error(int index, const char *msg);
void printf_error(int index, const char *format, ...);

/**
* Initialize the network configuration.
* @param index [in/out] Starting (and ending) Y position.
Expand Down
33 changes: 13 additions & 20 deletions ios_mcp/source/options/DebugSystemRegion.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ void option_DebugSystemRegion(void)
int productArea_id, gameRegion;
int res = getRegionInfo(&productArea_id, &gameRegion);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to get the system region code: %x", res);
waitButtonInput();
printf_error(index, "Failed to get the system region code: %x", res);
return;
}

Expand Down Expand Up @@ -125,17 +123,17 @@ void option_DebugSystemRegion(void)
}

// Show the errors.
gfx_set_font_color(COLOR_ERROR);
if (menu_count == 0 || menu_productArea_id < 0) {
gfx_print(16, index, 0, "Could not find a Wii U Menu title installed on this system.");
waitButtonInput();
print_error(index, "Could not find a Wii U Menu title installed on this system.");
return;
} else if (menu_count > 1) {
gfx_print(16, index, 0, "Multiple Wii U Menus were found. Someone dun goofed...");
waitButtonInput();
}

if (menu_count > 1) {
print_error(index, "Multiple Wii U Menus were found. Someone dun goofed...");
return;
}

gfx_set_font_color(COLOR_ERROR);
if (!menu_matches_region) {
gfx_printf(16, index, 0, "The %s region does not match the installed Wii U Menu.", "system");
index += CHAR_SIZE_DRC_Y + 4;
Expand Down Expand Up @@ -164,19 +162,15 @@ void option_DebugSystemRegion(void)
// Attempt to set the region code.
int mcpHandle = IOS_Open("/dev/mcp", 0);
if (mcpHandle < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "IOS_Open(\"/dev/mcp\") failed: %x", mcpHandle);
waitButtonInput();
printf_error(index, "IOS_Open(\"/dev/mcp\") failed: %x", mcpHandle);
return;
}

MCPSysProdSettings sysProdSettings;
res = MCP_GetSysProdSettings(mcpHandle, &sysProdSettings);
if (res < 0) {
IOS_Close(mcpHandle);
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "MCP_GetSysProdSettings() failed: %x", res);
waitButtonInput();
printf_error(index, "MCP_GetSysProdSettings() failed: %x", res);
return;
}

Expand All @@ -187,12 +181,11 @@ void option_DebugSystemRegion(void)
res = MCP_SetSysProdSettings(mcpHandle, &sysProdSettings);
IOS_Close(mcpHandle);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "MCP_SetSysProdSettings() failed: %x", res);
} else {
gfx_set_font_color(COLOR_SUCCESS);
gfx_printf(16, index, 0, "System region set to %s successfully.", menu_region_str);
printf_error(index, "MCP_SetSysProdSettings() failed: %x", res);
return;
}

gfx_set_font_color(COLOR_SUCCESS);
gfx_printf(16, index, 0, "System region set to %s successfully.", menu_region_str);
waitButtonInput();
}
32 changes: 9 additions & 23 deletions ios_mcp/source/options/DumpOtpAndSeeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@ int read_otp_seeprom(void *buf, int index)

int res = IOS_ReadOTP(0, otp, 0x400);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to read OTP: %x", res);
waitButtonInput();
printf_error(index, "Failed to read OTP: %x", res);
return res;
}

res = EEPROM_Read(0, 0x100, seeprom);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to read EEPROM: %x", res);
waitButtonInput();
printf_error(index, "Failed to read EEPROM: %x", res);
return res;
}

Expand Down Expand Up @@ -82,20 +78,16 @@ static int write_file_to_sd(uint32_t *index, int fsaHandle, const char *filename
int fileHandle;
int res = FSA_OpenFile(fsaHandle, path, "w", &fileHandle);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, *index, 0, "Failed to create %s: %x", filename, res);
printf_error(*index, "Failed to create %s: %x", filename, res);
*index += CHAR_SIZE_DRC_Y + 4;
waitButtonInput();
return res;
}

res = FSA_WriteFile(fsaHandle, buf, 1, size, fileHandle, 0);
FSA_CloseFile(fsaHandle, fileHandle);
if (res != size) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, *index, 0, "Failed to write %s: %x", filename, res);
printf_error(*index, "Failed to write %s: %x", filename, res);
*index += CHAR_SIZE_DRC_Y + 4;
waitButtonInput();
return res;
}

Expand All @@ -106,13 +98,12 @@ void option_DumpOtpAndSeeprom(void)
{
gfx_clear(COLOR_BACKGROUND);
drawTopBar("Dumping OTP + SEEPROM...");
setNotificationLED(NOTIF_LED_RED_BLINKING, 0);
uint32_t index = 16 + 8 + 2 + 8;

void* dataBuffer = IOS_HeapAllocAligned(CROSS_PROCESS_HEAP_ID, 0x400, 0x40);
if (!dataBuffer) {
gfx_set_font_color(COLOR_ERROR);
gfx_print(16, index, 0, "Out of memory!");
waitButtonInput();
print_error(index, "Out of memory!");
return;
}

Expand All @@ -123,11 +114,8 @@ void option_DumpOtpAndSeeprom(void)

int res = IOS_ReadOTP(0, dataBuffer, 0x400);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to read OTP: %x", res);
waitButtonInput();

IOS_HeapFree(CROSS_PROCESS_HEAP_ID, dataBuffer);
printf_error(index, "Failed to read OTP: %x", res);
return;
}

Expand All @@ -144,11 +132,8 @@ void option_DumpOtpAndSeeprom(void)

res = EEPROM_Read(0, 0x100, (uint16_t*) dataBuffer);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to read EEPROM: %x", res);
waitButtonInput();

IOS_HeapFree(CROSS_PROCESS_HEAP_ID, dataBuffer);
printf_error(index, "Failed to read EEPROM: %x", res);
return;
}

Expand All @@ -160,6 +145,7 @@ void option_DumpOtpAndSeeprom(void)

/** All done! **/

setNotificationLED(NOTIF_LED_PURPLE, 0);
gfx_set_font_color(COLOR_SUCCESS);
gfx_print(16, index, 0, "Done!");
waitButtonInput();
Expand Down
17 changes: 6 additions & 11 deletions ios_mcp/source/options/DumpSyslogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ void option_DumpSyslogs(void)
gfx_clear(COLOR_BACKGROUND);

drawTopBar("Dumping Syslogs...");
setNotificationLED(NOTIF_LED_RED_BLINKING, 0);

uint32_t index = 16 + 8 + 2 + 8;
gfx_print(16, index, 0, "Creating 'logs' directory...");
index += CHAR_SIZE_DRC_Y + 4;

int res = FSA_MakeDir(fsaHandle, "/vol/storage_recovsd/logs", 0x600);
if ((res < 0) && !(res == -0x30016)) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to create directory: %x", res);
waitButtonInput();
printf_error(index, "Failed to create directory: %x", res);
return;
}

Expand All @@ -29,9 +28,7 @@ void option_DumpSyslogs(void)
int dir_handle;
res = FSA_OpenDir(fsaHandle, "/vol/system/logs", &dir_handle);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to open system logs: %x", res);
waitButtonInput();
printf_error(index, "Failed to open system logs: %x", res);
return;
}

Expand All @@ -50,16 +47,14 @@ void option_DumpSyslogs(void)

res = copy_file(fsaHandle, src_path, dst_path);
if (res < 0) {
index += CHAR_SIZE_DRC_Y + 4;
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, GfxPrintFlag_ClearBG, "Failed to copy %s: %x", dir_entry.name, res);
waitButtonInput();

FSA_CloseDir(fsaHandle, dir_handle);
index += CHAR_SIZE_DRC_Y + 4;
printf_error(index, "Failed to copy %s: %x", dir_entry.name, res);
return;
}
}

setNotificationLED(NOTIF_LED_PURPLE, 0);
index += CHAR_SIZE_DRC_Y + 4;
gfx_set_font_color(COLOR_SUCCESS);
gfx_print(16, index, 0, "Done!");
Expand Down
27 changes: 8 additions & 19 deletions ios_mcp/source/options/InstallWUP.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
#include "gfx.h"
#include "mcp_install.h"
#include "imports.h"
#include "utils.h"

void option_InstallWUP(void)
{
gfx_clear(COLOR_BACKGROUND);
drawTopBar("Installing WUP");
setNotificationLED(NOTIF_LED_RED_BLINKING, 0);

uint32_t index = 16 + 8 + 2 + 8;
gfx_print(16, index, 0, "Make sure to place a valid signed WUP directly in 'sd:/install'");
index += CHAR_SIZE_DRC_Y + 4;

int mcpHandle = IOS_Open("/dev/mcp", 0);
if (mcpHandle < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to open /dev/mcp: %x", mcpHandle);
waitButtonInput();
printf_error(index, "Failed to open /dev/mcp: %x", mcpHandle);
return;
}

Expand All @@ -28,11 +28,8 @@ void option_InstallWUP(void)
MCPInstallInfo info;
int res = MCP_InstallGetInfo(mcpHandle, "/vol/storage_recovsd/install", &info);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to get install info: %x", res);
waitButtonInput();

IOS_Close(mcpHandle);
printf_error(index, "Failed to get install info: %x", res);
return;
}

Expand All @@ -43,34 +40,26 @@ void option_InstallWUP(void)
// only install to NAND
res = MCP_InstallSetTargetDevice(mcpHandle, 0);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "MCP_InstallSetTargetDevice: %x", res);
waitButtonInput();

IOS_Close(mcpHandle);
printf_error(index, "MCP_InstallSetTargetDevice: %x", res);
return;
}
res = MCP_InstallSetTargetUsb(mcpHandle, 0);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "MCP_InstallSetTargetUsb: %x", res);
waitButtonInput();

IOS_Close(mcpHandle);
printf_error(index, "MCP_InstallSetTargetUsb: %x", res);
return;
}

// TODO: async installations
res = MCP_InstallTitle(mcpHandle, "/vol/storage_recovsd/install");
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to install: %x", res);
waitButtonInput();

IOS_Close(mcpHandle);
printf_error(index, "Failed to install: %x", res);
return;
}

setNotificationLED(NOTIF_LED_PURPLE, 0);
gfx_set_font_color(COLOR_SUCCESS);
gfx_print(16, index, 0, "Done!");
waitButtonInput();
Expand Down
Loading

0 comments on commit 9ec6108

Please sign in to comment.