|
31 | 31 | def valid_pins(ce0_pin, ce1_pin):
|
32 | 32 | if ce0_pin is None and ce1_pin is not None:
|
33 | 33 | return False
|
34 |
| - if ce0_pin == ce1_pin: |
| 34 | + if ce0_pin is not None and ce0_pin == ce1_pin: |
35 | 35 | return False
|
36 |
| - if int(ce0_pin) not in allowed_gpios: |
| 36 | + if ce0_pin is not None and int(ce0_pin) not in allowed_gpios: |
37 | 37 | return False
|
38 |
| - if int(ce1_pin) not in allowed_gpios: |
| 38 | + if ce1_pin is not None and int(ce1_pin) not in allowed_gpios: |
39 | 39 | return False
|
40 | 40 | return True
|
41 | 41 |
|
| 42 | +def convert_option(pin): |
| 43 | + if pin == "disabled": |
| 44 | + return None |
| 45 | + return int(pin) |
| 46 | + |
| 47 | +def valid_options(ce0_option, ce1_option): |
| 48 | + if ce0_option is None or ce1_option is None: |
| 49 | + return False |
| 50 | + return valid_pins(convert_option(ce0_option), convert_option(ce1_option)) |
| 51 | + |
42 | 52 | def disable_spi():
|
43 | 53 | print("Disabling SPI")
|
44 | 54 | shell.run_command("sudo raspi-config nonint do_spi 1")
|
@@ -78,16 +88,18 @@ def write_new_custom(ce0_pin, ce1_pin):
|
78 | 88 | shell.write_text_file(f"{boot_dir}/config.txt", overlay_command + "\n")
|
79 | 89 |
|
80 | 90 | @click.command()
|
81 |
| -@click.option('--ce0', nargs=1, default=None, help="Specify a GPIO for CE0") |
82 |
| -@click.option('--ce1', nargs=1, default=None, help="Specify a GPIO for CE1") |
| 91 | +@click.option('--ce0', nargs=1, default=None, help="Specify a GPIO for CE0 or 'disabled' to disable", type=str) |
| 92 | +@click.option('--ce1', nargs=1, default=None, help="Specify a GPIO for CE1 or 'disabled' to disable", type=str) |
83 | 93 | @click.option('--reboot', nargs=1, default=None, type=click.Choice(['yes', 'no']), help="Specify whether to reboot after the script is finished")
|
84 | 94 | def main(ce0, ce1, reboot):
|
85 | 95 | ask_reboot = True
|
86 | 96 | auto_reboot = False
|
87 | 97 | if reboot is not None:
|
88 | 98 | ask_reboot = False
|
89 | 99 | auto_reboot = reboot.lower() == 'yes'
|
90 |
| - if valid_pins(ce0, ce1): |
| 100 | + if valid_options(ce0, ce1): |
| 101 | + ce0 = convert_option(ce0) |
| 102 | + ce1 = convert_option(ce1) |
91 | 103 | remove_custom()
|
92 | 104 | write_new_custom(ce0, ce1)
|
93 | 105 | if auto_reboot:
|
|
0 commit comments