Esempio n. 1
0
class Root(RestController):
    config = Config()
    crush = Crush()
    doc = Doc()
    mon = Mon()
    osd = Osd()
    pool = Pool()
    request = Request()
    server = Server()

    @expose(template='json')
    def get(self, **kwargs):
        """
        Show the basic information for the REST API
        This includes values like api version or auth method
        """
        return {
            'api_version':
            1,
            'auth':
            'Use "ceph tell mgr restful create_key <key>" to create a key pair, '
            'pass it as HTTP Basic auth to authenticate',
            'doc':
            'See /doc endpoint',
            'info':
            "Ceph Manager RESTful API server",
        }
Esempio n. 2
0
    def __init__(self, config_data):
        device = config_data['device']
        stations = config_data['stations']
        devices = []
        if device.lower() == 'auto':
            devices = scan_for_devices()
        else:
            devices = [device]

        self._devices = devices
        self._device = devices[0]
        self._tuners = []
        for dev in self._devices:
            tuner = Tuner(dev)
            tuner.init_stations(stations)
            self._tuners.append(tuner)
        self._tuner = self._tuners[0]
        self._osd = Osd()
        self._sleep_time = 0.2
        self._osd_time = None
        self._first_digit = None
        self._show_digit_time = 0
        self._show_shutdown_message = False
Esempio n. 3
0
    def __init__(self, config_data):
        device = config_data['device']
        stations = config_data['stations']
        devices = []
        if device.lower() == 'auto':
            devices = scan_for_devices()
        else:
            devices = [device]

        self._devices = devices
        self._device = devices[0]
        self._tuners = []
        for dev in self._devices:
            tuner = Tuner(dev)
            tuner.init_stations(stations)
            self._tuners.append(tuner)
        self._tuner = self._tuners[0]
        self._osd = Osd()
        self._sleep_time = 0.2
        self._osd_time = None
        self._first_digit = None
        self._show_digit_time = 0
        self._show_shutdown_message = False
Esempio n. 4
0
    def elaborate(self, platform):
        m = Module()

        # Read in the tilemap
        tile_map = readhex(self.char_file)

        tile_data = Memory(width=8 + self.inverse, depth=len(tile_map))

        tile_data.init = tile_map

        m.submodules.tr = tr = tile_data.read_port()
        m.submodules.tw = tw = tile_data.write_port()

        # Read in the font
        font = readbin(self.font_file)

        font_data = Memory(width=8, depth=4096)

        font_data.init = font

        m.submodules.fr = fr = font_data.read_port()

        ram_wr = Signal()
        ram_addr = Signal(32)
        ram_di = Signal(8)
        ram_do = Signal(8)
        osd_en = Signal(reset=self.init_on)
        osd_x = Signal(10)
        osd_y = Signal(10)
        dout = Signal(8)
        tile_addr = Signal(12)
        dout_align = Signal()
        osd_pixel = Signal()
        osd_r = Signal(8)
        osd_g = Signal(8)
        osd_b = Signal(8)

        m.submodules.spimem = spimem = SpiMem(addr_bits=32)

        m.d.comb += [
            # Connect spimem
            spimem.csn.eq(self.i_csn),
            spimem.sclk.eq(self.i_sclk),
            spimem.copi.eq(self.i_copi),
            spimem.din.eq(ram_di),
            self.o_cipo.eq(spimem.cipo),
            ram_do.eq(spimem.dout),
            ram_addr.eq(spimem.addr),
            ram_wr.eq(spimem.wr),
            # Connect tilemap
            tw.addr.eq(ram_addr),
            tw.en.eq(ram_wr & ram_addr[24:] == self.addr_display),
            tw.data.eq(Mux(self.inverse, Cat(ram_di, ram_addr[16]), ram_di)),
        ]

        with m.If(ram_wr & ram_addr[24:] == self.addr_enable):
            m.d.pixel += osd_en.eq(ram_di[0])

        m.d.comb += [
            tile_addr.eq((osd_y >> 4) * self.chars_y + (osd_x >> 3)),
            fr.data.eq(dout)
        ]

        if (self.inverse):
            m.d.comb += fr.addr.eq(
                Cat(osd_y[4], tr.data) ^ Repl(tr.data[8], 8))
        else:
            m.d.comb += fr.addr.eq(Cat(osd_y[:4], tr.data))

        m.submodules.osd = osd = Osd(
            x_start=self.start_x,
            x_stop=self.start_x + (8 * self.chars_x) - 1,
            y_start=self.start_y,
            y_stop=self.start_y + (8 * self.chars_y) - 1)

        m.d.comb += [
            osd.clk_ena.eq(1),
            osd.i_r.eq(self.i_r),
            osd.i_g.eq(self.i_g),
            osd.i_b.eq(self.i_b),
            osd.i_hsync.eq(self.i_hsync),
            osd.i_vsync.eq(self.i_vsync),
            osd.i_blank.eq(self.i_blank),
            osd.i_osd_ena.eq(osd_en),
            osd.i_osd_r.eq(osd_r),
            osd.i_osd_g.eq(osd_g),
            osd.i_osd_b.eq(osd_b),
            osd_x.eq(osd.o_osd_x),
            osd_y.eq(osd.o_osd_y),
            osd_r.eq(osd.o_r),
            osd_g.eq(osd.o_g),
            osd_b.eq(osd.o_b),
            self.o_hsync.eq(osd.o_hsync),
            self.o_vsync.eq(osd.o_vsync),
            self.o_blank.eq(osd.o_blank)
        ]

        return m
