Skip to content

Commit

Permalink
tools: Added camera selector tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
glddiv committed Feb 9, 2022
1 parent 59157aa commit efaf6d0
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
102 changes: 102 additions & 0 deletions Release/arducam_camera_selector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

### -c --clear : Clean up the drivers of IMX519 and arducam (restore the official camera)
### -a --add name : Specify the driver to be loaded, available options: imx519, arducam
### examples:
### arducam_camera_selector.sh --add imx519
### arducam_camera_selector.sh --add arducam
### arducam_camera_selector.sh --clear

CONFIG_FILE=/boot/config.txt

ARGS=`getopt -o a:chb:: --long clear,add:,long,help -- "$@"`
if [ $? != 0 ]; then
echo "Terminating..."
exit 1
fi

eval set -- "${ARGS}"

help() {
sed -rn 's/^### ?//;T;p;' "$0"
}
# echo $#
if [[ $# == 1 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
help
exit 1
fi


while true
do
case $1 in
# add Annotation
-c|--clear)
# Add notes
sudo sed 's/^\s*dtoverlay=imx519/#dtoverlay=imx519/g' -i $CONFIG_FILE
sudo sed 's/^\s*dtoverlay=arducam/#dtoverlay=arducam/g' -i $CONFIG_FILE
shift
;;

# Clear the annotation, if the required content is not exist, add it
-a|--add)

function get_search() {
awk 'END {print}' $CONFIG_FILE
}
SEARCH="$(get_search)"
NEED="[all]"
NA=$2

function get_all() {
grep -n '\[[all]*\]' $CONFIG_FILE | tail -n 1 | cut -d ":" -f 1
}
function get_imx519() {
grep -n "imx519" $CONFIG_FILE | cut -d ":" -f 1
}
function get_arducam() {
grep -n "arducam" $CONFIG_FILE | cut -d ":" -f 1
}
CHICKIMX="$(get_imx519)"
CHICKARD="$(get_arducam)"
# printf "${CHICKALL}\n"

if [ "$NA" = "imx519" ]; then
sudo sed 's/^\s*#\s*dtoverlay=imx519/dtoverlay=imx519/g' -i $CONFIG_FILE
sudo sed 's/^\s*dtoverlay=arducam/#dtoverlay=arducam/g' -i $CONFIG_FILE
if [ "$CHICKIMX" = "" ];
then
# if [ "$SEARCH" != "$NEED" ]; then
# sudo sed '$a[all]' -i $CONFIG_FILE
# fi
# CHICKimx="$(get_all)"
# sed -i "$a dtoverlay=imx519" $CONFIG_FILE
sudo sed '$adtoverlay=imx519' -i $CONFIG_FILE
fi

elif [ "$NA" = "arducam" ]; then
sudo sed 's/^\s*#\s*dtoverlay=arducam/dtoverlay=arducam/g' -i $CONFIG_FILE
sudo sed 's/^\s*dtoverlay=imx519/#dtoverlay=imx519/g' -i $CONFIG_FILE
if [ "$CHICKARD" = "" ];
then
# if [ "$SEARCH" != "$NEED" ]; then
# sudo sed '$a[all]' -i $CONFIG_FILE
# fi
# CHICKard="$(get_all)"
# sed -i "$CHICKard a dtoverlay=arducam" $CONFIG_FILE
sudo sed '$adtoverlay=arducam' -i $CONFIG_FILE
fi
fi
shift
;;
--)
# echo 1
shift
break
;;
*)
# echo "Internal error!"
exit 1
;;
esac
done
1 change: 1 addition & 0 deletions Release/install_driver.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
echo "Installing Arducam-Pivariety-V4L2-Driver..."
echo "--------------------------------------"
sudo install -p -m 755 ./arducam_camera_selector.sh /usr/bin/
sudo install -p -m 644 ./bin/$(uname -r)/arducam.ko /lib/modules/$(uname -r)/kernel/drivers/media/i2c/
sudo install -p -m 644 ./bin/$(uname -r)/arducam.dtbo /boot/overlays/
sudo /sbin/depmod -a $(uname -r)
Expand Down

0 comments on commit efaf6d0

Please sign in to comment.