maybe added threads
This commit is contained in:
parent
94a295b917
commit
33d8f6888d
1 changed files with 16 additions and 2 deletions
18
server.py
18
server.py
|
@ -7,6 +7,8 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
|
|||
from io import BytesIO
|
||||
import string
|
||||
import base64
|
||||
import queue
|
||||
from threading import Thread
|
||||
|
||||
NULL_CHAR = chr(0)
|
||||
file = open('/dev/hidg0', 'rb+')
|
||||
|
@ -14,6 +16,11 @@ file = open('/dev/hidg0', 'rb+')
|
|||
alphabet_lower = set(string.ascii_lowercase)
|
||||
alphabet_upper = set(string.ascii_uppercase)
|
||||
|
||||
message_queue = queue.SimpleQueue
|
||||
|
||||
thread = Thread(target = writer)
|
||||
thread.start()
|
||||
|
||||
colors = {
|
||||
"Z": "a", # Black
|
||||
"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):
|
||||
file.write(report.encode())
|
||||
|
||||
|
@ -141,9 +155,9 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
|||
response.write(b'Received: ')
|
||||
self.wfile.write(response.getvalue())
|
||||
if message == 'reset':
|
||||
printstring('\n' * 32)
|
||||
message_queue.put('\n' * 32)
|
||||
else:
|
||||
printstring(message + '\n')
|
||||
message_queue.put(message + '\n')
|
||||
# beep()
|
||||
reset_color()
|
||||
file.flush()
|
||||
|
|
Loading…
Reference in a new issue