def __init__(self): threading.Thread.__init__(self) self.lock = threading.Lock() self.usbuirt = UsbUirt() self.run_thread = False self.cmd = None #this object MUST be open just once through life of the daemon try: self.usbuirt.open(util.CONF_VAR['DEV_FILE']) util.log.debug('device ' + util.CONF_VAR['DEV_FILE'] + ' succesfully opened!') except: exit('device ' + util.CONF_VAR['DEV_FILE'] + ' has *NOT* been found')
class AsynUsbUIRT(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.lock = threading.Lock() self.usbuirt = UsbUirt() self.run_thread = False self.cmd = None #this object MUST be open just once through life of the daemon try: self.usbuirt.open(util.CONF_VAR['DEV_FILE']) util.log.debug('device ' + util.CONF_VAR['DEV_FILE'] + ' succesfully opened!') except: exit('device ' + util.CONF_VAR['DEV_FILE'] + ' has *NOT* been found') def sendIR(self, code): #Locking the device /dev/ttyUSBX self.lock.acquire() util.log.debug('sending cmd through sendIR() method and code:' + code) #opening device where usbuirt is hooked up self.usbuirt.transmitIR(code, IRFMT_PRONTO, 1 ,0) time.sleep(0.3) self.lock.release() def runThread(self, cmd, flag=True): self.run_thread = flag self.cmd = cmd def run(self): while True: if self.run_thread is True: time.sleep(float(util.TV_VAR['POWER_DELAY'])) #0.4 or 0.5 couldbe minimun time j = 3 while j > 0: #Locking the device /dev/ttyUSBXX self.lock.acquire() util.log.debug(str(j) + '--> sending cmd' + self.cmd + ' through thread() method') #opening device where usbuirt is hooked up self.usbuirt.transmitIR(util.REMOTE['special'][self.cmd], IRFMT_PRONTO, 1 ,0) self.lock.release() j -= 1 self.run_thread = False time.sleep(0.3)