Add backlight control scripts
authorSiraaj Khandkar <siraaj@khandkar.net>
Sun, 10 Mar 2019 03:55:02 +0000 (22:55 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sun, 10 Mar 2019 03:55:02 +0000 (22:55 -0500)
bin/backlight_adjust [new file with mode: 0755]
bin/backlight_max [new file with mode: 0755]
bin/backlight_min [new file with mode: 0755]

diff --git a/bin/backlight_adjust b/bin/backlight_adjust
new file mode 100755 (executable)
index 0000000..5c74ff9
--- /dev/null
@@ -0,0 +1,31 @@
+#! /bin/sh
+
+set -e
+
+fun="$1"
+screen_brightness_device_path="/sys/class/backlight/intel_backlight"
+
+# Padding with space because when fun="=10", awk fails to parse fun==10
+new=$(
+    awk -v fun=" $fun" '
+        FILENAME ~ "/max_brightness$" {max = $1; next}
+        FILENAME ~     "/brightness$" {cur = $1; next}
+
+        END {
+            unit  = max / 100
+            oper  = substr(fun, 2, 1)
+            units = substr(fun, 3, length(fun) - 1)
+            if (oper == "=") {new = unit * units} else
+            if (oper == "+") {new = cur + (unit * units)} else
+            if (oper == "-") {new = cur - (unit * units)} else {
+                printf("Unrecognized operator: %s\n", oper) > "/dev/stderr"
+                exit(1)
+            }
+            print int(new)
+        }
+    ' \
+    "$screen_brightness_device_path/max_brightness" \
+    "$screen_brightness_device_path/brightness"
+)
+
+echo "${new}" | tee "${screen_brightness_device_path}/brightness"
diff --git a/bin/backlight_max b/bin/backlight_max
new file mode 100755 (executable)
index 0000000..de0ef21
--- /dev/null
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+set -e
+
+dir="/sys/class/backlight/intel_backlight"
+cat "$dir/max_brightness" > "$dir/brightness"
diff --git a/bin/backlight_min b/bin/backlight_min
new file mode 100755 (executable)
index 0000000..2a7ea89
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+set -e
+
+echo 1 > '/sys/class/backlight/intel_backlight/brightness'
This page took 0.027618 seconds and 4 git commands to generate.