diff options
author | Marcin Chrzanowski <m@m-chrzan.xyz> | 2023-03-26 14:02:10 +0200 |
---|---|---|
committer | Marcin Chrzanowski <m@m-chrzan.xyz> | 2023-03-26 14:02:10 +0200 |
commit | 035f408753c04fcf85b32eeebba0e1267fa2e021 (patch) | |
tree | d6dc872cb2a60d4871084c517a6cb948dbc4d370 | |
parent | 7d0c54c7cd0f710fe5d1d3510819f352ec486c23 (diff) |
Add webcam script
-rwxr-xr-x | logitech | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/logitech b/logitech new file mode 100755 index 0000000..66bf61a --- /dev/null +++ b/logitech @@ -0,0 +1,50 @@ +#!/bin/bash + +# Configure a Logitech webcam (and possibly others) from the commandline. +# USAGE: logitech <-d DEVICE> [-e EXPOSURE] [-g GAIN] [-t TEMPERATURE] [-f FOCUS] +# DEVICE should be a device number as used by `v4l2-ctl`. This is usually 0 if +# there's only one webcam connected. +# NOTE: when one of the parameters is set, auto-setting it by the webcam is +# disabled. + +device= +exposure= +gain= +temperature= +focus= + +while getopts 'd:e:g:t:f:' flag; do + case "${flag}" in + d) device=$OPTARG ;; + e) exposure=$OPTARG ;; + g) gain=$OPTARG ;; + t) temperature=$OPTARG ;; + f) focus=$OPTARG ;; + *) error "Unexpected option ${flag}" ;; + esac +done + +if [ -z "$device" ]; then + echo "Provide device with -d flag" + exit 1 +fi + +if [ -n "$exposure" ]; then + v4l2-ctl -d "$device" --set-ctrl exposure_auto=1 + v4l2-ctl -d "$device" --set-ctrl exposure_auto_priority=0 + v4l2-ctl -d "$device" --set-ctrl exposure_absolute="$exposure" +fi + +if [ -n "$gain" ]; then + v4l2-ctl -d "$device" --set-ctrl gain="$gain" +fi + +if [ -n "$temperature" ]; then + v4l2-ctl -d "$device" --set-ctrl white_balance_temperature_auto=0 + v4l2-ctl -d "$device" --set-ctrl white_balance_temperature="$temperature" +fi + +if [ -n "$focus" ]; then + v4l2-ctl -d "$device" --set-ctrl focus_auto=0 + v4l2-ctl -d "$device" --set-ctrl focus_absolute="$focus" +fi |