From 3df7fedb4d38d2ce830c9a891abd987a36a8829f Mon Sep 17 00:00:00 2001
From: Stephan Wendel <me@stephanwe.de>
Date: Tue, 9 Aug 2022 20:34:01 +0200
Subject: [PATCH] fix: fixes error in brokenfokus function

This fixes error as described in #27

Signed-off-by: Stephan Wendel <me@stephanwe.de>
---
 libs/v4l2_control.sh | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libs/v4l2_control.sh b/libs/v4l2_control.sh
index 6a6850e..12091f2 100755
--- a/libs/v4l2_control.sh
+++ b/libs/v4l2_control.sh
@@ -72,12 +72,11 @@ function brokenfocus {
     }
 
     # checks if device has "focus_absolute"
-    # call has_focus_absolute <mycamnameornumber>
-    # returns greater 0 if true, 0 if false
+    # call has_focus_absolute <device>
+    # returns 1 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"
+        v4l2-ctl -d "${1}" -C "focus_absolute" &> /dev/null \
+        && echo "1" || echo "0"
     }
 
     # call get_conf_value <mycamnameornumber>
@@ -118,7 +117,7 @@ function brokenfocus {
             device="$(get_param "cam ${cam}" device)"
             cur_val="$(get_current_value "${device}")"
             conf_val="$(get_conf_value "${cam}")"
-            if [ "$(has_focus_absolute "${cam}")" != "0" ] &&
+            if [ "$(has_focus_absolute "${device}")" == "1" ] &&
             [ "$(if_focus_absolute "${cam}")" == "1" ] &&
             [ "${cur_val}" != "${conf_val}" ]; then
                 detected_broken_dev_msg