Skip to content

Commit

Permalink
Add volume slider override
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloMK7 authored and TuxSH committed Feb 6, 2024
1 parent 8cc294b commit bef642c
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 0 deletions.
Binary file modified arm9/data/config_template.ini
Binary file not shown.
7 changes: 7 additions & 0 deletions arm9/source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ static int configIniHandler(void* user, const char* section, const char* name, c
} else {
CHECK_PARSE_OPTION(-1);
}
} else if (strcmp(name, "volume_slider_override") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecIntOption(&opt, value, -1, 100));
cfg->volumeSliderOverride = (s8)opt;
return 1;
} else {
CHECK_PARSE_OPTION(-1);
}
Expand Down Expand Up @@ -671,6 +676,7 @@ static size_t saveLumaIniConfigToStr(char *out)
cfg->autobootTwlTitleId, (int)cfg->autobootCtrAppmemtype,

forceAudioOutputStr,
cfg->volumeSliderOverride,

(int)CONFIG(PATCHUNITINFO), (int)CONFIG(DISABLEARM11EXCHANDLERS),
(int)CONFIG(ENABLESAFEFIRMROSALINA)
Expand Down Expand Up @@ -775,6 +781,7 @@ bool readConfig(void)
configData.formatVersionMinor = CONFIG_VERSIONMINOR;
configData.config |= 1u << PATCHVERSTRING;
configData.splashDurationMsec = 3000;
configData.volumeSliderOverride = -1;
configData.hbldr3dsxTitleId = HBLDR_DEFAULT_3DSX_TID;
configData.rosalinaMenuCombo = 1u << 9 | 1u << 7 | 1u << 2; // L+Start+Select
configData.topScreenFilter.cct = 6500; // default temp, no-op
Expand Down
2 changes: 2 additions & 0 deletions arm9/source/patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32
u16 configFormatVersionMajor, configFormatVersionMinor;
u32 config, multiConfig, bootConfig;
u32 splashDurationMsec;
s8 volumeSliderOverride;
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
u32 pluginLoaderFlags;
Expand Down Expand Up @@ -215,6 +216,7 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32
info->multiConfig = configData.multiConfig;
info->bootConfig = configData.bootConfig;
info->splashDurationMsec = configData.splashDurationMsec;
info->volumeSliderOverride = configData.volumeSliderOverride;
info->hbldr3dsxTitleId = configData.hbldr3dsxTitleId;
info->rosalinaMenuCombo = configData.rosalinaMenuCombo;
info->pluginLoaderFlags = configData.pluginLoaderFlags;
Expand Down
1 change: 1 addition & 0 deletions arm9/source/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef struct CfgData {

u32 config, multiConfig, bootConfig;
u32 splashDurationMsec;
s8 volumeSliderOverride;

u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
Expand Down
1 change: 1 addition & 0 deletions k11_extension/include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ typedef struct CfwInfo
u16 configFormatVersionMajor, configFormatVersionMinor;
u32 config, multiConfig, bootConfig;
u32 splashDurationMsec;
s8 volumeSliderOverride;
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
u32 pluginLoaderFlags;
Expand Down
3 changes: 3 additions & 0 deletions k11_extension/source/svc/GetSystemInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Result GetSystemInfoHook(s64 *out, s32 type, s32 param)
case 6:
*out = cfwInfo.splashDurationMsec;
break;
case 7:
*out = (s64)cfwInfo.volumeSliderOverride;
break;
case 0x10:
*out = (s64)cfwInfo.autobootTwlTitleId;
break;
Expand Down
Binary file modified sysmodules/rosalina/data/config_template.ini
Binary file not shown.
3 changes: 3 additions & 0 deletions sysmodules/rosalina/include/menus/sysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

extern Menu sysconfigMenu;
extern bool isConnectionForced;
extern s8 currVolumeSliderOverride;

void SysConfigMenu_UpdateStatus(bool control);

Expand All @@ -40,3 +41,5 @@ void SysConfigMenu_TogglePowerButton(void);
void SysConfigMenu_ControlWifi(void);
void SysConfigMenu_DisableForcedWifiConnection(void);
void SysConfigMenu_ToggleCardIfPower(void);
void SysConfigMenu_LoadConfig(void);
void SysConfigMenu_AdjustVolume(void);
4 changes: 4 additions & 0 deletions sysmodules/rosalina/source/luma_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#include "config_template_ini.h"
#include "ifile.h"
#include "menus/miscellaneous.h"
#include "menus/sysconfig.h"
#include "plugin/plgloader.h"

typedef struct CfgData {
u16 formatVersionMajor, formatVersionMinor;

u32 config, multiConfig, bootConfig;
u32 splashDurationMsec;
s8 volumeSliderOverride;

u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
Expand Down Expand Up @@ -187,6 +189,7 @@ static size_t LumaConfig_SaveLumaIniConfigToStr(char *out, const CfgData *cfg)
cfg->autobootTwlTitleId, (int)cfg->autobootCtrAppmemtype,

forceAudioOutputStr,
cfg->volumeSliderOverride,

(int)CONFIG(PATCHUNITINFO), (int)CONFIG(DISABLEARM11EXCHANDLERS),
(int)CONFIG(ENABLESAFEFIRMROSALINA)
Expand Down Expand Up @@ -245,6 +248,7 @@ Result LumaConfig_SaveSettings(void)
configData.multiConfig = multiConfig;
configData.bootConfig = bootConfig;
configData.splashDurationMsec = splashDurationMsec;
configData.volumeSliderOverride = currVolumeSliderOverride;
configData.hbldr3dsxTitleId = Luma_SharedConfig->selected_hbldr_3dsx_tid;
configData.rosalinaMenuCombo = menuCombo;
configData.pluginLoaderFlags = PluginLoader__IsEnabled();
Expand Down
1 change: 1 addition & 0 deletions sysmodules/rosalina/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ int main(void)
Draw_Init();
Cheat_SeedRng(svcGetSystemTick());
ScreenFiltersMenu_LoadConfig();
SysConfigMenu_LoadConfig();

MyThread *menuThread = menuCreateThread();
MyThread *taskRunnerThread = taskRunnerCreateThread();
Expand Down
107 changes: 107 additions & 0 deletions sysmodules/rosalina/source/menus/sysconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include <3ds.h>
#include "luma_config.h"
#include "menus/sysconfig.h"
#include "memory.h"
#include "draw.h"
Expand All @@ -35,6 +36,7 @@
Menu sysconfigMenu = {
"System configuration menu",
{
{ "Control volume", METHOD, .method=&SysConfigMenu_AdjustVolume},
{ "Control Wireless connection", METHOD, .method = &SysConfigMenu_ControlWifi },
{ "Toggle LEDs", METHOD, .method = &SysConfigMenu_ToggleLEDs },
{ "Toggle Wireless", METHOD, .method = &SysConfigMenu_ToggleWireless },
Expand All @@ -45,6 +47,7 @@ Menu sysconfigMenu = {
};

bool isConnectionForced = false;
s8 currVolumeSliderOverride = -1;

void SysConfigMenu_ToggleLEDs(void)
{
Expand Down Expand Up @@ -380,3 +383,107 @@ void SysConfigMenu_ToggleCardIfPower(void)
}
while(!menuShouldExit);
}

static Result SysConfigMenu_ApplyVolumeOverride(void)
{
// Thanks profi200!
u8 tmp;
Result res = cdcChkInit();

if (R_SUCCEEDED(res)) res = CDCCHK_ReadRegisters2(0, 116, &tmp, 1); // CDC_REG_VOL_MICDET_PIN_SAR_ADC
if (currVolumeSliderOverride >= 0)
tmp &= ~0x80;
else
tmp |= 0x80;
if (R_SUCCEEDED(res)) res = CDCCHK_WriteRegisters2(0, 116, &tmp, 1);

if (currVolumeSliderOverride >= 0) {
s8 calculated = -128 + (((float)currVolumeSliderOverride/100.f) * 108);
if (calculated > -20)
return -1; // Just in case
s8 volumes[2] = {calculated, calculated}; // Volume in 0.5 dB steps. -128 (muted) to 48. Do not go above -20 (100%).
if (R_SUCCEEDED(res)) res = CDCCHK_WriteRegisters2(0, 65, volumes, 2); // CDC_REG_DAC_L_VOLUME_CTRL, CDC_REG_DAC_R_VOLUME_CTRL
}

cdcChkExit();
return res;
}

void SysConfigMenu_LoadConfig(void)
{
s64 out = -1;
svcGetSystemInfo(&out, 0x10000, 7);
currVolumeSliderOverride = (s8)out;
if (currVolumeSliderOverride >= 0)
SysConfigMenu_ApplyVolumeOverride();
}

void SysConfigMenu_AdjustVolume(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();

s8 tempVolumeOverride = currVolumeSliderOverride;
static s8 backupVolumeOverride = -1;
if (backupVolumeOverride == -1)
backupVolumeOverride = tempVolumeOverride >= 0 ? tempVolumeOverride : 85;

do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "System configuration menu");
u32 posY = Draw_DrawString(10, 30, COLOR_WHITE, "Y: Toggle volume slider override.\nDPAD: Adjust the volume level.\nA: Apply\nB: Go back\n\n");
Draw_DrawString(10, posY, COLOR_WHITE, "Current status:");
posY = Draw_DrawString(100, posY, (tempVolumeOverride == -1) ? COLOR_RED : COLOR_GREEN, (tempVolumeOverride == -1) ? " DISABLED" : " ENABLED ");
if (tempVolumeOverride != -1) {
posY = Draw_DrawFormattedString(30, posY, COLOR_WHITE, "\nValue: [%d%%]", tempVolumeOverride);
} else {
posY = Draw_DrawString(30, posY, COLOR_WHITE, "\n ");
}

u32 pressed = waitInputWithTimeout(1000);

if(pressed & KEY_A)
{
currVolumeSliderOverride = tempVolumeOverride;
Result res = SysConfigMenu_ApplyVolumeOverride();
LumaConfig_SaveSettings();
if (R_SUCCEEDED(res))
Draw_DrawString(10, posY, COLOR_GREEN, "\nSuccess!");
else
Draw_DrawFormattedString(10, posY, COLOR_RED, "\nFailed: 0x%08lX", res);
}
else if(pressed & KEY_B)
return;
else if(pressed & KEY_Y)
{
Draw_DrawString(10, posY, COLOR_WHITE, "\n ");
if (tempVolumeOverride == -1) {
tempVolumeOverride = backupVolumeOverride;
} else {
backupVolumeOverride = tempVolumeOverride;
tempVolumeOverride = -1;
}
}
else if ((pressed & (KEY_DUP | KEY_DDOWN | KEY_DLEFT | KEY_DRIGHT)) && tempVolumeOverride != -1)
{
Draw_DrawString(10, posY, COLOR_WHITE, "\n ");
if (pressed & KEY_DUP)
tempVolumeOverride++;
else if (pressed & KEY_DDOWN)
tempVolumeOverride--;
else if (pressed & KEY_DRIGHT)
tempVolumeOverride+=10;
else if (pressed & KEY_DLEFT)
tempVolumeOverride-=10;

if (tempVolumeOverride < 0)
tempVolumeOverride = 0;
if (tempVolumeOverride > 100)
tempVolumeOverride = 100;
}

} while(!menuShouldExit);
}

0 comments on commit bef642c

Please sign in to comment.