예제 #1
0
    def setRotaryInterface(self):
        global tunerknob
        global volumeknob

        # Internal pullup resistors can be disabled for rotary encoders (eg KY-040)
        # with their own pullup resistors. See rotary_gpio_pullup in radiod.conf

        if self.config.rotary_class == self.config.ALTERNATIVE:
            log.message("event.setInterface RotaryEncoder ALTERNATIVE",
                        log.DEBUG)
            volumeknob = RotaryEncoderAlternative(self.left_switch,
                                                  self.right_switch,
                                                  self.mute_switch,
                                                  self.volume_event)
            tunerknob = RotaryEncoderAlternative(self.down_switch,
                                                 self.up_switch,
                                                 self.menu_switch,
                                                 self.tuner_event)

        elif self.config.rotary_class == self.config.STANDARD:
            log.message("event.setInterface RotaryEncoder STANDARD", log.DEBUG)

            volumeknob = RotaryEncoder(self.left_switch,
                                       self.right_switch,
                                       self.mute_switch,
                                       self.volume_event,
                                       pullup=self.config.rotary_gpio_pullup)

            tunerknob = RotaryEncoder(self.down_switch,
                                      self.up_switch,
                                      self.menu_switch,
                                      self.tuner_event,
                                      pullup=self.config.rotary_gpio_pullup)

        msg = "Volume knob", self.left_switch, self.right_switch, self.mute_switch
        log.message(msg, log.DEBUG)
        msg = "Tuner knob", self.down_switch, self.up_switch, self.menu_switch
        log.message(msg, log.DEBUG)
        return
