Example #1
0
from translate_class import Translate

# Airplay (shairport-sync) pipe and files
AirplayDir = "/tmp/shairport"
AirplayInfo = AirplayDir + "/info"
AirplayMetadata = AirplayDir + "/metadata"
AirplayPipe = "/tmp/shairport-sync-metadata"
ShairportReader = "/usr/local/bin/shairport-sync-metadata-reader"

# Stored mixer volume
RadioLibDir = "/var/lib/radiod"
MixerVolumeFile = RadioLibDir + "/mixer_volume"

log = Log()
translate = Translate()
config = Configuration()


class AirplayReceiver:

    mixerVolume = 100  # Mixer volume
    saveMixerVolume = 0  # Saved Mixer volume for mute functions
    mixerPreset = 100  # Mixer preset volume
    mixerMuted = False  # Mixer muted yes no
    AirplayRunning = False
    hostname = None
    title = 'Uknown title'
    interrupt = False

    # Initialisation routine
    def __init__(self):
Example #2
0
# End of Button Class

### Test routine ###


def interrupt(gpio):
    print("Button pressed on GPIO", gpio)
    return


if __name__ == "__main__":

    from config_class import Configuration
    from log_class import Log
    config = Configuration()
    log = Log()

    pullupdown = ['DOWN', 'UP']

    print("Test Button Class")

    if pwd.getpwuid(os.geteuid()).pw_uid > 0:
        print("This program must be run with sudo or root permissions!")
        sys.exit(1)

    # Get configuration
    left_switch = config.getSwitchGpio("left_switch")
    right_switch = config.getSwitchGpio("right_switch")
    mute_switch = config.getSwitchGpio("mute_switch")
    down_switch = config.getSwitchGpio("down_switch")
Example #3
0
import socket
import errno

# Radio project imports
from config_class import Configuration
from rc_daemon import Daemon
from log_class import Log

log = Log()
IR_LED=11	# GPIO 11 pin 23
remote_led = IR_LED
muted = False
udphost = 'localhost'	# IR Listener UDP host default localhost
udpport = 5100		# IR Listener UDP port number default 5100

config = Configuration()

pidfile = '/var/run/pifacercd.pid'

# Signal SIGTERM handler
def signalHandler(signal,frame):
	global log
	pid = os.getpid()
	log.message("Remote control stopped, PID " + str(pid), log.INFO)
	sys.exit(0)

# Daemon class
class RemoteDaemon(Daemon):

	def run(self):
		global remote_led
Example #4
0
import socket
import errno

# Radio project imports
from config_class import Configuration
from rc_daemon import Daemon
from log_class import Log

log = Log()
IR_LED = 11  # GPIO 11 pin 23
remote_led = IR_LED
muted = False
udphost = 'localhost'  # IR Listener UDP host default localhost
udpport = 5100  # IR Listener UDP port number default 5100

config = Configuration()

pidfile = '/var/run/radiod.pid'


# Signal SIGTERM handler
def signalHandler(signal, frame):
    global log
    pid = os.getpid()
    log.message("Remote control stopped, PID " + str(pid), log.INFO)
    sys.exit(0)


# Daemon class
class RemoteDaemon(Daemon):
    def run(self):
Example #5
0
#	    The authors shall not be liable for any loss or damage however caused.
#

import sys, os, pwd
import time
import ast
import subprocess

if "/usr/share/cosmicd" not in sys.path:
    sys.path.append("/usr/share/cosmicd")
from rotary_class import RotaryEncoder
from status_led_class import StatusLed
from config_class import Configuration
from cosmic_class import Button

config = Configuration()

### Test routines ###
left_switch = 0
middle_switch = 0
right_switch = 0
encoder_switch = 0
encoder_a = 0
encoder_b = 0

statusLed = None
Names = ['NO_EVENT', 'CLOCKWISE', 'ANTICLOCKWISE', 'BUTTON DOWN', 'BUTTON UP']


def button_event(gpio):
    global encoder_switch, left_switch, middle_switch
