Skip to content

Commit

Permalink
Merge pull request #281 from makermelissa/main
Browse files Browse the repository at this point in the history
Allow 'disabled' to be passed in via command line in spi-reassign script
  • Loading branch information
makermelissa authored Dec 22, 2023
2 parents 4663279 + f5cfbca commit 30b4c74
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions raspi-spi-reassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@
def valid_pins(ce0_pin, ce1_pin):
if ce0_pin is None and ce1_pin is not None:
return False
if ce0_pin == ce1_pin:
if ce0_pin is not None and ce0_pin == ce1_pin:
return False
if int(ce0_pin) not in allowed_gpios:
if ce0_pin is not None and int(ce0_pin) not in allowed_gpios:
return False
if int(ce1_pin) not in allowed_gpios:
if ce1_pin is not None and int(ce1_pin) not in allowed_gpios:
return False
return True

def convert_option(pin):
if pin == "disabled":
return None
return int(pin)

def valid_options(ce0_option, ce1_option):
if ce0_option is None or ce1_option is None:
return False
return valid_pins(convert_option(ce0_option), convert_option(ce1_option))

def disable_spi():
print("Disabling SPI")
shell.run_command("sudo raspi-config nonint do_spi 1")
Expand Down Expand Up @@ -78,16 +88,18 @@ def write_new_custom(ce0_pin, ce1_pin):
shell.write_text_file(f"{boot_dir}/config.txt", overlay_command + "\n")

@click.command()
@click.option('--ce0', nargs=1, default=None, help="Specify a GPIO for CE0")
@click.option('--ce1', nargs=1, default=None, help="Specify a GPIO for CE1")
@click.option('--ce0', nargs=1, default=None, help="Specify a GPIO for CE0 or 'disabled' to disable", type=str)
@click.option('--ce1', nargs=1, default=None, help="Specify a GPIO for CE1 or 'disabled' to disable", type=str)
@click.option('--reboot', nargs=1, default=None, type=click.Choice(['yes', 'no']), help="Specify whether to reboot after the script is finished")
def main(ce0, ce1, reboot):
ask_reboot = True
auto_reboot = False
if reboot is not None:
ask_reboot = False
auto_reboot = reboot.lower() == 'yes'
if valid_pins(ce0, ce1):
if valid_options(ce0, ce1):
ce0 = convert_option(ce0)
ce1 = convert_option(ce1)
remove_custom()
write_new_custom(ce0, ce1)
if auto_reboot:
Expand Down

0 comments on commit 30b4c74

Please sign in to comment.