def test4_RotaryEncoder_set_callback(self, mock_wiringpi_ISR,
                                      mock_pullUpDnControl,
                                      mock_wiringpi_pinMode,
                                      mock_wiringpi_setup):
     d = dict()
     d[0] = 1
     def callback_function(arg):
         return 1
     gpio_pin_a = 1
     gpio_pin_b = 1
     r = RotaryEncoder(gpio_pin_a, gpio_pin_b)
     r.set_callback(callback_function, r, d)
     mock_wiringpi_ISR.assert_called_with(gpio_pin_b, wiringpi.INT_EDGE_BOTH, r._decode_rotary)
Exemple #2
0
    def test5_RotaryEncoder_set_callback(self, mock_wiringpi_digital_read, mock_wiringpi_ISR, \
            mock_wiringpi_pinMode, mock_wiringpi_setup):
        d = dict()

        def callback_function(r, arg):
            return r.direction, d[0]

        gpio_pin_a = 1
        gpio_pin_b = 1
        r = RotaryEncoder(gpio_pin_a, gpio_pin_b)
        r.set_callback(callback_function, r, d)
        d[0] = 1
        self.assertEqual(r._decode_rotary(), (RotaryEncoder.RIGHT, 1))
        sleep(1)
        self.assertEqual(r._decode_rotary(), (RotaryEncoder.RIGHT, 1))
        d[0] = 2
        sleep(1)
        self.assertEqual(r._decode_rotary(), (RotaryEncoder.LEFT, 2))
        sleep(1)
        self.assertEqual(r._decode_rotary(), (RotaryEncoder.LEFT, 2))
                client.volume_up()
            elif command == 'volume_down':
                client.volume_down()
            elif command == 'next_song':
                client.next()
            elif command == 'previous_song':
                client.previous()
            elif command == 'toggle_play':
                client.toggle_play()
            elif command == 'show_menu':
                # Display the menu modal for 3 sec
                display.menu(3)
            else:
                print "unknown command"

else:
    pipe.close(PipeWriter.IN)
    push_button = PushButton(PB1)
    push_button2 = PushButton(PB2)
    rotary_encoder = RotaryEncoder(ROT_ENC_1A, ROT_ENC_1B, minimum_delay=0.1)
    rotary_encoder2 = RotaryEncoder(ROT_ENC_2A, ROT_ENC_2B)

    push_button.set_callback(toggle_play, pipe)
    push_button2.set_callback(show_menu, pipe)

    rotary_encoder.set_callback(update_volume, rotary_encoder, pipe)
    rotary_encoder2.set_callback(previous_next, rotary_encoder2, pipe)

    while True:
        delay(2000)
Exemple #4
0
#!/usr/bin/python
# Copyright (c) 2016 Michiel Fokke
# Author: Michiel Fokke <*****@*****.**>
# vim: set ts=4 sw=4 expandtab si:

from volumio_buddy import RotaryEncoder
import wiringpi

def print_direction(rotary_encoder):
    if rotary_encoder.direction == RotaryEncoder.LEFT:
        print "direction: left"
    elif rotary_encoder.direction == RotaryEncoder.RIGHT:
        print "direction: right"
    else:
        print "direction: unknown (%s)" % rotary_encoder.direction

ROT_ENC_1A = 2
ROT_ENC_1B = 21
ROT_ENC_2A = 4
ROT_ENC_2B = 5

rotary_encoder = RotaryEncoder(ROT_ENC_1A, ROT_ENC_1B)
rotary_encoder.set_callback(print_direction, rotary_encoder)

rotary_encoder2 = RotaryEncoder(ROT_ENC_2A, ROT_ENC_2B)
rotary_encoder2.set_callback(print_direction, rotary_encoder)

while True:
    wiringpi.delay(2000)
    
Exemple #5
0
            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()
            elif command == 'toggle_play':
                client.toggle_play()
            elif command == 'show_menu':
                # Display the menu modal
                display.menu()
            else:
                print("unknown command")

else:
    pipe.close(PipeWriter.IN)
    push_button = PushButton(PB2, pud=PUD_UP)
    rotary_encoder = RotaryEncoder(ROT_ENC_2B,
                                   ROT_ENC_2A,
                                   minimum_delay=0.1,
                                   pud=PUD_UP)
    push_button.set_callback(toggle_play, pipe)
    rotary_encoder.set_callback(update_volume, rotary_encoder, pipe)

    while True:
        delay(2000)
Exemple #6
0
# Rotary encoder 2 pins (WiringPi numbering)
PB2 = 7
ROT_ENC_2A = 4
ROT_ENC_2B = 5

# LED pins (WiringPi numbering)
LED_RED = 23
LED_GREEN = 26
LED_BLUE = 22

# SSD3106 reset pin (not used)
RESET_PIN = 26

push_button = PushButton(PB1)
push_button2 = PushButton(PB2)
rotary_encoder = RotaryEncoder(ROT_ENC_1A, ROT_ENC_1B)
rotary_encoder2 = RotaryEncoder(ROT_ENC_2A, ROT_ENC_2B)

client = VolumioClient()

push_button.set_callback(toggle_play, client)
push_button2.set_callback(toggle_play, client)

rotary_encoder.set_callback(update_volume, rotary_encoder, client)
rotary_encoder2.set_callback(previous_next, rotary_encoder2, client)

# Wait for event from either one of the buttons
while True:
    delay(2000)
Exemple #7
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()