@@ -103,33 +103,33 @@ def savePinModeAlt(self, pin):
103
103
# convert the pin to a string and parse it. Example formats:
104
104
# "Pin(GPIO16, mode=OUT)"
105
105
# "Pin(GPIO16, mode=ALT, alt=SPI)"
106
- pinStr = str (pin )
106
+ pin_str = str (pin )
107
107
108
108
# Extract the "mode" parameter from the pin string
109
- if "mode=" in pinStr :
109
+ try :
110
110
# Split between "mode=" and the next comma or closing parenthesis
111
- modeStr = pinStr . split ("mode=" )[ 1 ]. split ("," )[0 ].split (")" )[0 ]
111
+ mode_str = pin_str [ pin_str . index ("mode=" ) + 5 :]. partition ("," )[0 ].partition (")" )[0 ]
112
112
113
113
# Look up the mode in Pin class dictionary
114
- mode = Pin .__dict__ [modeStr ]
115
- else :
114
+ mode = Pin .__dict__ [mode_str ]
115
+ except ( ValueError , KeyError ) :
116
116
# No mode specified, just set to -1 (default)
117
117
mode = - 1
118
118
119
119
# Extrct the "alt" parameter from the pin string
120
- if "alt=" in pinStr :
120
+ try :
121
121
# Split between "alt=" and the next comma or closing parenthesis
122
- altStr = pinStr . split ("alt=" )[ 1 ]. split ("," )[0 ].split (")" )[0 ]
122
+ alt_str = pin_str [ pin_str . index ("alt=" ) + 4 :]. partition ("," )[0 ].partition (")" )[0 ]
123
123
124
124
# Sometimes the value comes back as a number instead of a valid
125
125
# "ALT_xyz" string, so we need to check it
126
- if "ALT_" + altStr in Pin .__dict__ :
126
+ if "ALT_" + alt_str in Pin .__dict__ :
127
127
# Look up the alt in Pin class dictionary (with "ALT_" prefix)
128
- alt = Pin .__dict__ ["ALT_" + altStr ]
128
+ alt = Pin .__dict__ ["ALT_" + alt_str ]
129
129
else :
130
130
# Convert the altStr to an integer
131
- alt = int (altStr )
132
- else :
131
+ alt = int (alt_str )
132
+ except ( ValueError , KeyError ) :
133
133
# No alt specified, just set to -1 (default)
134
134
alt = - 1
135
135
0 commit comments