Guest User

Untitled

a guest
Oct 25th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1.  
  2. #!/usr/bin/env python
  3. # -*- coding: utf8 -*-
  4.  
  5. import RPi.GPIO as GPIO
  6. import MFRC522
  7. import signal
  8. import time
  9. import re
  10. import uinput
  11. from binascii import hexlify
  12. continue_reading = True
  13. def end_read(signal,frame):
  14.     global continue_reading
  15.     print "Ctrl+C captured, ending read."
  16.     continue_reading = False
  17.     GPIO.cleanup()
  18.  
  19. signal.signal(signal.SIGINT, end_read)
  20. MIFAREReader = MFRC522.MFRC522()
  21.  
  22. while continue_reading:
  23.     events = (
  24.       uinput.KEY_0,
  25.       uinput.KEY_1,
  26.       uinput.KEY_2,
  27.       uinput.KEY_3,
  28.       uinput.KEY_4,
  29.       uinput.KEY_5,
  30.       uinput.KEY_6,
  31.       uinput.KEY_7,
  32.       uinput.KEY_8,
  33.       uinput.KEY_9,
  34.      )
  35.     with uinput.Device(events) as device:
  36.        time.sleep(1)
  37.        (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
  38.  
  39.        (status,uid) = MIFAREReader.MFRC522_Anticoll()
  40.  
  41.        if status == MIFAREReader.MI_OK:
  42.            string = str(uid)
  43.            string = re.sub('[^0-9]', '', string)
  44.            hex1 = hex(uid[3])
  45.            hex2 = hex(uid[2])
  46.            hex2 = hex2[2:]
  47.            hex3 = hex(uid[1])
  48.            hex3 = hex3[2:]
  49.            hex4 = hex(uid[0])
  50.            hex4 = hex4[2:]
  51.            if len(hex1) == 1:
  52.                 hex1 = "0" + hex1
  53.            if len(hex2) == 1:
  54.                 hex2 = "0" + hex2
  55.            if len(hex3) == 1:
  56.                 hex3 = "0" + hex3
  57.            if len(hex4) == 1:
  58.                 hex4 = "0" + hex4
  59.            hexValue = hex1+hex2+hex3+hex4
  60.  
  61.            print(hexValue)
  62.            i = int(hexValue, 16)
  63.            print i
  64.            string = str(i)
  65.            for a in string:
  66.                 if a == "0":
  67.                     device.emit_click(uinput.KEY_0)
  68.                 if a == "1":
  69.                     device.emit_click(uinput.KEY_1)
  70.                 if a == "2":
  71.                     device.emit_click(uinput.KEY_2)
  72.                 if a == "3":
  73.                     device.emit_click(uinput.KEY_3)
  74.                 if a == "4":
  75.                     device.emit_click(uinput.KEY_4)
  76.                 if a == "5":
  77.                     device.emit_click(uinput.KEY_5)
  78.                 if a == "6":
  79.                     device.emit_click(uinput.KEY_6)
  80.                 if a == "7":
  81.                     device.emit_click(uinput.KEY_7)
  82.                 if a == "8":
  83.                     device.emit_click(uinput.KEY_8)
  84.                 if a == "9":
  85.                     device.emit_click(uinput.KEY_9)
  86.  
  87.            key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
  88.            time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment