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

Enable blue light schedule to work for Miyoo Minis with RTC #1706

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/common/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef struct settings_s {
int blue_light_rgb;
char blue_light_time[16];
char blue_light_time_off[16];
bool no_time_restore;

char mainui_button_x[JSON_STRING_LEN];
char mainui_button_y[JSON_STRING_LEN];
Expand Down Expand Up @@ -103,6 +104,7 @@ static settings_s __default_settings = (settings_s){
.vibration = 2,
.startup_tab = 0,
.startup_application = 0,
.no_time_restore = false,
// Menu button actions
.mainui_single_press = 1,
.mainui_long_press = 0,
Expand Down Expand Up @@ -206,6 +208,7 @@ void settings_load(void)
settings.blue_light_schedule = config_flag_get(".blf");
settings.rec_indicator = config_flag_get(".recIndicator");
settings.rec_hotkey = config_flag_get(".recHotkey");
settings.no_time_restore = config_flag_get(".noTimeRestore");

if (config_flag_get(".noLowBatteryAutoSave")) // flag is deprecated, but keep compatibility
settings.low_battery_autosave_at = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ int main(void)
}

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

Expand Down
16 changes: 9 additions & 7 deletions src/tweaks/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,12 @@ void menu_themeOverrides(void *_)

void menu_blueLight(void *_)
{
bool schedule_show = (DEVICE_ID == MIYOO354 || settings.no_time_restore || settings.blue_light_schedule);
bool schedule_disable = (!settings.no_time_restore && !network_state.ntp && !settings.blue_light_schedule);
if (!_menu_user_blue_light._created) {
network_loadState();
_menu_user_blue_light = list_createWithTitle(6, LIST_SMALL, "Blue light filter");
if (DEVICE_ID == MIYOO354) {
if (schedule_show) {
list_addItem(&_menu_user_blue_light,
(ListItem){
.label = "[DATESTRING]",
Expand All @@ -500,11 +502,11 @@ 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) {
if (schedule_show) {
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "",
.disabled = !network_state.ntp,
.disabled = schedule_disable,
.item_type = TOGGLE,
.value = (int)settings.blue_light_schedule,
.action = action_blueLightSchedule},
Expand All @@ -522,11 +524,11 @@ void menu_blueLight(void *_)
.value = value_blueLightLevel()},
"Change the strength of the \n"
"Blue light filter");
if (DEVICE_ID == MIYOO354) {
if (schedule_show) {
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "Time (On)",
.disabled = !network_state.ntp,
.disabled = schedule_disable,
.item_type = MULTIVALUE,
.value_max = 95,
.value_formatter = formatter_Time,
Expand All @@ -536,7 +538,7 @@ void menu_blueLight(void *_)
list_addItemWithInfoNote(&_menu_user_blue_light,
(ListItem){
.label = "Time (Off)",
.disabled = !network_state.ntp,
.disabled = schedule_disable,
.item_type = MULTIVALUE,
.value_max = 95,
.value_formatter = formatter_Time,
Expand All @@ -545,7 +547,7 @@ void menu_blueLight(void *_)
"Time schedule for the bluelight filter");
}
}
if (DEVICE_ID == MIYOO354) {
if (schedule_show) {
_writeDateString(_menu_user_blue_light.items[0].label);
char scheduleToggleLabel[100];
strcpy(scheduleToggleLabel, exists("/tmp/.blfIgnoreSchedule") ? "Schedule (ignored)" : "Schedule");
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.
To use Schedule you'll need a Miyoo Mini with RTC and .noTimeRestore set in config or a Miyoo Mini Plus with "[Set time automatically via internet](/docs/apps/tweaks#set-automatically-via-the-internet)" enabled.
:::

### Hotkeys
Expand Down