コード例 #1
0
def handle_key(index, state):
    global pttbutton
    global freq_up
    global freq_down
    global ptt

    if state:
        if index == pttbutton:
            if ptt == 1:
                delay = int(redis.get('pttDelay')) / 10
                time.sleep(delay)
                asyncio.run(flex_msg('ZZTX0;'))
                keybow.set_led(index, 0, 0, 0)
                ptt = 0
            else:
                asyncio.run(flex_msg('ZZTX1;'))
                keybow.set_led(index, 255, 0, 0)
                ptt = 1

        if index == freq_up:
            keybow.set_led(index, 0, 0, 255)
            asyncio.run(flex_freq_up())
        if index == freq_down:
            keybow.set_led(index, 0, 0, 255)
            asyncio.run(flex_freq_down())
    else:
        if index != pttbutton:
            keybow.set_led(index, 0, 0, 0)
    keybow.show()
コード例 #2
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()
コード例 #3
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()
コード例 #4
0
def test_show():
    _mock()

    class SpiDev():
        def __init__(self):
            self.captured = None

        def xfer2(self, data):
            self.captured = data

    import keybow
    spi = SpiDev()
    keybow.setup()
    keybow.spi = spi

    keybow.set_all(0, 255, 0)
    keybow.show()

    # Lazy capture recording
    # with open('/tmp/capture.txt', 'w') as f:
    #    f.write(str(spi.captured))
    # assert 1 == 2

    assert spi.captured == [
        0, 0, 0, 0, 0, 0, 0, 0,  # SOF
        255, 0, 255, 0,          # LED1
        255, 0, 255, 0,          # LED2
        255, 0, 255, 0,          # ...
        255, 0, 255, 0,
        255, 0, 255, 0,
        255, 0, 255, 0,
        255, 0, 255, 0,
        255, 0, 255, 0,
        255, 0, 255, 0,
        255, 0, 255, 0,
        255, 0, 255, 0,
        255, 0, 255, 0,          # LED12
        0]                       # EOF
コード例 #5
0
ファイル: WiKeyBow.py プロジェクト: DFranzen/WiKeyBow
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()
コード例 #6
0
ファイル: remoteKeys.py プロジェクト: on3ure/remoteShack
            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)
コード例 #7
0
def set_leds(colour):
    r, g, b = colour
    for i in range(3):
        keybow.set_led(i, r, g, b)
    keybow.show()
コード例 #8
0
def set_led(button: int, colour):
    r, g, b = colour
    keybow.set_led(button, r, g, b)
    keybow.show()