Exemplo n.º 1
0
    def run(self):
        GPIO.setmode(GPIO.BCM)
        #pylirc.init("pylirc","./irc_conf",blocking)
        pylirc.init("pylirc", "./irc_conf")
        allow = pylirc.blocking(0)
        while True:
            time.sleep(1)
            s = pylirc.nextcode()

            while (s):
                time.sleep(1)
                for (code) in s:
                    #print 'Command: ',code["config"]
                    print 'CommandS: ', s
                    lirchar = s[0]
                    print 'Command1:', lirchar
                    self._char = lirchar
                    if self._char == self._quitKey:
                        pylirc.exit()
                        print "QUIT!"
                        return
                    if self._char in self._handlersMap:
                        self._handlersMap[self._char]()

                if (not blocking):
                    s = pylirc.nextcode()
                else:
                    s = []
Exemplo n.º 2
0
 def startPyLirc(self):
     if(pylirc.init(LIRC_PROG_NAME, self.configFile, 0)):
         while(self.frontendActive):
             s = pylirc.nextcode(1)
             self.handleNextCode(s)
             sleep(0.1)
         pylirc.exit()
Exemplo n.º 3
0
 def suspend(self):
     """
     cleanup pylirc, close devices
     """
     logger.log(9, 'Lirc.suspend()')
     self.dispatcher.unregister()
     pylirc.exit()
Exemplo n.º 4
0
 def run(self):
     try:
         global lastInput
         global stopThreads
         if (pylirc.init("lircidle", "/home/myth/scripts/lircrc_lircidle",
                         0) == 0):
             syslog.syslog('lircidle.py: unable to init lirc')
             print('lircidle.py: unable to init lirc')
             sys.exit(1)
         while 1:
             time.sleep(1)
             c = pylirc.nextcode()
             if c is not None:
                 #for (code) in c:
                 #	syslog.syslog('lircidle.py (debug): code received (' + str(code["config"]) + ')')
                 #	print('lircidle.py (debug): code received (' + str(code["config"]) + ')')
                 lastInput = time.time()
             if stopThreads != 0: break
     except:
         syslog.syslog('lircidle.py: unexpected exception: ' +
                       str(sys.exc_info()))
         print('lircidle.py: unexpected exception: ' + str(sys.exc_info()))
     finally:
         pylirc.exit()
         syslog.syslog('lircidle.py: exiting lirc thread')
         print('lircidle.py: exiting lirc thread')
Exemplo n.º 5
0
 def suspend(self):
     """
     cleanup pylirc, close devices
     """
     logger.log( 9, 'Lirc.suspend()')
     self.dispatcher.unregister()
     pylirc.exit()
Exemplo n.º 6
0
    def work(self):
        blocking = 0
        run = 1
        try:
            if pylirc.init(self.prog, self.tempFile.name):
                while run:

                    if not blocking:
                        self.plugin.workerLock.acquire()
                        run = self.plugin.workerRunning
                        self.plugin.workerLock.release()
                        if run:
                            time.sleep(0.5)
                        else:
                            break

                    s = pylirc.nextcode(1)

                    blocking = 0

                    while s:
                        for code in s:
                            self.plugin.send_ir_command(code["config"])
                        blocking = 1
                        s = []
        except RuntimeError as e:
            self.logger.warning('LIRC Plugin could not be loaded. Retrying in 5 seconds. %s' % e)
            pylirc.exit()
            time.sleep(5)
            self.work()
Exemplo n.º 7
0
	def exit(self):
		'''
		Code to clean up before exit.
		'''
		if LIRC_ENABLED:
			pylirc.exit()
		pygame.quit()
		sys.exit()
Exemplo n.º 8
0
    def deactivate(self):
        """
        Deactivate the infrared sensor.
        """

        super(Infrared_Sensor, self).deactivate()

        self._active = False
        pylirc.exit()
