diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-08-04 09:40:56 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-08-04 09:40:56 +0200 |
commit | 7c93e78865698cc80dd96ccf0e7639cffc85d641 (patch) | |
tree | e5c6e968c18cd14bf6469238ae167c9cf64ffbfb /main.py | |
parent | 1bfd3543a7989e325c756547960b99d0d3eaed07 (diff) |
keep alive + nodejs binding
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -7,6 +7,7 @@ import sys mac = sys.argv[1] dev = None +messages = [] def verify_connection(): global dev @@ -16,9 +17,6 @@ def verify_connection(): except BTLEDisconnectError as e: continue -verify_connection() -print("connected") - def makemsg(r, g, b, l=0): return bytes([ int(g > 0), g, @@ -28,17 +26,24 @@ def makemsg(r, g, b, l=0): int(l > 0), l, ]) -messages = [] -def thread_func(): +def keep_alive(): while True: - if len(messages) < 1: continue - message = messages.pop(0) - verify_connection() - dev.writeCharacteristic(0x002A, message) + global messages + messages.append((0x0001, bytes(10))) + time.sleep(10) + +def user_input(): + for line in sys.stdin: + r, g, b, l = [ int(x, 16) for x in [ line.strip()[i:i+2] for i in range(0, 8, 2) ] ] + messages.append((0x002a, makemsg(r, g, b, l))) -threading.Thread(target=thread_func).start() +threading.Thread(target=keep_alive).start() +threading.Thread(target=user_input).start() -for line in sys.stdin: - r, g, b, l = [ int(x, 16) for x in [ line.strip()[i:i+2] for i in range(0, 8, 2) ] ] - messages.append(makemsg(r, g, b, l)) +verify_connection() +while True: + if len(messages) < 1: continue + message = messages.pop(0) + verify_connection() + dev.writeCharacteristic(message[0], bytearray(message[1])) |