m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/logitech
blob: 66bf61a67bcb055882cf46d14a16f6bcb318391b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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