Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log libamera device resolutions and controls #240

Merged
merged 40 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d8332a6
refactor: refactor detect_libcamera func
KwadFan Jan 20, 2024
94f2ec7
feat: print picamera resolutions
KwadFan Jan 31, 2024
5410a9e
chore: wip
KwadFan Jan 31, 2024
64000be
chore: wip
KwadFan Jan 31, 2024
f7bc73f
chore: wip
KwadFan Jan 31, 2024
b32a18c
chore: wip
KwadFan Jan 31, 2024
e9e4011
chore: wip
KwadFan Jan 31, 2024
63a5529
chore: wip
KwadFan Jan 31, 2024
947cb07
chore: wip
KwadFan Jan 31, 2024
a1429f1
chore: dont display controls on pi5
KwadFan Jan 31, 2024
63bbbea
chore: dont display resolutions on pi5
KwadFan Jan 31, 2024
09b19c9
fix: revert code style changes
KwadFan Jan 31, 2024
b901181
chore: switch to bash
KwadFan Mar 19, 2024
7b32509
fix: fix typo
KwadFan Mar 19, 2024
30b2aeb
fix: fix output
KwadFan Mar 19, 2024
8b39771
chore: wip
KwadFan Mar 19, 2024
1853129
chore: wip
KwadFan Mar 19, 2024
78d644e
chore: wip
KwadFan Mar 19, 2024
84267b9
chore: wip
KwadFan Mar 19, 2024
38e63a2
chore: wip
KwadFan Mar 19, 2024
127b0fc
chore: wip
KwadFan Mar 19, 2024
8dcb9cb
chore: wip
KwadFan Mar 19, 2024
3ff0296
chore: wip
KwadFan Mar 19, 2024
32bb8c2
chore: wip
KwadFan Mar 19, 2024
9c4266b
chore: wip
KwadFan Mar 19, 2024
9ce04f5
chore: wip
KwadFan Mar 19, 2024
1c2ce25
chore: wip
KwadFan Mar 19, 2024
094b15d
chore: wip
KwadFan Mar 19, 2024
d0e743b
chore: wip
KwadFan Mar 19, 2024
1df93b1
chore: wip
KwadFan Mar 19, 2024
058df55
chore: revert code style changes
KwadFan Mar 19, 2024
dd8e1d2
chore: revert code style change
KwadFan Mar 19, 2024
10ec828
chore: revert code style changes
KwadFan Mar 20, 2024
ae02f46
chore: revert code style changes
KwadFan Mar 20, 2024
55e2f06
chore: remove useless comment
KwadFan Mar 21, 2024
6bf8fd8
chore: wip
KwadFan Mar 21, 2024
9239cd8
chore: wip
KwadFan Mar 21, 2024
b26f5ed
chore: wip
KwadFan Mar 21, 2024
2cd11c4
chore: wip
KwadFan Mar 21, 2024
4ba3942
chore: wip
KwadFan Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 61 additions & 13 deletions libs/hwhandler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ set -Ee
### Detect Hardware
detect_avail_cams() {
local avail realpath
avail="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null)"
avail="$(find /dev/v4l/by-id/ -iname "*index0" 2>/dev/null)"
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
count="$(echo "${avail}" | wc -l)"
if [[ -d "/dev/v4l/by-id/" ]] &&
[[ -n "${avail}" ]]; then
[[ -n "${avail}" ]]; then
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
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 +63,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 @@ -77,30 +77,78 @@ detect_libcamera() {
## Spit /base/soc path for libcamera device
get_libcamera_path() {
if [[ "$(is_raspberry_pi)" = "1" ]] &&
[[ -x "$(command -v libcamera-hello)" ]]; then
[[ -x "$(command -v libcamera-hello)" ]]; then
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
libcamera-hello --list-cameras | sed '1,2d' \
| grep "\(/base/*\)" | cut -d"(" -f2 | tr -d '$)'
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() {
python - <<EOL
from picamera2 import Picamera2
picam = Picamera2()
ctrls = picam.camera_controls

for key, value in ctrls.items():
min, max, default = value
if type(min) is int:
ctrl_type = "int"
elif type(min) is float:
ctrl_type = "float"
elif type(min) is bool:
ctrl_type = "bool"
elif type(min) is tuple:
ctrl_type = "tuple"
else:
ctrl_type=type(min)

print(f"{key} ({ctrl_type}) :\t\tmin={min} max={max} default={default}")

EOL
}

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 \
)"
command -v vcgencmd &>/dev/null; then
mryel00 marked this conversation as resolved.
Show resolved Hide resolved
if vcgencmd get_camera &>/dev/null; then
avail="$(
vcgencmd get_camera \
| awk -F '=' '{ print $3 }' \
| cut -d',' -f1
)"
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
fi
fi
echo "${avail:-0}"
}

function dev_is_legacy {
v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}'
v4l2-ctl --list-devices | grep -A1 -e 'mmal' \
| awk 'NR==2 {print $1}'
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
}

## Determine if cam has H.264 Hardware encoder
Expand Down
18 changes: 11 additions & 7 deletions libs/logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ function print_cfg {
local prefix
prefix="$(date +'[%D %T]') crowsnest:"
log_msg "INFO: Print Configfile: '${CROWSNEST_CFG}'"
(sed '/^#.*/d;/./,$!d' | cut -d'#' -f1) < "${CROWSNEST_CFG}" | \
(sed '/^#.*/d;/./,$!d' | cut -d'#' -f1) <"${CROWSNEST_CFG}" |
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
while read -r line; do
printf "%s\t\t%s\n" "${prefix}" "${line}" >> "${CROWSNEST_LOG_PATH}"
printf "%s\t\t%s\n" "${prefix}" "${line}" >>"${CROWSNEST_LOG_PATH}"
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
printf "\t\t%s\n" "${line}"
done
}

function print_cams {
local device total v4l
v4l="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null | wc -l)"
v4l="$(find /dev/v4l/by-id/ -iname "*index0" 2>/dev/null | wc -l)"
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
libcamera="$(detect_libcamera)"
legacy="$(detect_legacy)"
total="$((v4l+libcamera+legacy))"
Expand All @@ -108,10 +108,14 @@ 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' | \
awk 'NR==2 {print $1}')"
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' \
| awk 'NR==2 {print $1}')"
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
log_msg "Detected 'Raspicam' Device -> ${raspicam}"
if [[ ! "${CROWSNEST_LOG_LEVEL}" = "quiet" ]]; then
list_cam_formats "${raspicam}"
Expand All @@ -135,8 +139,8 @@ function print_host {
## OS Infos
## OS Version
if [[ -f /etc/os-release ]]; then
log_msg "Host Info: Distribution: $(grep "PRETTY" /etc/os-release | \
cut -d '=' -f2 | sed 's/^"//;s/"$//')"
log_msg "Host Info: Distribution: $(grep "PRETTY" /etc/os-release \
| cut -d '=' -f2 | sed 's/^"//;s/"$//')"
KwadFan marked this conversation as resolved.
Show resolved Hide resolved
fi
## Release Version of MainsailOS (if file present)
if [[ -f /etc/mainsailos-release ]]; then
Expand Down
Loading