Esempio n. 5
0
class Remote(object):
    def __init__(self, config_data):
        device = config_data['device']
        stations = config_data['stations']
        devices = []
        if device.lower() == 'auto':
            devices = scan_for_devices()
        else:
            devices = [device]

        self._devices = devices
        self._device = devices[0]
        self._tuners = []
        for dev in self._devices:
            tuner = Tuner(dev)
            tuner.init_stations(stations)
            self._tuners.append(tuner)
        self._tuner = self._tuners[0]
        self._osd = Osd()
        self._sleep_time = 0.2
        self._osd_time = None
        self._first_digit = None
        self._show_digit_time = 0
        self._show_shutdown_message = False

    def show_tv(self):
        """
        Start vlc to show tv.
        """
        spawn('/usr/bin/vlc',
            ['vlc',
            '--quiet',
            '--video-filter=deinterlace',
            '--deinterlace-mode=blend',
            'pvr://%s' % self._device])

    def set_channel(self, channel):
        """
        Set channel.
        """
        self._tuner.set_channel(channel-1)
        self.show_osd(str(channel))
        self._first_digit = None

    def show_osd(self, message):
        """
        Show osd message for _OSD_SECONDS seconds.
        """
        self._osd.show(message)
        self._osd_time = _OSD_SECONDS

    def toggle_audio_mode(self):
        """
        Toggle between the available audio modes of the current channel.
        """
        mode = self._tuner.get_audio_mode()
        modes = self._tuner.get_available_audio_modes()
        index = 0
        try:
            index = modes.index(mode) + 1
        except ValueError:
            pass
        new_mode = modes[index % len(modes)]
        self._tuner.set_audio_mode(new_mode)
        self.show_osd(new_mode)

    def switch_device(self):
        ind = (self._devices.index(self._device) + 1) % len(self._devices)
        self._device = self._devices[ind]
        self._tuner = self._tuners[ind]

    def handle_code(self, code):
        """
        Handle the lirc commands.
        """
        logging.debug("Command: %s, Repeat: %d", code["config"], code["repeat"])
        config = code["config"]
        if config.isdigit():
            digit = int(config)
            if self._first_digit is None:
                self.show_osd('%d-' % digit)
                self._first_digit = digit
                self._show_digit_time = _SINGLE_DIGIT_SECONDS
            else:
                channel = self._first_digit * 10 + digit
                self.set_channel(channel)
        elif config == "ChanUp":
            channel = self._tuner.next_channel()
            self.show_osd(str(channel + 1))
        elif config == "ChanDown":
            channel = self._tuner.prev_channel()
            self.show_osd(str(channel + 1))
        elif config == "ShowTv":
            self.show_tv()
        elif config == "Enter" and not self._first_digit is None:
            self.set_channel(self._first_digit)
        elif config == "ToggleAudio":
            self.toggle_audio_mode()
        if config == 'Shutdown' and not is_running('vlc'):
            if self._show_shutdown_message:
                shutdown()
            else:
                self.show_osd('Shutdown?')
                self._show_shutdown_message = True
        else:
            self._show_shutdown_message = False
        if config == "SwitchDevice":
            self.switch_device()

    def _lirc_main_loop(self):
        """
        Pylirc main loop.
        """
        code = {"config" : ""}
        while True:
            # Delay...
            time.sleep(self._sleep_time)

            # reduce osd time
            if self._osd_time and self._osd_time > 0:
                self._osd_time -= self._sleep_time

            # set channel if one digit is set
            if self._first_digit:
                self._show_digit_time -= self._sleep_time
                if self._show_digit_time <= 0:
                    self.set_channel(self._first_digit)

            # hide osd message
            if self._osd_time and self._osd_time <= 0:
                self._osd.hide()
                self._osd_time = None

            # Read next code
            codes = 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 codes:
                for code in codes:
                    self.handle_code(code)

                # Read next code?
                codes = pylirc.nextcode(1)

    def start_main_loop(self):
        """
        Read lirc config file and start main pylirc main loop.
        """
        if pylirc.init("tvtuner", "~/.lircrc", False):
            try:
                self._lirc_main_loop()
            except KeyboardInterrupt:
                self._osd.hide()
                pylirc.exit()
        del self._osd
        logging.debug('Exiting..')
