Skip to content

Commit

Permalink
fix(v4l2ctl): fixes error in broken_focus detection
Browse files Browse the repository at this point in the history
This should fix #18

Error in detection leads to exiting crowsnest script.

Signed-off-by: Stephan Wendel <[email protected]>
  • Loading branch information
KwadFan committed Jun 12, 2022
1 parent 687be54 commit e42799b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libs/v4l2_control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ function brokenfocus {
get_param "cam ${cam}" v4l2ctl | grep -c "focus_absolute"
}

# checks if device has "focus_absolute"
# call has_focus_absolute <mycamnameornumber>
# returns greater 0 if true, 0 if false
function has_focus_absolute {
local cam
cam="${1}"
v4l2-ctl -d "${cam}" -L 2> /dev/null | grep -c "focus_absolute"
}

# call get_conf_value <mycamnameornumber>
# spits out value from config file
function get_conf_value {
Expand All @@ -91,7 +100,7 @@ function brokenfocus {
# 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:]]/=/'
v4l2-ctl -d "${1}" -C "focus_absolute" 2> /dev/null | sed 's/:[[:space:]]/=/'
}

# call set_current_value <device> <value>
Expand All @@ -109,7 +118,8 @@ function brokenfocus {
device="$(get_param "cam ${cam}" device)"
cur_val="$(get_current_value "${device}")"
conf_val="$(get_conf_value "${cam}")"
if [ "$(if_focus_absolute "${cam}")" == "1" ] &&
if [ "$(has_focus_absolute "${cam}")" != "0" ] &&
[ "$(if_focus_absolute "${cam}")" == "1" ] &&
[ "${cur_val}" != "${conf_val}" ]; then
detected_broken_dev_msg
set_focus_absolute "${device}" "${conf_val}"
Expand Down

0 comments on commit e42799b

Please sign in to comment.