Skip to content

Commit e42799b

Browse files
committed
fix(v4l2ctl): fixes error in broken_focus detection
This should fix #18 Error in detection leads to exiting crowsnest script. Signed-off-by: Stephan Wendel <[email protected]>
1 parent 687be54 commit e42799b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

libs/v4l2_control.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ function brokenfocus {
7171
get_param "cam ${cam}" v4l2ctl | grep -c "focus_absolute"
7272
}
7373

74+
# checks if device has "focus_absolute"
75+
# call has_focus_absolute <mycamnameornumber>
76+
# returns greater 0 if true, 0 if false
77+
function has_focus_absolute {
78+
local cam
79+
cam="${1}"
80+
v4l2-ctl -d "${cam}" -L 2> /dev/null | grep -c "focus_absolute"
81+
}
82+
7483
# call get_conf_value <mycamnameornumber>
7584
# spits out value from config file
7685
function get_conf_value {
@@ -91,7 +100,7 @@ function brokenfocus {
91100
# ex.: get_current_value /dev/video0
92101
# spits out focus_absolute=20 ( if set to 20 )
93102
function get_current_value {
94-
v4l2-ctl -d "${1}" -C "focus_absolute" | sed 's/:[[:space:]]/=/'
103+
v4l2-ctl -d "${1}" -C "focus_absolute" 2> /dev/null | sed 's/:[[:space:]]/=/'
95104
}
96105

97106
# call set_current_value <device> <value>
@@ -109,7 +118,8 @@ function brokenfocus {
109118
device="$(get_param "cam ${cam}" device)"
110119
cur_val="$(get_current_value "${device}")"
111120
conf_val="$(get_conf_value "${cam}")"
112-
if [ "$(if_focus_absolute "${cam}")" == "1" ] &&
121+
if [ "$(has_focus_absolute "${cam}")" != "0" ] &&
122+
[ "$(if_focus_absolute "${cam}")" == "1" ] &&
113123
[ "${cur_val}" != "${conf_val}" ]; then
114124
detected_broken_dev_msg
115125
set_focus_absolute "${device}" "${conf_val}"

0 commit comments

Comments
 (0)