m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/logitech
diff options
context:
space:
mode:
Diffstat (limited to 'logitech')
-rwxr-xr-xlogitech50
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