u
This commit is contained in:
@@ -179,6 +179,17 @@ discover_and_report_controls() {
|
|||||||
|
|
||||||
log "Discovering available camera 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
|
# Parse v4l2-ctl -L output into JSON
|
||||||
# Example lines:
|
# Example lines:
|
||||||
# brightness 0x00980900 (int) : min=-64 max=64 step=1 default=0 value=0
|
# 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
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
# Check if this is a control line (starts with control name)
|
# 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
|
# Save previous control if exists
|
||||||
if [[ -n "$current_ctrl" ]]; then
|
if [[ -n "$current_ctrl" ]]; then
|
||||||
if [[ "$in_menu" == "true" && -n "$menu_options" ]]; 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)
|
# Check if this is a menu option line (indented with number: description)
|
||||||
elif [[ "$in_menu" == "true" && "$line" =~ ^[[:space:]]+([0-9]+):[[:space:]]+(.+)$ ]]; then
|
elif [[ "$in_menu" == "true" && "$line" =~ ^[[:space:]]+([0-9]+):[[:space:]]+(.+)$ ]]; then
|
||||||
local opt_val="${BASH_REMATCH[1]}"
|
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\","
|
menu_options+="\"$opt_val\": \"$opt_name\","
|
||||||
fi
|
fi
|
||||||
done < <(v4l2-ctl -d "$VIDEO_DEVICE" -L 2>/dev/null)
|
done < <(v4l2-ctl -d "$VIDEO_DEVICE" -L 2>/dev/null)
|
||||||
|
|||||||
Reference in New Issue
Block a user