Exemplo n.º 1
0
def radio_loop(now, key_value):
    global currently_tuned
    switch_channel(key_value)  # change radio channel
    get_mpd_info(now)
    if app_states["play"] == 1:
        if mpd.stat() != "play" or currently_tuned != app_states["channel"]:
            mpd.play(app_states["channel"])
    else:
        if mpd.stat() == "play":
            mpd.stop()
    if key_value == "KEY_PLAYPAUSE":
        play_pause(now)
Exemplo n.º 2
0
def radio_loop(now,key_value):
    global currently_tuned
    switch_channel(key_value)    # change radio channel
    get_mpd_info(now)
    if app_states["play"] == 1:
        if mpd.stat() != "play" or currently_tuned != app_states["channel"]:
            mpd.play(app_states["channel"])
    else:
        if mpd.stat() == "play":
            mpd.stop()
    if key_value == "KEY_PLAYPAUSE":
        play_pause(now)
Exemplo n.º 3
0
def loop():
    now = millis()  # get timestamp
    key_value = controls.read_key()  # read controls
    if (now - last_update.panel_buttons > update_intervall.panel_buttons):
        button = controls.Read_Panel()
        if button != "":
            key_value = button
            time.sleep(0.2)

    tone_adjust(key_value)  # call tone adjust

    if key_value == "KEY_ENTER":  # switch tone mode
        switch_tone(now)

    if (now - last_update.time >
            update_intervall.time):  # update time in diaplay
        display.disp_content.time = time.strftime("%H:%M")
        last_update.time = now

    if (now - last_update.tone > update_intervall.tone):  # update tones
        update_tones(now)
        last_update.tone = now

    if (now - last_update.tone_adjust_idle > update_intervall.tone_adjust_idle
        ):  # switch back to volume after timeout
        mode_changed = True
        last_update.tone_adjust_idle = now
        app_states["tone_mode"] = tone_mode.volume

    if key_value == "KEY_MENU":
        switch_source(now)

    display.disp_content.tonemode = tone_strings[app_states["tone_mode"]]
    display.disp_content.tonevalue = app_states[tone_mode_to_string[
        app_states["tone_mode"]]]

    get_wifi(now)

    if app_states["app_mode"] == app_modes.IRadio:
        radio_loop(now, key_value)
    else:
        if mpd.stat() == "play":
            mpd.stop()

    if (now - last_update.disp_update >
            update_intervall.disp_update):  # update display
        display.update_display(now)
        last_update.disp_update = now
Exemplo n.º 4
0
def restore_tones():
    global app_states
    global prev_app_states
    if os.path.exists('appstates.sav'):
        print("restoring states")
        with open('appstates.sav') as data_file:
            try:
                app_states = json.load(data_file)
            except:
                print "unable to load json file"
    audio.switch_input(app_states["input"])
    if app_states["play"] == 0:
        mpd.stop()
    else:
        mpd.play(app_states["channel"])
    prev_app_states["play"] = app_states["play"]
    app_states["changed"] = True
Exemplo n.º 5
0
def restore_tones():
    global app_states
    global prev_app_states
    if os.path.exists('appstates.sav'):
        print("restoring states")
        with open('appstates.sav') as data_file:
            try:
                app_states = json.load(data_file)
            except:
                print"unable to load json file"
    audio.switch_input(app_states["input"])
    if app_states["play"] == 0:
        mpd.stop()
    else:
        mpd.play(app_states["channel"])
    prev_app_states["play"] = app_states["play"]
    app_states["changed"] = True
Exemplo n.º 6
0
def loop():
    now = millis()                  # get timestamp
    key_value = controls.read_key() # read controls
    if (now - last_update.panel_buttons > update_intervall.panel_buttons):
        button = controls.Read_Panel()
        if button != "":
            key_value = button
            time.sleep(0.2)

    tone_adjust(key_value)           # call tone adjust

    if key_value == "KEY_ENTER":    # switch tone mode
        switch_tone(now)

    if (now - last_update.time > update_intervall.time):       # update time in diaplay
        display.disp_content.time = time.strftime("%H:%M")
        last_update.time = now

    if (now - last_update.tone > update_intervall.tone ): # update tones
        update_tones(now)
        last_update.tone = now

    if (now - last_update.tone_adjust_idle > update_intervall.tone_adjust_idle ): # switch back to volume after timeout
        mode_changed = True
        last_update.tone_adjust_idle = now
        app_states["tone_mode"] = tone_mode.volume

    if key_value == "KEY_MENU":
        switch_source(now)

    display.disp_content.tonemode  = tone_strings[app_states["tone_mode"]]
    display.disp_content.tonevalue = app_states[tone_mode_to_string[app_states["tone_mode"]]]

    get_wifi(now)

    if app_states["app_mode"] == app_modes.IRadio:
        radio_loop(now,key_value)
    else:
        if mpd.stat() == "play":
            mpd.stop()

    if (now - last_update.disp_update > update_intervall.disp_update):    # update display
        display.update_display(now)
        last_update.disp_update = now
Exemplo n.º 7
0
def loop():
    now = millis()  # get timestamp
    key_value = ""
    if (now - last_update.get_input > update_intervall.get_input):
        key_value = controls.read_key()  # read controls
        last_update.get_input = now
    #if (now - last_update.panel_buttons > update_intervall.panel_buttons):
    #    button = controls.Read_Panel()
    #    if button != "":
    #        key_value = button
    #        time.sleep(0.2)

    tone_adjust(key_value)  # call tone adjust

    display.disp_content.power_state = controls.Power_State

    if prev_app_states["power"] != controls.Power_State:
        if app_states["app_mode"] == app_modes.IRadio:
            if controls.Power_State == "ON":
                app_states["play"] = 1
                led = open("/sys/class/leds/green_led/brightness", "w")
                led.write(str(1))
                led.close()
                time.sleep(3)
            else:
                app_states["play"] = 0
                led = open("/sys/class/leds/green_led/brightness", "w")
                led.write(str(0))
                led.close()
        prev_app_states["power"] = controls.Power_State

    if key_value == "KEY_ENTER":  # switch tone mode
        switch_tone(now)

    if (now - last_update.time >
            update_intervall.time):  # update time in diaplay
        display.disp_content.time = time.strftime("%H:%M")
        last_update.time = now

    if (now - last_update.tone > update_intervall.tone):  # update tones
        update_tones(now)
        last_update.tone = now

    if (now - last_update.tone_adjust_idle > update_intervall.tone_adjust_idle
        ):  # switch back to volume after timeout
        mode_changed = True
        last_update.tone_adjust_idle = now
        app_states["tone_mode"] = tone_mode.volume

    if key_value == "KEY_MENU":
        switch_source(now)

    display.disp_content.tonemode = tone_strings[app_states["tone_mode"]]
    display.disp_content.tonevalue = app_states[tone_mode_to_string[
        app_states["tone_mode"]]]
    display.disp_content.app_mode = app_mode_strings[app_states["app_mode"]]

    get_wifi(now)

    if app_states["app_mode"] == app_modes.IRadio:
        radio_loop(now, key_value)
    else:
        if mpd.stat() == "play":
            mpd.stop()

    if (now - last_update.disp_update >
            update_intervall.disp_update):  # update display
        display.update_display(now)
        last_update.disp_update = now