From b7ebac8283285f6abeb3799a842f79dc15727c12 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 22 Aug 2021 19:44:33 -0400 Subject: bin/bright: New script --- (limited to 'bin') diff --git a/bin/bright b/bin/bright new file mode 100755 index 0000000..7aa0801 --- /dev/null +++ b/bin/bright @@ -0,0 +1,62 @@ +#!/bin/sh + +set -eu + +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) + + return 0 +} + +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 + + return 0 +} + +usage() +{ + printf 'Usage: %s {-|+}\n' "${0}" + + return 0 +} + +main() +{ + local dir= + local b= + + if [ ${#} -ne 1 ]; then + usage 1>&2 + return 1 + fi + dir="${1}" + shift 1 + + case "${dir}" in + -|+);; + *) + usage 1>&2 + return 1 + ;; + esac + + b=$(get_b) || return 1 + set_b $((${b} ${dir} 1)) || return 1 + + return 0 +} + +main "${@}" -- cgit v0.9.1