コード例 #1
0
ファイル: volumio-buddy.py プロジェクト: maxiu1/volumio-buddy
pipe = PipeWriter()

if fork() != 0:
    pipe.close(PipeWriter.OUT)
    led = RGBLED(LED_RED, LED_GREEN, LED_BLUE)
    led.set(0, 0, 10)

    display = Display(RESET_PIN)
    display.image(path.dirname(path.realpath(filename)) + "/volumio.ppm")
    display.start_updates()

    while True:
        # Ensure client restarts after network disconnection
        print "start websocket connection"
        client = VolumioClient()
        client.set_callback(print_state, client, display, led)

        # Wait for events from the websocket connection in separate thread
        client.wait()
        while True:
            print 'waiting for command'
            command = '%s' % pipe.read()
            print 'recieved command: %s' % command
            if command == 'volume_up':
                client.volume_up()
            elif command == 'volume_down':
                client.volume_down()
            elif command == 'next_song':
                client.next()
            elif command == 'previous_song':
                client.previous()
コード例 #2
0
#!/usr/bin/python
# Copyright (c) 2016 Michiel Fokke
# Author: Michiel Fokke <*****@*****.**>
# vim: set ts=4 sw=4 expandtab si:

from volumio_buddy import VolumioClient

def print_state(client):
    print client.state

client=VolumioClient()
client.set_callback(print_state, client)
client.wait()
コード例 #3
0
# Copyright (c) 2016 Michiel Fokke
# Author: Michiel Fokke <*****@*****.**>
# vim: set ts=4 sw=4 expandtab si:

from volumio_buddy import RotaryEncoder, VolumioClient


def update_volume(d, client):
    if d == RotaryEncoder.LEFT:
        client.volume_down()
    elif d == RotaryEncoder.RIGHT:
        client.volume_up()
    else:
        print "unknown rotary encoder event"


def print_volume(client):
    print "volume: " + str(client.state["volume"])


ROT_ENC_1A = 2
ROT_ENC_1B = 21

client = VolumioClient()
client.set_callback(print_volume, client)

rotary_encoder = RotaryEncoder(ROT_ENC_1A, ROT_ENC_1B)
rotary_encoder.set_callback(update_volume, client)

client.wait()