Thanks boterham and francis.
This commit is contained in:
parent
6e0ac923fa
commit
94a295b917
1 changed files with 53 additions and 14 deletions
49
server.py
49
server.py
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
import string
|
import string
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import string
|
import string
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
||||||
NULL_CHAR = chr(0)
|
NULL_CHAR = chr(0)
|
||||||
file = open('/dev/hidg0', 'rb+')
|
file = open('/dev/hidg0', 'rb+')
|
||||||
|
|
||||||
|
@ -32,6 +33,40 @@ colors = {
|
||||||
"w": "p" # Light/blink White
|
"w": "p" # Light/blink White
|
||||||
}
|
}
|
||||||
|
|
||||||
|
special_chars = {
|
||||||
|
' ': [NULL_CHAR, chr(44)],
|
||||||
|
'\n': [NULL_CHAR, chr(40)],
|
||||||
|
'\\': [NULL_CHAR, chr(0x31)],
|
||||||
|
'.': [NULL_CHAR, chr(0x37)],
|
||||||
|
'/': [NULL_CHAR, chr(0x38)],
|
||||||
|
';': [NULL_CHAR, chr(0x33)],
|
||||||
|
'-': [NULL_CHAR, chr(0x2d)],
|
||||||
|
'=': [NULL_CHAR, chr(0x2e)],
|
||||||
|
'[': [NULL_CHAR, chr(0x2f)],
|
||||||
|
']': [NULL_CHAR, chr(0x30)],
|
||||||
|
'*': [NULL_CHAR, chr(0x55)],
|
||||||
|
',': [NULL_CHAR, chr(0x36)],
|
||||||
|
'!': [chr(32), chr(0x1e)],
|
||||||
|
'<': [chr(32), chr(0x36)],
|
||||||
|
'>': [chr(32), chr(0x37)],
|
||||||
|
'?': [chr(32), chr(0x38)],
|
||||||
|
':': [chr(32), chr(0x33)],
|
||||||
|
'(': [chr(32), chr(0x26)],
|
||||||
|
')': [chr(32), chr(0x27)],
|
||||||
|
'&': [chr(32), chr(0x24)],
|
||||||
|
'%': [chr(32), chr(0x22)],
|
||||||
|
'#': [chr(32), chr(0x20)],
|
||||||
|
'@': [chr(32), chr(0x1f)],
|
||||||
|
'$': [chr(32), chr(0x21)],
|
||||||
|
'_': [chr(32), chr(0x2d)],
|
||||||
|
'+': [chr(32), chr(0x2e)],
|
||||||
|
'{': [chr(32), chr(0x2f)],
|
||||||
|
'}': [chr(32), chr(0x30)],
|
||||||
|
'|': [chr(32), chr(0x31)],
|
||||||
|
'~': [chr(32), chr(0x35)],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def write_report(report):
|
def write_report(report):
|
||||||
file.write(report.encode())
|
file.write(report.encode())
|
||||||
|
|
||||||
|
@ -47,10 +82,8 @@ def printchar(c):
|
||||||
write_report(chr(32) + NULL_CHAR + chr(4 + ord(c) - ord('A')) + NULL_CHAR * 5)
|
write_report(chr(32) + NULL_CHAR + chr(4 + ord(c) - ord('A')) + NULL_CHAR * 5)
|
||||||
elif c.isdigit():
|
elif c.isdigit():
|
||||||
write_report(NULL_CHAR * 2 + chr(0x1e + ((ord(c) - ord('0') - 1) % 10)) + NULL_CHAR * 5)
|
write_report(NULL_CHAR * 2 + chr(0x1e + ((ord(c) - ord('0') - 1) % 10)) + NULL_CHAR * 5)
|
||||||
elif c == ' ':
|
elif c in special_chars:
|
||||||
write_report(NULL_CHAR*2+chr(44)+NULL_CHAR*5)
|
write_report(special_chars[c][0] + NULL_CHAR + special_chars[c][1] + NULL_CHAR * 5)
|
||||||
elif c == '\n':
|
|
||||||
write_report(NULL_CHAR*2+chr(40)+NULL_CHAR*5)
|
|
||||||
else:
|
else:
|
||||||
write_report(chr(32) + NULL_CHAR + chr(0x38) + NULL_CHAR * 5)
|
write_report(chr(32) + NULL_CHAR + chr(0x38) + NULL_CHAR * 5)
|
||||||
release_keys()
|
release_keys()
|
||||||
|
@ -85,6 +118,11 @@ def reset_color():
|
||||||
change_color('Z', 'g')
|
change_color('Z', 'g')
|
||||||
release_keys()
|
release_keys()
|
||||||
|
|
||||||
|
def beep():
|
||||||
|
write_report(NULL_CHAR * 2 + chr(0x29) + 'ff' + NULL_CHAR * 3)
|
||||||
|
release_keys()
|
||||||
|
print('beep')
|
||||||
|
|
||||||
|
|
||||||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
|
@ -106,6 +144,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
printstring('\n' * 32)
|
printstring('\n' * 32)
|
||||||
else:
|
else:
|
||||||
printstring(message + '\n')
|
printstring(message + '\n')
|
||||||
|
# beep()
|
||||||
reset_color()
|
reset_color()
|
||||||
file.flush()
|
file.flush()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue