Skip to content

Commit 827d003

Browse files
committed
【更新】获取 pin 号函数
1 parent 7468551 commit 827d003

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

examples/stm32l4_pandora/get_pin_num.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,13 @@ def get_pin_num(pin_index):
1414
"""
1515

1616
if pin_index[0] != 'P':
17-
print("ERROR : Please pass in the correct parameters")
17+
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE11")
1818
return
1919

20-
if pin_index[1] == 'A':
21-
pin_num = pin_index[2:]
22-
elif pin_index[1] == 'B':
23-
pin_num = (16 + int(pin_index[2:]))
24-
elif pin_index[1] == 'C':
25-
pin_num = (32 + int(pin_index[2:]))
26-
elif pin_index[1] == 'D':
27-
pin_num = (48 + int(pin_index[2:]))
28-
elif pin_index[1] == 'E':
29-
pin_num = (64 + int(pin_index[2:]))
30-
elif pin_index[1] == 'F':
31-
pin_num = (80 + int(pin_index[2:]))
32-
elif pin_index[1] == 'G':
33-
pin_num = (96 + int(pin_index[2:]))
34-
elif pin_index[1] == 'H':
35-
pin_num = (112 + int(pin_index[2:]))
36-
elif pin_index[1] == 'I':
37-
pin_num = (128 + int(pin_index[2:]))
38-
elif pin_index[1] == 'J':
39-
pin_num = (144 + int(pin_index[2:]))
40-
elif pin_index[1] == 'K':
41-
pin_num = (160 + int(pin_index[2:]))
20+
if not pin_index[1].isupper():
21+
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE11")
22+
return
4223

43-
return pin_num
24+
return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:])
4425

45-
pin_num = get_pin_num("PE11") # Get the pin number for PE11
46-
print(pin_num)
26+
print(get_pin_num("PE11")) # Get the pin number for PE11

0 commit comments

Comments
 (0)