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
|
@ -80,6 +80,10 @@ class MFRC522:
|
|||
|
||||
if isinstance(rst, int):
|
||||
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)
|
||||
else:
|
||||
|
@ -89,6 +93,10 @@ class MFRC522:
|
|||
|
||||
if isinstance(cs, int):
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue