No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

adafruit-pitft.sh 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. #!/bin/bash
  2. # (C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
  3. #
  4. # Instructions!
  5. # cd ~
  6. # wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
  7. # chmod +x adafruit-pitft.sh
  8. # sudo ./adafruit-pitft.sh
  9. if [ $(id -u) -ne 0 ]; then
  10. echo "Installer must be run as root."
  11. echo "Try 'sudo bash $0'"
  12. exit 1
  13. fi
  14. UPDATE_DB=false
  15. ############################ CALIBRATIONS ############################
  16. # For TSLib
  17. POINTERCAL_28r0="4232 11 -879396 1 5786 -752768 65536"
  18. POINTERCAL_28r90="33 -5782 21364572 4221 35 -1006432 65536"
  19. POINTERCAL_28r180="-4273 61 16441290 4 -5772 21627524 65536"
  20. POINTERCAL_28r270="-9 5786 -784608 -4302 19 16620508 65536"
  21. POINTERCAL_35r0="5724 -6 -1330074 26 8427 -1034528 65536"
  22. POINTERCAL_35r90="5 8425 -978304 -5747 61 22119468 65536"
  23. POINTERCAL_35r180="-5682 -1 22069150 13 -8452 32437698 65536"
  24. POINTERCAL_35r270="3 -8466 32440206 5703 -1 -1308696 65536"
  25. POINTERCAL_28c="320 65536 0 -65536 0 15728640 65536"
  26. # for PIXEL desktop
  27. TRANSFORM_28r0="0.988809 -0.023645 0.060523 -0.028817 1.003935 0.034176 0 0 1"
  28. TRANSFORM_28r90="0.014773 -1.132874 1.033662 1.118701 0.009656 -0.065273 0 0 1"
  29. TRANSFORM_28r180="-1.115235 -0.010589 1.057967 -0.005964 -1.107968 1.025780 0 0 1"
  30. TRANSFORM_28r270="-0.033192 1.126869 -0.014114 -1.115846 0.006580 1.050030 0 0 1"
  31. TRANSFORM_35r0="-1.098388 0.003455 1.052099 0.005512 -1.093095 1.026309 0 0 1"
  32. TRANSFORM_35r90="-0.000087 1.094214 -0.028826 -1.091711 -0.004364 1.057821 0 0 1"
  33. TRANSFORM_35r180="1.102807 0.000030 -0.066352 0.001374 1.085417 -0.027208 0 0 1"
  34. TRANSFORM_35r270="0.003893 -1.087542 1.025913 1.084281 0.008762 -0.060700 0 0 1"
  35. TRANSFORM_28c0="-1 0 1 0 -1 1 0 0 1"
  36. TRANSFORM_28c90="0 1 0 -1 0 1 0 0 1"
  37. TRANSFORM_28c180="1 0 0 0 1 0 0 0 1"
  38. TRANSFORM_28c270="0 -1 1 1 0 0 0 0 1"
  39. warning() {
  40. echo WARNING : $1
  41. }
  42. ############################ Script assisters ############################
  43. # Given a list of strings representing options, display each option
  44. # preceded by a number (1 to N), display a prompt, check input until
  45. # a valid number within the selection range is entered.
  46. selectN() {
  47. for ((i=1; i<=$#; i++)); do
  48. echo $i. ${!i}
  49. done
  50. echo
  51. REPLY=""
  52. while :
  53. do
  54. echo -n "SELECT 1-$#: "
  55. read
  56. if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
  57. return $REPLY
  58. fi
  59. done
  60. }
  61. function print_version() {
  62. echo "Adafruit PiTFT Helper v2.1.0"
  63. exit 1
  64. }
  65. function print_help() {
  66. echo "Usage: $0 "
  67. echo " -h Print this help"
  68. echo " -v Print version information"
  69. echo " -u [homedir] Specify path of primary user's home directory (defaults to /home/pi)"
  70. exit 1
  71. }
  72. group=ADAFRUIT
  73. function info() {
  74. system="$1"
  75. group="${system}"
  76. shift
  77. FG="1;32m"
  78. BG="40m"
  79. echo -e "[\033[${FG}\033[${BG}${system}\033[0m] $*"
  80. }
  81. function bail() {
  82. FG="1;31m"
  83. BG="40m"
  84. echo -en "[\033[${FG}\033[${BG}${group}\033[0m] "
  85. if [ -z "$1" ]; then
  86. echo "Exiting due to error"
  87. else
  88. echo "Exiting due to error: $*"
  89. fi
  90. exit 1
  91. }
  92. function ask() {
  93. # http://djm.me/ask
  94. while true; do
  95. if [ "${2:-}" = "Y" ]; then
  96. prompt="Y/n"
  97. default=Y
  98. elif [ "${2:-}" = "N" ]; then
  99. prompt="y/N"
  100. default=N
  101. else
  102. prompt="y/n"
  103. default=
  104. fi
  105. # Ask the question
  106. read -p "$1 [$prompt] " REPLY
  107. # Default?
  108. if [ -z "$REPLY" ]; then
  109. REPLY=$default
  110. fi
  111. # Check if the reply is valid
  112. case "$REPLY" in
  113. Y*|y*) return 0 ;;
  114. N*|n*) return 1 ;;
  115. esac
  116. done
  117. }
  118. function has_repo() {
  119. # Checks for the right raspbian repository
  120. # http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi firmware
  121. if [[ $(grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* | grep "mirrordirector.raspbian.org") ]]; then
  122. return 0
  123. else
  124. return 1
  125. fi
  126. }
  127. progress() {
  128. count=0
  129. until [ $count -eq $1 ]; do
  130. echo -n "..." && sleep 1
  131. ((count++))
  132. done
  133. echo
  134. }
  135. sysupdate() {
  136. if ! $UPDATE_DB; then
  137. # echo "Checking for correct software repositories..."
  138. # has_repo || { warning "Missing Apt repo, please add deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi firmware to /etc/apt/sources.list.d/raspi.list" && exit 1; }
  139. echo "Updating apt indexes..." && progress 3 &
  140. sudo apt-get update 1> /dev/null || { warning "Apt failed to update indexes!" && exit 1; }
  141. echo "Reading package lists..."
  142. progress 3 && UPDATE_DB=true
  143. fi
  144. }
  145. # Given a filename, a regex pattern to match and a replacement string,
  146. # perform replacement if found, else append replacement to end of file.
  147. # (# $1 = filename, $2 = pattern to match, $3 = replacement)
  148. reconfig() {
  149. grep $2 $1 >/dev/null
  150. if [ $? -eq 0 ]; then
  151. # Pattern found; replace in file
  152. sed -i "s/$2/$3/g" $1 >/dev/null
  153. else
  154. # Not found; append (silently)
  155. echo $3 | sudo tee -a $1 >/dev/null
  156. fi
  157. }
  158. ############################ Sub-Scripts ############################
  159. function softwareinstall() {
  160. echo "Installing Pre-requisite Software...This may take a few minutes!"
  161. apt-get install -y libts0 1> /dev/null 2>&1 || apt-get install -y tslib 1> /dev/null 2>&1 || { warning "Apt failed to install TSLIB!" && exit 1; }
  162. apt-get install -y bc fbi git python-dev python-pip python-smbus python-spidev evtest libts-bin 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
  163. pip install evdev 1> /dev/null || { warning "Pip failed to install software!" && exit 1; }
  164. }
  165. # update /boot/config.txt with appropriate values
  166. function update_configtxt() {
  167. if grep -q "adafruit-pitft-helper" "/boot/config.txt"; then
  168. echo "Already have an adafruit-pitft-helper section in /boot/config.txt."
  169. echo "Removing old section..."
  170. cp /boot/config.txt /boot/configtxt.bak
  171. sed -i -e "/^# --- added by adafruit-pitft-helper/,/^# --- end adafruit-pitft-helper/d" /boot/config.txt
  172. fi
  173. # remove any old flexfb/fbtft stuff
  174. rm -f /etc/modprobe.d/fbtft.conf
  175. sed -i 's/flexfb//g' "/etc/modules"
  176. sed -i 's/fbtft_device//g' "/etc/modules"
  177. sed -i 's/spi-bcm2835//g' "/etc/modules"
  178. if [ "${pitfttype}" == "22" ]; then
  179. overlay="dtoverlay=pitft22,rotate=${pitftrot},speed=64000000,fps=30"
  180. fi
  181. if [ "${pitfttype}" == "28r" ]; then
  182. overlay="dtoverlay=pitft28-resistive,rotate=${pitftrot},speed=64000000,fps=30"
  183. fi
  184. if [ "${pitfttype}" == "28c" ]; then
  185. overlay="dtoverlay=pitft28-capacitive,rotate=${pitftrot},speed=64000000,fps=30"
  186. fi
  187. if [ "${pitfttype}" == "35r" ]; then
  188. overlay="dtoverlay=pitft35-resistive,rotate=${pitftrot},speed=20000000,fps=20"
  189. fi
  190. if [ "${pitfttype}" == "st7789_240x240" ]; then
  191. cat >> /etc/modprobe.d/fbtft.conf <<EOF
  192. # --- added by adafruit-pitft-helper $date ---
  193. options fbtft_device name=flexfb gpios=dc:25,cs:8,led:26 speed=40000000 bgr=1 fps=60
  194. options flexfb setaddrwin=0 width=240 height=240 init=-1,0x11,-2,120,-1,0x36,0x00,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3
  195. # --- end adafruit-pitft-helper $date ---
  196. EOF
  197. echo "flexfb" >> /etc/modules
  198. echo "fbtft_device" >> /etc/modules
  199. echo "spi-bcm2835" >> /etc/modules
  200. overlay=""
  201. fi
  202. date=`date`
  203. cat >> /boot/config.txt <<EOF
  204. # --- added by adafruit-pitft-helper $date ---
  205. dtparam=spi=on
  206. dtparam=i2c1=on
  207. dtparam=i2c_arm=on
  208. $overlay
  209. # --- end adafruit-pitft-helper $date ---
  210. EOF
  211. }
  212. function update_udev() {
  213. cat > /etc/udev/rules.d/95-touchmouse.rules <<EOF
  214. SUBSYSTEM=="input", ATTRS{name}=="touchmouse", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  215. EOF
  216. cat > /etc/udev/rules.d/95-ftcaptouch.rules <<EOF
  217. SUBSYSTEM=="input", ATTRS{name}=="EP0110M09", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  218. EOF
  219. cat > /etc/udev/rules.d/95-stmpe.rules <<EOF
  220. SUBSYSTEM=="input", ATTRS{name}=="*stmpe*", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  221. EOF
  222. }
  223. function update_pointercal() {
  224. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
  225. echo $(eval echo "\$POINTERCAL_$pitfttype$pitftrot") > /etc/pointercal
  226. fi
  227. if [ "${pitfttype}" == "28c" ]; then
  228. echo $(eval echo "\$POINTERCAL_$pitfttype") > /etc/pointercal
  229. fi
  230. }
  231. function install_console() {
  232. echo "Set up main console turn on"
  233. if ! grep -q 'fbcon=map:10 fbcon=font:VGA8x8' /boot/cmdline.txt; then
  234. echo "Updating /boot/cmdline.txt"
  235. sed -i 's/rootwait/rootwait fbcon=map:10 fbcon=font:VGA8x8/g' "/boot/cmdline.txt"
  236. else
  237. echo "/boot/cmdline.txt already updated"
  238. fi
  239. echo "Turning off console blanking"
  240. # pre-stretch this is what you'd do:
  241. if [ -e /etc/kbd/config ]; then
  242. sed -i 's/BLANK_TIME=.*/BLANK_TIME=0/g' "/etc/kbd/config"
  243. fi
  244. # as of stretch....
  245. # removing any old version
  246. sed -i -e '/^# disable console blanking.*/d' /etc/rc.local
  247. sed -i -e '/^sudo sh -c "TERM=linux setterm -blank.*/d' /etc/rc.local
  248. sed -i -e "s|^exit 0|# disable console blanking on PiTFT\\nsudo sh -c \"TERM=linux setterm -blank 0 >/dev/tty0\"\\nexit 0|" /etc/rc.local
  249. reconfig /etc/default/console-setup "^.*FONTFACE.*$" "FONTFACE=\"Terminus\""
  250. reconfig /etc/default/console-setup "^.*FONTSIZE.*$" "FONTSIZE=\"6x12\""
  251. echo "Setting raspi-config to boot to console w/o login..."
  252. (cd "$target_homedir" && raspi-config nonint do_boot_behaviour B2)
  253. # remove fbcp
  254. sed -i -e "/^.*fbcp.*$/d" /etc/rc.local
  255. }
  256. function uninstall_console() {
  257. echo "Removing console fbcon map from /boot/cmdline.txt"
  258. sed -i 's/rootwait fbcon=map:10 fbcon=font:VGA8x8/rootwait/g' "/boot/cmdline.txt"
  259. echo "Screen blanking time reset to 10 minutes"
  260. if [ -e "/etc/kbd/config" ]; then
  261. sed -i 's/BLANK_TIME=0/BLANK_TIME=10/g' "/etc/kbd/config"
  262. fi
  263. sed -i -e '/^# disable console blanking.*/d' /etc/rc.local
  264. sed -i -e '/^sudo sh -c "TERM=linux.*/d' /etc/rc.local
  265. }
  266. function install_fbcp() {
  267. echo "Installing cmake..."
  268. apt-get --yes --force-yes install cmake 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
  269. echo "Downloading rpi-fbcp..."
  270. cd /tmp
  271. #curl -sLO https://github.com/tasanakorn/rpi-fbcp/archive/master.zip
  272. curl -sLO https://github.com/adafruit/rpi-fbcp/archive/master.zip
  273. echo "Uncompressing rpi-fbcp..."
  274. rm -rf /tmp/rpi-fbcp-master
  275. unzip master.zip 1> /dev/null || { warning "Failed to uncompress fbcp!" && exit 1; }
  276. cd rpi-fbcp-master
  277. mkdir build
  278. cd build
  279. echo "Building rpi-fbcp..."
  280. echo -e "\nset (CMAKE_C_FLAGS \"-std=gnu99 ${CMAKE_C_FLAGS}\")" >> ../CMakeLists.txt
  281. cmake .. 1> /dev/null || { warning "Failed to cmake fbcp!" && exit 1; }
  282. make 1> /dev/null || { warning "Failed to make fbcp!" && exit 1; }
  283. echo "Installing rpi-fbcp..."
  284. install fbcp /usr/local/bin/fbcp
  285. cd ~
  286. rm -rf /tmp/rpi-fbcp-master
  287. # Start fbcp in the appropriate place, depending on init system:
  288. if [ "$SYSTEMD" == "0" ]; then
  289. # Add fbcp to /etc/rc.local:
  290. echo "We have sysvinit, so add fbcp to /etc/rc.local..."
  291. grep fbcp /etc/rc.local >/dev/null
  292. if [ $? -eq 0 ]; then
  293. # fbcp already in rc.local, but make sure correct:
  294. sed -i "s|^.*fbcp.*$|/usr/local/bin/fbcp \&|g" /etc/rc.local >/dev/null
  295. else
  296. # Insert fbcp into rc.local before final 'exit 0':
  297. sed -i "s|^exit 0|/usr/local/bin/fbcp \&\\nexit 0|g" /etc/rc.local >/dev/null
  298. fi
  299. else
  300. # Install fbcp systemd unit, first making sure it's not in rc.local:
  301. uninstall_fbcp_rclocal
  302. echo "We have systemd, so install fbcp systemd unit..."
  303. install_fbcp_unit || bail "Unable to install fbcp unit file"
  304. sudo systemctl enable fbcp.service
  305. fi
  306. # if there's X11 installed...
  307. if [ -e /etc/lightdm ]; then
  308. echo "Setting raspi-config to boot to desktop w/o login..."
  309. raspi-config nonint do_boot_behaviour B4
  310. fi
  311. # Disable overscan compensation (use full screen):
  312. raspi-config nonint do_overscan 1
  313. # Set up HDMI parameters:
  314. echo "Configuring boot/config.txt for forced HDMI"
  315. reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1"
  316. reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2"
  317. reconfig /boot/config.txt "^.*hdmi_mode.*$" "hdmi_mode=87"
  318. # if there's X11 installed...
  319. if [ -e /etc/lightdm ]; then
  320. if [ "${pitfttype}" == "35r" ]; then
  321. echo "Using x1.5 resolution"
  322. SCALE=1.5
  323. else
  324. echo "Using x2 resolution"
  325. SCALE=2.0
  326. fi
  327. else
  328. echo "Using native resolution"
  329. SCALE=1
  330. fi
  331. WIDTH=`python -c "print(int(${WIDTH_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
  332. HEIGHT=`python -c "print(int(${HEIGHT_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
  333. reconfig /boot/config.txt "^.*hdmi_cvt.*$" "hdmi_cvt=${WIDTH} ${HEIGHT} 60 1 0 0 0"
  334. if [ "${pitftrot}" == "90" ] || [ "${pitftrot}" == "270" ]; then
  335. # dont rotate HDMI on 90 or 270
  336. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" ""
  337. fi
  338. if [ "${pitftrot}" == "0" ]; then
  339. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=1"
  340. # this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
  341. pitftrot=90
  342. update_configtxt || bail "Unable to update /boot/config.txt"
  343. pitftrot=0
  344. fi
  345. if [ "${pitftrot}" == "180" ]; then
  346. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=3"
  347. # this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
  348. pitftrot=90
  349. update_configtxt || bail "Unable to update /boot/config.txt"
  350. pitftrot=180
  351. fi
  352. }
  353. function install_fbcp_unit() {
  354. cat > /etc/systemd/system/fbcp.service <<EOF
  355. [Unit]
  356. Description=Framebuffer copy utility for PiTFT
  357. After=network.target
  358. [Service]
  359. Type=simple
  360. ExecStartPre=/bin/sleep 10
  361. ExecStart=/usr/local/bin/fbcp
  362. [Install]
  363. WantedBy=multi-user.target
  364. EOF
  365. }
  366. function uninstall_fbcp() {
  367. uninstall_fbcp_rclocal
  368. # Enable overscan compensation
  369. raspi-config nonint do_overscan 0
  370. # Set up HDMI parameters:
  371. echo "Configuring boot/config.txt for default HDMI"
  372. reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=0"
  373. sed -i -e '/^hdmi_group=2.*$/d' /boot/config.txt
  374. sed -i -e '/^hdmi_mode=87.*$/d' /boot/config.txt
  375. sed -i -e '/^hdmi_cvt=.*$/d' /boot/config.txt
  376. }
  377. function uninstall_fbcp_rclocal() {
  378. # Remove fbcp from /etc/rc.local:
  379. echo "Remove fbcp from /etc/rc.local, if it's there..."
  380. sed -i -e '/^.*fbcp.*$/d' /etc/rc.local
  381. }
  382. function update_xorg() {
  383. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
  384. matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
  385. transform="Option \"TransformationMatrix\" \"${matrix}\""
  386. cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
  387. Section "InputClass"
  388. Identifier "STMPE Touchscreen Calibration"
  389. MatchProduct "stmpe"
  390. MatchDevicePath "/dev/input/event*"
  391. Driver "libinput"
  392. ${transform}
  393. EndSection
  394. EOF
  395. fi
  396. if [ "${pitfttype}" == "28c" ]; then
  397. matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
  398. transform="Option \"TransformationMatrix\" \"${matrix}\""
  399. cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
  400. Section "InputClass"
  401. Identifier "FocalTech Touchscreen Calibration"
  402. MatchProduct "EP0110M09"
  403. MatchDevicePath "/dev/input/event*"
  404. Driver "libinput"
  405. ${transform}
  406. EndSection
  407. EOF
  408. fi
  409. }
  410. ####################################################### MAIN
  411. target_homedir="/home/pi"
  412. clear
  413. echo "This script downloads and installs"
  414. echo "PiTFT Support using userspace touch"
  415. echo "controls and a DTO for display drawing."
  416. echo "one of several configuration files."
  417. echo "Run time of up to 5 minutes. Reboot required!"
  418. echo
  419. echo "Select configuration:"
  420. selectN "PiTFT 2.4\", 2.8\" or 3.2\" resistive (240x320)" \
  421. "PiTFT 2.2\" no touch (240x320)" \
  422. "PiTFT 2.8\" capacitive touch (240x320)" \
  423. "PiTFT 3.5\" resistive touch (320x480)" \
  424. "Braincraft 1.54\" display (240x240)" \
  425. "Quit without installing"
  426. PITFT_SELECT=$?
  427. if [ $PITFT_SELECT -gt 5 ]; then
  428. exit 1
  429. fi
  430. echo "Select rotation:"
  431. selectN "90 degrees (landscape)" \
  432. "180 degrees (portait)" \
  433. "270 degrees (landscape)" \
  434. "0 degrees (portait)"
  435. PITFT_ROTATE=$?
  436. if [ $PITFT_ROTATE -gt 4 ]; then
  437. exit 1
  438. fi
  439. PITFT_ROTATIONS=("90" "180" "270" "0")
  440. PITFT_TYPES=("28r" "22" "28c" "35r" "st7789_240x240")
  441. WIDTH_VALUES=(320 320 320 480 240)
  442. HEIGHT_VALUES=(240 240 240 320 240)
  443. HZ_VALUES=(64000000 64000000 64000000 32000000 64000000)
  444. args=$(getopt -uo 'hvri:o:b:u:' -- $*)
  445. [ $? != 0 ] && print_help
  446. set -- $args
  447. for i
  448. do
  449. case "$i"
  450. in
  451. -h)
  452. print_help
  453. ;;
  454. -v)
  455. print_version
  456. ;;
  457. -u)
  458. target_homedir="$2"
  459. echo "Homedir = ${2}"
  460. shift
  461. shift
  462. ;;
  463. esac
  464. done
  465. # check init system (technique borrowed from raspi-config):
  466. info PITFT 'Checking init system...'
  467. if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
  468. echo "Found systemd"
  469. SYSTEMD=1
  470. elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
  471. echo "Found sysvinit"
  472. SYSTEMD=0
  473. else
  474. bail "Unrecognised init system"
  475. fi
  476. if grep -q boot /proc/mounts; then
  477. echo "/boot is mounted"
  478. else
  479. echo "/boot must be mounted. if you think it's not, quit here and try: sudo mount /dev/mmcblk0p1 /boot"
  480. if ask "Continue?"; then
  481. echo "Proceeding."
  482. else
  483. bail "Aborting."
  484. fi
  485. fi
  486. if [[ ! -e "$target_homedir" || ! -d "$target_homedir" ]]; then
  487. bail "$target_homedir must be an existing directory (use -u /home/foo to specify)"
  488. fi
  489. pitfttype=${PITFT_TYPES[$PITFT_SELECT-1]}
  490. pitftrot=${PITFT_ROTATIONS[$PITFT_ROTATE-1]}
  491. if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ] && [ "${pitfttype}" != "st7789_240x240" ]; then
  492. echo "Type must be one of:"
  493. echo " '28r' (2.8\" resistive, PID 1601)"
  494. echo " '28c' (2.8\" capacitive, PID 1983)"
  495. echo " '35r' (3.5\" Resistive)"
  496. echo " '22' (2.2\" no touch)"
  497. echo " 'st7789_240x240' (1.54\" or 1.3\" no touch)"
  498. echo
  499. print_help
  500. fi
  501. info PITFT "System update"
  502. sysupdate || bail "Unable to apt-get update"
  503. info PITFT "Installing Python libraries & Software..."
  504. softwareinstall || bail "Unable to install software"
  505. info PITFT "Updating /boot/config.txt..."
  506. update_configtxt || bail "Unable to update /boot/config.txt"
  507. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ] || [ "${pitfttype}" == "28c" ] ; then
  508. info PITFT "Updating SysFS rules for Touchscreen..."
  509. update_udev || bail "Unable to update /etc/udev/rules.d"
  510. info PITFT "Updating TSLib default calibration..."
  511. update_pointercal || bail "Unable to update /etc/pointercal"
  512. fi
  513. # ask for console access
  514. if ask "Would you like the console to appear on the PiTFT display?"; then
  515. info PITFT "Updating console to PiTFT..."
  516. uninstall_fbcp || bail "Unable to uninstall fbcp"
  517. install_console || bail "Unable to configure console"
  518. else
  519. info PITFT "Making sure console doesn't use PiTFT"
  520. uninstall_console || bail "Unable to configure console"
  521. if ask "Would you like the HDMI display to mirror to the PiTFT display?"; then
  522. info PITFT "Adding FBCP support..."
  523. install_fbcp || bail "Unable to configure fbcp"
  524. if [ -e /etc/lightdm ]; then
  525. info PITFT "Updating X11 default calibration..."
  526. update_xorg || bail "Unable to update calibration"
  527. fi
  528. fi
  529. fi
  530. #info PITFT "Updating X11 setup tweaks..."
  531. #update_x11profile || bail "Unable to update X11 setup"
  532. #if [ "${pitfttype}" != "35r" ]; then
  533. # # ask for 'on/off' button
  534. # if ask "Would you like GPIO #23 to act as a on/off button?"; then
  535. # info PITFT "Adding GPIO #23 on/off to PiTFT..."
  536. # install_onoffbutton || bail "Unable to add on/off button"
  537. # fi
  538. #fi
  539. # update_bootprefs || bail "Unable to set boot preferences"
  540. info PITFT "Success!"
  541. echo
  542. echo "Settings take effect on next boot."
  543. echo
  544. echo -n "REBOOT NOW? [y/N] "
  545. read
  546. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  547. echo "Exiting without reboot."
  548. exit 0
  549. fi
  550. echo "Reboot started..."
  551. reboot
  552. exit 0