def destroy():
	p_R.stop()
	p_G.stop()
	p_B.stop()
	GPIO.output(Rpin, GPIO.HIGH)    # Turn off all leds
	GPIO.output(Gpin, GPIO.HIGH)
	GPIO.output(Bpin, GPIO.HIGH)
	GPIO.cleanup()
	pylirc.exit()
Exemplo n.º 10
0
def destroy():
    p_R.stop()
    p_G.stop()
    p_B.stop()
    GPIO.output(Rpin, GPIO.HIGH)  # Turn off all leds
    GPIO.output(Gpin, GPIO.HIGH)
    GPIO.output(Bpin, GPIO.HIGH)
    GPIO.cleanup()
    pylirc.exit()
Exemplo n.º 11
0
 def quit(self):
   """
   Screen.quit() -- close all components
   """
   pygame.display.quit()
   os.unlink(os.path.expanduser(os.path.join('~', '.cmus', 'inhibit-osd')))
   if hasattr(self, 'lircsock'):
     pylirc.exit()
   if self.thread and self.queue:
     self.queue.put('quit', False)
     self.queue.join()
   self.activate_screensaver()
Exemplo n.º 12
0
def stop():
    """
    Callback for shutdown.
    """
    global _dispatcher
    if not _dispatcher:
        # already disconnected
        return
    _dispatcher.unregister()
    _dispatcher = None
    pylirc.exit()
    kaa.main.signals["shutdown"].disconnect(stop)
Exemplo n.º 13
0
def stop():
    """
    Callback for shutdown.
    """
    global _dispatcher
    if not _dispatcher:
        # already disconnected
        return
    _dispatcher.unregister()
    _dispatcher = None
    pylirc.exit()
    kaa.main.signals["shutdown"].disconnect(stop)
Exemplo n.º 14
0
 def start_main_loop(self):
     """
     Read lirc config file and start main pylirc main loop.
     """
     if pylirc.init("tvtuner", "~/.lircrc", False):
         try:
             self._lirc_main_loop()
         except KeyboardInterrupt:
             self._osd.hide()
             pylirc.exit()
     del self._osd
     logging.debug('Exiting..')
Exemplo n.º 15
0
 def start_main_loop(self):
     """
     Read lirc config file and start main pylirc main loop.
     """
     if pylirc.init("tvtuner", "~/.lircrc", False):
         try:
             self._lirc_main_loop()
         except KeyboardInterrupt:
             self._osd.hide()
             pylirc.exit()
     del self._osd
     logging.debug('Exiting..')
Exemplo n.º 16
0
def runPylirc(configuration):
    if pylirc is None:
        logger.debug('Not initializing pylirc')
        yield
        return
    logger.debug('Initializing pylirc with configuration: ' + configuration)
    fd = pylirc.init('browser', configuration)
    if not fd:
        raise RuntimeError('Failed to initialize pylirc')
    try:
        yield fd
    finally:
        pylirc.exit()
Exemplo n.º 17
0
def runPylirc(configuration):
    if pylirc is None:
        logger.debug('Not initializing pylirc')
        yield
        return
    logger.debug('Initializing pylirc with configuration: ' + configuration)
    fd = pylirc.init('browser', configuration)
    if not fd:
        raise RuntimeError('Failed to initialize pylirc')
    try:
        yield fd
    finally:
        pylirc.exit()
	def test(self):
		blocking = 0;

		#
		if(pylirc.init("pylirc", "./conf", blocking)):

		   code = {"config" : ""}
		   while(code["config"] != "quit"):

		      # Very intuitive indeed
		      if(not blocking):
			 print "."

			 # Delay...
			 time.sleep(1)

		      # Read next code
		      s = pylirc.nextcode(1)

		      # Loop as long as there are more on the queue
		      # (dont want to wait a second if the user pressed many buttons...)
		      while(s):
			 
			 # Print all the configs...
			 for (code) in s:
			 
			    print "Command: %s, Repeat: %d" % (code["config"], code["repeat"])
			    
			    if(code["config"] == "blocking"):
			       blocking = 1
			       pylirc.blocking(1)

			    elif(code["config"] == "nonblocking"):
			       blocking = 0
			       pylirc.blocking(0)

			 # Read next code?
			 if(not blocking):
			    s = pylirc.nextcode(1)
			 else:
			    s = []

		   # Clean up lirc
		   pylirc.exit()
    def run(self):
        try:
            lirchandle = pylirc.init("ude-dbus-lirc-bridge", "/usr/share/ude/dbus-lirc-bridge/lircrc", True)
            if lirchandle:
                while True:
                    if self.stopped():
                        break
                    try:
                        timeout = select.select([lirchandle], [], [], 1) == ([], [], [])
                    except Exception, e:
                        print "IRWorker Exception", e
                        continue

                    if not timeout:
                        s = pylirc.nextcode()
                        if s:
                            for code in s:
                                if dbusobj:
                                    dbusobj.IREvent(code)
                                    # print "cmd",code
            pylirc.exit()
