fenrir/play zone/epollScreen.py

38 lines
1.1 KiB
Python
Raw Permalink Normal View History

2017-06-21 18:04:07 -04:00
#!/bin/python
import select
import time
2017-06-21 19:27:31 -04:00
currScreen = '2'
2017-06-21 18:04:07 -04:00
vcsa = {}
for i in range(1,7):
vcsa[str(i)] = open('/dev/vcs'+str(i),'rb')
tty = open('/sys/devices/virtual/tty/tty0/active','r')
2017-06-21 19:27:31 -04:00
currScreen = str(tty.read()[3:-1])
oldScreen = currScreen
watchdog = select.epoll()
watchdog.register(vcsa[currScreen], select.EPOLLPRI)
2017-06-21 18:04:07 -04:00
watchdog.register(tty, select.EPOLLPRI)
2017-06-21 19:27:31 -04:00
2017-06-21 18:04:07 -04:00
while True:
2017-06-21 19:27:31 -04:00
changes = watchdog.poll()
2017-06-21 18:04:07 -04:00
print('-----------------------------')
2017-06-21 19:27:31 -04:00
print(changes)
for change in changes:
fileno = change[0]
event = change[1]
print(change,fileno, tty.fileno())
if fileno == tty.fileno():
tty.seek(0)
currScreen = str(tty.read()[3:-1])
if currScreen != oldScreen:
watchdog.unregister(vcsa[ oldScreen ])
watchdog.register(vcsa[ currScreen ], select.EPOLLPRI)
oldScreen = currScreen
print('new screen '+ currScreen)
2017-06-21 18:04:07 -04:00
else:
2017-06-21 19:27:31 -04:00
vcsa[currScreen].seek(0)
content = vcsa[currScreen].read()
print('update '+ str(time.time()))