Skip to content

Commit

Permalink
Update functions.sh: Keep track of RPi command was found
Browse files Browse the repository at this point in the history
Also, don't run determineCommandToRun() if it was already run.
  • Loading branch information
EricClaeys authored Dec 8, 2024
1 parent 1885bc1 commit e6e9b44
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function determineCommandToUse()
local PREFIX="${2}" # Only used if calling doExit().
local IGNORE_ERRORS="${3:-false}" # True if just checking

local CRET RET MSG EXIT_MSG
local CRET RET MSG EXIT_MSG CMD_FOUND="false"

# If libcamera is installed and works, use it.
# If it's not installed, or IS installed but doesn't work (the user may not have it configured),
Expand All @@ -203,7 +203,9 @@ function determineCommandToUse()
CRET=$?
fi
if [[ ${CRET} -eq 0 ]]; then
# Found the command - see if it works.
CMD_FOUND="true" # one of the commands were found.

# Found a command - see if it works.
"${CMD_TO_USE_}" --timeout 1 --nopreview > /dev/null 2>&1
RET=$?
if [[ ${RET} -eq 137 ]]; then
Expand All @@ -230,9 +232,15 @@ function determineCommandToUse()
fi
fi

return 1
if [[ ${CMD_FOUND} == "true" ]]; then
return 1
else
return 2 # no command was found
fi
fi

CMD_FOUND="true" # some command was found.

# On Buster, raspistill sometimes hangs if no camera is found,
# so work around that.
if ! timeout 4 "${CMD_TO_USE_}" --timeout 1 --nopreview > /dev/null 2>&1 ; then
Expand Down Expand Up @@ -261,14 +269,20 @@ function determineCommandToUse()
# Prepend each line with the CAMERA_TYPE.
function get_connected_cameras_info()
{
local dCTU_RUN="false" # determine Command To Use
if [[ ${1} == "--dctu" ]]; then
dCTU_RUN="true"
shift
fi
local IGNORE_ERRORS="${1:-false}"

####### Check for RPi
# Tab-separated output will be:
# RPi camera_number camera_sensor
# for each camera found.
# camera_sensor will be one word.
if [[ -z ${CMD_TO_USE_} ]]; then
# Only run determineCommandToUse() if it wasn't already run.
if [[ -z ${CMD_TO_USE_} && ${dCTU_RUN} == "false" ]]; then
determineCommandToUse "false" "" "${IGNORE_ERRORS}" > /dev/null
fi
if [[ -n ${CMD_TO_USE_} ]]; then
Expand Down

0 comments on commit e6e9b44

Please sign in to comment.