Exemplo n.º 20
0
def ir_codes():
    global read_ir_key_val
    GPIO.setup(26, GPIO.IN)
    pylirc.init("my_lirc", ir_conf_path, 0)
    ir_codes = pylirc.nextcode(1)
    # while with time out
    timeout_start = time.time()
    while True:
        ir_codes = pylirc.nextcode(1)
        if ir_codes != None:
            conf_key = ir_codes[0]['config']
            #print("ircodes = %s"%ir_codes)
            #print(type(conf_key))
            pylirc.exit()
            read_ir_key_val = conf_key
            return conf_key
        elif (time.time() - timeout_start > ir_time_out):
            pylirc.exit()
            read_ir_key_val = None
            print "time out"
            return -1
        time.sleep(0.05)
Exemplo n.º 21
0
    def run(self):
        try:
            lirchandle = pylirc.init("ude-dbus-lirc-bridge",
                                     "/usr/share/ude/dbus-lirc-bridge/lircrc",
                                     True)
            if lirchandle:
                while True:
                    if self.stopped():
                        break
                    try:
                        timeout = select.select([lirchandle], [], [],
                                                1) == ([], [], [])
                    except Exception, e:
                        print "IRWorker Exception", e
                        continue

                    if not timeout:
                        s = pylirc.nextcode()
                        if s:
                            for code in s:
                                if dbusobj:
                                    dbusobj.IREvent(code)
                                #print "cmd",code
            pylirc.exit()
Exemplo n.º 22
0
	def run(self):
		try:
			global lastInput
			global stopThreads
			if (pylirc.init("lircidle","/home/myth/scripts/lircrc_lircidle",0) == 0):
				syslog.syslog('lircidle.py: unable to init lirc')
				print('lircidle.py: unable to init lirc')
				sys.exit(1)
			while 1:
				time.sleep(1)
				c = pylirc.nextcode()
				if c is not None:
					#for (code) in c:
					#	syslog.syslog('lircidle.py (debug): code received (' + str(code["config"]) + ')')
					#	print('lircidle.py (debug): code received (' + str(code["config"]) + ')')
					lastInput = time.time()
				if stopThreads != 0: break
		except:
			syslog.syslog('lircidle.py: unexpected exception: ' + str(sys.exc_info()))
			print('lircidle.py: unexpected exception: ' + str(sys.exc_info()))
		finally:
			pylirc.exit()
			syslog.syslog('lircidle.py: exiting lirc thread')
			print('lircidle.py: exiting lirc thread')