예제 #2
0
파일: rradio4.py 프로젝트: towmeod/piradio
    def run(self):
        global CurrentFile
        global volumeknob, tunerknob

        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)

        boardrevision = radio.getBoardRevision()
        lcd.init(boardrevision)

        # Set up LCD line width
        width = lcd.getWidth()
        if width > 0:
            lcd.setWidth(width)
        else:
            lcd.setWidth(20)

        lcd.scroll1("Radio version " + radio.getVersion(), nointerrupt)

        hostname = exec_cmd('hostname -s')

        # Display daemon pid on the LCD
        message = "Radio pid " + str(os.getpid())
        lcd.line2(message)

        # Wait for the IP network
        ipaddr = ""
        waiting4network = True
        count = 10
        while waiting4network:
            lcd.scroll4("Waiting for network", nointerrupt)
            ipaddr = exec_cmd('hostname -I')
            time.sleep(1)
            count -= 1
            if (count < 0) or (len(ipaddr) > 1):
                waiting4network = False

        if len(ipaddr) < 1:
            lcd.line4("No IP network")
        else:
            lcd.line4("IP " + ipaddr)
            log.message("IP " + ipaddr, log.INFO)

        lcd.line3("Starting MPD")
        log.message("GPIO version " + str(GPIO.VERSION), log.INFO)
        radio.start()
        log.message("MPD started", log.INFO)
        time.sleep(0.5)

        mpd_version = radio.getMpdVersion()
        log.message(mpd_version, log.INFO)
        lcd.scroll3("MPD version " + mpd_version, nointerrupt)
        lcd.scroll4("GPIO version " + str(GPIO.VERSION), nointerrupt)
        time.sleep(2.0)

        # Auto-load music library if no Internet
        if len(ipaddr) < 1 and radio.autoload():
            log.message("Loading music library", log.INFO)
            radio.setSource(radio.PLAYER)

        # Load radio
        reload(lcd, radio)
        radio.play(get_stored_id(CurrentFile))
        log.message("Current ID = " + str(radio.getCurrentID()), log.INFO)
        lcd.line3("Radio Station " + str(radio.getCurrentID()))

        # Get rotary switches configuration
        up_switch = radio.getSwitchGpio("up_switch")
        down_switch = radio.getSwitchGpio("down_switch")
        left_switch = radio.getSwitchGpio("left_switch")
        right_switch = radio.getSwitchGpio("right_switch")
        menu_switch = radio.getSwitchGpio("menu_switch")
        mute_switch = radio.getSwitchGpio("mute_switch")
        aux_switch = radio.getSwitchGpio("aux_switch")

        if radio.getRotaryClass() is radio.ROTARY_STANDARD:
            volumeknob = RotaryEncoder(left_switch, right_switch, mute_switch,
                                       volume_event, boardrevision)
            tunerknob = RotaryEncoder(down_switch, up_switch, menu_switch,
                                      tuner_event, boardrevision)
        elif radio.getRotaryClass() is radio.ROTARY_ALTERNATIVE:
            volumeknob = RotaryEncoderAlternative(left_switch, right_switch,
                                                  mute_switch, volume_event,
                                                  boardrevision)
            tunerknob = RotaryEncoderAlternative(down_switch, up_switch,
                                                 menu_switch, tuner_event,
                                                 boardrevision)

        log.message("Running", log.INFO)

        # Main processing loop
        count = 0
        toggleScrolling = True  # Toggle scrolling between Line 2 and 3
        while True:

            # Check for audio device error
            if radio.audioError():
                lcd.line1("Audio Error!")
                lcd.line2("Aborting!")
                time.sleep(5)
                sys.exit(1)

            # See if we have had an interrupt
            switch = radio.getSwitch()
            if switch > 0:
                get_switch_states(lcd, radio, rss, volumeknob, tunerknob)

            display_mode = radio.getDisplayMode()

            lcd.setScrollSpeed(0.3)  # Scroll speed normal
            dateFormat = radio.getDateFormat()
            todaysdate = strftime(dateFormat)

            # Shutdown command issued
            if display_mode == radio.MODE_SHUTDOWN:
                log.message("Shutting down", log.DEBUG)
                displayShutdown(lcd, radio)
                while True:
                    time.sleep(1)

            ipaddr = exec_cmd('hostname -I')
            source = radio.getSource()
            if len(ipaddr) < 1 and source != radio.PLAYER:
                lcd.line3("No IP network")

            elif display_mode == radio.MODE_TIME:
                if radio.getReload():
                    log.message("Reload ", log.DEBUG)
                    reload(lcd, radio)
                    radio.setReload(False)

                msg = todaysdate
                if radio.getStreaming():
                    msg = msg + ' *'
                lcd.line1(msg)
                if source == radio.AIRPLAY:
                    displayAirplay(lcd, radio)
                else:
                    display_current(lcd, radio, toggleScrolling)

            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:
                displayInfo(lcd, ipaddr, mpd_version)

            elif display_mode == radio.MODE_RSS:
                lcd.line1(todaysdate)
                input_source = radio.getSource()
                current_id = radio.getCurrentID()
                if input_source == radio.RADIO:
                    lcd.line2(radio.getRadioStation())
                elif input_source == radio.PLAYER:
                    lcd.line2("Current track:" + str(current_id))
                else:
                    displayVolume(lcd, radio)
                display_rss(lcd, rss)

            elif display_mode == radio.MODE_SLEEP:
                lcd.line1(todaysdate)
                display_sleep(lcd, radio)

            # Timer function
            checkTimer(radio)

            # Check state (pause or play)
            checkState(radio)

            # Alarm wakeup function
            if display_mode == radio.MODE_SLEEP and radio.alarmFired():
                log.message("Alarm fired", log.INFO)
                radio.unmute()
                displayWakeUpMessage(lcd)
                radio.setDisplayMode(radio.MODE_TIME)

            # Toggle line 2 & 3 scrolling
            if toggleScrolling:
                toggleScrolling = False
            else:
                toggleScrolling = True

            time.sleep(0.1)
