m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/logitech
blob: 2ac35bb17a077bfde5aad45cf27d003d856d0744 (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
51
52
#!/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.
#
# Getting device info:
# v4l2-ctl -d <device ID> --all

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 auto_exposure=1
    v4l2-ctl -d "$device" --set-ctrl exposure_time_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_automatic=0
    v4l2-ctl -d "$device" --set-ctrl white_balance_temperature="$temperature"
fi

if [ -n "$focus" ]; then
    v4l2-ctl -d "$device" --set-ctrl focus_automatic_absolute=0
    v4l2-ctl -d "$device" --set-ctrl focus_absolute="$focus"
fi