Exemplo n.º 23
0
def main():
    usage = "usage: pstream3_client_lirc [options]"
    parser = OptionParser(usage)
    parser.add_option("--daemon",
                      help="Run me as daemon", action="store_true", dest="daemon")
    parser.add_option("--ip",
                      help="Ip where should i listen", dest="ip")
    parser.add_option("--port",
                      help="Port where should i bind", dest="port")
    parser.add_option("--dump",
                      help="Folder where should i dump", dest="dump")
    parser.add_option("--lirc-config",
                      help="Path to lirc config", dest="lirc_config")
    parser.add_option("--pid",
                      help="Process pid", dest="pid")
    (options, args) = parser.parse_args()

    if options.daemon:
        ret= createDaemon()

        if options.pid:
            pid= os.getpid()
            f= open(options.pid, "w")
            f.write(str(pid))
            f.close()

    if options.ip and options.port:
        ip= options.ip
        port= options.port
    else:
        ip= "localhost"
        port= str(8400)

    client = xmlrpclib.ServerProxy("http://%s:%s/" % (ip, port))
    h264_client= None

    blocking= 1
    if options.lirc_config:
        lirc_path= options.lirc_config
    else:
        lirc_path="/etc/pstream/conf"
    if(pylirc.init("pylirc", lirc_path, blocking)):
        code= {"config": ""}
        while(code["config"] != "quit"):
            #Read next code
            s= pylirc.nextcode(1)
            #Right now i don't care what you press on remote.
            code["config"]= "start_stream"

            status= None
            if(code["config"] == "start_stream"):
                try:
                    status=h264_client.GetAppRunStatus()
                except:
                    status=None

                if (status!=AppStatus.RUNNING) or not status:
                    print("Creating new app")
                    h264= client.CreateApp("h264Stream")
                    notifyCopyProcess= client.CreateApp("NotifyCopyProcess")
                    notifyCopyProcess_client= xmlrpclib.ServerProxy("http://%s:%s/" % (ip,port) + str(notifyCopyProcess))
                    print h264, client.GetAppInstances()
                    h264_client= xmlrpclib.ServerProxy("http://%s:%s/" % (ip,port) + str(h264))
                    h264_client.SetAppValue("auto_restart", 1)
                    if options.dump:
                        h264_client.SetAppValue("dumpfolder", options.dump)
                    else:
                        h264_client.SetAppValue("dumpfolder", "/home/recode/dump")
                    h264_client.StartApp()
                else:
                    print("Stoping stream")
                    client.DestroyInstance(h264)
                    client.DestroyInstance(notifyCopyProcess)
                    continue

                while h264_client.GetAppRunStatus()!=AppStatus.RUNNING:
                    print "here"
                    sleep(.5)
                print("Next code")
 

        client.DestroyInstances()
        pylirc.exit()
Exemplo n.º 24
0
def destroy():
    pylirc.exit()
Exemplo n.º 25
0
                    print code


lirchandle = pylirc.init("pylirc", "./conf", blocking)
if (lirchandle):

    print "Succesfully opened lirc, handle is " + str(lirchandle)

    tim = Timer()
    tim.start()

    irrec = IRRec(lirchandle)
    irrec.start()

    code = ""
    while (code != "quit"):

        if (irrec.isAlive() == 0):
            irrec = IRRec(lirchandle)
            irrec.start()

        # Very intuitive indeed
        #if(not blocking):
        print "."

        # Delay...
        time.sleep(1)

    # Clean up lirc
    pylirc.exit()
Exemplo n.º 26
0
 def quit(self):
     pylirc.exit()
Exemplo n.º 27
0
scores = sorted(scores)
winningScore = scores[-1]
winningPlayers = []
for player in players:
    if player['score'] == winningScore:
        winningPlayers.append(player['name'])
winners = ' and '.join(winningPlayers)

    
if len(winningPlayers) > 1:
    titleText = 'The winning players are:'
else:
    titleText = 'The winning player is:'

titleHeight = font.size(titleText)[1]
titleWidth = font.size(titleText)[0]
title = font.render(titleText, 1, [0,0,0])
screen.blit(title, [(width/2)-(titleWidth/2), (height/4)-(titleHeight/2)])

winnerHeight = font.size(winners)[1]
winnerWidth = font.size(winners)[0]
winnerText = font.render(winners, 1, [255,0,0])
screen.blit(winnerText, [(width/2)-(winnerWidth/2), (height/2)-(winnerHeight/2)])

pygame.display.flip()
waitForOk()
displayScores(players, 'Final Scores')

pylirc.exit()