예제 #3
0
    def run(self):
        global CurrentFile
        global menu_switch_value
        global volumeknob, tunerknob, statusLed, menu_switch

        menu_settle = 5  # Allow menu switch to settle

        log.init('radio')
        signal.signal(signal.SIGTERM, signalHandler)

        # Configure RGB status LED
        rgb_red = radio.getRgbLed('rgb_red')
        rgb_green = radio.getRgbLed('rgb_green')
        rgb_blue = radio.getRgbLed('rgb_blue')
        statusLed = StatusLed(rgb_red, rgb_green, rgb_blue)
        statusLed.set(StatusLed.BUSY)

        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)

        hostname = exec_cmd('hostname')
        ipaddr = exec_cmd('hostname -I')

        # Display daemon pid on the LCD
        message = "Radio pid " + str(os.getpid())

        # Wait for the IP network
        ipaddr = ""
        waiting4network = True
        count = 10
        while waiting4network:
            ipaddr = exec_cmd('hostname -I')
            time.sleep(1)
            count -= 1
            if (count < 0) or (len(ipaddr) > 1):
                waiting4network = False

        if len(ipaddr) < 1:
            log.message("No IP network", log.INFO)
            statusLed.set(StatusLed.ERROR)
            time.sleep(1)
        else:
            log.message("IP " + ipaddr, log.INFO)

        time.sleep(2)
        log.message("Starting MPD", log.INFO)
        radio.start()
        log.message("MPD started", log.INFO)

        radio.setLastMode(radio.MODE_OPTIONS)
        radio.setLastOption(radio.RELOADLIB)
        mpd_version = radio.execMpcCommand("version")
        log.message(mpd_version, log.INFO)
        time.sleep(1)

        # Auto-load music library if no Internet
        if len(ipaddr) < 1 and radio.autoload():
            log.message("Loading music library", log.INFO)
            radio.setSource(radio.PLAYER)

        # Load radio
        reload(radio)
        radio.play(get_stored_id(CurrentFile))
        log.message("Current ID = " + str(radio.getCurrentID()), log.INFO)

        # Get rotary switches configuration
        up_switch = radio.getSwitchGpio("up_switch")
        down_switch = radio.getSwitchGpio("down_switch")
        left_switch = radio.getSwitchGpio("left_switch")
        right_switch = radio.getSwitchGpio("right_switch")
        menu_switch = radio.getSwitchGpio("menu_switch")
        mute_switch = radio.getSwitchGpio("mute_switch")

        boardrevision = radio.getBoardRevision()

        if radio.getRotaryClass() is radio.ROTARY_STANDARD:
            boardrevision = radio.getBoardRevision()
            volumeknob = RotaryEncoder(left_switch, right_switch, mute_switch,
                                       volume_event, boardrevision)
            tunerknob = RotaryEncoder(up_switch, down_switch, menu_switch,
                                      tuner_event, boardrevision)
        elif radio.getRotaryClass() is radio.ROTARY_ALTERNATIVE:
            volumeknob = RotaryEncoderAlternative(left_switch, right_switch,
                                                  mute_switch, volume_event,
                                                  boardrevision)
            tunerknob = RotaryEncoderAlternative(up_switch, down_switch,
                                                 menu_switch, tuner_event,
                                                 boardrevision)

        # Configure rotary switch (not rotary encoder)
        switch1 = radio.getMenuSwitch('menu_switch_value_1')
        switch2 = radio.getMenuSwitch('menu_switch_value_2')
        switch4 = radio.getMenuSwitch('menu_switch_value_4')
        menu_switch = MenuSwitch(switch1, switch2, switch4, menu_swich_event)

        log.message("Running", log.INFO)
        statusLed.set(StatusLed.NORMAL)

        # Main processing loop
        count = 0
        while True:
            display_mode = radio.getDisplayMode()
            if not radio.getReload():
                if display_mode is radio.MODE_SEARCH:
                    statusLed.set(StatusLed.SELECT)
                else:
                    statusLed.set(StatusLed.NORMAL)
            switch = radio.getSwitch()
            if switch > 0:
                get_switch_states(radio, volumeknob, tunerknob)
                radio.setSwitch(0)

            if menu_switch_value > 0:
                menu_settle -= 1
                if menu_settle < 0:
                    setMenu(radio, menu_switch_value)
                    menu_settle = 5
                else:
                    time.sleep(0.2)

            dateFormat = radio.getDateFormat()
            todaysdate = strftime(dateFormat)

            # Check for IP address
            ipaddr = exec_cmd('hostname -I')
            if len(ipaddr) < 1 and radio.getSource() != radio.PLAYER:
                statusLed.set(StatusLed.ERROR)

            # Shutdown command issued
            if display_mode == radio.MODE_SHUTDOWN:
                while True:
                    # Not an error just shutting down
                    statusLed.set(StatusLed.ERROR)
                    radio.execCommand("shutdown -h now")
                    time.sleep(1)

            elif display_mode == radio.MODE_TIME:

                if radio.getReload():
                    log.message("Reload ", log.DEBUG)
                    reload(radio)
                    radio.setReload(False)

            # Check state (pause or play)
            checkState(radio)

            if radio.volumeChanged():
                time.sleep(0.1)

            time.sleep(0.1)
