From d0306609c394fe84c670b6638271854dfd15db2f Mon Sep 17 00:00:00 2001 From: panicbit Date: Sun, 15 Apr 2018 16:26:20 +0200 Subject: [PATCH] Apply screen filter when waking up from standby --- .../rosalina/include/menus/screen_filters.h | 6 +- sysmodules/rosalina/include/shell_open.h | 30 ++++++++ sysmodules/rosalina/rosalina.rsf | 4 + sysmodules/rosalina/source/main.c | 8 +- sysmodules/rosalina/source/menu.c | 2 +- .../rosalina/source/menus/screen_filters.c | 20 +++-- sysmodules/rosalina/source/shell_open.c | 77 +++++++++++++++++++ 7 files changed, 137 insertions(+), 10 deletions(-) create mode 100644 sysmodules/rosalina/include/shell_open.h create mode 100644 sysmodules/rosalina/source/shell_open.c diff --git a/sysmodules/rosalina/include/menus/screen_filters.h b/sysmodules/rosalina/include/menus/screen_filters.h index a720e14..21a1c7d 100644 --- a/sysmodules/rosalina/include/menus/screen_filters.h +++ b/sysmodules/rosalina/include/menus/screen_filters.h @@ -26,12 +26,16 @@ #pragma once +#include "menu.h" + extern Menu screenFiltersMenu; +int screenFiltersCurrentTemperature; + void screenFiltersSetDisabled(void); void screenFiltersReduceBlueLevel1(void); void screenFiltersReduceBlueLevel2(void); void screenFiltersReduceBlueLevel3(void); void screenFiltersReduceBlueLevel4(void); void screenFiltersReduceBlueLevel5(void); -void screenFiltersSetTemperature(int temperature); +void screenFiltersSetTemperature(int temperature); \ No newline at end of file diff --git a/sysmodules/rosalina/include/shell_open.h b/sysmodules/rosalina/include/shell_open.h new file mode 100644 index 0000000..785ac1f --- /dev/null +++ b/sysmodules/rosalina/include/shell_open.h @@ -0,0 +1,30 @@ +/* +* This file is part of Luma3DS +* Copyright (C) 2016-2017 Aurora Wright, TuxSH, panicbit +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include + +MyThread *shellOpenCreateThread(void); +void shellOpenThreadMain(void); diff --git a/sysmodules/rosalina/rosalina.rsf b/sysmodules/rosalina/rosalina.rsf index 67d62b5..f2f256d 100644 --- a/sysmodules/rosalina/rosalina.rsf +++ b/sysmodules/rosalina/rosalina.rsf @@ -50,8 +50,12 @@ AccessControlInfo: # The kernel extension removes svc perms checks, so below is just to avoid a makerom error Backdoor: 123 KernelSetState: 124 + BindInterrupt: 80 + UnbindInterrupt: 81 InterruptNumbers: + - 0x60 # Shell opened + ServiceAccessControl: - fs:USER # Not strictly needed as rosalina has access to everything, it's rather to avoid a makerom warning FileSystemAccess: diff --git a/sysmodules/rosalina/source/main.c b/sysmodules/rosalina/source/main.c index e75ffac..ba4f1db 100644 --- a/sysmodules/rosalina/source/main.c +++ b/sysmodules/rosalina/source/main.c @@ -35,6 +35,8 @@ #include "MyThread.h" #include "menus/process_patches.h" #include "menus/miscellaneous.h" +#include "menus/screen_filters.h" +#include "shell_open.h" // this is called before main bool isN3DS; @@ -99,14 +101,15 @@ int main(void) Result res = 0; Handle notificationHandle; - MyThread *menuThread = menuCreateThread(), *errDispThread = errDispCreateThread(), *hbldrThread = hbldrCreateThread(); - if(R_FAILED(srvEnableNotification(¬ificationHandle))) svcBreak(USERBREAK_ASSERT); if(R_FAILED(svcCreateEvent(&terminationRequestEvent, RESET_STICKY))) svcBreak(USERBREAK_ASSERT); + MyThread *menuThread = menuCreateThread(), *errDispThread = errDispCreateThread(), *hbldrThread = hbldrCreateThread(); + MyThread *shellOpenThread = shellOpenCreateThread(); + do { res = svcWaitSynchronization(notificationHandle, -1LL); @@ -131,6 +134,7 @@ int main(void) MyThread_Join(menuThread, -1LL); MyThread_Join(errDispThread, -1LL); MyThread_Join(hbldrThread, -1LL); + MyThread_Join(shellOpenThread, -1LL); svcCloseHandle(notificationHandle); return 0; diff --git a/sysmodules/rosalina/source/menu.c b/sysmodules/rosalina/source/menu.c index ab010a4..72162d2 100644 --- a/sysmodules/rosalina/source/menu.c +++ b/sysmodules/rosalina/source/menu.c @@ -129,7 +129,7 @@ static u8 batteryLevel = 255; MyThread *menuCreateThread(void) { - if(R_FAILED(MyThread_Create(&menuThread, menuThreadMain, menuThreadStack, THREAD_STACK_SIZE, 52, CORE_SYSTEM))) + if(R_FAILED(MyThread_Create(&menuThread, menuThreadMain, menuThreadStack, 0x3000, 52, CORE_SYSTEM))) svcBreak(USERBREAK_PANIC); return &menuThread; } diff --git a/sysmodules/rosalina/source/menus/screen_filters.c b/sysmodules/rosalina/source/menus/screen_filters.c index b6b0798..a2265d6 100644 --- a/sysmodules/rosalina/source/menus/screen_filters.c +++ b/sysmodules/rosalina/source/menus/screen_filters.c @@ -34,6 +34,8 @@ #define TEMP_DEFAULT NEUTRAL_TEMP +int screenFiltersCurrentTemperature = TEMP_DEFAULT; + void writeLut(u32* lut) { u8 idx = 0; @@ -101,32 +103,38 @@ Menu screenFiltersMenu = { void screenFiltersSetDisabled(void) { - screenFiltersSetTemperature(TEMP_DEFAULT); + screenFiltersCurrentTemperature = TEMP_DEFAULT; + screenFiltersSetTemperature(screenFiltersCurrentTemperature); } void screenFiltersReduceBlueLevel1(void) { - screenFiltersSetTemperature(4300); + screenFiltersCurrentTemperature = 4300; + screenFiltersSetTemperature(screenFiltersCurrentTemperature); } void screenFiltersReduceBlueLevel2(void) { - screenFiltersSetTemperature(3200); + screenFiltersCurrentTemperature = 3200; + screenFiltersSetTemperature(screenFiltersCurrentTemperature); } void screenFiltersReduceBlueLevel3(void) { - screenFiltersSetTemperature(2100); + screenFiltersCurrentTemperature = 2100; + screenFiltersSetTemperature(screenFiltersCurrentTemperature); } void screenFiltersReduceBlueLevel4(void) { - screenFiltersSetTemperature(1550); + screenFiltersCurrentTemperature = 1550; + screenFiltersSetTemperature(screenFiltersCurrentTemperature); } void screenFiltersReduceBlueLevel5(void) { - screenFiltersSetTemperature(1000); + screenFiltersCurrentTemperature = 1000; + screenFiltersSetTemperature(screenFiltersCurrentTemperature); } void screenFiltersSetTemperature(int temperature) diff --git a/sysmodules/rosalina/source/shell_open.c b/sysmodules/rosalina/source/shell_open.c new file mode 100644 index 0000000..c6a77a4 --- /dev/null +++ b/sysmodules/rosalina/source/shell_open.c @@ -0,0 +1,77 @@ +/* +* This file is part of Luma3DS +* Copyright (C) 2016-2017 Aurora Wright, TuxSH, panicbit +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "shell_open.h" +#include "menus/screen_filters.h" +#include "draw.h" + +#define INT_SHELL_OPEN 0x60 +#define STACK_SIZE 0x3000 + +static MyThread shellOpenThread; +static u8 ALIGN(8) shellOpenStack[STACK_SIZE]; +static Handle shellOpenEvent; + +extern Handle terminationRequestEvent; + +MyThread *shellOpenCreateThread(void) +{ + if (R_FAILED(MyThread_Create(&shellOpenThread, shellOpenThreadMain, shellOpenStack, STACK_SIZE, 0x3F, CORE_SYSTEM))) + svcBreak(USERBREAK_PANIC); + return &shellOpenThread; +} + +void shellOpenThreadMain(void) { + if (R_FAILED(svcCreateEvent(&shellOpenEvent, RESET_ONESHOT))) + svcBreak(USERBREAK_ASSERT); + + if (R_FAILED(svcBindInterrupt(INT_SHELL_OPEN, shellOpenEvent, 0, false))) + svcBreak(USERBREAK_ASSERT); + + Handle handles[2] = {terminationRequestEvent, shellOpenEvent}; + + while (true) { + s32 idx = -1; + + svcWaitSynchronizationN(&idx, handles, 2, false, U64_MAX); + + if (idx < 0) { + continue; + } + + if (handles[idx] == terminationRequestEvent) { + break; + } + + // Need to wait for the GPU to get initialized + svcSleepThread(16 * 1000 * 1000LL); + + screenFiltersSetTemperature(screenFiltersCurrentTemperature); + } + + svcUnbindInterrupt(INT_SHELL_OPEN, shellOpenEvent); + svcCloseHandle(shellOpenEvent); +}