From 0db916db66ced76b7e4d05a0407189224c070ad0 Mon Sep 17 00:00:00 2001 From: Michael Theall Date: Fri, 26 Jun 2020 17:30:48 -0500 Subject: [PATCH] Avoid toggling backlight with Rosalina menu combo --- source/3ds/platform.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/source/3ds/platform.cpp b/source/3ds/platform.cpp index dbfe3c9..97e6e60 100644 --- a/source/3ds/platform.cpp +++ b/source/3ds/platform.cpp @@ -72,6 +72,8 @@ platform::Mutex s_acuFence; /// \brief Whether to power backlight bool s_backlight = true; +/// \brief Button state for toggling backlight +unsigned s_buttons = 0; /// \brief APT hook cookie aptHookCookie s_aptHookCookie; @@ -439,16 +441,34 @@ bool platform::loop () hidScanInput (); auto const kDown = hidKeysDown (); + auto const kHeld = hidKeysHeld (); + auto const kUp = hidKeysUp (); // 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) + // avoid toggling during the Rosalina menu default combo + if (kDown == KEY_SELECT && kHeld == KEY_SELECT) { - s_backlight = !s_backlight; - enableBacklight (s_backlight); + // SELECT was pressed and no other keys are held, so reset state + s_buttons = KEY_SELECT; + } + else if (kUp & KEY_SELECT) + { + // SELECT was released + if (s_buttons == KEY_SELECT) + { + // no other button was held at the same time as SELECT, so toggle + s_backlight = !s_backlight; + enableBacklight (s_backlight); + } + } + else + { + // add any held buttons + s_buttons |= kHeld; } #ifndef CLASSIC