diff --git a/Release/arducam_camera_selector.sh b/Release/arducam_camera_selector.sh new file mode 100755 index 0000000..034abfe --- /dev/null +++ b/Release/arducam_camera_selector.sh @@ -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 \ No newline at end of file diff --git a/Release/install_driver.sh b/Release/install_driver.sh index 1305aca..e0a1b2e 100755 --- a/Release/install_driver.sh +++ b/Release/install_driver.sh @@ -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)