Refactor pin initialization in MFRC522
class
- Raise error for invalid pin type for `rst` or `cs` if not `int` or `Pin` instance - Set `self.rst` based on `rst` type - Set `self.cs` based on `cs` type
This commit is contained in:
parent
b3937dd93c
commit
b1baecaf09
1 changed files with 9 additions and 1 deletions
10
mfrc522.py
10
mfrc522.py
|
@ -80,6 +80,10 @@ class MFRC522:
|
||||||
|
|
||||||
if isinstance(rst, int):
|
if isinstance(rst, int):
|
||||||
self.rst = Pin(rst, Pin.OUT)
|
self.rst = Pin(rst, Pin.OUT)
|
||||||
|
elif isinstance(rst, Pin):
|
||||||
|
self.rst = rst
|
||||||
|
else:
|
||||||
|
raise TypeError("Invalid pin type for rst")
|
||||||
|
|
||||||
self.rst.value(1)
|
self.rst.value(1)
|
||||||
else:
|
else:
|
||||||
|
@ -89,7 +93,11 @@ class MFRC522:
|
||||||
|
|
||||||
if isinstance(cs, int):
|
if isinstance(cs, int):
|
||||||
self.cs = Pin(cs, Pin.OUT)
|
self.cs = Pin(cs, Pin.OUT)
|
||||||
|
elif isinstance(cs, Pin):
|
||||||
|
self.cs = cs
|
||||||
|
else:
|
||||||
|
raise TypeError("Invalid pin type for cs")
|
||||||
|
|
||||||
self.cs.value(1)
|
self.cs.value(1)
|
||||||
|
|
||||||
# Continue in dedicated function
|
# Continue in dedicated function
|
||||||
|
|
Loading…
Reference in a new issue