Esempio n. 1
0
def control_down(diff):
    logger.debug('control_down')
    player = radio.get_player()
    if player is None:
        return
    radio.down(diff)
    display.overlay_rect(int(256 / 100 * player.volume), 1)
Esempio n. 2
0
def print_tags():
    while True:
        sleep(1)

        if STATE['playback_mode'] is PlaybackMode.Radio:
            try:
                player = radio.get_player()

                if player.metadata is not None and 'icy-title' in player.metadata:  # soemtimes buggy
                    station = get_station_object_by_player(player, stations)
                    tag = player.metadata['icy-title']
                    # print(tag)

                    if tag in station['skip_strings']:
                        tag = station['name']

                    display.tag_text(tag)

            except Exception as e:
                logger.debug(
                    "Couldn't run the icy_title while loop in print tags:")
                print(e)

        if STATE['playback_mode'] is PlaybackMode.CD:
            try:
                player = radio.get_player()

                txt = str(player.playlist_pos + 1) + \
                    '/' + str(player.playlist_count)

                txts = []
                if 'title' in player.metadata:
                    txts.append(player.metadata['title'])
                if 'artist' in player.metadata:
                    txts.append(player.metadata['artist'])
                txts = txt + ' ' + ' - '.join(txts)

                display.tag_text(txts)
                # logger.debug("CD tag is : {}".format(txts))

            except Exception as e:
                pass
                logger.error("Couldn't get CD tag: {}".format(e))
Esempio n. 3
0
def control_mute_toggle():
    logger.debug('control_mute_toggle')

    player = radio.get_player()
    if player is None:
        return

    radio.mute_toggle()

    if STATE['muted']:
        display.set_pause_or_mute_text('Lautlos')

    else:
        display.remove_pause_or_mute_text()
Esempio n. 4
0
def _rfid_loop():
    t = threading.current_thread()
    last_stop = 0
    max_cont_fails = 0

    SET_CD_LIB = CONST.SET_CD_LIB
    write_cd_lib_mode = False
    last_set_cd = None
    last_played_rfid_tag = ""

    while t.name == 'run':
        sleep(2 / CONST.MAX_CONT_FAILS)

        rdr.wait_for_tag(0.5)
        (error, tag_type) = rdr.request()
        if not error:
            (error, uid) = rdr.anticoll()
            if not error:
                # logger.debug("Tag with UID: {} detected".format(uid))
                max_cont_fails = 0
                rfid = str(utils.uid_to_num(uid))

                if SET_CD_LIB == rfid and write_cd_lib_mode is False:
                    write_cd_lib_mode = True
                    display.forced_text('Karte weg (3 sec)', 5)
                    sleep(4)
                elif SET_CD_LIB == rfid and write_cd_lib_mode is True:
                    write_cd_lib_mode = False
                    last_set_cd = None
                    display.forced_text('Karte weg (3 sec)', 5)
                    sleep(4)
                    continue

                cd_path = None
                
                if write_cd_lib_mode:
                    if last_set_cd is not None:  # write tag
                        """try to assign new cd, fall through for next selection """
                        if rfid in music_lib:
                            display.forced_text('CD existiert', 5)
                            continue

                        display.forced_text('CD gespeichert', 5)
                        logger.debug('assign: "' + rfid + '" to CD: ' + cd_paths_without_id[0])
                        music_lib[rfid] = cd_paths_without_id[0]
                        utils.save_music_lib()
                        last_set_cd = None
                        cd_paths_without_id.pop(0)
                        sleep(5)

                    if last_set_cd is None:
                        if 0 == len(cd_paths_without_id):
                            display.forced_text('no cds to sort', 5)
                            continue

                        cd_path = CONST.MUSIC_LIB_PATH + cd_paths_without_id[0]
                        last_set_cd = cd_paths_without_id[0]
                        display.forced_text('place cd card', 5)
                        STATE['playback_mode'] = PlaybackMode.Unknown

                elif write_cd_lib_mode is False:
                    if rfid not in music_lib:
                        continue

                    cd_path = CONST.MUSIC_LIB_PATH + music_lib[rfid]

                    if rfid != last_played_rfid_tag:  # tag changed
                        last_stop = 0
                        STATE['playback_mode'] = PlaybackMode.Unknown

                if STATE['playback_mode'] is not PlaybackMode.CD and STATE['playback_mode'] is not PlaybackMode.BT:
                    last_played_rfid_tag = rfid
                    # TODO: disconnect all bt devices

                    diff = time() - last_stop  # time since tag was removed

                    if 60 < diff:  # restart cd playback
                        radio.start_cd(cd_path)
                        logger.debug(
                            "CD Player started fresh with playlist: {}".format(radio.get_player().playlist))
                    else:
                        radio.start_cd(None)
                        logger.debug(
                            "CD Player resumed with old playlist: {}".format(radio.get_player().playlist))
                continue
            logger.debug('error rdr.anticoll()')

        max_cont_fails += 1

        if write_cd_lib_mode is True or max_cont_fails < CONST.MAX_CONT_FAILS:
            logger.debug('error rdr.request(), fails ' + str(max_cont_fails))
            continue

        if STATE['playback_mode'] is PlaybackMode.CD:
            # tag was removed
            radio.pause_cd()
            last_stop = time()

            # switch back to radio
            STATE['playback_mode'] = PlaybackMode.Radio
            radio.unmute_unpause_current_player()