mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2025-01-03 16:11:49 +01:00
Press select/minus to toggle backlight
This commit is contained in:
parent
f46efc9286
commit
900df7882d
@ -8,6 +8,9 @@ FTP Server for 3DS/Switch/Linux.
|
||||
- Supports multiple simultaneous clients. The 3DS itself only appears to support enough sockets to perform 4-5 simultaneous data transfers, so it will help if you limit your FTP client to this many parallel requests.
|
||||
- Cutting-edge graphics.
|
||||
|
||||
- Toggle backlight on 3DS with SELECT button
|
||||
- Toggle backlight on Switch with MINUS button
|
||||
|
||||
## Latest Builds
|
||||
NDS: https://mtheall.com/~mtheall/ftpd.nds
|
||||
|
||||
|
@ -70,6 +70,12 @@ u32 *s_socuBuffer = nullptr;
|
||||
/// \brief ac:u fence
|
||||
platform::Mutex s_acuFence;
|
||||
|
||||
/// \brief Whether to power backlight
|
||||
bool s_backlight = true;
|
||||
|
||||
/// \brief APT hook cookie
|
||||
aptHookCookie s_aptHookCookie;
|
||||
|
||||
#ifdef CLASSIC
|
||||
in_addr_t s_addr = 0;
|
||||
#else
|
||||
@ -118,6 +124,43 @@ C3D_Tex s_gfxTexture;
|
||||
Tex3DS_Texture s_gfxT3x;
|
||||
#endif
|
||||
|
||||
/// \brief Enable backlight
|
||||
/// \param enable_ Whether to enable backligh
|
||||
void enableBacklight (bool const enable_)
|
||||
{
|
||||
if (R_FAILED (gspLcdInit ()))
|
||||
return;
|
||||
|
||||
(enable_ ? GSPLCD_PowerOnBacklight : GSPLCD_PowerOffBacklight) (GSPLCD_SCREEN_BOTH);
|
||||
|
||||
gspLcdExit ();
|
||||
}
|
||||
|
||||
/// \brief Handle APT cookie
|
||||
/// \param type_ Hook type
|
||||
/// \param param_ User param
|
||||
void handleAPTHook (APT_HookType const type_, void *const param_)
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case APTHOOK_ONSUSPEND:
|
||||
case APTHOOK_ONSLEEP:
|
||||
// turn on backlight, or you can't see the home menu!
|
||||
if (!s_backlight)
|
||||
enableBacklight (true);
|
||||
break;
|
||||
|
||||
case APTHOOK_ONRESTORE:
|
||||
case APTHOOK_ONWAKEUP:
|
||||
// restore backlight setting
|
||||
enableBacklight (s_backlight);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// \brief Get network visibility
|
||||
bool getNetworkVisibility ()
|
||||
{
|
||||
@ -328,6 +371,8 @@ bool platform::init ()
|
||||
std::setvbuf (stderr, nullptr, _IOLBF, 0);
|
||||
#endif
|
||||
|
||||
aptHook (&s_aptHookCookie, handleAPTHook, nullptr);
|
||||
|
||||
#ifndef CLASSIC
|
||||
// initialize citro3d
|
||||
C3D_Init (2 * C3D_DEFAULT_CMDBUF_SIZE);
|
||||
@ -392,9 +437,19 @@ bool platform::loop ()
|
||||
|
||||
hidScanInput ();
|
||||
|
||||
if (hidKeysDown () & KEY_START)
|
||||
auto const kDown = hidKeysDown ();
|
||||
|
||||
// check if the user wants to exit
|
||||
if (kDown & KEY_START)
|
||||
return false;
|
||||
|
||||
// check if the user wants to toggle the backlight
|
||||
if (kDown & KEY_SELECT)
|
||||
{
|
||||
s_backlight = !s_backlight;
|
||||
enableBacklight (s_backlight);
|
||||
}
|
||||
|
||||
#ifndef CLASSIC
|
||||
auto &io = ImGui::GetIO ();
|
||||
|
||||
@ -455,6 +510,12 @@ void platform::exit ()
|
||||
s_socuActive = false;
|
||||
std::free (s_socuBuffer);
|
||||
|
||||
aptUnhook (&s_aptHookCookie);
|
||||
|
||||
// turn backlight back on
|
||||
if (!s_backlight)
|
||||
enableBacklight (true);
|
||||
|
||||
gfxExit ();
|
||||
#ifndef CLASSIC
|
||||
romfsExit ();
|
||||
|
@ -40,6 +40,8 @@ PrintConsole g_sessionConsole;
|
||||
namespace
|
||||
{
|
||||
struct in_addr s_addr = {0};
|
||||
/// \brief Whether to power backlight
|
||||
bool s_backlight = true;
|
||||
}
|
||||
|
||||
bool platform::networkVisible ()
|
||||
@ -99,9 +101,18 @@ bool platform::loop ()
|
||||
{
|
||||
scanKeys ();
|
||||
|
||||
if (keysDown () & KEY_START)
|
||||
// check if the user wants to exit
|
||||
auto const kDown = keysDown ();
|
||||
if (kDown & KEY_START)
|
||||
return false;
|
||||
|
||||
// check if the user wants to toggle the backlight
|
||||
if (kDown & KEY_SELECT)
|
||||
{
|
||||
s_backlight = !s_backlight;
|
||||
(s_backlight ? powerOn : powerOff) (POWER_LCD);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -112,12 +123,5 @@ void platform::render ()
|
||||
|
||||
void platform::exit ()
|
||||
{
|
||||
info ("Press any key to exit\n");
|
||||
render ();
|
||||
|
||||
do
|
||||
{
|
||||
swiWaitForVBlank ();
|
||||
scanKeys ();
|
||||
} while (!keysDown ());
|
||||
powerOn (POWER_LCD);
|
||||
}
|
||||
|
@ -50,6 +50,12 @@ PrintConsole g_sessionConsole;
|
||||
|
||||
namespace
|
||||
{
|
||||
/// \brief Whether to power backlight
|
||||
bool s_backlight = true;
|
||||
|
||||
/// \brief Applet hook cookie
|
||||
AppletHookCookie s_appletHookCookie;
|
||||
|
||||
#ifdef CLASSIC
|
||||
in_addr_t s_addr = 0;
|
||||
#else
|
||||
@ -397,6 +403,24 @@ void deko3dExit ()
|
||||
}
|
||||
#endif
|
||||
|
||||
/// \brief Handle applet hook
|
||||
/// \param hook_ Callback reason
|
||||
/// \param param_ User param
|
||||
void handleAppletHook (AppletHookType const hook_, void *const param_)
|
||||
{
|
||||
(void)param_;
|
||||
switch (hook_)
|
||||
{
|
||||
case AppletHookType_OnFocusState:
|
||||
if (appletGetFocusState () == AppletFocusState_Focused)
|
||||
appletSetLcdBacklightOffEnabled (!s_backlight);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// \brief Draw status
|
||||
void drawStatus ()
|
||||
{
|
||||
@ -503,6 +527,8 @@ void drawStatus ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool platform::init ()
|
||||
{
|
||||
#ifdef CLASSIC
|
||||
@ -534,6 +560,8 @@ bool platform::init ()
|
||||
FB_NUM);
|
||||
#endif
|
||||
|
||||
appletHook (&s_appletHookCookie, handleAppletHook, nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -561,9 +589,18 @@ bool platform::loop ()
|
||||
hidScanInput ();
|
||||
|
||||
auto const keysDown = hidKeysDown (CONTROLLER_P1_AUTO);
|
||||
|
||||
// check if the user wants to exit
|
||||
if (keysDown & KEY_PLUS)
|
||||
return false;
|
||||
|
||||
// check if the user wants to toggle the backlight
|
||||
if (keysDown & KEY_MINUS)
|
||||
{
|
||||
s_backlight = !s_backlight;
|
||||
appletSetLcdBacklightOffEnabled (!s_backlight);
|
||||
}
|
||||
|
||||
#ifndef CLASSIC
|
||||
imgui::nx::newFrame ();
|
||||
ImGui::NewFrame ();
|
||||
@ -647,6 +684,11 @@ void platform::exit ()
|
||||
imgui::deko3d::exit ();
|
||||
deko3dExit ();
|
||||
#endif
|
||||
|
||||
appletUnhook (&s_appletHookCookie);
|
||||
|
||||
if (!s_backlight)
|
||||
appletSetLcdBacklightOffEnabled (false);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user