예제 #4
0
    def run(self):
        global CurrentFile
        global volumeknob, tunerknob
        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)

        boardrevision = radio.getBoardRevision()
        lcd.init(boardrevision)
        lcd.setWidth(8)

        hostname = exec_cmd('hostname')
        ipaddr = exec_cmd('hostname -I')

        # Display daemon pid on the LCD
        message = "PID " + str(os.getpid())
        lcd.line1(message)

        # Wait for the IP network
        ipaddr = ""
        waiting4network = True
        count = 10
        while waiting4network:
            lcd.line2("Connect")
            ipaddr = exec_cmd('hostname -I')
            time.sleep(1)
            count -= 1
            if (count < 0) or (len(ipaddr) > 1):
                waiting4network = False

        if len(ipaddr) < 1:
            lcd.scroll1("No IP network")
        else:
            lcd.scroll2("IP " + ipaddr, no_interrupt)

        time.sleep(2)
        log.message("Starting MPD", log.INFO)
        lcd.line1("Starting")
        lcd.line2("MPD")
        radio.start()
        log.message("MPD started", log.INFO)

        mpd_version = radio.execMpcCommand("version")
        log.message(mpd_version, log.INFO)
        lcd.line1("Ver " + radio.getVersion())
        lcd.scroll2(mpd_version, no_interrupt)
        time.sleep(1)

        # Auto-load music library if no Internet
        if len(ipaddr) < 1 and radio.autoload():
            log.message("Loading music library", log.INFO)
            radio.setSource(radio.PLAYER)

        # Load radio
        reload(lcd, radio)
        radio.play(get_stored_id(CurrentFile))
        log.message("Current ID = " + str(radio.getCurrentID()), log.INFO)

        # Get switches configuration
        up_switch = radio.getSwitchGpio("up_switch")
        down_switch = radio.getSwitchGpio("down_switch")
        left_switch = radio.getSwitchGpio("left_switch")
        right_switch = radio.getSwitchGpio("right_switch")
        menu_switch = radio.getSwitchGpio("menu_switch")
        mute_switch = radio.getSwitchGpio("mute_switch")

        if radio.getRotaryClass() is radio.ROTARY_STANDARD:
            volumeknob = RotaryEncoder(left_switch, right_switch, mute_switch,
                                       volume_event, boardrevision)
            tunerknob = RotaryEncoder(down_switch, up_switch, menu_switch,
                                      tuner_event, boardrevision)
        elif radio.getRotaryClass() is radio.ROTARY_ALTERNATIVE:
            volumeknob = RotaryEncoderAlternative(left_switch, right_switch,
                                                  mute_switch, volume_event,
                                                  boardrevision)
            tunerknob = RotaryEncoderAlternative(down_switch, up_switch,
                                                 menu_switch, tuner_event,
                                                 boardrevision)

        log.message("Running", log.INFO)

        # Main processing loop
        count = 0
        while True:
            switch = radio.getSwitch()
            if switch > 0:
                get_switch_states(lcd, radio, rss, volumeknob, tunerknob)
                radio.setSwitch(0)

            display_mode = radio.getDisplayMode()
            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)

            if len(ipaddr) < 1 and radio.getSource() != radio.PLAYER:
                lcd.line2("No IP")

            elif display_mode == radio.MODE_TIME:

                if radio.getReload():
                    log.message("Reload ", log.DEBUG)
                    reload(lcd, radio)
                    radio.setReload(False)

                displayTime(lcd, radio)
                if radio.muted():
                    msg = "Muted"
                    if radio.getStreaming():
                        msg = msg + ' *'
                    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("Ver " + radio.getVersion())
                if len(ipaddr) < 1:
                    lcd.scroll1("No IP network", interrupt)
                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)

            # Timer function
            checkTimer(radio)

            # Check state (pause or play)
            checkState(radio)

            # 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():
                displayVolume(lcd, radio)

            time.sleep(0.1)
