예제 #1
0
def handle_key(index, state):
    global doubleClickThreshold
    global longPressThreshold
    global currentClickCount
    global clickThread
    global releaseThread
    global isLongPress

    if state:
        keybow.set_led(index, 255, 50, 255)
        keybow.show
        isLongPress = False
        if clickThread is None:
            currentClickCount = 1
            clickThread = threading.Timer(doubleClickThreshold, handleClick)
            clickThread.start()
        else:
            clickThread.cancel()
            currentClickCount += 1
            clickThread = threading.Timer(doubleClickThreshold, handleClick)
            clickThread.start()

        if releaseThread is None:
            releaseThread = threading.Timer(longPressThreshold,
                                            longPressDetected)
            releaseThread.start()
        else:
            releaseThread.cancel()
            releaseThread = threading.Timer(longPressThreshold,
                                            longPressDetected)
            releaseThread.start()
    else:
        keybow.set_led(index, r, g, b)
        keybow.show()
        releaseThread.cancel()
예제 #2
0
def handle_key(index, state):
    print("{}: Key {} has been {}".format(time.time(), index,
                                          'pressed' if state else 'released'))

    if state:
        keybow.set_led(index, 255, 0, 0)
    else:
        keybow.set_led(index, 0, 0, 0)
예제 #3
0
def test_set_led_out_of_range():
    _mock()
    import keybow

    keybow.setup(keybow.MINI)

    with pytest.raises(IndexError):
        keybow.set_led(4, 255, 0, 0)
예제 #4
0
def handle_key(index, state):
    if state:
        keybow.set_led(index, 50, 255, 50)
        keybow.show()

    else:
        keybow.set_led(index, r, g, b)
        keybow.show()
def handle_key(index, state):
    print("{}: Key {} has been {}".format(
        time.time(),
        index,
        'pressed' if state else 'released'))

    if state:
        keybow.set_led(index, 255, 0, 0)
        os.system("mpc -h 192.168.9.44 clear; mpc -h 192.168.9.44 add tunein:station:s266113; mpc -h 192.168.9.44 play")
    else:
        keybow.set_led(index, 127, 0, 0)
def handle_key(index, state=True):
    print("{}: Key {} has been {}".format(
        time.time(),
        index,
        'pressed' if state else 'released'))
    
    if state:
        keybow.set_led(index, 0, 0, 255)
        os.system("ssh [email protected] sudo systemctl restart mopidy")
    else:
        keybow.set_led(index, 0, 0, 127)
def handle_key(index, state):
    print("{}: Key {} has been {}".format(
        time.time(),
        index,
        'pressed' if state else 'released'))

    if state:
        keybow.set_led(index, 0, 255, 0)
        os.system("mpc -h 192.168.9.44 clear; mpc -h 192.168.9.44 add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p; mpc -h 192.168.9.44 play")
    else:
        keybow.set_led(index, 0, 127, 0)
예제 #8
0
def led_fade(index, c1, c2):
    r1, g1, b1 = c1
    r2, g2, b2 = c2

    steps = 10
    delta_r = int((r1 - r2) // steps)
    delta_g = int((g1 - g2) // steps)
    delta_b = int((b1 - b2) // steps)

    for i in range(0, steps):
        keybow.set_led(index, i * delta_r, i * delta_g, i * delta_b)
        time.sleep(2.0 / 60.0)
    keybow.set_led(index, r2, g2, b2)
def handle_key(index, state):
    global brightlist
    if state and brightlist == off:
        brightlist = quarter
        keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2])
    elif state and brightlist == quarter:
        brightlist = half
        keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2])
    elif state and brightlist == half:
        brightlist = threequarter
        keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2])
    elif state and brightlist == threequarter:
        brightlist = full
        keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2])
    elif state and brightlist == full:
        brightlist = off
        keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2])
    return brightlist