Exemplo n.º 28
0
 def shutdown(self):
     self.logger.debug("Shutting down.")        
     self.stopFlag.set()
     pylirc.exit()        
Exemplo n.º 29
0
 def suspend(self):
     """
     cleanup pylirc, close devices
     """
     _debug_('Lirc.suspend()', 2)
     pylirc.exit()
Exemplo n.º 30
0
def stop():
    pylirc.exit()
Exemplo n.º 31
0
 def __del__(self):
     import pylirc
     pylirc.exit()
     os.remove(self.config_file)
Exemplo n.º 32
0
 def startPyLirc(self):
     lircHandle = pylirc.init(LIRC_PROG_NAME, self.configFile, 0)
     if(lircHandle != 0):
         while(self.frontendActive):
             self.consumePylirc(lircHandle)
         pylirc.exit()
Exemplo n.º 33
0
 def cleanup(self):
   # Clean up lirc
   pylirc.exit()
Exemplo n.º 34
0
 def __del__(self):
     pylirc.exit()
Exemplo n.º 35
0
 def __del__(self):
     import pylirc
     pylirc.exit()
     os.remove(self.config_file)
Exemplo n.º 36
0
def main():
  #build ipcam list from config.xml
  config = 'config.xml'
  parser = XmlParser(config)
  cam_list = parser.build_cam_list()
  print 'Full List'
  for item in cam_list:
		print item.get_name()
  default = 0 
  current_proc = subprocess.Popen(['omxplayer', cam_list[default].get_rem_addr()] , stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
  #ir input section
  blocking  = 0;
  if(pylirc.init("pylirc", "./pylirc/conf", blocking)):

   code = {"config" : ""}
   while (code["config"] != "0"):
      # Very intuitive indeed
      if(not blocking):
         print "."
         # Delay...
         sleep(0.5)
      # Read next code
      s = pylirc.nextcode(1)
      # Loop as long as there are more on the queue
      # (dont want to wait a second if the user pressed many buttons...)
      while(s):
         
         # Print all the configs...
         for (code) in s:
            char = code["config"]	
            print "Command: %s, Repeat: %d" % (code["config"], code["repeat"])
         # Read next code?
         if(not blocking):
            s = pylirc.nextcode(1)
         else:
            s = []
	# if 0 pressed exit close player and pylirc
#	 if int(char) == 0:
#		subprocess.Popen(['killall', 'omxplayer.bin'])
#		pylirc.exit()
#		break
	 if (int(char) <= len(cam_list) and int(char) != 0):
		index = int(char)-1
		url = cam_list[index].get_rem_addr()
		print url
  #comment
		try:	
			next_proc = subprocess.Popen(['omxplayer', url],  stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			    #current_proc.communicate('p')
			    #current_proc.stdin.flush()
			    #print next_proc.stdout
			current_proc.communicate('q')
			temp = current_proc
			current_proc = next_proc
			next_proc = temp
		except: 
			out, err = current_proc.communicate()
			print ("Error: " + err.rstrip())
	 else: 
		  print ("there are no cam corresponding to this number")
		  
   sleep(0.1)	
  subprocess.Popen(['killall', 'omxplayer.bin'])
  pylirc.exit()
Exemplo n.º 37
0
 def startPyLirc(self):
     lircHandle = pylirc.init(LIRC_PROG_NAME, self.configFile, 0)
     if (lircHandle != 0):
         while (self.frontendActive):
             self.consumePylirc(lircHandle)
         pylirc.exit()
Exemplo n.º 38
0
def destroy():
	GPIO.cleanup()
	pylirc.exit()
Exemplo n.º 39
0
def destroy():
    GPIO.cleanup()
    pylirc.exit()
Exemplo n.º 40
0
def stop():
    pylirc.exit()
Exemplo n.º 41
0
 def on_exit(self, result):
     self.logger.info('Exited with (%s)' % result)
     pylirc.exit()
     os.unlink(self.tmpFileName)
Exemplo n.º 42
0
 def suspend(self):
     """
     cleanup pylirc, close devices
     """
     pylirc.exit()