-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·219 lines (185 loc) · 5.8 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/bash
# hellods s
# test,delete when real use.
RED='\033[0;31m'
NC='\033[0m'
initAutodetect() {
array=()
arr_subscript=0
InstallName=
SenorId=
OpenCameraName=
BOOTCONFIG="/boot/config.txt"
TMP="/tmp/arducam.json"
BIT=`getconf LONG_BIT`
PWD_GET=`pwd`
}
# removeDtoverlay() {
# sudo dtoverlay -r imx519>/dev/null 2>&1
# sudo dtoverlay -r arducam>/dev/null 2>&1
# sudo dtoverlay -r arducam_64mp>/dev/null 2>&1
# }
configCheck() {
grepcmd i2cdetect
if [ $? -ne 0 ]; then
echo "Download i2c-tools."
sudo apt install -y i2c-tools
fi
if ! grep -q "^i2c[-_]dev" /etc/modules; then
sudo printf "i2c-dev\n" >>/etc/modules
sudo modprobe i2c-dev
fi
if [ $(grep -c "dtparam=i2c_vc=on" "$BOOTCONFIG") -eq 0 ]; then
sudo sed -i '$adtparam=i2c_vc=on' "$BOOTCONFIG"
sudo sed -i '$adtparam=i2c_arm=on' "$BOOTCONFIG"
echo "Already add 'dtparam=i2c_vc=on' and 'dtparam=i2c_arm=on' in /boot/config.txt"
sudo dtparam i2c_vc
sudo dtparam i2c_arm
fi
if [[ $(grep -c "^dtoverlay=imx519" "$BOOTCONFIG") -ne 0 \
|| $(grep -c "^dtoverlay=arducam" "$BOOTCONFIG") -ne 0 ]]; then
printf '{\n\t"camera":1,\t\n}\n' > "$TMP"
echo "You have installed our driver and it works."
echo "If you want to redetect the camera, you need to modify the /boot/config.txt file and reboot."
echo "Do you agree to modify the file?(y/n):"
read USER_INPUT
case $USER_INPUT in
'y'|'Y')
echo "File has been changed."
sudo sed 's/^\s*dtoverlay=imx519/#dtoverlay=imx519/g' -i $BOOTCONFIG
sudo sed 's/^\s*dtoverlay=arducam/#dtoverlay=arducam/g' -i $BOOTCONFIG
sudo sed 's/^\s*dtoverlay=arducam-pivariety/#dtoverlay=arducam-pivariety/g' -i $BOOTCONFIG
sudo sed 's/^\s*dtoverlay=arducam_64mp/#dtoverlay=arducam_64mp/g' -i $BOOTCONFIG
sudo sed 's/^\s*dtoverlay=arducam-64mp/#dtoverlay=arducam-64mp/g' -i $BOOTCONFIG
echo "reboot now?(y/n):"
read USER_INPUT
case $USER_INPUT in
'y'|'Y')
echo "reboot"
sudo reboot
;;
*)
echo "cancel"
echo "Re-execution of the script will only take effect after restarting."
exit -1
;;
esac
;;
*)
echo "cancel"
exit -1
;;
esac
fi
if [ -s $TMP ]; then
echo "Please restart the camera first."
exit -1
fi
}
installFile() {
CAMERA_I2C_FILE_NAME="camera_i2c"
CAMERA_I2C_FILE_DOWNLOAD_LINK="https://raw.githubusercontent.com/ArduCAM/MIPI_Camera/master/RPI/utils/camera_i2c"
RPI3_GPIOVIRTBUF_FILE_NAME="rpi3-gpiovirtbuf"
if [ ! -s $CAMERA_I2C_FILE_NAME ]; then
wget -O $CAMERA_I2C_FILE_NAME $CAMERA_I2C_FILE_DOWNLOAD_LINK
chmod +x $CAMERA_I2C_FILE_NAME
fi
if [ $? -ne 0 ]; then
echo -e "${RED}Download failed.${NC}"
echo "Please check your network and try again."
exit -1
fi
if [ "$BIT" = 32 ]; then
RPI3_GPIOVIRTBUF_FILE_DOWNLOAD_LINK="https://github.com/ArduCAM/MIPI_Camera/raw/master/RPI/utils/rpi3-gpiovirtbuf/32/rpi3-gpiovirtbuf"
elif [ "$BIT" = 64 ]; then
RPI3_GPIOVIRTBUF_FILE_DOWNLOAD_LINK="https://github.com/ArduCAM/MIPI_Camera/raw/master/RPI/utils/rpi3-gpiovirtbuf/64/rpi3-gpiovirtbuf"
fi
if [ ! -s $RPI3_GPIOVIRTBUF_FILE_NAME ]; then
wget -O $RPI3_GPIOVIRTBUF_FILE_NAME $RPI3_GPIOVIRTBUF_FILE_DOWNLOAD_LINK
fi
if [ $? -ne 0 ]; then
echo -e "${RED}Download failed.${NC}"
echo "Please check your network and try again."
exit -1
else
chmod +x $RPI3_GPIOVIRTBUF_FILE_NAME
./camera_i2c>/dev/null 2>&1
fi
}
grepcmd() {
type $1 >/dev/null 2>&1 || {
echo >&2 "Start install $1."
return 1
}
}
judgeI2c() {
for element in ${array[@]}; do
if [ "$1" = "$element" ]; then
return 0
fi
done
return 1
}
judgeSenorId() {
if [ "$1" = "0c" ]; then
i2ctransfer -y 10 w2@0x0c 0x01 0x03 r4
elif [ "$1" = "1a" ]; then
i2ctransfer -y 10 w2@0x1a 0x00 0x16 r2
fi
}
camera() {
while read lines; do
for line in $lines; do
case "$line" in
[0-9a-zA-z][0-9a-zA-Z])
array[arr_subscript]=$line
let arr_subscript++
;;
esac
done
done <$1
judgeI2c 1a
if [ $? -eq 0 ]; then
SenorId=$(judgeSenorId 1a 2>&1)
if [ "$SenorId" = "0x05 0x19" ]; then
InstallName="imx519_kernel_driver_low_speed"
OpenCameraName=imx519
echo "Recognize that your camera is IMX519."
elif [ "$SenorId" = "0x06 0x82" ]; then
InstallName="64mp_pi_hawk_eye_kernel_driver"
OpenCameraName=arducam_64mp
echo "Recognize that your camera is 64MP."
fi
fi
if [ -z "$InstallName" ]; then
SenorId=$(judgeSenorId 0c 2>&1)
judgeI2c 0c
if [ $? -eq 0 ]; then
if [ "$SenorId" = "0x00 0x00 0x00 0x30" ]; then
InstallName="kernel_driver"
OpenCameraName=arducam
echo "Recognize that your camera is Pirvarty"
fi
fi
fi
if [ -z "$InstallName" ]; then
echo "Your camera does not need to install drivers."
exit -1
fi
}
openCamera() {
if [ -n "$OpenCameraName" ]; then
sudo dtoverlay $OpenCameraName>/dev/null 2>&1
fi
}
autoDetect() {
initAutodetect
configCheck
echo 3
installFile
i2cdetect -y 10 > i2c.txt
camera i2c.txt
openCamera
package=${InstallName}
}
autoDetect