예제 #10
0
def handle_key(index, state):
    global pttbutton
    global cwselect
    global ccwselect
    global ptt

    if state:
        if index == pttbutton:
            if ptt == 1:
                try:
                    time.sleep(0.5)
                    requests.get(url=pttOFF_URL, timeout=1)
                except requests.exceptions.RequestException as e:  # This is the correct syntax
                    print(e)
                ptt = 0
            else:
                try:
                    requests.get(url=pttON_URL, timeout=1)
                except requests.exceptions.RequestException as e:  # This is the correct syntax
                    print(e)
                ptt = 1

        if index == cwselect:
            keybow.set_led(index, 0, 0, 255)
            try:
                requests.get(url=cwURL, timeout=1)
            except requests.exceptions.RequestException as e:  # This is the correct syntax
                print(e)
        if index == ccwselect:
            keybow.set_led(index, 0, 0, 255)
            try:
                requests.get(url=ccwURL, timeout=1)
            except requests.exceptions.RequestException as e:  # This is the correct syntax
                print(e)
    else:
        if index != pttbutton:
            keybow.set_led(index, 0, 0, 0)
예제 #11
0
def set_color(key_name, color):
    index = keyNames.index(key_name)
    r,g,b = hex_to_rgb(color)
    keybow.set_led(index,r,g,b)
    keybow.show()
예제 #12
0
            keybow.set_led(index, 0, 0, 255)
            try:
                requests.get(url=cwURL, timeout=1)
            except requests.exceptions.RequestException as e:  # This is the correct syntax
                print(e)
        if index == ccwselect:
            keybow.set_led(index, 0, 0, 255)
            try:
                requests.get(url=ccwURL, timeout=1)
            except requests.exceptions.RequestException as e:  # This is the correct syntax
                print(e)
    else:
        if index != pttbutton:
            keybow.set_led(index, 0, 0, 0)


while True:
    keybow.show()
    if redis.get('ptt'):
        if pttlight == 0:
            keybow.set_led(pttbutton, 255, 0, 0)
            pttlight = 1
            ptt = 1
    else:
        if pttlight == 1:
            keybow.set_led(pttbutton, 0, 0, 0)
            pttlight = 0
            ptt = 0

    time.sleep(1.0 / 120.0)
#!/usr/bin/env python
import keybow
import time
import os

keybow.setup(keybow.MINI)

keybow.set_led(0, 0, 0, 127)
keybow.set_led(1, 0, 127, 0)
keybow.set_led(2, 127, 0, 0)


@keybow.on(index=0)
def handle_key(index, state=True):
    print("{}: Key {} has been {}".format(
        time.time(),
        index,
        'pressed' if state else 'released'))
    
    if state:
        keybow.set_led(index, 0, 0, 255)
        os.system("ssh [email protected] sudo systemctl restart mopidy")
    else:
        keybow.set_led(index, 0, 0, 127)

@keybow.on(index=1)
def handle_key(index, state):
    print("{}: Key {} has been {}".format(
        time.time(),
        index,
        'pressed' if state else 'released'))
#!/usr/bin/env python
import keybow

keybow.setup(keybow.MINI)

keybow.set_led(0, 0, 0, 0)
keybow.set_led(1, 0, 0, 0)
keybow.set_led(2, 0, 0, 0)

keybow.show()
def set_leds(colour):
    r, g, b = colour
    for i in range(3):
        keybow.set_led(i, r, g, b)
    keybow.show()
def set_led(button: int, colour):
    r, g, b = colour
    keybow.set_led(button, r, g, b)
    keybow.show()
def handle_key(index, state):
    if state:
        keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2])
    else:
        keybow.set_led(index, 0, 0, 0)
def handle_key(index, state):
    global rgblist
    if state and rgblist == off:
        rgblist = candle
        keybow.set_led(index, rgblist[0], rgblist[1], rgblist[2])
    elif state and rgblist == candle:
        rgblist = fortyw
        keybow.set_led(index, rgblist[0], rgblist[1], rgblist[2])
    elif state and rgblist == fortyw:
        rgblist = hundredw
        keybow.set_led(index, rgblist[0], rgblist[1], rgblist[2])
    elif state and rgblist == hundredw:
        rgblist = halogen
        keybow.set_led(index, rgblist[0], rgblist[1], rgblist[2])
    elif state and rgblist == halogen:
        rgblist = carbon
        keybow.set_led(index, rgblist[0], rgblist[1], rgblist[2])
    elif state and rgblist == carbon:
        rgblist = off
        keybow.set_led(index, rgblist[0], rgblist[1], rgblist[2])
    return rgblist