ondryaso / pi-rc522

Raspberry Pi Python library for SPI RFID RC522 module
MIT License
412 stars 150 forks source link

Error in code #23

Open Himura2la opened 7 years ago

Himura2la commented 7 years ago

https://github.com/ondryaso/pi-rc522/blob/master/pirc522/__init__.py#L127

>>> not ~(0b1000101 & 0x01)
False
>>> not ~(0b1000100 & 0x01)
False

This mistake was copy-pasted, I filed an issue to the original repo. Sad.

Himura2la commented 7 years ago

This is my version. We don't need a timeout variable, if the TimerIRq is set, we can be sure everything is lost and won't work. In my UART version it takes 5 iterations on 9600 baud to have TimerIRq set.

        while True:
            n = self.dev_read(0x04)
            if n == 0:
                continue  # Too fast
            if n & irq_wait:
                break  # Got it!
            if n & 0x01:
                error = True
                break  # The timer decrements the timer value in register TCounterValReg to zero

You should also change following condition to if not error: and delete its else branch