add good heuristic for typing detection

This commit is contained in:
Chrys 2019-08-22 21:02:54 +02:00
parent 7527fc3552
commit 6bf7ad6b74

View File

@ -103,17 +103,20 @@ class driver(screenDriver):
vcsaDevices = glob.glob('/dev/vcsa*') vcsaDevices = glob.glob('/dev/vcsa*')
vcsu = {} vcsu = {}
vcsuDevices = None vcsuDevices = None
lastScreenContent = b''
tty = open('/sys/devices/virtual/tty/tty0/active','r')
currScreen = str(tty.read()[3:-1])
oldScreen = currScreen
for vcsaDev in vcsaDevices: for vcsaDev in vcsaDevices:
index = vcsaDev[9:] index = str(vcsaDev[9:])
vcsa[str(index)] = open(vcsaDev,'rb') vcsa[index] = open(vcsaDev,'rb')
if index == currScreen:
lastScreenContent = vcsa[str(index)].read()
if useVCSU: if useVCSU:
vcsuDevices = glob.glob('/dev/vcsu*') vcsuDevices = glob.glob('/dev/vcsu*')
for vcsuDev in vcsuDevices: for vcsuDev in vcsuDevices:
index = vcsuDev[9:] index = vcsuDev[9:]
vcsu[str(index)] = open(vcsuDev,'rb') vcsu[str(index)] = open(vcsuDev,'rb')
tty = open('/sys/devices/virtual/tty/tty0/active','r')
currScreen = str(tty.read()[3:-1])
oldScreen = currScreen
self.updateCharMap(currScreen) self.updateCharMap(currScreen)
watchdog = select.epoll() watchdog = select.epoll()
watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR) watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR)
@ -140,7 +143,7 @@ class driver(screenDriver):
oldScreen = currScreen oldScreen = currScreen
try: try:
vcsa[currScreen].seek(0) vcsa[currScreen].seek(0)
lastScreenContent = vcsa[currScreen].read() lastScreenContent = vcsa[currScreen].read()
except: except:
pass pass
vcsuContent = None vcsuContent = None
@ -153,20 +156,35 @@ class driver(screenDriver):
else: else:
self.env['runtime']['debug'].writeDebugOut('ScreenUpdate',debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('ScreenUpdate',debug.debugLevel.INFO)
vcsa[currScreen].seek(0) vcsa[currScreen].seek(0)
dirtyContent = vcsa[currScreen].read() screenContent = vcsa[currScreen].read()
screenContent = b'' dirtyContent = b''
vcsuContent = None vcsuContent = None
timeout = time.time() timeout = time.time()
while screenContent != dirtyContent: if screenContent == b'':
screenContent = dirtyContent continue
if time.time() - timeout >= 0.4: if lastScreenContent == b'':
break lastScreenContent = screenContent
time.sleep(0.02) if abs( int(screenContent[2]) - int(lastScreenContent[2])) in [1]:
vcsa[currScreen].seek(0) # Skip X Movement
dirtyContent = vcsa[currScreen].read() pass
elif abs( int(screenContent[3]) - int(lastScreenContent[3])) in [1]:
# Skip Y Movement
pass
else:
# anything else? wait for completion
while True:
screenContent = dirtyContent
vcsa[currScreen].seek(0)
time.sleep(0.03)
dirtyContent = vcsa[currScreen].read()
if screenContent == dirtyContent:
break
if time.time() - timeout >= 0.3:
break
if useVCSU: if useVCSU:
vcsu[currScreen].seek(0) vcsu[currScreen].seek(0)
vcsuContent = vcsu[currScreen].read() vcsuContent = vcsu[currScreen].read()
lastScreenContent = screenContent
eventQueue.put({"Type":fenrirEventType.ScreenUpdate, eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
"Data":self.createScreenEventData(currScreen, screenContent, vcsuContent) "Data":self.createScreenEventData(currScreen, screenContent, vcsuContent)
}) })