Declutter main rosalina menu & reorder

"Change screen brightness" (due to limitations), "Power Off", "Reboot" moved to sysconfig menu
This commit is contained in:
TuxSH 2024-09-09 00:44:48 +02:00
parent 14e462be20
commit a7bd3208a5
4 changed files with 165 additions and 166 deletions

View File

@ -33,12 +33,9 @@
extern Menu rosalinaMenu; extern Menu rosalinaMenu;
void RosalinaMenu_TakeScreenshot(void); void RosalinaMenu_TakeScreenshot(void);
void RosalinaMenu_ChangeScreenBrightness(void);
void RosalinaMenu_ShowCredits(void); void RosalinaMenu_ShowCredits(void);
void RosalinaMenu_ProcessList(void); void RosalinaMenu_ProcessList(void);
void RosalinaMenu_SaveSettings(void); void RosalinaMenu_SaveSettings(void);
void RosalinaMenu_PowerOff(void);
void RosalinaMenu_Reboot(void);
void RosalinaMenu_Cheats(void); void RosalinaMenu_Cheats(void);
void RosalinaMenu_ShowSystemInfo(); void RosalinaMenu_ShowSystemInfo();

View File

@ -43,3 +43,6 @@ void SysConfigMenu_DisableForcedWifiConnection(void);
void SysConfigMenu_ToggleCardIfPower(void); void SysConfigMenu_ToggleCardIfPower(void);
void SysConfigMenu_LoadConfig(void); void SysConfigMenu_LoadConfig(void);
void SysConfigMenu_AdjustVolume(void); void SysConfigMenu_AdjustVolume(void);
void SysConfigMenu_ChangeScreenBrightness(void);
void SysConfigMenu_PowerOff(void);
void SysConfigMenu_Reboot(void);

View File

