示例#1
0
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()
示例#2
0
    def setupDisplay(self):
        global screen
        dtype = config.getDisplayType()
        i2c_address = 0x0
        configured_i2c = config.i2c_address
        self.i2c_bus = config.i2c_bus
        i2c_interface = False

        # Set up font code page. If 0 use codepage in font file
        # If > 1 override with the codepage parameter in configuration file
        code_page = config.codepage  # 0, 1 or 2
        log.message("Translation code page in radiod.conf = " + str(code_page),
                    log.INFO)

        if code_page > 0:
            self.code_page = code_page - 1
        else:
            self.code_page = self.translate.getPrimaryCodePage()

        if dtype == config.NO_DISPLAY:
            from no_display import No_Display
            screen = No_Display()
            self.has_screen = False

        elif dtype == config.LCD_I2C_PCF8574:
            from lcd_i2c_pcf8574 import Lcd_i2c_pcf8574
            screen = Lcd_i2c_pcf8574()

            if configured_i2c != 0:
                i2c_address = configured_i2c
            else:
                i2c_address = 0x27

            screen.init(address=i2c_address,
                        busnum=self.i2c_bus,
                        code_page=self.code_page)
            i2c_interface = True

        elif dtype == config.LCD_I2C_ADAFRUIT:
            from lcd_i2c_adafruit import Lcd_i2c_Adafruit
            screen = Lcd_i2c_Adafruit(code_page=self.code_page)

            if configured_i2c != 0:
                i2c_address = configured_i2c
            else:
                i2c_address = 0x20

            screen.init(address=i2c_address, busnum=self.i2c_bus)
            i2c_interface = True

        elif dtype == config.LCD_ADAFRUIT_RGB:
            from lcd_adafruit_class import Adafruit_lcd
            screen = Adafruit_lcd()

            if configured_i2c != 0:
                i2c_address = configured_i2c
            else:
                i2c_address = 0x20

            screen.init(address=i2c_address,
                        busnum=self.i2c_bus,
                        callback=self.callback,
                        code_page=self.code_page)

            # This device has its own buttons on the I2C intertface
            self.has_buttons = True
            i2c_interface = True

        elif dtype == config.OLED_128x64:
            from oled_class import Oled
            screen = Oled()
            self.width = 20
            self.lines = 5
            # Set vertical display
            screen.flip_display_vertically(config.flip_display_vertically)
            self._isOLED = True
            self._mute_line = 4

        elif dtype == config.PIFACE_CAD:
            from lcd_piface_class import Lcd_Piface_Cad
            screen = Lcd_Piface_Cad()
            screen.init(callback=self.callback, code_page=code_page)
            # This device has its own buttons on the SPI intertface
            self.has_buttons = True

        elif dtype == config.ST7789TFT:
            from st7789tft_class import ST7789
            screen = ST7789()
            screen.init(callback=self.callback, code_page=code_page)
            self.has_buttons = False  # Use standard button ineterface
            self._isOLED = True
            self._mute_line = 5

        elif dtype == config.SSD1306:
            from ssd1306_class import SSD1306
            screen = SSD1306()
            screen.init(callback=self.callback, code_page=code_page)
            self.has_buttons = False  # Use standard button interface
            self._isOLED = True
            self._mute_line = 4

        else:
            # Default LCD
            from lcd_class import Lcd
            screen = Lcd()
            screen.init(code_page=self.code_page)

        # Log code files used and codepage
        log.message("Display code page " + str(hex(self.code_page)), log.INFO)

        font_files = self.translate.getFontFiles()
        for i in range(0, len(font_files)):
            log.message("Loaded " + str(font_files[i]), log.INFO)

        # Set up screen width (if 0 use default)
        self.width = config.display_width
        self.lines = self.getLines()

        if self.width != 0:
            screen.setWidth(config.display_width)
        else:
            screen.setWidth(SCREEN_WIDTH)

        sName = self.getDisplayName()
        msg = 'Screen ' + sName + ' Lines=' + str(self.lines) \
             + ' Width=' + str(self.width)

        if i2c_address > 0 and i2c_interface:
            msg = msg + ' Address=' + hex(i2c_address)

        log.message(msg, log.INFO)

        self.splash()

        # Set up number of lines and display buffer
        for i in range(0, self.lines):
            self.lineBuffer.insert(i, '')
        return