[+] Initial version

This commit is contained in:
Azalea
2023-11-24 20:15:25 -05:00
parent cdd3adabe5
commit 5b28a2a390
4 changed files with 172 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
from pathlib import Path
import time
import serial
import re
from playsound import playsound
from pynput.keyboard import Key, Controller
keyboard = Controller()
# Configure your serial port and baud rate
SERIAL_PORT = 'COMx' # Replace 'COMx' with your serial port (e.g., 'COM3' on Windows or '/dev/ttyUSB0' on Linux)
# SERIAL_PORT = '/dev/ttyACM0'
BAUD_RATE = 115200
PATH = Path('C:/MUGS/felica.txt')
# PATH = Path('/tmp/felica.txt')
AUDIO_EFFECT = Path(__file__).parent / 'Audio/tofu.wav'
def parse_uid(data):
"""
Parse the UID from the serial data.
"""
uid_value_match = re.search(r'UID Value: ([0-9A-F]+)', data)
if uid_value_match:
uid = uid_value_match.group(1)
# If UID is not 8 bytes, pad it with zeros
if len(uid) < 16:
uid = uid.zfill(16)
# If the UID Doesn't start with 01 2E, set it to 01 2E
if uid[:4] != '012E':
uid = '012E' + uid[4:]
# Write the UID to the file
print(f"UID: {uid}")
PATH.write_text(uid)
# Play audio effect
playsound(str(AUDIO_EFFECT))
# Press ENTER button
keyboard.press(Key.enter)
time.sleep(0.5)
keyboard.release(Key.enter)
return uid
if __name__ == "__main__":
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
print(f"Listening on {SERIAL_PORT}...")
try:
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8', errors='replace').strip()
print(line)
parse_uid(line)
except KeyboardInterrupt:
print("Exiting...")
finally:
ser.close()