|
23 | 23 | """
|
24 | 24 |
|
25 | 25 | import sys
|
| 26 | +import argparse |
26 | 27 | import adafruit_platformdetect
|
27 | 28 | from adafruit_platformdetect.revcodes import PiDecoder
|
28 | 29 |
|
29 | 30 | detector = adafruit_platformdetect.Detector()
|
30 |
| -pi_rev_code = detector.board._pi_rev_code() # pylint: disable=protected-access |
31 |
| - |
32 |
| -if pi_rev_code is None: |
33 |
| - print("Raspberry Pi not detected. Using interactive mode") |
34 |
| - pi_rev_code = input("Enter a Raspberry Pi revision code (e.g. d03114 or 000f): ") |
35 |
| - |
36 |
| -try: |
37 |
| - decoder = PiDecoder(pi_rev_code) |
38 |
| -except ValueError as e: |
39 |
| - print("Invalid revision code. It should be a hexadecimal value.") |
40 |
| - sys.exit(1) |
41 |
| - |
42 |
| -if not decoder.is_valid_code(): |
43 |
| - print( |
44 |
| - "Code is invalid. This rev code includes at least one " |
45 |
| - "value that is outside of the expected range." |
46 |
| - ) |
47 |
| - sys.exit(1) |
| 31 | +parser = argparse.ArgumentParser() |
48 | 32 |
|
49 | 33 |
|
50 | 34 | def print_property(label, value):
|
51 |
| - "Format and print a property" |
| 35 | + """Format and print a property""" |
52 | 36 | print(f"{label}: {value}")
|
53 | 37 |
|
54 | 38 |
|
55 |
| -if decoder.is_new_format(): |
56 |
| - print_property("Overvoltage", decoder.overvoltage) |
57 |
| - print_property("OTP Program", decoder.otp_program) |
58 |
| - print_property("OTP Read", decoder.otp_read) |
59 |
| - print_property("Warranty bit", decoder.warranty_bit) |
60 |
| - print_property("New flag", decoder.rev_style) |
61 |
| - print_property("Memory size", decoder.memory_size) |
62 |
| - print_property("Manufacturer", decoder.manufacturer) |
63 |
| - print_property("Processor", decoder.processor) |
64 |
| - print_property("Type", decoder.type) |
65 |
| - print_property("Revision", decoder.revision) |
66 |
| -else: |
67 |
| - print_property("Warranty bit", decoder.warranty_bit) |
68 |
| - print_property("Model", decoder.type) |
69 |
| - print_property("Revision", decoder.revision) |
70 |
| - print_property("RAM", decoder.memory_size) |
71 |
| - print_property("Manufacturer", decoder.manufacturer) |
| 39 | +def main(interactive): |
| 40 | + """Run the program""" |
| 41 | + pi_rev_code = detector.board._pi_rev_code() # pylint: disable=protected-access |
| 42 | + |
| 43 | + if pi_rev_code is None: |
| 44 | + print("Raspberry Pi not detected. Using interactive mode") |
| 45 | + |
| 46 | + if pi_rev_code is None or interactive: |
| 47 | + pi_rev_code = input( |
| 48 | + "Enter a Raspberry Pi revision code (e.g. d03114 or 000f): " |
| 49 | + ) |
| 50 | + |
| 51 | + print_property("Revision Code", pi_rev_code) |
| 52 | + |
| 53 | + try: |
| 54 | + decoder = PiDecoder(pi_rev_code) |
| 55 | + except ValueError: |
| 56 | + print("Invalid revision code. It should be a hexadecimal value.") |
| 57 | + sys.exit(1) |
| 58 | + |
| 59 | + if not decoder.is_valid_code(): |
| 60 | + print( |
| 61 | + "Code is invalid. This rev code includes at least one " |
| 62 | + "value that is outside of the expected range." |
| 63 | + ) |
| 64 | + sys.exit(1) |
| 65 | + |
| 66 | + if decoder.is_new_format(): |
| 67 | + print_property("Overvoltage", decoder.overvoltage) |
| 68 | + print_property("OTP Program", decoder.otp_program) |
| 69 | + print_property("OTP Read", decoder.otp_read) |
| 70 | + print_property("Warranty bit", decoder.warranty_bit) |
| 71 | + print_property("New flag", decoder.rev_style) |
| 72 | + print_property("Memory size", decoder.memory_size) |
| 73 | + print_property("Manufacturer", decoder.manufacturer) |
| 74 | + print_property("Processor", decoder.processor) |
| 75 | + print_property("Type", decoder.type) |
| 76 | + print_property("Revision", decoder.revision) |
| 77 | + else: |
| 78 | + print_property("Warranty bit", decoder.warranty_bit) |
| 79 | + print_property("Model", decoder.type) |
| 80 | + print_property("Revision", decoder.revision) |
| 81 | + print_property("RAM", decoder.memory_size) |
| 82 | + print_property("Manufacturer", decoder.manufacturer) |
| 83 | + |
| 84 | + |
| 85 | +# Main function |
| 86 | +if __name__ == "__main__": |
| 87 | + parser.add_argument( |
| 88 | + "-i", "--interactive", help="Interactive Mode", action="store_true" |
| 89 | + ) |
| 90 | + args = parser.parse_args() |
| 91 | + main(args.interactive) |
0 commit comments