Compare commits

...

1 commit

Author SHA1 Message Date
Hannes Klinckaert
33d8f6888d maybe added threads 2019-10-02 18:18:27 +02:00

View file

@ -7,6 +7,8 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
from io import BytesIO from io import BytesIO
import string import string
import base64 import base64
import queue
from threading import Thread
NULL_CHAR = chr(0) NULL_CHAR = chr(0)
file = open('/dev/hidg0', 'rb+') file = open('/dev/hidg0', 'rb+')
@ -14,6 +16,11 @@ file = open('/dev/hidg0', 'rb+')
alphabet_lower = set(string.ascii_lowercase) alphabet_lower = set(string.ascii_lowercase)
alphabet_upper = set(string.ascii_uppercase) alphabet_upper = set(string.ascii_uppercase)
message_queue = queue.SimpleQueue
thread = Thread(target = writer)
thread.start()
colors = { colors = {
"Z": "a", # Black "Z": "a", # Black
"B": "b", # Blue "B": "b", # Blue
@ -67,6 +74,13 @@ special_chars = {
} }
def writer() {
while true:
if not message_queue.empty():
message = message_queue.get()
printstring(message)
}
def write_report(report): def write_report(report):
file.write(report.encode()) file.write(report.encode())
@ -141,9 +155,9 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
response.write(b'Received: ') response.write(b'Received: ')
self.wfile.write(response.getvalue()) self.wfile.write(response.getvalue())
if message == 'reset': if message == 'reset':
printstring('\n' * 32) message_queue.put('\n' * 32)
else: else:
printstring(message + '\n') message_queue.put(message + '\n')
# beep() # beep()
reset_color() reset_color()
file.flush() file.flush()