port more functions in from pitftupdater

This commit is contained in:
Brennen Bearnes 2015-02-09 11:15:36 -07:00
parent 69ea86a50a
commit 84a3563cbf

View file

@ -2,82 +2,116 @@
set -e
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
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
}
function update_etcmodules() {
if grep -xq "spi-bcm2708" "/etc/modules" ; then
echo "Already had spi-bcm2708"
else
echo "Adding spi-bcm2708"
echo 'spi-bcm2708' >> /etc/modules
fi
if grep -xq "spi-bcm2708" "/etc/modules" ; then
echo "Already had spi-bcm2708"
else
echo "Adding spi-bcm2708"
echo 'spi-bcm2708' >> /etc/modules
fi
if [ "${pitfttype}" == "28c" ]
then
if grep -xq "i2c-bcm2708" "/etc/modules" ; then
echo "Already had i2c-bcm2708"
else
echo "Adding i2c-bcm2708"
echo 'i2c-bcm2708' >> /etc/modules
fi
fi
if [ "${pitfttype}" == "28c" ] ; then
if grep -xq "i2c-bcm2708" "/etc/modules" ; then
echo "Already had i2c-bcm2708"
else
echo "Adding i2c-bcm2708"
echo 'i2c-bcm2708' >> /etc/modules
fi
fi
if grep -xq "fbtft_device" "${chr}/etc/modules" ; then
echo "Already had fbtft_device"
else
echo "Adding fbtft_device"
echo 'fbtft_device' >> /etc/modules
fi
if grep -xq "fbtft_device" "${chr}/etc/modules" ; then
echo "Already had fbtft_device"
else
echo "Adding fbtft_device"
echo 'fbtft_device' >> /etc/modules
fi
}
function update_adafruitconf() {
if [ "${pitfttype}" == "22" ]
then
cat > /etc/modprobe.d/adafruit.conf <<EOF
if [ "${pitfttype}" == "22" ] ; then
cat > /etc/modprobe.d/adafruit.conf <<EOF
options fbtft_device name=adafruit22a gpios=dc:25 rotate=270 frequency=32000000
EOF
fi
if [ "${pitfttype}" == "28r" ]
then
cat > /etc/modprobe.d/adafruit.conf <<EOF
fi
if [ "${pitfttype}" == "28r" ] ; then
cat > /etc/modprobe.d/adafruit.conf <<EOF
options fbtft_device name=adafruitrt28 rotate=90 frequency=32000000
EOF
fi
fi
if [ "${pitfttype}" == "28c" ]
then
cat > /etc/modprobe.d/adafruit.conf <<EOF
if [ "${pitfttype}" == "28c" ] ; then
cat > /etc/modprobe.d/adafruit.conf <<EOF
options fbtft_device name=adafruitct28 rotate=90 frequency=32000000
EOF
fi
fi
if [ "${pitfttype}" == "35r" ]
then
cat > /etc/modprobe.d/adafruit.conf <<EOF
if [ "${pitfttype}" == "35r" ] ; then
cat > /etc/modprobe.d/adafruit.conf <<EOF
options fbtft_device name=adafruitrt35 rotate=90 frequency=32000000
EOF
fi
fi
}
# currently for '90' rotation only
function update_xorg() {
mkdir -p /etc/X11/xorg.conf.d
mkdir -p /etc/X11/xorg.conf.d
if [ "${pitfttype}" == "28r" ]
then
cat > /etc/X11/xorg.conf.d/99-calibration.conf <<EOF
if [ "${pitfttype}" == "28r" ] ; then
cat > /etc/X11/xorg.conf.d/99-calibration.conf <<EOF
Section "InputClass"
Identifier "calibration"
MatchProduct "stmpe-ts"
@ -85,11 +119,10 @@ Section "InputClass"
Option "SwapAxes" "1"
EndSection
EOF
fi
fi
if [ "${pitfttype}" == "35r" ]
then
cat > /etc/X11/xorg.conf.d/99-calibration.conf <<EOF
if [ "${pitfttype}" == "35r" ] ; then
cat > /etc/X11/xorg.conf.d/99-calibration.conf <<EOF
Section "InputClass"
Identifier "calibration"
MatchProduct "stmpe-ts"
@ -97,11 +130,10 @@ Section "InputClass"
Option "SwapAxes" "1"
EndSection
EOF
fi
fi
if [ "${pitfttype}" == "28c" ]
then
cat > /etc/X11/xorg.conf.d/99-calibration.conf <<EOF
if [ "${pitfttype}" == "28c" ] ; then
cat > /etc/X11/xorg.conf.d/99-calibration.conf <<EOF
Section "InputClass"
Identifier "captouch"
MatchProduct "ft6x06_ts"
@ -110,39 +142,127 @@ Section "InputClass"
Option "Calibration" "0 320 0 240"
EndSection
EOF
fi
fi
}
function update_x11profile() {
fbturbo_path="/usr/share/X11/xorg.conf.d/99-fbturbo.conf"
if [ -e $fbturbo_path ] ; then
echo "Moving ${fbturbo_path} to /home/pi/"
mv $fbturbo_path /home/pi
fi
fbturbo_path="/usr/share/X11/xorg.conf.d/99-fbturbo.conf"
if [ -e $fbturbo_path ] ; then
echo "Moving ${fbturbo_path} to /home/pi/"
mv $fbturbo_path /home/pi
fi
if grep -xq "export FRAMEBUFFER=/dev/fb1" "/home/pi/.profile" ; then
echo "Already had 'export FRAMEBUFFER=/dev/fb1'"
else
echo "Adding 'export FRAMEBUFFER=/dev/fb1'"
cat >> /home/pi/.profile <<EOF
if grep -xq "export FRAMEBUFFER=/dev/fb1" "/home/pi/.profile" ; then
echo "Already had 'export FRAMEBUFFER=/dev/fb1'"
else
echo "Adding 'export FRAMEBUFFER=/dev/fb1'"
cat >> /home/pi/.profile <<EOF
export FRAMEBUFFER=/dev/fb1
EOF
fi
fi
}
# currently for '90' rotation only
function update_pointercal() {
if [ "${pitfttype}" == "28r" ]; then
cat > /etc/pointercal <<EOF
-30 -5902 22077792 4360 -105 -1038814 65536
EOF
fi
if [ "${pitfttype}" == "35r" ]; then
cat > /etc/pointercal <<EOF
8 -8432 32432138 5699 -112 -965922 65536
EOF
fi
if [ "${pitfttype}" == "28c" ]; then
cat > /etc/pointercal <<EOF
320 65536 0 -65536 0 15728640 65536
EOF
fi
}
function update_udev() {
if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
cat > /etc/udev/rules.d/95-stmpe.rules <<EOF
SUBSYSTEM=="input", ATTRS{name}=="stmpe-ts", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
EOF
fi
if [ "${pitfttype}" == "28c" ]; then
cat > /etc/udev/rules.d/95-ft6206.rules <<EOF
SUBSYSTEM=="input", ATTRS{name}=="ft6x06_ts", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
EOF
fi
}
function install_console() {
sudo sed -i 's/rootwait$/rootwait fbcon=map:10 fbcon=font:VGA8x8/g' "/boot/cmdline.txt"
sudo sed -i 's/BLANK_TIME=.*/BLANK_TIME=0/g' "/etc/kbd/config"
}
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 <<EOF
rpi_power_switch
EOF
fi
echo "Adding rpi_power_switch config to /etc/modprobe.d/adafruit.conf"
if grep -xq "options rpi_power_switch gpio_pin=23 mode=0" "${chr}/etc/modprobe.d/adafruit.conf" ; then
echo "Already had rpi_power_switch config"
else
echo "Adding rpi_power_switch"
cat >> /etc/modprobe.d/adafruit.conf <<EOF
options rpi_power_switch gpio_pin=23 mode=0
EOF
fi
}
# MAIN
# TODO:
# TODO: re-parameterize this
pitfttype="28r"
if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ]
then
echo "Type must be '28r' (2.8\" resistive, PID 1601) or '28c' (2.8\" capacitive, PID 1983) or '35r' (3.5\" Resistive) or '22' (2.2\" no touch)"
print_help
echo "Type must be '28r' (2.8\" resistive, PID 1601) or '28c' (2.8\" capacitive, PID 1983) or '35r' (3.5\" Resistive) or '22' (2.2\" no touch)"
# print_help
fi
info PITFT "Updating /etc/modules..."
update_etcmodules || bail "Unable to update /etc/modules"
info PITFT "Updating /etc/modprobe.d/adafruit.conf..."
update_adafruitconf || bail "Unable to update /etc/modprobe.d/adafruit.conf"
info PITFT "Updating X11 default calibration..."
update_xorg || bail "Unable to update /etc/X11/xorg.conf.d/99-calibration.conf"
info PITFT "Updating X11 setup tweaks..."
update_x11profile || bail "Unable to update X11 setup"
info PITFT "Updating TSLib default calibration..."
update_pointercal || bail "Unable to update /etc/pointercal"
info PITFT "Updating SysFS rules for Touchscreen..."
update_udev || bail "Unable to update /etc/udev/rules.d"
# ask for console access?
if ask "Would you like the console to appear on the PiTFT display?"; then
info PITFT "Updating console to PiTFT..."
install_console || bail "Unable to configure console"
fi
if [ "${pitfttype}" != "35r" ]; then
# ask for 'on/off' button
if ask "Would you like GPIO #23 to act as a on/off button?"; then
info PITFT "Adding GPIO #23 on/off to PiTFT..."
install_onoffbutton || bail "Unable to add on/off button"
fi
fi