@ -40,25 +40,21 @@
#include "memory.h" #include "memory.h"
#include "fmt.h" #include "fmt.h"
#include "process_patches.h" #include "process_patches.h"
#include "luminance.h"
#include "luma_config.h" #include "luma_config.h"
Menu rosalinaMenu = { Menu rosalinaMenu = {
"Rosalina menu", "Rosalina menu",
{ {
{ "Take screenshot", METHOD, .method = &RosalinaMenu_TakeScreenshot }, { "Take screenshot", METHOD, .method = &RosalinaMenu_TakeScreenshot },
{ "Change screen brightness", METHOD, .method = &RosalinaMenu_ChangeScreenBrightness }, { "Screen filters...", MENU, .menu = &screenFiltersMenu },
{ "Cheats...", METHOD, .method = &RosalinaMenu_Cheats }, { "Cheats...", METHOD, .method = &RosalinaMenu_Cheats },
{ "", METHOD, .method = PluginLoader__MenuCallback}, { "", METHOD, .method = PluginLoader__MenuCallback},
{ "New 3DS menu...", MENU, .menu = &N3DSMenu, .visibility = &menuCheckN3ds },
{ "Process list", METHOD, .method = &RosalinaMenu_ProcessList }, { "Process list", METHOD, .method = &RosalinaMenu_ProcessList },
{ "Debugger options...", MENU, .menu = &debuggerMenu }, { "Debugger options...", MENU, .menu = &debuggerMenu },
{ "System configuration...", MENU, .menu = &sysconfigMenu }, { "System configuration...", MENU, .menu = &sysconfigMenu },
{ "Screen filters...", MENU, .menu = &screenFiltersMenu },
{ "New 3DS menu...", MENU, .menu = &N3DSMenu, .visibility = &menuCheckN3ds },
{ "Miscellaneous options...", MENU, .menu = &miscellaneousMenu }, { "Miscellaneous options...", MENU, .menu = &miscellaneousMenu },
{ "Save settings", METHOD, .method = &RosalinaMenu_SaveSettings }, { "Save settings", METHOD, .method = &RosalinaMenu_SaveSettings },
{ "Power off", METHOD, .method = &RosalinaMenu_PowerOff },
{ "Reboot", METHOD, .method = &RosalinaMenu_Reboot },
{ "System info", METHOD, .method = &RosalinaMenu_ShowSystemInfo }, { "System info", METHOD, .method = &RosalinaMenu_ShowSystemInfo },
{ "Credits", METHOD, .method = &RosalinaMenu_ShowCredits }, { "Credits", METHOD, .method = &RosalinaMenu_ShowCredits },
{ "Debug info", METHOD, .method = &RosalinaMenu_ShowDebugInfo, .visibility = &rosalinaMenuShouldShowDebugInfo }, { "Debug info", METHOD, .method = &RosalinaMenu_ShowDebugInfo, .visibility = &rosalinaMenuShouldShowDebugInfo },
@ -216,163 +212,6 @@ void RosalinaMenu_ShowCredits(void)
while(!(waitInput() & KEY_B) && !menuShouldExit); while(!(waitInput() & KEY_B) && !menuShouldExit);
} }
void RosalinaMenu_Reboot(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Reboot");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to reboot, press B to go back.");
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if(pressed & KEY_A)
{
menuLeave();
APT_HardwareResetAsync();
return;
} else if(pressed & KEY_B)
return;
}
while(!menuShouldExit);
}
void RosalinaMenu_ChangeScreenBrightness(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
// gsp:LCD GetLuminance is stubbed on O3DS so we have to implement it ourselves... damn it.
// Assume top and bottom screen luminances are the same (should be; if not, we'll set them to the same values).
u32 luminance = getCurrentLuminance(false);
u32 minLum = getMinLuminancePreset();
u32 maxLum = getMaxLuminancePreset();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Screen brightness");
u32 posY = 30;
posY = Draw_DrawFormattedString(
10,
posY,
COLOR_WHITE,
"Current luminance: %lu (min. %lu, max. %lu)\n\n",
luminance,
minLum,
maxLum
);
posY = Draw_DrawString(10, posY, COLOR_WHITE, "Controls: Up/Down for +-1, Right/Left for +-10.\n");
posY = Draw_DrawString(10, posY, COLOR_WHITE, "Press A to start, B to exit.\n\n");
posY = Draw_DrawString(10, posY, COLOR_RED, "WARNING: \n");
posY = Draw_DrawString(10, posY, COLOR_WHITE, " * value will be limited by the presets.\n");
posY = Draw_DrawString(10, posY, COLOR_WHITE, " * bottom framebuffer will be restored until\nyou exit.");
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if (pressed & KEY_A)
break;
if (pressed & KEY_B)
return;
}
while (!menuShouldExit);
Draw_Lock();
Draw_RestoreFramebuffer();
Draw_FreeFramebufferCache();
svcKernelSetState(0x10000, 2); // unblock gsp
gspLcdInit(); // assume it doesn't fail. If it does, brightness won't change, anyway.
// gsp:LCD will normalize the brightness between top/bottom screen, handle PWM, etc.
s32 lum = (s32)luminance;
do
{
u32 pressed = waitInputWithTimeout(1000);
if (pressed & DIRECTIONAL_KEYS)
{
if (pressed & KEY_UP)
lum += 1;
else if (pressed & KEY_DOWN)
lum -= 1;
else if (pressed & KEY_RIGHT)
lum += 10;
else if (pressed & KEY_LEFT)
lum -= 10;
lum = lum < (s32)minLum ? (s32)minLum : lum;
lum = lum > (s32)maxLum ? (s32)maxLum : lum;
// We need to call gsp here because updating the active duty LUT is a bit tedious (plus, GSP has internal state).
// This is actually SetLuminance:
GSPLCD_SetBrightnessRaw(BIT(GSP_SCREEN_TOP) | BIT(GSP_SCREEN_BOTTOM), lum);
}
if (pressed & KEY_B)
break;
}
while (!menuShouldExit);
gspLcdExit();
svcKernelSetState(0x10000, 2); // block gsp again
if (R_FAILED(Draw_AllocateFramebufferCache(FB_BOTTOM_SIZE)))
{
// Shouldn't happen
__builtin_trap();
}
else
Draw_SetupFramebuffer();
Draw_Unlock();
}
void RosalinaMenu_PowerOff(void) // Soft shutdown.
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Power off");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to power off, press B to go back.");
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if(pressed & KEY_A)
{
menuLeave();
srvPublishToSubscriber(0x203, 0);
return;
}
else if(pressed & KEY_B)
return;
}
while(!menuShouldExit);
}
#define TRY(expr) if(R_FAILED(res = (expr))) goto end; #define TRY(expr) if(R_FAILED(res = (expr))) goto end;
static s64 timeSpentConvertingScreenshot = 0; static s64 timeSpentConvertingScreenshot = 0;

View File

