Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTC: Enable blue light schedule to work with real RTC #1706

Merged
merged 16 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,7 @@ int main(void)
}

// Check bluelight filter
if (DEVICE_ID == MIYOO354) {
system("/mnt/SDCARD/.tmp_update/script/blue_light.sh check");
}
system("/mnt/SDCARD/.tmp_update/script/blue_light.sh check");

// Quit RetroArch / auto-save when battery too low
if (settings.low_battery_autosave_at && battery_getPercentage() <= settings.low_battery_autosave_at && check_autosave()) {
Expand Down
79 changes: 34 additions & 45 deletions src/tweaks/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,11 @@ void menu_blueLight(void *_)
if (!_menu_user_blue_light._created) {
network_loadState();
_menu_user_blue_light = list_createWithTitle(6, LIST_SMALL, "Blue light filter");
if (DEVICE_ID == MIYOO354) {
list_addItem(&_menu_user_blue_light,
(ListItem){
.label = "[DATESTRING]",
.disabled = 1,
.action = NULL});
}
list_addItem(&_menu_user_blue_light,
(ListItem){
.label = "[DATESTRING]",
.disabled = 1,
.action = NULL});
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "State",
Expand All @@ -500,16 +498,13 @@ void menu_blueLight(void *_)
.value = (int)settings.blue_light_state || exists("/tmp/.blfOn"),
.action = action_blueLight},
"Set the selected strength now\n");
if (DEVICE_ID == MIYOO354) {
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "",
.disabled = !network_state.ntp,
.item_type = TOGGLE,
.value = (int)settings.blue_light_schedule,
.action = action_blueLightSchedule},
"Enable or disable the bluelight filter schedule\n");
}
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "",
.item_type = TOGGLE,
.value = (int)settings.blue_light_schedule,
.action = action_blueLightSchedule},
"Enable or disable the bluelight filter schedule\n");
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "Strength",
Expand All @@ -522,35 +517,29 @@ void menu_blueLight(void *_)
.value = value_blueLightLevel()},
"Change the strength of the \n"
"Blue light filter");
if (DEVICE_ID == MIYOO354) {
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "Time (On)",
.disabled = !network_state.ntp,
.item_type = MULTIVALUE,
.value_max = 95,
.value_formatter = formatter_Time,
.action = action_blueLightTimeOn,
.value = value_blueLightTimeOn()},
"Time schedule for the bluelight filter");
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "Time (Off)",
.disabled = !network_state.ntp,
.item_type = MULTIVALUE,
.value_max = 95,
.value_formatter = formatter_Time,
.action = action_blueLightTimeOff,
.value = value_blueLightTimeOff()},
"Time schedule for the bluelight filter");
}
}
if (DEVICE_ID == MIYOO354) {
_writeDateString(_menu_user_blue_light.items[0].label);
char scheduleToggleLabel[100];
strcpy(scheduleToggleLabel, exists("/tmp/.blfIgnoreSchedule") ? "Schedule (ignored)" : "Schedule");
strcpy(_menu_user_blue_light.items[2].label, scheduleToggleLabel);
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "Time (On)",
.item_type = MULTIVALUE,
.value_max = 95,
.value_formatter = formatter_Time,
.action = action_blueLightTimeOn,
.value = value_blueLightTimeOn()},
"Time schedule for the bluelight filter");
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "Time (Off)",
.item_type = MULTIVALUE,
.value_max = 95,
.value_formatter = formatter_Time,
.action = action_blueLightTimeOff,
.value = value_blueLightTimeOff()},
"Time schedule for the bluelight filter");
}
_writeDateString(_menu_user_blue_light.items[0].label);
char scheduleToggleLabel[100];
strcpy(scheduleToggleLabel, exists("/tmp/.blfIgnoreSchedule") ? "Schedule (ignored)" : "Schedule");
strcpy(_menu_user_blue_light.items[2].label, scheduleToggleLabel);
menu_stack[++menu_level] = &_menu_user_blue_light;
header_changed = true;
}
Expand Down
4 changes: 3 additions & 1 deletion static/build/.tmp_update/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ main() {
touch /tmp/no_charging_ui

# Check if blf needs enabling
if [ -f $sysdir/config/.blfOn ]; then
if [ -f $sysdir/config/.blf ]; then
/mnt/SDCARD/.tmp_update/script/blue_light.sh check &
elif [ -f $sysdir/config/.blfOn ]; then
/mnt/SDCARD/.tmp_update/script/blue_light.sh enable &
fi

Expand Down
76 changes: 21 additions & 55 deletions static/build/.tmp_update/script/blue_light.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,6 @@ set_intensity() {
rm $lockfile
}

disable_blue_light_filter() {
sync

combinedBGR=$(cat $sysdir/config/display/blueLightRGB)
combinedBGR=$(echo "$combinedBGR" | tr -d '[:space:]/#')

echo $combinedBGR > $sysdir/config/display/blueLightRGBtemp

lastR=$(( (combinedBGR >> 16) & 0xFF ))
lastG=$(( (combinedBGR >> 8) & 0xFF ))
lastB=$(( combinedBGR & 0xFF ))

# echo "Last BGR: B: $lastB, G: $lastG, R: $lastR"
# echo "Target BGR: B: 128, G: 128, R: 128"

for i in $(seq 0 20); do
newR=$(( lastR + (128 - lastR) * i / 20 ))
newG=$(( lastG + (128 - lastG) * i / 20 ))
newB=$(( lastB + (128 - lastB) * i / 20 ))

echo "colortemp 0 0 0 0 $newB $newG $newR" > /proc/mi_modules/mi_disp/mi_disp0
usleep 50000
done

echo ":: Blue Light Filter: Disabled"
rm -f $blf_key_on
rm -f $blf_key_on_user
}

check_disp_init() {
if [ -z "$sysdir" ] || [ ! -x "$sysdir/bin/disp_init" ]; then
echo "Error: disp_init not found or not executable"
Expand Down Expand Up @@ -192,14 +163,15 @@ disable_blue_light_filter() {

echo ":: Blue Light Filter: Disabled"
rm -f $blf_key_on
rm -f $sysdir/config/.blfOn
rm -f $blf_key_on_user
}

check_blf() {
sync
if [ ! -f "$ignore_schedule" ]; then
if [ ! -f "$sysdir/config/.ntpState" ]; then
return
if [ -f "$blf_key" ] || [ ! -f "$ignore_schedule" ]; then

if [ ! -f "$blf_key_on" ] && [ -f "$blf_key_on_user" ]; then
rm -f $blf_key_on_user
fi

blueLightTimeOnFile="$sysdir/config/display/blueLightTime"
Expand All @@ -218,30 +190,24 @@ check_blf() {
blueLightTimeOnMinutes=$(to_minutes_since_midnight "$blueLightTimeOn")
blueLightTimeOffMinutes=$(to_minutes_since_midnight "$blueLightTimeOff")

if [ -f "$blf_key" ]; then
if [ "$blueLightTimeOffMinutes" -lt "$blueLightTimeOnMinutes" ]; then
if [ "$currentTimeMinutes" -ge "$blueLightTimeOnMinutes" ] || [ "$currentTimeMinutes" -lt "$blueLightTimeOffMinutes" ]; then
if [ ! -f $blf_key_on ]; then
enable_blue_light_filter
touch $blf_key_on
fi
else
if [ -f $blf_key_on ]; then
disable_blue_light_filter
rm $blf_key_on
fi
if [ "$blueLightTimeOffMinutes" -lt "$blueLightTimeOnMinutes" ]; then
if [ "$currentTimeMinutes" -ge "$blueLightTimeOnMinutes" ] || [ "$currentTimeMinutes" -lt "$blueLightTimeOffMinutes" ]; then
if [ ! -f $blf_key_on ]; then
enable_blue_light_filter
fi
else
if [ -f $blf_key_on ]; then
disable_blue_light_filter
fi
fi
else
if [ "$currentTimeMinutes" -ge "$blueLightTimeOnMinutes" ] && [ "$currentTimeMinutes" -lt "$blueLightTimeOffMinutes" ]; then
if [ ! -f $blf_key_on ]; then
enable_blue_light_filter
fi
else
if [ "$currentTimeMinutes" -ge "$blueLightTimeOnMinutes" ] && [ "$currentTimeMinutes" -lt "$blueLightTimeOffMinutes" ]; then
if [ ! -f $blf_key_on ]; then
enable_blue_light_filter
touch $blf_key_on
fi
else
if [ -f $blf_key_on ]; then
disable_blue_light_filter
rm $blf_key_on
fi
if [ -f $blf_key_on ]; then
disable_blue_light_filter
fi
fi
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ You'll find it in Tweaks app: [`Appearance` -› `Blue light filter...`](/docs/a
5. **Time (Off)** - Time Blue light filter will be disabled

:::note
To use Schedule you'll need a Miyoo Mini Plus with "[Set time automatically via internet](/docs/apps/tweaks#set-automatically-via-the-internet)" enabled.
Schedule requires a Miyoo Mini Plus with "[Set time automatically via internet](/docs/apps/tweaks#set-automatically-via-the-internet)" enabled or a Miyoo Mini with RTC and .noTimeRestore (to prevent clock from overwriting the time) in order to function properly.
:::

### Hotkeys
Expand Down