#!/usr/bin/env bash set -e function print_version() { echo "Adafruit PiTFT Helper v0.5.0" exit 1 } function print_help() { echo "Usage: $0 -t [pitfttype]" echo " -h Print this help" echo " -v Print version information" echo " -u [homedir] Specify path of primary user's home directory (defaults to /home/pi)" echo " -t [type] Specify the type of PiTFT: '28r' (PID 1601) or '28c' (PID 1983) or '35r' or '22'" echo echo "You must specify a type of display." exit 1 } group=ADAFRUIT function info() { system="$1" group="${system}" shift FG="1;32m" BG="40m" echo -e "[\033[${FG}\033[${BG}${system}\033[0m] $*" } function bail() { FG="1;31m" BG="40m" echo -en "[\033[${FG}\033[${BG}${group}\033[0m] " if [ -z "$1" ]; then echo "Exiting due to error" else echo "Exiting due to error: $*" fi exit 1 } function ask() { # http://djm.me/ask while true; do if [ "${2:-}" = "Y" ]; then prompt="Y/n" default=Y elif [ "${2:-}" = "N" ]; then prompt="y/N" default=N else prompt="y/n" default= fi # Ask the question read -p "$1 [$prompt] " REPLY # Default? if [ -z "$REPLY" ]; then REPLY=$default fi # Check if the reply is valid case "$REPLY" in Y*|y*) return 0 ;; N*|n*) return 1 ;; esac done } # update /boot/config.txt with appropriate values function update_configtxt() { if grep -q "adafruit-pitft-helper" "/boot/config.txt"; then echo "Already have an adafruit-pitft-helper section in /boot/config.txt." echo "Adding new section, but please run:" echo "sudo nano /boot/config.txt" echo "...and remove any duplicate sections." fi if [ "${pitfttype}" == "22" ]; then # formerly: options fbtft_device name=adafruit22a gpios=dc:25 rotate=270 frequency=32000000 overlay="dtoverlay=pitft22,rotate=270,speed=32000000,fps=20" fi if [ "${pitfttype}" == "28r" ]; then overlay="dtoverlay=pitft28r,rotate=90,speed=32000000,fps=20" fi if [ "${pitfttype}" == "28c" ]; then overlay="dtoverlay=pitft28c,rotate=90,speed=32000000,fps=20" fi if [ "${pitfttype}" == "35r" ]; then overlay="dtoverlay=pitft35r,rotate=90,speed=42000000,fps=20" fi date=`date` cat >> /boot/config.txt < /etc/X11/xorg.conf.d/99-calibration.conf < /etc/X11/xorg.conf.d/99-calibration.conf < /etc/X11/xorg.conf.d/99-calibration.conf <> "${target_homedir}.profile" < /etc/pointercal < /etc/pointercal < /etc/pointercal < /etc/udev/rules.d/95-stmpe.rules < /etc/udev/rules.d/95-ft6206.rules <> /etc/modules fi } function install_onoffbutton() { echo "Adding rpi_power_switch to /etc/modules" if grep -xq "rpi_power_switch" "${chr}/etc/modules"; then echo "Already had rpi_power_switch" else echo "Adding rpi_power_switch" cat >> /etc/modules <> /etc/modprobe.d/adafruit.conf <