From 510124ec89a356bcc5d2ad28c3adcf7866c62dea Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 22 Aug 2021 20:14:10 -0400 Subject: bin/bright: Don't hardcode parameters --- (limited to 'bin') diff --git a/bin/bright b/bin/bright index 87126e1..dd8f2df 100755 --- a/bin/bright +++ b/bin/bright @@ -2,14 +2,20 @@ set -eu +STEPS=8 +MIN=2 +max= + get_b() { local b= b=$(brightnessctl --class=backlight get) || return 1 printf '%.0f\n' $(printf \ - 'scale = 4; (7 * sqrt((2 - %d) * (%d - 3102))) / 1550\n' \ - ${b} ${b} | bc) + 'scale = 4;'$(: \ + )'((%d - 1) * sqrt((%d - %d) * (%d - (2 * %d - %d)))) / '$(: \ + )'(%d - %d)\n' \ + ${STEPS} ${MIN} ${b} ${b} ${max} ${MIN} ${max} ${MIN} | bc) return 0 } @@ -19,9 +25,10 @@ set_b() local b="${1}" shift 1 - brightnessctl --class=backlight set $(printf '%.0f\n' \ - $(printf 'scale = 4; 2 + (1 - sqrt(1 - (%d / 7)^2)) * 1550\n' \ - ${b} | bc)) || return 1 + brightnessctl --class=backlight set $(printf '%.0f\n' $(printf \ + 'scale = 4;'$(: \ + )'%d + (1 - sqrt(1 - (%d / (%d - 1))^2)) * (%d - %d)\n' \ + ${MIN} ${b} ${STEPS} ${max} ${MIN} | bc)) || return 1 return 0 } @@ -53,6 +60,8 @@ main() ;; esac + max=$(brightnessctl --class=backlight max) + b=$(get_b) || return 1 : $((b += 1)) : $((b ${dir}= 1)) -- cgit v0.9.1