예제 #5
0
    def run(self):
        global lcd
        global CurrentFile
        global volumeknob, tunerknob
        log.init('radio')

        # Setup signal handlers
        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)

        i2c_address = radio.getI2Caddress()

        # Load pcf8574 i2c class or Adafruit backpack
        if radio.getBackPackType() == radio.PCF8574:
            log.message("PCF8574 backpack, address: " + hex(i2c_address),
                        log.INFO)
            lcd = lcd_i2c_pcf8574()
        else:
            log.message("Adafruit backpack, address: " + hex(i2c_address),
                        log.INFO)
            lcd = lcd_i2c()

        boardrevision = radio.getBoardRevision()
        lcd.init(board_rev=boardrevision, address=i2c_address)
        lcd.backlight(True)

        # Set up LCD line width
        width = lcd.getWidth()
        if width > 0:
            lcd.setWidth(width)
        else:
            lcd.setWidth(20)

        lcd.line1("Radio vers " + radio.getVersion())
        time.sleep(0.5)

        ipaddr = exec_cmd('hostname -I')
        hostname = exec_cmd('hostname -s')

        # Display daemon pid on the LCD
        message = "Radio pid " + str(os.getpid())
        lcd.line2(message)

        lcd.line3("Starting MPD")
        log.message("GPIO version " + str(GPIO.VERSION), log.INFO)
        lcd.line4("IP " + ipaddr)
        radio.start()
        log.message("MPD started", log.INFO)
        time.sleep(0.5)

        mpd_version = radio.execMpcCommand("version")
        log.message(mpd_version, log.INFO)
        lcd.scroll3(mpd_version, no_interrupt)
        lcd.scroll4("GPIO version " + str(GPIO.VERSION), no_interrupt)
        time.sleep(2.0)

        # Auto-load music library if no Internet
        if len(ipaddr) < 1 and radio.autoload():
            log.message("Loading music library", log.INFO)
            radio.setSource(radio.PLAYER)

        # Load radio
        reload(lcd, radio)
        radio.play(get_stored_id(CurrentFile))
        log.message("Current ID = " + str(radio.getCurrentID()), log.INFO)
        lcd.line3("Radio Station " + str(radio.getCurrentID()))

        # Get rotary switches configuration
        up_switch = radio.getSwitchGpio("up_switch")
        down_switch = radio.getSwitchGpio("down_switch")
        left_switch = radio.getSwitchGpio("left_switch")
        right_switch = radio.getSwitchGpio("right_switch")
        menu_switch = radio.getSwitchGpio("menu_switch")
        mute_switch = radio.getSwitchGpio("mute_switch")

        if radio.getRotaryClass() is radio.ROTARY_STANDARD:
            volumeknob = RotaryEncoder(left_switch, right_switch, mute_switch,
                                       volume_event, boardrevision)
            tunerknob = RotaryEncoder(down_switch, up_switch, menu_switch,
                                      tuner_event, boardrevision)
        elif radio.getRotaryClass() is radio.ROTARY_ALTERNATIVE:
            volumeknob = RotaryEncoderAlternative(left_switch, right_switch,
                                                  mute_switch, volume_event,
                                                  boardrevision)

        log.message("Running", log.INFO)

        # Main processing loop
        count = 0
        toggleScrolling = True  # Toggle scrolling between Line 2 and 3
        while True:

            # See if we have had an interrupt
            switch = radio.getSwitch()
            if switch > 0:
                get_switch_states(lcd, radio, rss, volumeknob, tunerknob)

            display_mode = radio.getDisplayMode()

            lcd.setScrollSpeed(0.3)  # Scroll speed normal
            dateFormat = radio.getDateFormat()
            todaysdate = strftime(dateFormat)

            ipaddr = exec_cmd('hostname -I')

            # Shutdown command issued
            if display_mode == radio.MODE_SHUTDOWN:
                log.message("Shutting down", log.DEBUG)
                displayShutdown(lcd)
                while True:
                    time.sleep(1)

            if ipaddr is "":
                lcd.line3("No IP network")

            elif display_mode == radio.MODE_TIME:

                if radio.getReload():
                    log.message("Reload ", log.DEBUG)
                    reload(lcd, radio)
                    radio.setReload(False)

                msg = todaysdate
                if radio.getStreaming():
                    msg = msg + ' *'
                lcd.line1(msg)
                display_current(lcd, radio, toggleScrolling)

            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:
                displayInfo(lcd, ipaddr, mpd_version)

            elif display_mode == radio.MODE_RSS:
                lcd.line1(todaysdate)
                input_source = radio.getSource()
                current_id = radio.getCurrentID()
                if input_source == radio.RADIO:
                    station = radio.getRadioStation() + ' (' + str(
                        current_id) + ')'
                    lcd.line2(station)
                else:
                    lcd.line2("Current track:" + str(current_id))
                display_rss(lcd, rss)

            elif display_mode == radio.MODE_SLEEP:
                lcd.line1(todaysdate)
                display_sleep(lcd, radio)

            # Timer function
            checkTimer(radio)

            # Check state (pause or play)
            checkState(radio)

            # Alarm wakeup function
            if display_mode == radio.MODE_SLEEP and radio.alarmFired():
                log.message("Alarm fired", log.INFO)
                radio.unmute()
                displayWakeUpMessage(lcd)
                radio.setDisplayMode(radio.MODE_TIME)

            # Toggle line 2 & 3 scrolling
            if toggleScrolling:
                toggleScrolling = False
            else:
                toggleScrolling = True

            time.sleep(0.1)
