def __init__(self, dest, name, config): self.dest = dest sock = pylirc.init(name, config) pylirc.blocking(False) super(client, self).__init__(sock, Qt.QSocketNotifier.Read, dest) self.setEnabled(True) self.activated.connect(self.read_nextcode)
def init(appname = None, cfg = None): """ Init pylirc and connect to the mainloop. """ global _dispatcher if _dispatcher: # already running return False if not pylirc: # not installed return False if cfg == None: cfg = os.path.expanduser("~/.lircrc") if appname == None: appname = "kaa" try: fd = pylirc.init(appname, cfg) except IOError: # something went wrong return False if not fd: # something went wrong return False pylirc.blocking(0) _dispatcher = kaa.IOMonitor(_handle_lirc_input) _dispatcher.register(fd) kaa.main.signals["shutdown"].connect(stop) return True
def resume(self): """ (re-)initialize pylirc, e.g. after calling close() """ _debug_('Lirc.resume()', 2) pylirc.init('freevo', config.LIRCRC) pylirc.blocking(0)
def start(): try: pylirc.init('freevo', config.LIRCRC) pylirc.blocking(1) except RuntimeError: print 'WARNING: Could not initialize PyLirc!' sys.exit(0) except IOError: print 'WARNING: %s not found!' % config.LIRCRC sys.exit(0)
def __init__(self): threading.Thread.__init__(self) self.lock = threading.Lock() self.daemon = True self.MAIN_THREAD_DELAY = 0.01 self.lircConnected = True try: self.sockid = pylirc.init("myamp", "/root/.lircrc") pylirc.blocking(0) except: print "error connecting to lircd!" self.lircConnected = False self.code = None
def startReading(self): if self._fd != -1: try: os.fstat(self.fileno()) abstract.FileDescriptor.startReading(self) return except OSError: pass if self._lirc_config is not None: self._fd = pylirc.init(self._program_name, self._lirc_config) else: self._fd = pylirc.init(self._program_name) pylirc.blocking(0) self.protocol.connectionMade() abstract.FileDescriptor.startReading(self)
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 = []
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 init(appname=None, cfg=None): """ Initialize lirc and begin monitoring for events. :param appname: the name of the program that corresponds to the *prog* value in the lircrc file (default: kaa) :param cfg: the path to the lircrc config file (default: ~/.lircrc). See http://www.lirc.org/html/configure.html for more details. :raises: ImportError if pylirc is not installed. """ global _dispatcher if _dispatcher: # already running return False # This will raise if pylirc isn't available, however if it is, this will # already be imported, so there is no risk of this being imported from a # thread. import pylirc if cfg == None: cfg = os.path.expanduser("~/.lircrc") if appname == None: appname = "kaa" try: fd = pylirc.init(appname, cfg) except IOError: # something went wrong return False if not fd: # something went wrong return False pylirc.blocking(0) _dispatcher = kaa.IOMonitor(_handle_lirc_input) _dispatcher.register(fd) kaa.main.signals["shutdown"].connect(stop) return True
def __init__(self, appname): self.fileno = pylirc.init(appname) pylirc.blocking(False)
def run(self): global CurrentFile global ConfigFile global tunerknob configOK = False GPIO.setmode(GPIO.BCM) # Use BCM GPIO numbers GPIO.setwarnings(False) # Ignore warnings boardrevision = radio.getBoardRevision() if boardrevision == 1: # For rev 1 boards with no inbuilt pull-up/down resistors # Wire the GPIO inputs to ground via a 10K resistor GPIO.setup(MENU_SWITCH, GPIO.IN) GPIO.setup(UP_SWITCH, GPIO.IN) GPIO.setup(DOWN_SWITCH, GPIO.IN) GPIO.setup(LEFT_SWITCH, GPIO.IN) GPIO.setup(RIGHT_SWITCH, GPIO.IN) else: # For rev 2 boards with inbuilt pull-up/down resistors the # following lines are used instead of the above, so # there is no need to physically wire the 10k resistors GPIO.setup(MENU_SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(UP_SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(DOWN_SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(LEFT_SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(RIGHT_SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(STREAM_SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Initialise IR if not (pylirc.init("radio", "/home/pi/radio/ir.conf")): log.message("IR initialization failed.", log.ERROR) else: pylirc.blocking(0) # Initialise radio log.init('radio') signal.signal(signal.SIGTERM, signalHandler) progcall = str(sys.argv) log.message('Radio running pid ' + str(os.getpid()), log.INFO) log.message( "Radio " + progcall + " daemon version " + radio.getVersion(), log.INFO) log.message("GPIO version " + str(GPIO.VERSION), log.INFO) if not os.path.isfile(ConfigFile) or os.path.getsize(ConfigFile) == 0: log.message("Missing configuration file " + ConfigFile, log.ERROR) else: log.message("Reading configuration file", log.INFO) self.configOK = True # Must be set before calling getConfig() self.getConfig() lcd.init(boardrevision) lcd.setWidth(self.display_width) hostname = exec_cmd('hostname') ipaddr = exec_cmd('hostname -I') myos = exec_cmd('uname -a') log.message(myos, log.INFO) # Display daemon pid on the LCD message = "Radio pid " + str(os.getpid()) lcd.line1(message) lcd.line2("IP " + ipaddr) time.sleep(2) log.message("Starting MPD", log.INFO) lcd.line2("Starting MPD") radio.start() log.message("MPD started", log.INFO) mpd_version = radio.execMpcCommand("version") log.message(mpd_version, log.INFO) lcd.line1("Radio ver " + radio.getVersion()) lcd.scroll2(mpd_version, no_interrupt) time.sleep(1) reload(lcd, radio) radio.play(get_stored_id(CurrentFile)) log.message("Current ID = " + str(radio.getCurrentID()), log.INFO) tunerknob = RotaryEncoder(ROTA_SWITCH, ROTB_SWITCH, PUSH_SWITCH, tuner_event, boardrevision) # Set up switch event processing GPIO.add_event_detect(MENU_SWITCH, GPIO.RISING, callback=switch_event, bouncetime=200) GPIO.add_event_detect(LEFT_SWITCH, GPIO.RISING, callback=switch_event, bouncetime=200) GPIO.add_event_detect(RIGHT_SWITCH, GPIO.RISING, callback=switch_event, bouncetime=200) GPIO.add_event_detect(UP_SWITCH, GPIO.RISING, callback=switch_event, bouncetime=200) GPIO.add_event_detect(DOWN_SWITCH, GPIO.RISING, callback=switch_event, bouncetime=200) GPIO.add_event_detect(STREAM_SWITCH, GPIO.RISING, callback=switch_event, bouncetime=200) # Main processing loop count = 0 while True: #log.message("===BEGIN MAIN LOOP===",log.DEBUG) ir = pylirc.nextcode(1) if (ir): ir_event(ir, lcd, radio, rss, tunerknob) ir = [] switch = radio.getSwitch() if switch > 0: get_switch_states(lcd, radio, rss, tunerknob) radio.setSwitch(0) #log.message("=== 0 ===",log.DEBUG) display_mode = radio.getDisplayMode() dateFormat = radio.getDateFormat() todaysdate = strftime(dateFormat) lcd.setScrollSpeed(0.3) # Scroll speed normal ipaddr = exec_cmd('hostname -I') # Shutdown command issued if display_mode == radio.MODE_SHUTDOWN: displayShutdown(lcd) while True: time.sleep(1) elif ipaddr is "": lcd.line2("No IP network") elif display_mode == radio.MODE_TIME: #log.message("=== MODE_TIME ===",log.DEBUG) displayTime(lcd, radio) if radio.muted(): msg = "Sound muted" lcd.line2(msg) else: display_current(lcd, radio) elif display_mode == radio.MODE_SEARCH: display_search(lcd, radio) elif display_mode == radio.MODE_SOURCE: display_source_select(lcd, radio) elif display_mode == radio.MODE_OPTIONS: display_options(lcd, radio) elif display_mode == radio.MODE_IP: lcd.line2("Radio v" + radio.getVersion()) if ipaddr is "": lcd.line1("No IP network") else: lcd.scroll1("IP " + ipaddr, interrupt) elif display_mode == radio.MODE_RSS: displayTime(lcd, radio) display_rss(lcd, rss) elif display_mode == radio.MODE_SLEEP: displayTime(lcd, radio) display_sleep(lcd, radio) #log.message("=== 1 ===",log.DEBUG) # Timer function checkTimer(radio) #log.message("=== 2 ===",log.DEBUG) # Check state (pause or play) checkState(radio) #log.message("=== 3 ===",log.DEBUG) # Alarm wakeup function if display_mode == radio.MODE_SLEEP and radio.alarmFired(): log.message("Alarm fired", log.INFO) unmuteRadio(lcd, radio) displayWakeUpMessage(lcd) radio.setDisplayMode(radio.MODE_TIME) if radio.volumeChanged(): lcd.line2("Volume " + str(radio.getVolume())) time.sleep(0.75) #log.message("=== 4 ===",log.DEBUG) time.sleep(0.1)
# (dont want to wait a second if the user pressed many buttons…) while(s): # Print all the configs… for (code) in s: handle = os.popen(code[„config“]) line = “ “ while line: line = handle.read() print line handle.close() 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() #https://www.marcuslausch.de/2017/08/15/lirc-mit-python-pylirc/
def __init__(self, app, conf): if not pylirc.init(app, conf, 1): raise Exception("Unable to init pylirc"); pylirc.blocking(0)
def __init__(self, app, conf): if not pylirc.init(app, conf, 1): raise Exception("Unable to init pylirc") pylirc.blocking(0)
# 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) elif code["config"] == "x": GPIO.output(7, True) time.sleep(3) GPIO.output(7, False) # Read next code? if not blocking: s = pylirc.nextcode(1) else: s = []
def __init__(self): ''' Constructor. ''' global XMAX, YMAX # Set defaults. # These are overwritten by settings in the config file. self.chart_dir = 'charts' self.font_dir = 'fonts' self.default_font = 'Sloan.ttf' # Dimensions in mm. # Builtin monitor and lane sizes. self.monitor_vert_size = 287.0 self.lane_length = 6096.0 # Flag for background color - 0 = White, 1 = Red/Green. self.background_flag = 0 # Read the config file - possibly overwriting the defaults. self.readConfig() self.start_dir = os.getcwd() # Set up the default font. # TODO: Test the handeling of font pathing. # FIXME: Need to have full path. self.full_font_name = os.path.join(self.start_dir, self.font_dir, self.default_font) #Find the chart files. full_chart_dir = os.path.join(self.start_dir, self.chart_dir) # Change to the chart directory - need to be in this directory or else need # to use full path names and that's annoying. os.chdir(full_chart_dir) self.chart_list = os.listdir(full_chart_dir) self.chart_list.sort() self.current_chart_index = 0 self.max_chart_index = len(self.chart_list) - 1 # Need minus one, 'cause count from zero! chart_name = self.chart_list[self.current_chart_index] # Initilize lirc if avialble, and register optichart as the client. if LIRC_ENABLED: ret_val = pylirc.init('optichart') if ret_val <= 0: print 'Error with lirc!', ret_val # Ensure that pylirc does not block. ret_val = pylirc.blocking(0) # Initilize pygame. pygame.init() # Set keyboard repeat (delay, interval). pygame.key.set_repeat(200, 10) # Find DPI # Some versions of xrandr will return a resolution in pixles and a size in mm. # However this dosesn't work on all systems. # So we are going to ask SDL for a full screen window at whatever size happens # to be the current size. We then figure out what dpi we are dealing with # based on a physical measurement entered in the config file and the returned # SDL surface size. # May need (on some systems) to actually specifiy what size we want. # Create a screen. # Calling set_mode with zeros will return a surface the same size as the # current display. # size = (0, 0) size = (1920, 1080) # NOTE! The dpi depends on resolution and physical size if change one other must change too else get funny results. # size = (1280, 768) self.screen = pygame.display.set_mode(size, pygame.NOFRAME) # screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) # screen = pygame.display.set_mode((XMAX, YMAX), pygame.FULLSCREEN) # screen = pygame.display.set_mode((XMAX, YMAX)) # Flag for red/green self.red_green = 0 # Flag for Enter Button # We incriment this when changing from full screen to line mode to # character mode. So: # 0 - Full Screen. # 1 - Line Mode - first time. # 2 - Character Mode. # 3 - Line Mode - second time. self.mode = 0 # Variable to hold state of viewport across blank screen calls. self.previous_view_size = 0 # Fill the screen with a while background. self.screen.fill(WHITE) # Must call update to actually display anything. pygame.display.update() # Calculate the vertical dpi. width_px, height_px = self.screen.get_size() print self.monitor_vert_size dpi = height_px / self.monitor_vert_size print 'dpi:', dpi # Asign screen x & y size values to global XMAX and YMAX. XMAX = width_px YMAX = height_px # Create a slide of the chart. self.slide = Slide() self.slide.setDefaultFont(self.full_font_name) self.slide.setFontDirectory(self.font_dir) self.slide.setDpi(dpi) self.slide.setLaneLength(self.lane_length) self.slide.setSlideHeight(self.chart_vert_size) self.slide.setSlideWidth(self.chart_horz_size) # Create the default viewport window. Move this to display() function # if need slides to reset to the default view when switching. # The viewport is the same size as the virtual chart projections size. self.viewport = pygame.Rect(0, 0, self.slide.slideWidth(), self.slide.slideHeight()) # Set the viewport to the top of the screen. self.viewport.left = 0 self.viewport.top = 0 self.display(chart_name) self.checkVerticalCentering() self.update()