This commit is contained in:
sebseb7
2025-12-21 22:54:32 +01:00
parent bd6b20e6ed
commit 7b0fb8ce6f

View File

@@ -179,6 +179,17 @@ discover_and_report_controls() {
log "Discovering available camera controls..."
# Helper function to escape strings for JSON
json_escape() {
local str="$1"
# Escape backslashes first, then quotes
str="${str//\\/\\\\}"
str="${str//\"/\\\"}"
# Remove any control characters
str=$(echo "$str" | tr -d '\n\r\t')
echo "$str"
}
# Parse v4l2-ctl -L output into JSON
# Example lines:
# brightness 0x00980900 (int) : min=-64 max=64 step=1 default=0 value=0
@@ -197,7 +208,7 @@ discover_and_report_controls() {
while IFS= read -r line || [[ -n "$line" ]]; do
# Check if this is a control line (starts with control name)
if [[ "$line" =~ ^[[:space:]]*([a-z_]+)[[:space:]]+0x[0-9a-f]+[[:space:]]+\(([a-z]+)\)[[:space:]]*:[[:space:]]*(.*) ]]; then
if [[ "$line" =~ ^[[:space:]]*([a-z_][a-z0-9_]*)[[:space:]]+0x[0-9a-f]+[[:space:]]+\(([a-z]+)\)[[:space:]]*:[[:space:]]*(.*) ]]; then
# Save previous control if exists
if [[ -n "$current_ctrl" ]]; then
if [[ "$in_menu" == "true" && -n "$menu_options" ]]; then
@@ -250,7 +261,8 @@ discover_and_report_controls() {
# Check if this is a menu option line (indented with number: description)
elif [[ "$in_menu" == "true" && "$line" =~ ^[[:space:]]+([0-9]+):[[:space:]]+(.+)$ ]]; then
local opt_val="${BASH_REMATCH[1]}"
local opt_name="${BASH_REMATCH[2]}"
local opt_name
opt_name=$(json_escape "${BASH_REMATCH[2]}")
menu_options+="\"$opt_val\": \"$opt_name\","
fi
done < <(v4l2-ctl -d "$VIDEO_DEVICE" -L 2>/dev/null)