Add shell code
This commit is contained in:
3
Readme.md
Normal file
3
Readme.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# brightness
|
||||||
|
|
||||||
|
Set the screen brightness using your camera.
|
||||||
18
brightness.sh
Executable file
18
brightness.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/env bash
|
||||||
|
|
||||||
|
# camera device
|
||||||
|
FFMPEG_DEVICE='/dev/video0'
|
||||||
|
# min brightness
|
||||||
|
MIN=50
|
||||||
|
# get max brightness
|
||||||
|
MAX=$(cat /sys/class/backlight/intel_backlight/max_brightness)
|
||||||
|
# sys path for backligt control
|
||||||
|
SET='/sys/class/backlight/intel_backlight/brightness'
|
||||||
|
|
||||||
|
# get grayscale and calculate brightness value for the screen
|
||||||
|
GET_GRAYSCALE=$(ffmpeg -i $FFMPEG_DEVICE -vf scale=1:1 -pix_fmt gray -f rawvideo -frames:v 1 -v quiet pipe:1)
|
||||||
|
AMBIENT=$(echo -n $GET_GRAYSCALE | od -t u | sed "s/000000[01]\s*//" | sed q)
|
||||||
|
BRIGHTNESS=$(( $AMBIENT * $MAX / 255 ))
|
||||||
|
|
||||||
|
# set brightness and limit boundaries
|
||||||
|
echo $(( $BRIGHTNESS > $MIN ? $BRIGHTNESS : $MIN )) | sudo tee $SET
|
||||||
Reference in New Issue
Block a user