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 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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.0.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 bc fbi git python-dev python-pip python-smbus python-spidev evtest tslib libts-bin 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
  162. pip install evdev 1> /dev/null || { warning "Pip failed to install software!" && exit 1; }
  163. }
  164. # update /boot/config.txt with appropriate values
  165. function update_configtxt() {
  166. if grep -q "adafruit-pitft-helper" "/boot/config.txt"; then
  167. echo "Already have an adafruit-pitft-helper section in /boot/config.txt."
  168. echo "Removing old section..."
  169. cp /boot/config.txt /boot/configtxt.bak
  170. sed -i -e "/^# --- added by adafruit-pitft-helper/,/^# --- end adafruit-pitft-helper/d" /boot/config.txt
  171. fi
  172. if [ "${pitfttype}" == "22" ]; then
  173. overlay="dtoverlay=pitft22,rotate=${pitftrot},speed=64000000,fps=30"
  174. fi
  175. if [ "${pitfttype}" == "28r" ]; then
  176. overlay="dtoverlay=pitft28-resistive,rotate=${pitftrot},speed=64000000,fps=30"
  177. fi
  178. if [ "${pitfttype}" == "28c" ]; then
  179. overlay="dtoverlay=pitft28-capacitive,rotate=${pitftrot},speed=64000000,fps=30"
  180. fi
  181. if [ "${pitfttype}" == "35r" ]; then
  182. overlay="dtoverlay=pitft35-resistive,rotate=${pitftrot},speed=20000000,fps=20"
  183. fi
  184. date=`date`
  185. cat >> /boot/config.txt <<EOF
  186. # --- added by adafruit-pitft-helper $date ---
  187. dtparam=spi=on
  188. dtparam=i2c1=on
  189. dtparam=i2c_arm=on
  190. $overlay
  191. # --- end adafruit-pitft-helper $date ---
  192. EOF
  193. }
  194. function update_udev() {
  195. cat > /etc/udev/rules.d/95-touchmouse.rules <<EOF
  196. SUBSYSTEM=="input", ATTRS{name}=="touchmouse", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  197. EOF
  198. cat > /etc/udev/rules.d/95-ftcaptouch.rules <<EOF
  199. SUBSYSTEM=="input", ATTRS{name}=="EP0110M09", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  200. EOF
  201. cat > /etc/udev/rules.d/95-stmpe.rules <<EOF
  202. SUBSYSTEM=="input", ATTRS{name}=="*stmpe*", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  203. EOF
  204. }
  205. function update_pointercal() {
  206. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
  207. echo $(eval echo "\$POINTERCAL_$pitfttype$pitftrot") > /etc/pointercal
  208. fi
  209. if [ "${pitfttype}" == "28c" ]; then
  210. echo $(eval echo "\$POINTERCAL_$pitfttype") > /etc/pointercal
  211. fi
  212. }
  213. function install_console() {
  214. echo "Set up main console turn on"
  215. if ! grep -q 'fbcon=map:10 fbcon=font:VGA8x8' /boot/cmdline.txt; then
  216. echo "Updating /boot/cmdline.txt"
  217. sed -i 's/rootwait/rootwait fbcon=map:10 fbcon=font:VGA8x8/g' "/boot/cmdline.txt"
  218. else
  219. echo "/boot/cmdline.txt already updated"
  220. fi
  221. echo "Turning off console blanking"
  222. # pre-stretch this is what you'd do:
  223. if [ -e /etc/kbd/config ]; then
  224. sed -i 's/BLANK_TIME=.*/BLANK_TIME=0/g' "/etc/kbd/config"
  225. fi
  226. # as of stretch....
  227. # removing any old version
  228. sed -i -e '/^# disable console blanking.*/d' /etc/rc.local
  229. sed -i -e '/^sudo sh -c "TERM=linux setterm -blank.*/d' /etc/rc.local
  230. 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
  231. reconfig /etc/default/console-setup "^.*FONTFACE.*$" "FONTFACE=\"Terminus\""
  232. reconfig /etc/default/console-setup "^.*FONTSIZE.*$" "FONTSIZE=\"6x12\""
  233. echo "Setting raspi-config to boot to console w/o login..."
  234. (cd "$target_homedir" && raspi-config nonint do_boot_behaviour B2)
  235. # remove fbcp
  236. sed -i -e "/^.*fbcp.*$/d" /etc/rc.local
  237. }
  238. function uninstall_console() {
  239. echo "Removing console fbcon map from /boot/cmdline.txt"
  240. sed -i 's/rootwait fbcon=map:10 fbcon=font:VGA8x8/rootwait/g' "/boot/cmdline.txt"
  241. echo "Screen blanking time reset to 10 minutes"
  242. if [ -e "/etc/kbd/config" ]; then
  243. sed -i 's/BLANK_TIME=0/BLANK_TIME=10/g' "/etc/kbd/config"
  244. fi
  245. sed -i -e '/^# disable console blanking.*/d' /etc/rc.local
  246. sed -i -e '/^sudo sh -c "TERM=linux.*/d' /etc/rc.local
  247. }
  248. function install_fbcp() {
  249. echo "Installing cmake..."
  250. apt-get --yes --force-yes install cmake 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
  251. echo "Downloading rpi-fbcp..."
  252. cd /tmp
  253. #curl -sLO https://github.com/tasanakorn/rpi-fbcp/archive/master.zip
  254. curl -sLO https://github.com/adafruit/rpi-fbcp/archive/master.zip
  255. echo "Uncompressing rpi-fbcp..."
  256. rm -rf /tmp/rpi-fbcp-master
  257. unzip master.zip 1> /dev/null || { warning "Failed to uncompress fbcp!" && exit 1; }
  258. cd rpi-fbcp-master
  259. mkdir build
  260. cd build
  261. echo "Building rpi-fbcp..."
  262. echo -e "\nset (CMAKE_C_FLAGS \"-std=gnu99 ${CMAKE_C_FLAGS}\")" >> ../CMakeLists.txt
  263. cmake .. 1> /dev/null || { warning "Failed to cmake fbcp!" && exit 1; }
  264. make 1> /dev/null || { warning "Failed to make fbcp!" && exit 1; }
  265. echo "Installing rpi-fbcp..."
  266. install fbcp /usr/local/bin/fbcp
  267. cd ~
  268. rm -rf /tmp/rpi-fbcp-master
  269. # Start fbcp in the appropriate place, depending on init system:
  270. if [ "$SYSTEMD" == "0" ]; then
  271. # Add fbcp to /etc/rc.local:
  272. echo "We have sysvinit, so add fbcp to /etc/rc.local..."
  273. grep fbcp /etc/rc.local >/dev/null
  274. if [ $? -eq 0 ]; then
  275. # fbcp already in rc.local, but make sure correct:
  276. sed -i "s|^.*fbcp.*$|/usr/local/bin/fbcp \&|g" /etc/rc.local >/dev/null
  277. else
  278. # Insert fbcp into rc.local before final 'exit 0':
  279. sed -i "s|^exit 0|/usr/local/bin/fbcp \&\\nexit 0|g" /etc/rc.local >/dev/null
  280. fi
  281. else
  282. # Install fbcp systemd unit, first making sure it's not in rc.local:
  283. uninstall_fbcp_rclocal
  284. echo "We have systemd, so install fbcp systemd unit..."
  285. install_fbcp_unit || bail "Unable to install fbcp unit file"
  286. sudo systemctl enable fbcp.service
  287. fi
  288. # if there's X11 installed...
  289. if [ -e /etc/lightdm ]; then
  290. echo "Setting raspi-config to boot to desktop w/o login..."
  291. raspi-config nonint do_boot_behaviour B4
  292. fi
  293. # Disable overscan compensation (use full screen):
  294. raspi-config nonint do_overscan 1
  295. # Set up HDMI parameters:
  296. echo "Configuring boot/config.txt for forced HDMI"
  297. reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1"
  298. reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2"
  299. reconfig /boot/config.txt "^.*hdmi_mode.*$" "hdmi_mode=87"
  300. # if there's X11 installed...
  301. if [ -e /etc/lightdm ]; then
  302. if [ "${pitfttype}" == "35r" ]; then
  303. echo "Using x1.5 resolution"
  304. SCALE=1.5
  305. else
  306. echo "Using x2 resolution"
  307. SCALE=2.0
  308. fi
  309. else
  310. echo "Using native resolution"
  311. SCALE=1
  312. fi
  313. WIDTH=`python -c "print(int(${WIDTH_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
  314. HEIGHT=`python -c "print(int(${HEIGHT_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
  315. reconfig /boot/config.txt "^.*hdmi_cvt.*$" "hdmi_cvt=${WIDTH} ${HEIGHT} 60 1 0 0 0"
  316. if [ "${pitftrot}" == "90" ] || [ "${pitftrot}" == "270" ]; then
  317. # dont rotate HDMI on 90 or 270
  318. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" ""
  319. fi
  320. if [ "${pitftrot}" == "0" ]; then
  321. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=1"
  322. # this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
  323. pitftrot=90
  324. update_configtxt || bail "Unable to update /boot/config.txt"
  325. pitftrot=0
  326. fi
  327. if [ "${pitftrot}" == "180" ]; then
  328. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=3"
  329. # this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
  330. pitftrot=90
  331. update_configtxt || bail "Unable to update /boot/config.txt"
  332. pitftrot=180
  333. fi
  334. }
  335. function install_fbcp_unit() {
  336. cat > /etc/systemd/system/fbcp.service <<EOF
  337. [Unit]
  338. Description=Framebuffer copy utility for PiTFT
  339. After=network.target
  340. [Service]
  341. Type=simple
  342. ExecStartPre=/bin/sleep 10
  343. ExecStart=/usr/local/bin/fbcp
  344. [Install]
  345. WantedBy=multi-user.target
  346. EOF
  347. }
  348. function uninstall_fbcp() {
  349. uninstall_fbcp_rclocal
  350. # Enable overscan compensation
  351. raspi-config nonint do_overscan 0
  352. # Set up HDMI parameters:
  353. echo "Configuring boot/config.txt for default HDMI"
  354. reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=0"
  355. sed -i -e '/^hdmi_group=2.*$/d' /boot/config.txt
  356. sed -i -e '/^hdmi_mode=87.*$/d' /boot/config.txt
  357. sed -i -e '/^hdmi_cvt=.*$/d' /boot/config.txt
  358. }
  359. function uninstall_fbcp_rclocal() {
  360. # Remove fbcp from /etc/rc.local:
  361. echo "Remove fbcp from /etc/rc.local, if it's there..."
  362. sed -i -e '/^.*fbcp.*$/d' /etc/rc.local
  363. }
  364. function update_xorg() {
  365. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
  366. matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
  367. transform="Option \"TransformationMatrix\" \"${matrix}\""
  368. cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
  369. Section "InputClass"
  370. Identifier "STMPE Touchscreen Calibration"
  371. MatchProduct "stmpe"
  372. MatchDevicePath "/dev/input/event*"
  373. Driver "libinput"
  374. ${transform}
  375. EndSection
  376. EOF
  377. fi
  378. if [ "${pitfttype}" == "28c" ]; then
  379. matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
  380. transform="Option \"TransformationMatrix\" \"${matrix}\""
  381. cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
  382. Section "InputClass"
  383. Identifier "FocalTech Touchscreen Calibration"
  384. MatchProduct "EP0110M09"
  385. MatchDevicePath "/dev/input/event*"
  386. Driver "libinput"
  387. ${transform}
  388. EndSection
  389. EOF
  390. fi
  391. }
  392. ####################################################### MAIN
  393. target_homedir="/home/pi"
  394. clear
  395. echo "This script downloads and installs"
  396. echo "PiTFT Support using userspace touch"
  397. echo "controls and a DTO for display drawing."
  398. echo "one of several configuration files."
  399. echo "Run time of up to 5 minutes. Reboot required!"
  400. echo
  401. echo "Select configuration:"
  402. selectN "PiTFT 2.4\", 2.8\" or 3.2\" resistive (240x320)" \
  403. "PiTFT 2.2\" no touch (240x320)" \
  404. "PiTFT 2.8\" capacitive touch (240x320)" \
  405. "PiTFT 3.5\" resistive touch (320x480)" \
  406. "Quit without installing"
  407. PITFT_SELECT=$?
  408. if [ $PITFT_SELECT -gt 4 ]; then
  409. exit 1
  410. fi
  411. echo "Select rotation:"
  412. selectN "90 degrees (landscape)" \
  413. "180 degrees (portait)" \
  414. "270 degrees (landscape)" \
  415. "0 degrees (portait)"
  416. PITFT_ROTATE=$?
  417. if [ $PITFT_ROTATE -gt 4 ]; then
  418. exit 1
  419. fi
  420. PITFT_ROTATIONS=("90" "180" "270" "0")
  421. PITFT_TYPES=("28r" "22" "28c" "35r")
  422. WIDTH_VALUES=(320 320 320 480)
  423. HEIGHT_VALUES=(240 240 240 320)
  424. HZ_VALUES=(64000000 64000000 64000000 32000000)
  425. args=$(getopt -uo 'hvri:o:b:u:' -- $*)
  426. [ $? != 0 ] && print_help
  427. set -- $args
  428. for i
  429. do
  430. case "$i"
  431. in
  432. -h)
  433. print_help
  434. ;;
  435. -v)
  436. print_version
  437. ;;
  438. -u)
  439. target_homedir="$2"
  440. echo "Homedir = ${2}"
  441. shift
  442. shift
  443. ;;
  444. esac
  445. done
  446. # check init system (technique borrowed from raspi-config):
  447. info PITFT 'Checking init system...'
  448. if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
  449. echo "Found systemd"
  450. SYSTEMD=1
  451. elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
  452. echo "Found sysvinit"
  453. SYSTEMD=0
  454. else
  455. bail "Unrecognised init system"
  456. fi
  457. if grep -q boot /proc/mounts; then
  458. echo "/boot is mounted"
  459. else
  460. echo "/boot must be mounted. if you think it's not, quit here and try: sudo mount /dev/mmcblk0p1 /boot"
  461. if ask "Continue?"; then
  462. echo "Proceeding."
  463. else
  464. bail "Aborting."
  465. fi
  466. fi
  467. if [[ ! -e "$target_homedir" || ! -d "$target_homedir" ]]; then
  468. bail "$target_homedir must be an existing directory (use -u /home/foo to specify)"
  469. fi
  470. pitfttype=${PITFT_TYPES[$PITFT_SELECT-1]}
  471. pitftrot=${PITFT_ROTATIONS[$PITFT_ROTATE-1]}
  472. if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ]; then
  473. echo "Type must be one of:"
  474. echo " '28r' (2.8\" resistive, PID 1601)"
  475. echo " '28c' (2.8\" capacitive, PID 1983)"
  476. echo " '35r' (3.5\" Resistive)"
  477. echo " '22' (2.2\" no touch)"
  478. echo
  479. print_help
  480. fi
  481. info PITFT "System update"
  482. sysupdate || bail "Unable to apt-get update"
  483. info PITFT "Installing Python libraries & Software..."
  484. softwareinstall || bail "Unable to install software"
  485. info PITFT "Updating /boot/config.txt..."
  486. update_configtxt || bail "Unable to update /boot/config.txt"
  487. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ] || [ "${pitfttype}" == "28c" ] ; then
  488. info PITFT "Updating SysFS rules for Touchscreen..."
  489. update_udev || bail "Unable to update /etc/udev/rules.d"
  490. info PITFT "Updating TSLib default calibration..."
  491. update_pointercal || bail "Unable to update /etc/pointercal"
  492. fi
  493. # ask for console access
  494. if ask "Would you like the console to appear on the PiTFT display?"; then
  495. info PITFT "Updating console to PiTFT..."
  496. uninstall_fbcp || bail "Unable to uninstall fbcp"
  497. install_console || bail "Unable to configure console"
  498. else
  499. info PITFT "Making sure console doesn't use PiTFT"
  500. uninstall_console || bail "Unable to configure console"
  501. if ask "Would you like the HDMI display to mirror to the PiTFT display?"; then
  502. info PITFT "Adding FBCP support..."
  503. install_fbcp || bail "Unable to configure fbcp"
  504. if [ -e /etc/lightdm ]; then
  505. info PITFT "Updating X11 default calibration..."
  506. update_xorg || bail "Unable to update calibration"
  507. fi
  508. fi
  509. fi
  510. #info PITFT "Updating X11 setup tweaks..."
  511. #update_x11profile || bail "Unable to update X11 setup"
  512. #if [ "${pitfttype}" != "35r" ]; then
  513. # # ask for 'on/off' button
  514. # if ask "Would you like GPIO #23 to act as a on/off button?"; then
  515. # info PITFT "Adding GPIO #23 on/off to PiTFT..."
  516. # install_onoffbutton || bail "Unable to add on/off button"
  517. # fi
  518. #fi
  519. # update_bootprefs || bail "Unable to set boot preferences"
  520. info PITFT "Success!"
  521. echo
  522. echo "Settings take effect on next boot."
  523. echo
  524. echo -n "REBOOT NOW? [y/N] "
  525. read
  526. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  527. echo "Exiting without reboot."
  528. exit 0
  529. fi
  530. echo "Reboot started..."
  531. reboot
  532. exit 0