Skip to content

Instantly share code, notes, and snippets.

@joel16
Created November 21, 2017 20:24
Show Gist options
  • Save joel16/42e4396c9dffa3f27e076870e146375e to your computer and use it in GitHub Desktop.
Save joel16/42e4396c9dffa3f27e076870e146375e to your computer and use it in GitHub Desktop.
Set each screen's brightness individually using the D-PAD.
#include <3ds.h>
#include <stdio.h>
u32 getBrightness(u32 screen)
{
u32 brightness = 0;
u32 result = 0;
if (R_SUCCEEDED(gspLcdInit()))
{
GSPLCD_GetBrightness(screen, &brightness);
gspLcdExit();
}
switch (brightness)
{
case 16:
result = 1;
break;
case 28:
result = 2;
break;
case 48:
result = 3;
break;
case 82:
result = 4;
break;
case 142:
result = 5;
break;
}
return result;
}
Result setBrightness(u32 screen, u32 brightness)
{
if (R_SUCCEEDED(gspLcdInit()))
{
GSPLCD_SetBrightness(screen, brightness);
gspLcdExit();
}
return 0;
}
int main(int argc, char *argv[])
{
hidInit();
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
printf("\x1b[1;1H");
printf("\x1b[32;1mMulti-screen Brightness Setter\x1b[0m\n\n");
printf("\x1b[31;1mInstructions:\n\n\x1b[0m");
printf("Use DPAD left or right to adjust top screen.\n");
printf("Use DPAD up or down to adjust bottom screen.\n");
printf("\x1b[11;0H");
printf("\x1b[32;1mPress start to exit.\x1b[0m\n\n");
u32 top_brightness = 0, bottom_brightness = 0;
while (aptMainLoop())
{
printf("\x1b[8;0H");
printf("Top screen level: \x1b[34;1m%lu\x1b[0m \n", getBrightness(GSPLCD_SCREEN_TOP));
printf("\x1b[9;0H");
printf("Bottom screen level: \x1b[34;1m%lu\x1b[0m \n", getBrightness(GSPLCD_SCREEN_BOTTOM));
hidScanInput();
u32 kDown = hidKeysDown();
if (kDown & KEY_DLEFT)
{
top_brightness = getBrightness(GSPLCD_SCREEN_TOP);
top_brightness--;
setBrightness(GSPLCD_SCREEN_TOP, top_brightness);
}
if (kDown & KEY_DRIGHT)
{
top_brightness = getBrightness(GSPLCD_SCREEN_TOP);
top_brightness++;
setBrightness(GSPLCD_SCREEN_TOP, top_brightness);
}
if (kDown & KEY_DUP)
{
bottom_brightness = getBrightness(GSPLCD_SCREEN_BOTTOM);
bottom_brightness++;
setBrightness(GSPLCD_SCREEN_BOTTOM, bottom_brightness);
}
if (kDown & KEY_DDOWN)
{
bottom_brightness = getBrightness(GSPLCD_SCREEN_BOTTOM);
bottom_brightness--;
setBrightness(GSPLCD_SCREEN_BOTTOM, bottom_brightness);
}
if (top_brightness == 6)
top_brightness = 1;
if (top_brightness == 0)
top_brightness = 5;
if (bottom_brightness == 6)
bottom_brightness = 1;
if (bottom_brightness == 0)
bottom_brightness = 5;
if (kDown & KEY_START)
break;
// Flush and swap framebuffers
gfxFlushBuffers();
gfxSwapBuffers();
//Wait for VBlank
gspWaitForVBlank();
}
gfxExit();
hidExit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment