feat: add debug logging for v4l2_control
If log_level: debug it logs settings after its done. Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
parent
acf9516058
commit
2e3cf93568
@ -17,6 +17,8 @@
|
||||
set -e
|
||||
|
||||
## Message Helpers
|
||||
|
||||
## core lib
|
||||
function missing_args_msg {
|
||||
echo -e "webcamd: Missing Arguments!"
|
||||
echo -e "\n\tTry: webcamd -h\n"
|
||||
@ -54,3 +56,15 @@ function provides_omx_msg {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## v4l2_control lib
|
||||
function detected_broken_dev_msg {
|
||||
log_msg "WARN: Detected 'brokenfocus' device."
|
||||
log_msg "INFO: Trying to set to configured Value."
|
||||
}
|
||||
|
||||
# call debug_focus_val_msg <value>
|
||||
# ex.: debug_focus_val_msg focus_absolute=30
|
||||
function debug_focus_val_msg {
|
||||
log_msg "DEBUG: Value is now: ${1}"
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
# shellcheck enable=require-variable-braces
|
||||
|
||||
# Exit upon Errors
|
||||
set -e
|
||||
set -eE
|
||||
|
||||
function v4l2_control {
|
||||
log_msg "V4L2 Control:"
|
||||
@ -48,6 +48,9 @@ function v4l2_control {
|
||||
v4l2-ctl -d "${device}" -c "${param}" 2> /dev/null
|
||||
fi
|
||||
done
|
||||
if [ "$(log_level)" == "debug" ]; then
|
||||
v4l2-ctl -d "${device}" -L | log_output "v4l2ctl"
|
||||
fi
|
||||
else
|
||||
log_msg "No parameters set for [cam ${cam}]. Skipped."
|
||||
fi
|
||||
@ -57,3 +60,78 @@ function v4l2_control {
|
||||
### MAIN
|
||||
main
|
||||
}
|
||||
|
||||
function brokenfocus {
|
||||
|
||||
# call get_dev_id <device>
|
||||
# ex.: get_dev_id /dev/v4l/by-id/mywierd-cam-index0
|
||||
# spits out device id like lsusb
|
||||
function get_dev_id {
|
||||
local device uevent_path
|
||||
device="$(realpath "${1}" | sed 's|/dev/||')"
|
||||
uevent_path="/sys/class/video4linux/${device}/device/uevent"
|
||||
grep "PRODUCT" "${uevent_path}" | cut -d'=' -f2 | awk -F'/' '{print $1":"$2}'
|
||||
}
|
||||
|
||||
# checks if "focus_absolute" is configured
|
||||
# call if_focus_absolute <mycamnameornumber>
|
||||
# returns 1 = true, 0 = false
|
||||
function if_focus_absolute {
|
||||
local cam
|
||||
cam="${1}"
|
||||
get_param "cam ${cam}" v4l2ctl | grep -c "focus_absolute"
|
||||
}
|
||||
|
||||
# call get_conf_value <mycamnameornumber>
|
||||
# spits out value from config file
|
||||
function get_conf_value {
|
||||
local cam conf_val
|
||||
local -a params
|
||||
cam="${1}"
|
||||
conf_val="$(get_param "cam ${cam}" v4l2ctl)"
|
||||
if [ -n "${conf_val}" ]; then
|
||||
IFS=','; read -ra params <<< "${conf_val}"
|
||||
unset IFS
|
||||
for i in "${params[@]}"; do
|
||||
grep "focus_absolute" <<< "${i}" || true
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# call get_current_value <device>
|
||||
# ex.: get_current_value /dev/video0
|
||||
# spits out focus_absolute=20 ( if set to 20 )
|
||||
function get_current_value {
|
||||
v4l2-ctl -d "${1}" -C "focus_absolute" | sed 's/:[[:space:]]/=/'
|
||||
}
|
||||
|
||||
# call set_current_value <device> <value>
|
||||
# ex.: set_current_value /dev/video0 focus_absolute=30
|
||||
function set_focus_absolute {
|
||||
local device value
|
||||
device="${1}"
|
||||
value="${2}"
|
||||
v4l2-ctl -d "${device}" -c "${value}"
|
||||
}
|
||||
|
||||
function main {
|
||||
local cur_val conf_val device
|
||||
for cam in $(configured_cams); do
|
||||
device="$(get_param "cam ${cam}" device)"
|
||||
cur_val="$(get_current_value "${device}")"
|
||||
conf_val="$(get_conf_value "${cam}")"
|
||||
if [ "$(if_focus_absolute "${cam}")" == "1" ] &&
|
||||
[ "${cur_val}" != "${conf_val}" ]; then
|
||||
detected_broken_dev_msg
|
||||
set_focus_absolute "${device}" "${conf_val}"
|
||||
fi
|
||||
if [ "$(log_level)" == "debug" ]; then
|
||||
debug_focus_val_msg "$(get_current_value "${device}")"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
### MAIN
|
||||
main
|
||||
|
||||
}
|
||||
|
1
webcamd
1
webcamd
@ -66,6 +66,7 @@ init_log_entry
|
||||
initial_check
|
||||
v4l2_control
|
||||
construct_streamer
|
||||
brokenfocus
|
||||
|
||||
## Loop and Watchdog
|
||||
## In this case watchdog acts more like a "cable defect detector"
|
||||
|
Loading…
x
Reference in New Issue
Block a user