Esempio n. 6
0
class Remote(object):
    def __init__(self, config_data):
        device = config_data['device']
        stations = config_data['stations']
        devices = []
        if device.lower() == 'auto':
            devices = scan_for_devices()
        else:
            devices = [device]

        self._devices = devices
        self._device = devices[0]
        self._tuners = []
        for dev in self._devices:
            tuner = Tuner(dev)
            tuner.init_stations(stations)
            self._tuners.append(tuner)
        self._tuner = self._tuners[0]
        self._osd = Osd()
        self._sleep_time = 0.2
        self._osd_time = None
        self._first_digit = None
        self._show_digit_time = 0
        self._show_shutdown_message = False

    def show_tv(self):
        """
        Start vlc to show tv.
        """
        spawn('/usr/bin/vlc', [
            'vlc', '--quiet', '--video-filter=deinterlace',
            '--deinterlace-mode=blend',
            'pvr://%s' % self._device
        ])

    def set_channel(self, channel):
        """
        Set channel.
        """
        self._tuner.set_channel(channel - 1)
        self.show_osd(str(channel))
        self._first_digit = None

    def show_osd(self, message):
        """
        Show osd message for _OSD_SECONDS seconds.
        """
        self._osd.show(message)
        self._osd_time = _OSD_SECONDS

    def toggle_audio_mode(self):
        """
        Toggle between the available audio modes of the current channel.
        """
        mode = self._tuner.get_audio_mode()
        modes = self._tuner.get_available_audio_modes()
        index = 0
        try:
            index = modes.index(mode) + 1
        except ValueError:
            pass
        new_mode = modes[index % len(modes)]
        self._tuner.set_audio_mode(new_mode)
        self.show_osd(new_mode)

    def switch_device(self):
        ind = (self._devices.index(self._device) + 1) % len(self._devices)
        self._device = self._devices[ind]
        self._tuner = self._tuners[ind]

    def handle_code(self, code):
        """
        Handle the lirc commands.
        """
        logging.debug("Command: %s, Repeat: %d", code["config"],
                      code["repeat"])
        config = code["config"]
        if config.isdigit():
            digit = int(config)
            if self._first_digit is None:
                self.show_osd('%d-' % digit)
                self._first_digit = digit
                self._show_digit_time = _SINGLE_DIGIT_SECONDS
            else:
                channel = self._first_digit * 10 + digit
                self.set_channel(channel)
        elif config == "ChanUp":
            channel = self._tuner.next_channel()
            self.show_osd(str(channel + 1))
        elif config == "ChanDown":
            channel = self._tuner.prev_channel()
            self.show_osd(str(channel + 1))
        elif config == "ShowTv":
            self.show_tv()
        elif config == "Enter" and not self._first_digit is None:
            self.set_channel(self._first_digit)
        elif config == "ToggleAudio":
            self.toggle_audio_mode()
        if config == 'Shutdown' and not is_running('vlc'):
            if self._show_shutdown_message:
                shutdown()
            else:
                self.show_osd('Shutdown?')
                self._show_shutdown_message = True
        else:
            self._show_shutdown_message = False
        if config == "SwitchDevice":
            self.switch_device()

    def _lirc_main_loop(self):
        """
        Pylirc main loop.
        """
        code = {"config": ""}
        while True:
            # Delay...
            time.sleep(self._sleep_time)

            # reduce osd time
            if self._osd_time and self._osd_time > 0:
                self._osd_time -= self._sleep_time

            # set channel if one digit is set
            if self._first_digit:
                self._show_digit_time -= self._sleep_time
                if self._show_digit_time <= 0:
                    self.set_channel(self._first_digit)

            # hide osd message
            if self._osd_time and self._osd_time <= 0:
                self._osd.hide()
                self._osd_time = None

            # Read next code
            codes = 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 codes:
                for code in codes:
                    self.handle_code(code)

                # Read next code?
                codes = pylirc.nextcode(1)

    def start_main_loop(self):
        """
        Read lirc config file and start main pylirc main loop.
        """
        if pylirc.init("tvtuner", "~/.lircrc", False):
            try:
                self._lirc_main_loop()
            except KeyboardInterrupt:
                self._osd.hide()
                pylirc.exit()
        del self._osd
        logging.debug('Exiting..')