From aef5f7bdb64d4f178a4d66336c9ebd159d9f7994 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 26 Jan 2021 13:20:46 -0800 Subject: [PATCH] Moved converted scripts and converted joy-bonnet --- .../adafruit-pitft.sh | 0 .../adafruit_fanservice.sh | 0 .../i2smic.sh | 0 joy-bonnet.py | 119 ++++++++++++++++++ 4 files changed, 119 insertions(+) rename adafruit-pitft.sh => converted_shell_scripts/adafruit-pitft.sh (100%) rename adafruit_fanservice.sh => converted_shell_scripts/adafruit_fanservice.sh (100%) rename i2smic.sh => converted_shell_scripts/i2smic.sh (100%) create mode 100755 joy-bonnet.py diff --git a/adafruit-pitft.sh b/converted_shell_scripts/adafruit-pitft.sh similarity index 100% rename from adafruit-pitft.sh rename to converted_shell_scripts/adafruit-pitft.sh diff --git a/adafruit_fanservice.sh b/converted_shell_scripts/adafruit_fanservice.sh similarity index 100% rename from adafruit_fanservice.sh rename to converted_shell_scripts/adafruit_fanservice.sh diff --git a/i2smic.sh b/converted_shell_scripts/i2smic.sh similarity index 100% rename from i2smic.sh rename to converted_shell_scripts/i2smic.sh diff --git a/joy-bonnet.py b/joy-bonnet.py new file mode 100755 index 0000000..fe59c88 --- /dev/null +++ b/joy-bonnet.py @@ -0,0 +1,119 @@ +try: + from adafruit_shell import Shell +except ImportError: + raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell") + +shell = Shell() +shell.group = "JOY" + +def main(): + shell.clear() + print("""This script installs software for the Adafruit +Joy Bonnet for Raspberry Pi. Steps include: +- Update package index files (apt-get update). +- Install Python libraries: smbus, evdev. +- Install joyBonnet.py in /boot and + configure /etc/rc.local to auto-start script. +- Enable I2C bus. +- OPTIONAL: disable overscan. +Run time ~10 minutes. Reboot required. +EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN. +""") + if not shell.prompt("CONTINUE?", default='n'): + print("Canceled.") + shell.exit() + print("Continuing...") + disable_overscan = shell.prompt("Disable overscan?", default='n') + install_halt = shell.prompt("Install GPIO-halt utility?", default='n') + if install_halt: + #halt_pin = shell.prompt("Install GPIO-halt utility?" + halt_pin = input("GPIO pin for halt: ").strip() + print("\n") + if disable_overscan: + print("Overscan: disable.") + else: + print("Overscan: keep current setting.") + + if install_halt: + print("Install GPIO-halt: YES (GPIO{})".format(halt_pin)) + else: + print("Install GPIO-halt: NO") + + if not shell.prompt("CONTINUE?", default='n'): + print("Canceled.") + shell.exit() + + # START INSTALL ------------------------------------------------------------ + # All selections are validated at this point... + + print(""" +Starting installation... +Updating package index files...""") + shell.run_command('sudo apt-get update', True) + + print("Installing Python libraries...") + shell.run_command('sudo apt-get install -y python3-pip python3-dev python3-smbus') + shell.run_command('pip3 install evdev --upgrade') + + print("Installing Adafruit code in /boot...") + shell.chdir("/tmp") + shell.run_command("curl -LO https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/joyBonnet.py") + # Moving between filesystems requires copy-and-delete: + shell.copy("joyBonnet.py", "/boot") + shell.remove("joyBonnet.py") + if install_halt: + print("Installing gpio-halt in /usr/local/bin...") + shell.run_command("curl -LO https://github.com/adafruit/Adafruit-GPIO-Halt/archive/master.zip") + shell.run_command("unzip -u master.zip") + shell.chdir("Adafruit-GPIO-Halt-master") + shell.run_command("make") + shell.move("gpio-halt", "/usr/local/bin") + shell.chdir("..") + shell.remove("Adafruit-GPIO-Halt-master") + + # CONFIG ------------------------------------------------------------------- + + print("Configuring system...") + + # Enable I2C using raspi-config + shell.run_command("sudo raspi-config nonint do_i2c 0") + + # Disable overscan compensation (use full screen): + if disable_overscan: + shell.run_command("sudo raspi-config nonint do_overscan 1") + + if install_halt: + if shell.pattern_search("/etc/rc.local", "gpio-halt"): + # gpio-halt already in rc.local, but make sure correct: + shell.pattern_replace("/etc/rc.local", "^.*gpio-halt.*$", "/usr/local/bin/gpio-halt {} &".format(halt_pin)) + else: + # Insert gpio-halt into rc.local before final 'exit 0' + shell.pattern_replace("/etc/rc.local", "^exit 0", "/usr/local/bin/gpio-halt {} &\\nexit 0".format(halt_pin)) + + # Auto-start joyBonnet.py on boot + if shell.pattern_search("/etc/rc.local", "joyBonnet.py"): + # joyBonnet.py already in rc.local, but make sure correct: + shell.pattern_replace("/etc/rc.local", "^.*joyBonnet.py.*$", "cd /boot;python3 joyBonnet.py &") + else: + # Insert joyBonnet.py into rc.local before final 'exit 0' + shell.pattern_replace("/etc/rc.local", "^exit 0", "cd /boot;python3 joyBonnet.py &\\nexit 0") + + # Add udev rule (will overwrite if present) + shell.write_text_file("/etc/udev/rules.d/10-retrogame.rules", "SUBSYSTEM==\"input\", ATTRS{name}==\"retrogame\", ENV{ID_INPUT_KEYBOARD}=\"1\"", append=False) + + # PROMPT FOR REBOOT -------------------------------------------------------- + print("""DONE. + +Settings take effect on next boot. +""") + if not shell.prompt("REBOOT NOW?", default="n"): + print("Exiting without reboot.") + shell.exit() + print("Reboot started...") + shell.reboot() + shell.exit() + +# Main function +if __name__ == "__main__": + shell.require_root() + main()