mirror of
https://github.com/pinout-xyz/Pinout.xyz.git
synced 2024-11-08 17:47:04 +00:00
32 lines
604 B
Python
32 lines
604 B
Python
import json
|
|
import sys
|
|
|
|
|
|
db = json.load(open('pi-pinout.db'))
|
|
|
|
|
|
def from_phys(phys, mode="bcm"):
|
|
pin = db['pins'][str(phys)]
|
|
if 'scheme' in pin:
|
|
if mode in pin['scheme']:
|
|
return int(pin['scheme'][mode])
|
|
return None
|
|
|
|
|
|
def to_phys(pin, mode="bcm"):
|
|
for pin in db['pins']:
|
|
if 'scheme' in db['pins'][pin]:
|
|
if mode in db['pins'][pin]['scheme']:
|
|
return int(pin)
|
|
return None
|
|
|
|
|
|
pin = int(sys.argv[1])
|
|
|
|
mode = 'bcm'
|
|
|
|
if len(sys.argv) > 2:
|
|
mode = sys.argv[2]
|
|
|
|
print("Pin {} is {}: {}".format(pin, mode.upper(), from_phys(pin, mode)))
|