def setupRadio(self): global radio,radioEvent,message,display log.init('radio') log.message("Starting graphic radio ", log.INFO) # Stop the pygame mixer as it conflicts with MPD pygame.mixer.quit() radioEvent = Event() # Add radio event handler radio = Radio(menu,radioEvent) # Define radio radio.start() # Start it radio.loadSource() # Load sources and playlists font = pygame.font.SysFont('Comic Sans MS', 20) display = GraphicDisplay(font) display.setSize(size) message = Message(radio,display)
UP = 0 DOWN = 1 # Player options RANDOM = 0 CONSUME = 1 REPEAT = 2 RELOADLIB = 3 OPTION_LAST = RELOADLIB CurrentStationFile = "/var/lib/radiod/current_station" CurrentTrackFile = "/var/lib/radiod/current_track" CurrentFile = CurrentStationFile log = Log() radio = Radio() rss = Rss() lcd = Adafruit_lcd() # Register exit routine def finish(): lcd.clear() lcd.line1("Radio stopped") atexit.register(finish) # Daemon class class MyDaemon(Daemon): def run(self): global CurrentFile
from rotary_class import RotaryEncoder from rotary_class_alternative import RotaryEncoderAlternative # To use GPIO 14 and 15 (Serial RX/TX) # Remove references to /dev/ttyAMA0 from /boot/cmdline.txt and /etc/inittab UP = 0 DOWN = 1 CurrentStationFile = "/var/lib/radiod/current_station" CurrentTrackFile = "/var/lib/radiod/current_track" CurrentFile = CurrentStationFile PlaylistsDirectory = "/var/lib/mpd/playlists/" log = Log() radio = Radio() lcd = Lcd() rss = Rss() # Signal SIGTERM handler def signalHandler(signal, frame): global lcd global log pid = os.getpid() log.message("Radio stopped, PID " + str(pid), log.INFO) lcd.line1("Radio stopped") lcd.line2("") lcd.line3("") lcd.line4("") radio.exit()
# System files RadioLibDir = "/var/lib/radiod" CurrentStationFile = RadioLibDir + "/current_station" CurrentTrackFile = RadioLibDir + "/current_track" VolumeFile = RadioLibDir + "/volume" TimerFile = RadioLibDir + "/timer" AlarmFile = RadioLibDir + "/alarm" StreamFile = RadioLibDir + "/streaming" LogLevelFile = RadioLibDir + "/loglevel" RssFile = "/var/lib/radiod/rss" MpdPortFile = "/var/lib/radiod/mpdport" alarmType = ["off", "on", "repeat", "weekdays"] radio = Radio() # Exec system command def execCommand(cmd): return commands.getoutput(cmd) # Display flags def displayConfig(radio): todaysdate = strftime("%H:%M %d/%m/%Y") print "Radio Configuration " + todaysdate print "MPD port " + execCommand("cat " + MpdPortFile) print "Volume " + str(radio.getStoredVolume()) print "Timer " + str(radio.getStoredTimer()) AlarmString = radio.getStoredAlarm()
display = GraphicDisplay(font) size = display.config.screen_size if display.config.fullscreen: flags = FULLSCREEN | DOUBLEBUF else: flags = DOUBLEBUF # Setup radio log.init('radio') if config.log_creation_mode: log.truncate() log.message("===== Graphic radio (vgradio.py) started ===", log.INFO) radioEvent = Event(config) # Add radio event handler radio = Radio(rmenu, radioEvent, translate, config, log) # Define radio log.message("Python version " + str(sys.version_info[0]), log.INFO) # Set up the screen size = config.screen_size try: screen = pygame.display.set_mode(size, flags) except Exception as e: msg = "vgradio screen size error: " + str(e) print(msg) log.message(msg, log.ERROR) msg = "Fatal error - exiting" print(msg) log.message(msg, log.ERROR) sys.exit(1)