Skip to content

Commit

Permalink
feat: log libamera device resolutions and controls (#240)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Wendel <me@stephanwe.de>
  • Loading branch information
KwadFan authored Mar 21, 2024
1 parent faee46d commit 46f3586
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
57 changes: 47 additions & 10 deletions libs/hwhandler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ detect_avail_cams() {
local avail realpath
avail="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null)"
count="$(echo "${avail}" | wc -l)"
if [[ -d "/dev/v4l/by-id/" ]] &&
[[ -n "${avail}" ]]; then
if [[ -d "/dev/v4l/by-id/" ]] && [[ -n "${avail}" ]]; then
log_msg "INFO: Found ${count} available v4l2 (UVC) camera(s)"
echo "${avail}" | while read -r v4l; do
realpath=$(readlink -e "${v4l}")
Expand Down Expand Up @@ -63,8 +62,8 @@ detect_libcamera() {
local avail
if [[ "$(is_raspberry_pi)" = "1" ]] &&
[[ -x "$(command -v libcamera-hello)" ]]; then
avail="$(libcamera-hello --list-cameras | sed '/^\[.*\].*/d' | awk 'NR==1 {print $1}')"
if [[ "${avail}" = "Available" ]]; then
avail="$(libcamera-hello --list-cameras | grep -c "Available")"
if [[ "${avail}" = "1" ]]; then
get_libcamera_path | wc -l
else
echo "0"
Expand All @@ -83,23 +82,61 @@ get_libcamera_path() {
fi
}

# print libcamera resolutions
list_picam_resolution() {
local prefix
prefix="$(date +'[%D %T]') crowsnest:"
log_msg "'libcamera' device(s) resolution(s) :"
while read -r i; do
printf "%s\t\t%s\n" "${prefix}" "${i}" >> "${CROWSNEST_LOG_PATH}"
done < <(libcamera-hello --list-cameras | sed '1,2d;s/Modes:/Colorspace:/')
}

get_libcamera_controls() {
local ust_bin flags
flags=( --camera-type=libcamera --camera-list_options )
ust_bin="${BASE_CN_PATH}/bin/camera-streamer/camera-streamer"
if [[ -x "${ust_bin}" ]]; then
"${ust_bin}" "${flags[@]}" --camera-path="$(get_libcamera_path)" 2> /dev/null | \
sed 's/device//g;/^SNAPSHOT/q' | sed '/^SNAPSHOT/d' | \
sed '/^CAMERA/d;/- property/d' | sed '/camera-streamer Version:/d' | \
sed 's/- available option: //g' | sed '/^$/d;' | \
sed 's/([0-9]*[a-z,0-9]\,//g' | sed '/type=7/d;/type=4/d' | \
sed 's/type=1/ (bool/g;s/type=3/ (int/g;s/type=5/ (float/g' | \
sed 's/\[/min=/g;s/\.\./ max=/g;s/\]$//g'
else
log_msg "WARN: 'libcamera' device option can not be displayed, because"
log_msg "WARN: camera-streamer is not installed"
fi
}

list_picam_controls() {
local prefix
prefix="$(date +'[%D %T]') crowsnest:"
log_msg "'libcamera' device controls :"
while read -r i; do
if [[ ! "${i}" =~ "INFO" ]]; then
printf "%s\t\t%s\n" "${prefix}" "${i}" >>"${CROWSNEST_LOG_PATH}"
fi
done < <(get_libcamera_controls)
# blank line workaround
log_msg ""
}

# Determine connected "legacy" device
function detect_legacy {
local avail
if [[ "$(is_raspberry_pi)" = "1" ]] &&
command -v vcgencmd &> /dev/null; then
if vcgencmd get_camera &> /dev/null ; then
avail="$(vcgencmd get_camera \
| awk -F '=' '{ print $3 }' \
| cut -d',' -f1 \
)"
if vcgencmd get_camera &> /dev/null; then
avail="$( vcgencmd get_camera | awk -F '=' '{ print $3 }' | cut -d',' -f1)"
fi
fi
echo "${avail:-0}"
}

function dev_is_legacy {
v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}'
}

Expand Down
6 changes: 5 additions & 1 deletion libs/logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ function print_cams {
for device in $(get_libcamera_path); do
log_msg "Detected 'libcamera' device -> ${device}"
done
if [[ "$(is_pi5)" = "0" ]]; then
list_picam_resolution
list_picam_controls
fi
fi
if [[ "${legacy}" -ne 0 ]]; then
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}')"
log_msg "Detected 'Raspicam' Device -> ${raspicam}"
if [[ ! "${CROWSNEST_LOG_LEVEL}" = "quiet" ]]; then
Expand Down

0 comments on commit 46f3586

Please sign in to comment.