예제 #6
0
    def run(self):
        global lcd
        global CurrentFile
        global volumeknob, tunerknob
        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)

        i2c_address = radio.getI2Caddress()  # Get address from configuration

        # Load pcf8574 i2c class or Adafruit backpack
        if radio.getBackPackType() == radio.PCF8574:
            log.message("PCF8574 backpack address: " + hex(i2c_address),
                        log.INFO)
            lcd = lcd_i2c_pcf8574()
        else:
            log.message("Adafruit backpack address: " + hex(i2c_address),
                        log.INFO)
            lcd = lcd_i2c()

        boardrevision = radio.getBoardRevision()
        lcd.init(board_rev=boardrevision, address=i2c_address)
        lcd.backlight(True)

        hostname = exec_cmd('hostname')
        ipaddr = exec_cmd('hostname -I')

        # Display daemon pid on the LCD
        message = "Radio pid " + str(os.getpid())
        lcd.line1(message)
        lcd.line2("IP " + ipaddr)
        time.sleep(4)
        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)

        # Get rotary switches configuration
        up_switch = radio.getSwitchGpio("up_switch")
        down_switch = radio.getSwitchGpio("down_switch")
        left_switch = radio.getSwitchGpio("left_switch")
        right_switch = radio.getSwitchGpio("right_switch")
        menu_switch = radio.getSwitchGpio("menu_switch")
        mute_switch = radio.getSwitchGpio("mute_switch")

        if radio.getRotaryClass() is radio.ROTARY_STANDARD:
            volumeknob = RotaryEncoder(left_switch, right_switch, mute_switch,
                                       volume_event, boardrevision)
            tunerknob = RotaryEncoder(up_switch, down_switch, menu_switch,
                                      tuner_event, boardrevision)
        elif radio.getRotaryClass() is radio.ROTARY_ALTERNATIVE:
            volumeknob = RotaryEncoderAlternative(left_switch, right_switch,
                                                  mute_switch, volume_event,
                                                  boardrevision)
            tunerknob = RotaryEncoderAlternative(up_switch, down_switch,
                                                 menu_switch, tuner_event,
                                                 boardrevision)

        log.message("Running", log.INFO)

        # Main processing loop
        count = 0
        while True:
            switch = radio.getSwitch()
            if switch > 0:
                get_switch_states(lcd, radio, rss, volumeknob, tunerknob)
                radio.setSwitch(0)

            display_mode = radio.getDisplayMode()
            lcd.setScrollSpeed(0.3)  # Scroll speed normal
            dateFormat = radio.getDateFormat()
            todaysdate = strftime(dateFormat)

            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:
                if radio.getReload():
                    log.message("Reload ", log.DEBUG)
                    reload(lcd, radio)
                    radio.setReload(False)

                displayTime(lcd, radio)
                if radio.muted():
                    msg = "Sound muted"
                    if radio.getStreaming():
                        msg = msg + ' *'
                    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:
                lcd.line1(todaysdate)
                display_rss(lcd, rss)

            elif display_mode == radio.MODE_SLEEP:
                lcd.line1(todaysdate)
                display_sleep(lcd, radio)

            # Timer function
            checkTimer(radio)

            # Check state (pause or play)
            checkState(radio)

            # 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.5)

            time.sleep(0.1)