@ -32,6 +32,7 @@
#include "fmt.h" #include "fmt.h"
#include "utils.h" #include "utils.h"
#include "ifile.h" #include "ifile.h"
#include "luminance.h"
Menu sysconfigMenu = { Menu sysconfigMenu = {
"System configuration menu", "System configuration menu",
@ -42,6 +43,9 @@ Menu sysconfigMenu = {
{ "Toggle Wireless", METHOD, .method = &SysConfigMenu_ToggleWireless }, { "Toggle Wireless", METHOD, .method = &SysConfigMenu_ToggleWireless },
{ "Toggle Power Button", METHOD, .method=&SysConfigMenu_TogglePowerButton }, { "Toggle Power Button", METHOD, .method=&SysConfigMenu_TogglePowerButton },
{ "Toggle power to card slot", METHOD, .method=&SysConfigMenu_ToggleCardIfPower}, { "Toggle power to card slot", METHOD, .method=&SysConfigMenu_ToggleCardIfPower},
{ "Change screen brightness", METHOD, .method = &SysConfigMenu_ChangeScreenBrightness },
{ "Power off", METHOD, .method = &SysConfigMenu_PowerOff },
{ "Reboot", METHOD, .method = &SysConfigMenu_Reboot },
{}, {},
} }
}; };
@ -488,3 +492,159 @@ void SysConfigMenu_AdjustVolume(void)
} }
} while(!menuShouldExit); } while(!menuShouldExit);
} }
void SysConfigMenu_ChangeScreenBrightness(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
// gsp:LCD GetLuminance is stubbed on O3DS so we have to implement it ourselves... damn it.
// Assume top and bottom screen luminances are the same (should be; if not, we'll set them to the same values).
u32 luminance = getCurrentLuminance(false);
u32 minLum = getMinLuminancePreset();
u32 maxLum = getMaxLuminancePreset();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Screen brightness");
u32 posY = 30;
posY = Draw_DrawFormattedString(
10,
posY,
COLOR_WHITE,
"Current luminance: %lu (min. %lu, max. %lu)\n\n",
luminance,
minLum,
maxLum
);
posY = Draw_DrawString(10, posY, COLOR_WHITE, "Controls: Up/Down for +-1, Right/Left for +-10.\n");
posY = Draw_DrawString(10, posY, COLOR_WHITE, "Press A to start, B to exit.\n\n");
posY = Draw_DrawString(10, posY, COLOR_RED, "WARNING: \n");
posY = Draw_DrawString(10, posY, COLOR_WHITE, " * value will be limited by the presets.\n");
posY = Draw_DrawString(10, posY, COLOR_WHITE, " * bottom framebuffer will be restored until\nyou exit.");
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if (pressed & KEY_A)
break;
if (pressed & KEY_B)
return;
}
while (!menuShouldExit);
Draw_Lock();
Draw_RestoreFramebuffer();
Draw_FreeFramebufferCache();
svcKernelSetState(0x10000, 2); // unblock gsp
gspLcdInit(); // assume it doesn't fail. If it does, brightness won't change, anyway.
// gsp:LCD will normalize the brightness between top/bottom screen, handle PWM, etc.
s32 lum = (s32)luminance;
do
{
u32 pressed = waitInputWithTimeout(1000);
if (pressed & DIRECTIONAL_KEYS)
{
if (pressed & KEY_UP)
lum += 1;
else if (pressed & KEY_DOWN)
lum -= 1;
else if (pressed & KEY_RIGHT)
lum += 10;
else if (pressed & KEY_LEFT)
lum -= 10;
lum = lum < (s32)minLum ? (s32)minLum : lum;
lum = lum > (s32)maxLum ? (s32)maxLum : lum;
// We need to call gsp here because updating the active duty LUT is a bit tedious (plus, GSP has internal state).
// This is actually SetLuminance:
GSPLCD_SetBrightnessRaw(BIT(GSP_SCREEN_TOP) | BIT(GSP_SCREEN_BOTTOM), lum);
}
if (pressed & KEY_B)
break;
}
while (!menuShouldExit);
gspLcdExit();
svcKernelSetState(0x10000, 2); // block gsp again
if (R_FAILED(Draw_AllocateFramebufferCache(FB_BOTTOM_SIZE)))
{
// Shouldn't happen
__builtin_trap();
}
else
Draw_SetupFramebuffer();
Draw_Unlock();
}
void SysConfigMenu_PowerOff(void) // Soft shutdown.
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Power off");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to power off, press B to go back.");
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if(pressed & KEY_A)
{
menuLeave();
srvPublishToSubscriber(0x203, 0);
return;
}
else if(pressed & KEY_B)
return;
}
while(!menuShouldExit);
}
void SysConfigMenu_Reboot(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Reboot");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to reboot, press B to go back.");
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if(pressed & KEY_A)
{
menuLeave();
APT_HardwareResetAsync();
return;
} else if(pressed & KEY_B)
return;
}
while(!menuShouldExit);
}