如何让我的程序在后台进入 shell?

问题描述

我有一个程序可以通过 RFID 扫描仪打开一扇门。可接受的卡片加载到txt文件中。

我的问题是当脚本运行时,我扫描了一张卡片,但没有任何反应。我 alt-tab 进入代码并在程序运行时在 shell 内部单击。当我扫描可接受和不可接受的卡片时,就会出现这种情况,视频运行并使用可接受的卡片按预期打开门。不可接受的卡片不按预期执行。

如何解决此问题,以便除非扫描可接受的卡以触发视频并解锁,否则图像会运行? 这是我的代码

#!/usr/bin/env python3
from evdev import InputDevice
from select import select
import RPi.GPIO as GPIO
import time
from time import sleep
import subprocess
from subprocess import run
import datetime
import os
import sys
import re
import pygame
from pygame.locals import *

def main():    

    def check_if_string_in_file(file_name,string_to_search):
        """Check if any line in the file contains given string"""
        with open(file_name,'r') as read_obj:
            for line in read_obj:
                if string_to_search in line:
                    return True
        return False
    
    
    keys = "X^1234567890asdfghjklXXXXXycbnmXXXXXXXXXXXXXXXXXXXXXXX"
    dev = InputDevice('/dev/input/event0')
    
    pygame.init()
    windowSurface = pygame.display.set_mode ((1024,600),pygame.NOFRAME)
    img = pygame.image.load("/home/pi/Access/New Phone Wallpaper copy.jpg")
    pygame.mouse.set_cursor((8,8),(0,0),0))
    windowSurface.blit(img,0))
    pygame.display.flip()
    pygame.event.clear()
    
    while True:
            r,w,x = select([dev],[],[])
            for event in dev.read():
                    if event.type==1 and event.value==1:
                        if event.code==28:
                            rfid_presented = input()
                            print(rfid_presented)
                            e = rfid_presented
                            if check_if_string_in_file("/home/pi/Access/Loaded_Cards.txt",e):
                                videoPath = "/home/pi/Access/18 Test_1.mp4"
                                omx = run(["omxplayer",'--win','1,1,1024,600',videoPath])
                                GPIO.setmode(GPIO.BCM)
                                GPIO.setwarnings(False)
                                GPIO.setup(26,GPIO.OUT,initial=GPIO.LOW)
                                GPIO.output(26,GPIO.HIGH)
                                time.sleep(0.5)
                                GPIO.output(26,GPIO.LOW)
                                
                            else:              
                                    rfid_presented = ""
                                      
    else:
                    rfid_presented += keys[event.code]
    del e
main()       

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)