rfid_utils – the main helper module
This module provides pre-configured instances of the board LEDs, input and output pins, and the buzzer.
It also provides a simplified wrapper for the mfrc522 class.
Pre-defined objects
RGB- an instance of theSmartLEDclass.GLED,RLED- instances of theSignalLEDclass.The name
GLED(shorthand for theGreen LED) is kept for compatibility reasons. The default color of this led is0x1FFFFF. The nameRLED(shorthand for theRed LED) is kept for compatibility reasons. The default color of this led is0xFF1FFF.
OUT- an instance of the pin, controlling theOUT+ - OUT-pair on the board.OUT(1)pulls theOUT-to the ground,OUT(0)leaves it floating. TheOUT+is always connected to the positive power input.IN- an instance of the pin, corresponding to theINcontact on the board.IN.value()returns1when theINcontact is floating,0when theINcontact is short-circuited to the ground.BUZZ- an instance of theBuzzer.
Classes
- class rfid_utils.CardFilter(lifetime)
lifetimeis the life time of an entry in seconds.The class inherits a dictionary, but it’s intended use is more like a
set:c_filter = CardFilter(2) while 1: c_filter.clean(time()) uid = rfid.read() if uid not in c_filter: # Process the new uid c_filter.append(uid)
- append(value)
Puts the value and the current time in the dict. This can also be used to refresh the value (for example, update the “last seen” time).
- clean(now=None)
Remove all entries with expired lifetime.
- class rfid_utils.RFID(gain=rfid.G_33dB, key=None, type=None, ul=None)
gain- the RFID receiver gainkey- Mifare Classic tag access key (Noneor a byte-like object)typ- the key type (b'A', orb'B', orrfid.KEY_A, orrfid.KEY_B). If provided, thekeyshould be 6 bytes long. IfNone, and thekeyis notNone, thekeyshould be 6 bytes long (will be interpreted as the Mifare Classic A key).ul- the Mifare Ultralight password (and integer or a 4 byes long byte-like object).
- read(fmt='hU*', key=None, type=None, ul=None)
fmt- the format of the output (ref. (RFID format string)[https://open-dev.ru/rfid-format])key,typ,ul- if notNone, override the corresponding constructor parameter.
- scan():
Resets the rfid IC and scans for a tag. Refer to the
scan()method of themfrc522class.
- write(block, data, key=None, typ=None, ul=None)
block- the number of the block to be written. Starts at zero (NB: most tags have a read-only first block).data- a bytes-like object. Must be 4 or 16 bytes long, depending on the type of the tag.key,typ,ul- if notNone, override the corresponding constructor parameter.the
typparameter accepts only therfid.KEY_Aorrfid.KEY_Bconstants.