Created
October 17, 2020 06:20
-
-
Save metaquanta/95440b0f3f6d0a2638e72f23054a66ec to your computer and use it in GitHub Desktop.
Adjust backlight throughout the day to correspond to the location of the sun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /usr/local/bin/autobacklight | |
BL_DARK=15 | |
BL_BRIGHT=187 | |
SOLAR_NOON=17:15Z | |
now_s=$(date +%s) | |
noon_s=$(date -d "${SOLAR_NOON}" +%s) | |
bl_t=$(bc -l <<MATH | |
pi = 3.14159; | |
blm = (${BL_BRIGHT} - ${BL_DARK})/2; | |
blz = ${BL_DARK}; | |
rad = (1 + c((${now_s} - ${noon_s})/(12*60*60)*pi)); | |
rad * blm + blz | |
MATH | |
) | |
bl_tr=$(printf "%.0f\n" "${bl_t}") | |
bl_current=$(cat /sys/class/backlight/intel_backlight/brightness) | |
if [ "$bl_current" -gt "$bl_tr" ]; then | |
echo $(($bl_current - 1)) > /sys/class/backlight/intel_backlight/brightness | |
fi | |
if [ "$bl_current" -lt "$bl_tr" ]; then | |
echo $(($bl_current + 1)) > /sys/class/backlight/intel_backlight/brightness | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/system/autobacklight-first-run.service | |
# systemctl enable autobacklight-first-run.service | |
[Unit] | |
Description=where's the sun? | |
Before=sysinit.target shutdown.target | |
[Service] | |
Type=oneshot | |
RemainAfterExit=no | |
ExecStart=/usr/local/bin/autobacklight_first_run | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Adjust backlight corresponding to position of the sun | |
[Service] | |
Type=oneshot | |
RemainAfterExit=no | |
ExecStart=/usr/local/bin/autobacklight | |
ExecReload=/usr/local/bin/autobacklight | |
StandardOutput=journal | |
StandardError=journal | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/system/autobacklight.timer | |
# systemctl enable autobacklight.timer | |
[Unit] | |
Description=Adjusts backlight to correspond to the position of the sun | |
[Timer] | |
OnUnitActiveSec=5s | |
OnActiveSec=60s | |
Unit=autobacklight.service | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /usr/local/bin/autobacklight_first_run | |
BL_DARK=15 | |
BL_BRIGHT=187 | |
SOLAR_NOON="17:15Z" | |
DEV="/sys/class/backlight/intel_backlight/brightness" | |
now_s=$(date +%s) | |
noon_s=$(date -d "${SOLAR_NOON}" +%s) | |
bl_t=$(bc -l <<MATH | |
pi = 3.14159; | |
blm = (${BL_BRIGHT} - ${BL_DARK})/2; | |
blz = ${BL_DARK}; | |
rad = (1 + c((${now_s} - ${noon_s})/(12*60*60)*pi)); | |
rad * blm + blz | |
MATH | |
) | |
bl_tr=$(printf "%.0f\n" "${bl_t}") | |
echo $bl_tr > "$DEV" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment