-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcalibration_tool.sh
executable file
·136 lines (129 loc) · 4.91 KB
/
calibration_tool.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
#!/bin/bash
# Function: modify the configuration of touch screen's Calibrator.
# Author: Jacky.li
# Date: 2017-04-26
#
# clear screen.
clear
install_basic_package(){
echo -n "Updating yours system and installing basic_packages,please wait..."
sudo apt-get update
sudo apt-get install -y dialog
}
#Install some packages for touch screen calibration.
install_packages(){
echo -e "\033[32mInstall Calibration packages,Please wait...\033[0m"
for x in xinput-calibrator xserver-xorg-input-evdev libx11-dev libxext-dev x11proto-input-dev evtest dh-autoreconf libts-bin libxi-dev
do
sudo apt-get -y install $x
done
}
# Funciton greeting.
greeting(){
dialog --backtitle "GeeekPi Touch Screen Calibrator Configure Panel" \
--msgbox "Welcome to GeeekPi Touch Screen Calibrator Configure Panel, please select your screen's Calibrator and press OK to continue.It supports 5inch 800x480 GPIO Touch Screen, 7inch 1024x600 touch screen, more information please access http://wiki.52pi.com/. Thanks" \
20 80 --begin 20 10
}
# Function yesno
yesno(){
dialog --backtitle "GeeekPi Touch Screen Calibrator Configure Panel" \
--title "Configure /boot/config.txt file" \
--clear \
--yesno "Do you agree to modify /boot/config.txt file?" 20 80
result=$?
if [ $result -eq 0 ]; then
change_Calibrator;
elif [ $result -eq 255 ]; then
exit 255;
fi
}
# do calibration.
calibrate(){
install_packages
sudo mv /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf
export DISPLAY=:0.0
if [ -f /etc/X11/xorg.conf.d/99-calibration.conf ]; then
sudo rm /etc/X11/xorg.conf.d/99-calibration.conf
fi
xinput_calibrator > /tmp/touch.conf
res=$?
if [ $? -eq 0 ]; then
sudo sh -c "sed '1,7d' /tmp/touch.conf > /etc/X11/xorg.conf.d/99-calibration.conf"
export -n DISPLAY
else
echo "The calibration process does not finished properly, please try again!"
sudo bash /home/pi/lcd-config/calibration_tool.sh
fi
}
#Define a function to setup.
change_Calibrator(){
dialog --clear --backtitle "GeeekPi Touch Screen Calibrator Configure Panel" \
--title "Calibrator select" \
--radiolist "Please select Calibrator of your screen" 20 80 30 R1 "5inch 800x480 GPIO Touch Screen" on R2 "7inch 800x480 Touch Screen" off R3 "7inch 1024x600 Touch Screen" off 2>.select
RES_NUM=$(cat .select)
case $RES_NUM in
R1)
sudo sed -i '/^#.*framebuffer.*/s/^#//' /boot/config.txt
sudo sed -i '/^framebuffer_width.*/s/framebuffer_width.*/framebuffer_width=800/' /boot/config.txt
sudo sed -i '/^framebuffer_height.*/s/framebuffer_height.*/framebuffer_height=480/' /boot/config.txt
sudo sed -i '/hdmi_force_hotplug/s/^#//' /boot/config.txt
sudo sed -i '/hdmi_group.*/d' /boot/config.txt
sudo sed -i '/hdmi_mode.*/d' /boot/config.txt
sudo sed -i '/hdmi_cvt.*/d' /boot/config.txt
sudo sed -i '/device_tree.*/d' /boot/config.txt
sudo sed -i '/dtoverlay=ads7846.*/d' /boot/config.txt
sudo sed -i '/hdmi_force/a\hdmi_group=2' /boot/config.txt
sudo sed -i '/hdmi_force/a\hdmi_mode=87' /boot/config.txt
sudo sed -i '/hdmi_force/a\hdmi_cvt 800 480 60 3 0 0 0' /boot/config.txt
sudo sed -i '/hdmi_group/a\device_tree=bcm2710-rpi-3-b.dtb' /boot/config.txt
sudo sed -i '/device_tree=.*/a\dtoverlay=ads7846,penirq=22,speed=100000,xohms=150' /boot/config.txt
sudo sed -i '/^#dtparam=spi.*/s/#//' /boot/config.txt
calibrate
;;
R2)
sudo sed -i '/^#.*framebuffer.*/s/^#//' /boot/config.txt
sudo sed -i '/^framebuffer_width.*/s/framebuffer_width.*/framebuffer_width=800/' /boot/config.txt
sudo sed -i '/^framebuffer_height.*/s/framebuffer_height.*/framebuffer_height=480/' /boot/config.txt
sudo sed -i '/hdmi_force_hotplug/s/^#//' /boot/config.txt
sudo sed -i '/hdmi_group.*/d' /boot/config.txt
sudo sed -i '/hdmi_mode.*/d' /boot/config.txt
sudo sed -i '/hdmi_cvt.*/d' /boot/config.txt
sudo sed -i '/hdmi_force/a\hdmi_group=2' /boot/config.txt
sudo sed -i '/hdmi_force/a\hdmi_mode=87' /boot/config.txt
sudo sed -i '/hdmi_force/a\hdmi_cvt 800 480 60 3 0 0 0' /boot/config.txt
calibrate
;;
R3)
sudo sed -i '/^framebuffer_width.*/s/framebuffer_width.*/framebuffer_width=1024/' /boot/config.txt
sudo sed -i '/^framebuffer_height.*/s/framebuffer_height.*/framebuffer_height=600/' /boot/config.txt
calibrate
;;
*)
exit 255
esac
}
#Display the configuration of /boot/config.txt file.
show_config_details(){
dialog --backtitle "GeeekPi Touch Screen Calibrator Configure Panel" --textbox "/boot/config.txt" 20 80
}
#Clear the screen buffer when exit the script.
clear_window(){
dialog --msgbox "Configuration is compelete!" 20 80 --begin 20 10 --yesno "Do you want to reboot your system?" 20 60
if [ $? -eq 0 ];then
sudo sync && sudo reboot
elif [ $? -eq 255 ];then
exit 255
fi
dialog --clear
}
# Call greeting and yesno,when it's done, clear all the temp files.
install_basic_package
greeting
yesno
show_config_details
sudo rm -rf .select
sudo rm -rf /home/pi/__MAC*
sudo rm -rf /home/pi/Edid.*
clear_window
clear
##End of file##