EDIT: 我想我已经把所有的东西都弄好了,只是我的第二个循环一直出现索引故障。只是我的第二个循环一直有一个索引失败......任何想法,为什么我的coms循环是失败的?
我目前正试图获取我的HD180x optomoa投影机的红外代码。它变成了一个非常困难的问题,我只是需要能够打开我的HD180x optomoa投影机的红外代码。
我只需要能够打开电源,没有别的。
我没有一个红外传感器来直接捕捉代码,并把它作为一个挑战,试图做到这一点没有一个。
到目前为止,这是不可能的。我已经尝试了几种不同的方法,用树莓派从遥控器上直接获取红外代码,但都没有成功。
我的下一个想法是使用一个IR blaster,只是循环浏览所有可能的IR Power ON代码。
LIRC,这是唯一的Pi红外软件,有很多遥控器的列表。http: /lirc.sourceforge.netremotes
我想做的是制作一个python脚本,从列表中抓取所有的文件,然后尝试所有的文件。我的目标是打开投影机,所以我可以让它运行多久就运行多久,如果它打开了,我就可以找出是哪个文件做的。
所以我的伪代码如下。
我不知道如何做的问题是采集配置文件中的 "Name "字段和 "code "字段。
另外,不知道如何通过python发送终端命令。
有什么好办法吗?
我能够让代码开始发送,现在我只需要找出如何从配置文件中获取 "IR Codes"......
我很接近了... 我只需要能够做一个 "irsend列表""" >>homepilist.ist",这样我就可以找到当前激活的遥控器的名称....... 我只是不知道如何使该命令正确运行。我想是引号把它弄乱了......。
import os
import shutil
import subprocess
import time
# Using readline()
count = 0
#os.remove("list.list")
os.system("touch /home/pi/com.list")
os.system("touch /home/pi/list.list")
os.system("systemctl start lircd")
for filename in os.listdir('confs'):
currconf = "/home/pi/confs/" + filename
print "**********start*******"
print "1. ", filename
#print "2. ", currconf
#os.system("systemctl stop lircd")
#subprocess.call('systemctl stop lircd', shell=True)
shutil.move(currconf, "/etc/lirc/lircd.conf")
subprocess.call('systemctl reset-failed lircd', shell=True)
subprocess.call('systemctl restart lircd', shell=True)
time.sleep(1)
subprocess.call('systemctl status lircd | tail -3', shell=True)
# os.system("systemctl start lircd")
# irlist = ""
#print "3. ", irlist
os.remove("/home/pi/list.list")
os.remove("/home/pi/com.list")
os.system('irsend list \"\" \"\" >> /home/pi/list.list')
qbfile = open("/home/pi/list.list", "r")
for aline in qbfile:
values = aline.split()
print(values[0])
rname = values[0].strip('\n')
print "2. rname", rname
comlist = 'irsend list ' + rname + ' \"\" >> /home/pi/com.list'
print "3. comlist", comlist
os.system(comlist)
comfile = open("/home/pi/com.list", "r")
for coms in comfile:
comvalues = coms.split()
comand = comvalues[1]#.strip('\n')
cmd = "irsend SEND_ONCE " + rname + " " + comand
print "4. cmd ", cmd
time.sleep(.001)
os.system(cmd)
print "**********end*******"
我把所有的东西都弄好了......这里是代码。
import os
import shutil
import subprocess
import time
#removes files to start fresh
os.system("touch /home/pi/com.list")
os.system("touch /home/pi/list.list")
os.system("systemctl start lircd")
#gets a sorted list of all the configuration files from LIRC remote storage
for filename in sorted(os.listdir('/home/pi/confs')):
#gets the first file
currconf = "/home/pi/confs/" + filename
print "**********start*******"
print "1. ", filename
#moves the first config file to lircd.conf so restart can make it show up
shutil.move(currconf, "/etc/lirc/lircd.conf")
#restarts lircd (the reset-failed is to make sure there are no time outs
subprocess.call('systemctl reset-failed lircd', shell=True)
subprocess.call('systemctl restart lircd', shell=True)
time.sleep(1)
#shows the status of lircd
subprocess.call('systemctl status lircd | tail -3', shell=True)
#removes files again to make sure it is fresh
os.remove("/home/pi/list.list")
os.remove("/home/pi/com.list")
# sends an iresend to get list of all remotes in the remote configuration file that was used and pits it in list.list to be used for configuration later
os.system('irsend list \"\" \"\" >> /home/pi/list.list')
#opens list.list
qbfile = open("/home/pi/list.list", "r")
#for all remotes in list.list
for aline in qbfile:
#this gets the remote names
values = aline.split()
if values:
print(values[0])
#removes end of file from remote names
rname = values[0].strip('\n')
print "2. rname", rname
#creates command that is going to list all commands of given remote names
comlist = 'irsend list ' + rname + ' \"\" >> /home/pi/com.list'
print "3. comlist", comlist
#runs command
os.system(comlist)
#opens command list file
comfile = open("/home/pi/com.list", "r")
for coms in comfile:
#gets command name, and not command hex
comvalues = coms.split()
#makes sure if there is a null value it does not hang the loop
if comvalues:
comand = comvalues[1]#.strip('\n')
print "4. cmd ", comand
time.sleep(.1)
command2 = 'irsend SEND_ONCE ' + rname + " " + comand
print "5. command2", command2
ppp = subprocess.Popen(command2, universal_newlines=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
text = ppp.stdout.read()
retcode = ppp.wait()
print text
print "**********end*******"