Example #6
0
class GraphicDisplay:
    columns = 100
    rows = 21
    size = [600, 400]
    font = None
    current_row = 1
    current_column = 1
    delay = 15
    config = Configuration()

    # Display window modes
    MAIN = 0
    RSS = 1
    INFO = 2
    LAST = 2
    mode = MAIN

    # Search modes
    SEARCH_LIST = 0
    SEARCH_PLAYLIST = 1
    SEARCH_ARTISTS = 2
    search_mode = SEARCH_LIST

    # Scroll line values
    textIndex = [0, 0, 0, 0]
    holdCountBegin = [delay, delay, delay, delay, delay]
    holdCountEnd = [delay, delay, delay, delay, delay]
    lineText = ['', '', '', '', '']

    def __init__(self, font):
        self.font = font
        self.size = self.config.screen_size
        self.setSize(self.size)
        return

    # Get display columns
    def getWidth(self):
        return self.columns

    # Get display rows
    def getRows(self):
        return self.rows

    # Get display lines (compatability for message class)
    def getLines(self):
        return self.rows

    # Get display Columns
    def getColumns(self):
        return self.columns

    # Get row x position
    def getRowPos(self, row):
        self.current_row = row
        h = self.averageFontSize[1]
        pos = int(row * h * 1.5)
        return pos

    # Get next row position
    def getNextRow(self):
        self.current_row += 1
        return self.getRowPos(self.current_row)

    # Get row x position
    def getColumnPos(self, column):
        w = self.averageFontSize[0]
        pos = int(column * w / 1.1)
        return pos

    # Get window title
    def getWindowTitle(self, radio):
        version = radio.getVersion()
        hostname = socket.gethostname()
        title = self.config.window_title
        title = title.replace('%V', version)
        title = title.replace('%H', hostname)
        return title

    # Set the display size, rows and columns
    def setSize(self, size):
        self.size = size
        self.averageFontSize = self.font.size("W")
        w = self.averageFontSize[0]
        h = self.averageFontSize[1]
        self.columns = int(1.1 * self.size[0] / w)
        self.rows = int(self.size[1] / (h * 1.5))
        return size

    # Scroll text routine
    def scroll(self, text, line, max_columns):
        idx = line - 1
        index = self.textIndex[idx]

        # Has the line text changed then reset
        if text != self.lineText[idx]:
            index = 0
            self.lineText[idx] = text

        leng = len(text)

        newText = text[index:(max_columns + index)]

        # Increment index and check
        index += 1

        # this delays scrolling at beginning of sroll
        if self.holdCountBegin[idx] > 0:
            self.holdCountBegin[idx] -= 1
            index = 0

        # this delays scrolling at end of scroll
        if (index + len(newText)) > leng:
            if self.holdCountEnd[idx] < 1:
                self.holdCountEnd[idx] = self.delay
                self.holdCountBegin[idx] = self.delay
                self.textIndex[idx] = 0

            self.holdCountEnd[idx] -= 1
        else:
            self.textIndex[idx] = index

        return newText

    # Cycle through display modes
    def cycleMode(self):
        self.mode += 1
        if self.mode > self.LAST:
            self.mode = self.MAIN
        return self.mode

    # Set display mode (Source change)
    def setMode(self, mode):
        self.mode = mode
        if self.mode > self.LAST:
            self.mode = self.MAIN
        return self.mode

    # Get display mode
    def getMode(self):
        return self.mode

    # Get search mode
    def getSearchMode(self):
        return self.search_mode

    # Get search mode
    def setSearchMode(self, mode):
        self.search_mode = mode

    # Cycle search mode
    def cycleSearchMode(self):
        self.search_mode += 1
        if self.search_mode > self.SEARCH_ARTISTS:
            self.search_mode = self.SEARCH_LIST
        return self.search_mode

    # Start column
    def getStartColumn(self):
        cols = self.columns
        if cols < 50:
            startColumn = 3
        elif cols < 70:
            startColumn = 7.5
        elif cols < 90:
            startColumn = 10
        else:
            startColumn = 20
        return startColumn