rosalina: properly restore screen filters when lid is reopened

This commit is contained in:
TuxSH 2020-07-10 22:58:07 +01:00
parent 2d58ec4c86
commit dc67d438dc
3 changed files with 38 additions and 11 deletions

View File

@ -32,6 +32,8 @@ extern Menu screenFiltersMenu;
extern int screenFiltersCurrentTemperature; extern int screenFiltersCurrentTemperature;
void ScreenFiltersMenu_RestoreCct(void);
void ScreenFiltersMenu_SetDefault(void); // 6500K (default) void ScreenFiltersMenu_SetDefault(void); // 6500K (default)
void ScreenFiltersMenu_SetAquarium(void); // 10000K void ScreenFiltersMenu_SetAquarium(void); // 10000K

View File

@ -156,6 +156,14 @@ static void handleSleepNotification(u32 notificationId)
ptmSysmExit(); ptmSysmExit();
} }
static void handleShellOpenedNotification(u32 notificationId)
{
(void)notificationId;
// Note that this is called on system init
ScreenFiltersMenu_RestoreCct();
}
static void handlePreTermNotification(u32 notificationId) static void handlePreTermNotification(u32 notificationId)
{ {
(void)notificationId; (void)notificationId;
@ -213,6 +221,7 @@ static const ServiceManagerNotificationEntry notifications[] = {
{ PTMNOTIFID_FULLY_WAKING_UP, handleSleepNotification }, { PTMNOTIFID_FULLY_WAKING_UP, handleSleepNotification },
{ PTMNOTIFID_FULLY_AWAKE, handleSleepNotification }, { PTMNOTIFID_FULLY_AWAKE, handleSleepNotification },
{ PTMNOTIFID_HALF_AWAKE, handleSleepNotification }, { PTMNOTIFID_HALF_AWAKE, handleSleepNotification },
{ 0x213, handleShellOpenedNotification },
{ 0x1000, handleNextApplicationDebuggedByForce }, { 0x1000, handleNextApplicationDebuggedByForce },
{ 0x2000, handlePreTermNotification }, { 0x2000, handlePreTermNotification },
{ 0x3000, handleRestartHbAppNotification }, { 0x3000, handleRestartHbAppNotification },

View File

@ -32,26 +32,29 @@
#include "redshift/redshift.h" #include "redshift/redshift.h"
#include "redshift/colorramp.h" #include "redshift/colorramp.h"
typedef struct { typedef union {
u8 r; struct {
u8 g; u8 r;
u8 b; u8 g;
u8 z; u8 b;
u8 z;
};
u32 raw;
} Pixel; } Pixel;
static u16 g_c[0x600]; static u16 g_c[0x600];
static Pixel g_px[0x400]; static Pixel g_px[0x400];
int screenFiltersCurrentTemperature = 6500; int screenFiltersCurrentTemperature = -1;
static void ScreenFiltersMenu_WriteLut(const u32* lut) static void ScreenFiltersMenu_WriteLut(const Pixel* lut)
{ {
GPU_FB_TOP_COL_LUT_INDEX = 0; GPU_FB_TOP_COL_LUT_INDEX = 0;
GPU_FB_BOTTOM_COL_LUT_INDEX = 0; GPU_FB_BOTTOM_COL_LUT_INDEX = 0;
for (int i = 0; i <= 255; i++) { for (int i = 0; i <= 255; i++) {
GPU_FB_TOP_COL_LUT_ELEM = *lut; GPU_FB_TOP_COL_LUT_ELEM = lut->raw;
GPU_FB_BOTTOM_COL_LUT_ELEM = *lut; GPU_FB_BOTTOM_COL_LUT_ELEM = lut->raw;
lut++; lut++;
} }
} }
@ -84,7 +87,7 @@ static void ScreenFiltersMenu_ApplyColorSettings(color_setting_t* cs)
g_px[i].b = *(g_c + i + 0x200) >> 8; g_px[i].b = *(g_c + i + 0x200) >> 8;
} while(++i); } while(++i);
ScreenFiltersMenu_WriteLut((u32*)g_px); ScreenFiltersMenu_WriteLut(g_px);
} }
static void ScreenFiltersMenu_SetCct(int cct) static void ScreenFiltersMenu_SetCct(int cct)
@ -101,7 +104,6 @@ static void ScreenFiltersMenu_SetCct(int cct)
ScreenFiltersMenu_ApplyColorSettings(&cs); ScreenFiltersMenu_ApplyColorSettings(&cs);
} }
Menu screenFiltersMenu = { Menu screenFiltersMenu = {
"Screen filters menu", "Screen filters menu",
{ {
@ -126,6 +128,20 @@ void ScreenFiltersMenu_Set##name(void)\
ScreenFiltersMenu_SetCct(temp);\ ScreenFiltersMenu_SetCct(temp);\
} }
void ScreenFiltersMenu_RestoreCct(void)
{
// Not initialized: return
if (screenFiltersCurrentTemperature == -1)
return;
// Wait for GSP to restore the CCT table
while (GPU_FB_TOP_COL_LUT_ELEM != g_px[0].raw)
svcSleepThread(10 * 1000 * 1000LL);
svcSleepThread(10 * 1000 * 1000LL);
ScreenFiltersMenu_WriteLut(g_px);
}
DEF_CCT_SETTER(6500, Default) DEF_CCT_SETTER(6500, Default)
DEF_CCT_SETTER(10000, Aquarium) DEF_CCT_SETTER(10000, Aquarium)