improve display

- display config has only one line for startup text
- faster display daeomon startup
- added newer fonts (e.g. medium) to display.py
This commit is contained in:
2024-01-15 11:34:03 +01:00
parent fe1303efdc
commit ae6ba7a031
3 changed files with 65 additions and 57 deletions

View File

@ -37,12 +37,14 @@ SET_STARTUP = 0xf2
IDENT = 0xf3 IDENT = 0xf3
FONT_GEO = [(6, 8), (8, 16), (20, 40)] FONT_GEO = [(6, 8), (8, 16), (20, 40), (38,64), (16, 16), (12, 24)]
TOPGAP = 8 # upper part of display is not useable TOPGAP = 8 # upper part of display is not useable
HEIGHT = 120 HEIGHT = 120
WIDTH = 480 WIDTH = 480
MAGIC = b'\xcb\xef\x20\x18'
def xy(x, y): def xy(x, y):
x = min(480, int(x)) x = min(480, int(x))
@ -83,7 +85,7 @@ class Display:
if daemon: if daemon:
threading.Thread(target=self.gethostthread, daemon=True).start() threading.Thread(target=self.gethostthread, daemon=True).start()
self.event.wait(1) # wait for thread to be started self.event.wait(1) # wait for thread to be started
self.refresh() self.net_display(None)
def reset(self): def reset(self):
self.send(MODE_GRAPH) self.send(MODE_GRAPH)
@ -200,7 +202,6 @@ class Display:
return return
if data[0] == TOUCH and len(data) == 3: if data[0] == TOUCH and len(data) == 3:
x = (data[1] % 2) * 256 + data[2] x = (data[1] % 2) * 256 + data[2]
print(x)
return x return x
print('skipped', data) print('skipped', data)

View File

@ -14,13 +14,14 @@ import filecmp
import shutil import shutil
import serial import serial
import types import types
import socket
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from glob import glob from glob import glob
from ipaddress import IPv4Interface from ipaddress import IPv4Interface
from configparser import ConfigParser from configparser import ConfigParser
from os.path import join, getmtime, exists, basename from os.path import join, getmtime, exists, basename
more_info = sys.argv[1] if len(sys.argv) > 1 else 'NONE' more_info = False
os.chdir('/root/aputools/to_system') os.chdir('/root/aputools/to_system')
DEL = '__to_delete__' DEL = '__to_delete__'
@ -96,6 +97,13 @@ ExecStart = /usr/bin/python3 /root/aputools/display.py -d
WantedBy = multi-user.target WantedBy = multi-user.target
""" """
ifname_mapping = {
'eth0': 'enp1s0',
'eth1': 'enp2s0',
'eth2': 'enp3s0',
'eth3': 'enp4s0',
}
pip_requirements = { pip_requirements = {
'l_samenv': {}, 'l_samenv': {},
'root': {} 'root': {}
@ -108,7 +116,7 @@ main_info = { # info to be determined depending on cfg
'ifname': '', # name of interface of wan (dhcp) port 'ifname': '', # name of interface of wan (dhcp) port
'addr': '', # addr of wan port 'addr': '', # addr of wan port
'current': None, 'current': None,
'hostname': gethostname() # effective or given host name 'hostname': socket.gethostname() # effective or given host name
} }
for netif in os.scandir('/sys/class/net'): for netif in os.scandir('/sys/class/net'):
@ -145,19 +153,15 @@ def router(**opts):
def display_update(cfg): def display_update(cfg):
text = '\n'.join(cfg.get(key, '') for key in ('line0', 'line1', 'line2')) text = '\n'.join(cfg.get('startup_text', '').split('|')[:3])
text = text.replace('HOST', main_info['hostname']) \ text = text.replace('HOST', main_info['hostname']) \
.replace('ADDR', main_info['addr']) + '\n' .replace('ADDR', main_info['addr']) + '\n'
try: if write_when_new(STARTUP_TEXT, text):
with open(STARTUP_TEXT) as f: print('change startup text')
if f.read() == text: if doit:
return os.rename(STARTUP_TEXT, STARTUP_TEXT + '.todo')
except FileNotFoundError: return True
pass return False
print('new startup text:')
print(text)
with open(STARTUP_TEXT + '.todo', 'w') as f:
f.write(text)
def display(**opts): def display(**opts):
@ -230,7 +234,8 @@ def write_when_new(filename, content, ignore_reduction=False):
fil.write(content) fil.write(content)
else: else:
os.remove(filename) os.remove(filename)
elif filename.endswith(more_info): elif more_info:
print('.' * 80)
print('changes in', filename) print('changes in', filename)
old = [] if old is None else old.split('\n') old = [] if old is None else old.split('\n')
top_lines = 0 # in case of empty loop top_lines = 0 # in case of empty loop
@ -254,6 +259,7 @@ def write_when_new(filename, content, ignore_reduction=False):
print('>>>') print('>>>')
print('\n'.join(old[-bottom_lines:-1])) print('\n'.join(old[-bottom_lines:-1]))
print("===") print("===")
print('.' * 80)
return content return content
@ -344,20 +350,21 @@ class Show(Walker):
def diff(self, title, files): def diff(self, title, files):
self.dirty = True self.dirty = True
if more_info == 'NONE': if more_info:
print('%s %s:\n %s' % (title, self.syspath, ' '.join(files)))
else:
for f in files: for f in files:
if f.endswith(more_info): if f.endswith(more_info):
print('diff %s %s' % (join(self.dirpath, f), join(self.syspath, f))) print('diff %s %s' % (join(self.dirpath, f), join(self.syspath, f)))
print('.' * 80)
else:
print('%s %s:\n %s' % (title, self.syspath, ' '.join(files)))
def show(self, title, dirpath, files): def show(self, title, dirpath, files):
if more_info == 'NONE': if more_info:
print('%s %s:\n %s' % (title, self.syspath, ' '.join(files)))
else:
for f in files: for f in files:
if f.endswith(more_info): print('cat %s' % join(dirpath, f))
print('cat %s' % join(dirpath, f)) print('.' * 80)
else:
print('%s %s:\n %s' % (title, self.syspath, ' '.join(files)))
def newer(self, files): def newer(self, files):
self.show('get from', self.dirpath, files) self.show('get from', self.dirpath, files)
@ -392,6 +399,7 @@ class Do(Walker):
def handle_config(): def handle_config():
cfgfile = None cfgfile = None
cfgfiles = [] cfgfiles = []
dhcp_server_cfg.clear()
for file in glob(CFGPATH % ('*', apuid)): for file in glob(CFGPATH % ('*', apuid)):
cfgfiles.append(file) cfgfiles.append(file)
for i in [1, 2, 3]: for i in [1, 2, 3]:
@ -400,7 +408,7 @@ def handle_config():
print('cfg files found with bad apu id (use net addr of leftmost plug)') print('cfg files found with bad apu id (use net addr of leftmost plug)')
print(bad) print(bad)
return False return False
newhostname = main['hostname'] newhostname = main_info['hostname']
if not cfgfiles: if not cfgfiles:
# determine if display is present # determine if display is present
disp = serial.Serial('/dev/ttyS1', baudrate=115200, timeout=1) disp = serial.Serial('/dev/ttyS1', baudrate=115200, timeout=1)
@ -428,7 +436,7 @@ def handle_config():
print('ERROR: ambiguous cfg files: %s' % ', '.join(cfgfiles)) print('ERROR: ambiguous cfg files: %s' % ', '.join(cfgfiles))
else: else:
cfgfile = cfgfiles[0] cfgfile = cfgfiles[0]
if cfgfile != CFGPATH % (hostname, apuid): if cfgfile != CFGPATH % (newhostname, apuid):
if cfgfile: if cfgfile:
newhostname = basename(cfgfile).rpartition('_')[0] newhostname = basename(cfgfile).rpartition('_')[0]
if doit: if doit:
@ -445,12 +453,12 @@ def handle_config():
parser = ConfigParser() parser = ConfigParser()
try: try:
parser.read(cfgfile) parser.read(cfgfile)
network = dict(parser['NETWORK']) network = {ifname_mapping.get(k, k): v for k, v in parser['NETWORK'].items()}
for ifname in net_addr: for ifname in net_addr:
content = create_if(ifname, network.pop(ifname, 'off')) content = create_if(ifname, network.pop(ifname, 'off'))
content = '\n'.join('%s=%s' % kv for kv in content.items()) content = '\n'.join('%s=%s' % kv for kv in content.items())
todo = write_when_new('/etc/sysconfig/network-scripts/ifcfg-%s' % ifname, content) todo = write_when_new('/etc/sysconfig/network-scripts/ifcfg-%s' % ifname, content)
if todo and more_info == 'NONE': if todo and not more_info:
print('change', ifname) print('change', ifname)
show.dirty = True show.dirty = True
to_start[ifname] = 'if_restart' to_start[ifname] = 'if_restart'
@ -472,7 +480,7 @@ def handle_config():
if todo: if todo:
print('change dhcpd.conf') print('change dhcpd.conf')
to_start['dhcpd'] = 'restart' to_start['dhcpd'] = 'restart'
show.dirty = True show.dirty = True
elif doit: elif doit:
unix_cmd('systemctl stop dhcpd') unix_cmd('systemctl stop dhcpd')
unix_cmd('systemctl disable dhcpd') unix_cmd('systemctl disable dhcpd')
@ -485,7 +493,8 @@ def handle_config():
content.append(COMMENT) content.append(COMMENT)
section_dict = dict(parser[section].items()) section_dict = dict(parser[section].items())
if section == 'DISPLAY': if section == 'DISPLAY':
display_update(section_dict) if display_update(section_dict):
to_start['display'] = 'restart'
for key, value in section_dict.items(): for key, value in section_dict.items():
content.append('%s=%s' % (key, value)) content.append('%s=%s' % (key, value))
content.append('') content.append('')
@ -551,30 +560,30 @@ def handle_config():
return '\n'.join(result) return '\n'.join(result)
more_info = 'NONE' more_info = False
while True: doit = False
doit = False print(' ')
print('---') show = Show()
show = Show() walk(show)
walk(show) result = handle_config()
result = handle_config()
if not result: if not result:
print('fix first above errors') print('fix first above errors')
break else:
if show.dirty and more_info == 'NONE': if show.dirty:
print('---') print('---')
answer = input('enter y(es) to do above or a filename to check changes? ') answer = input('enter "y(es)" to do above or "m(ore)" for more info: ')
doit = True if not answer:
if answer.lower() in {'y', 'yes'}: print('cancel')
elif 'yes'.startswith(answer.lower()):
doit = True
handle_config() handle_config()
walk(Do()) walk(Do())
with open('/root/aputools/current', 'w') as f: with open('/root/aputools/current', 'w') as f:
f.write(result) f.write(result)
break elif 'more'.startswith(answer.lower()):
if not answer: more_info = True
print('cancel') walk(show)
break result = handle_config()
else: else:
print('nothing to do') print('nothing to do')
break

View File

@ -1,12 +1,10 @@
[NETWORK] [NETWORK]
; please refer to README.md for help ; please refer to README.md for help
enp1s0=dhcp eth0=dhcp
enp2s0=192.168.1.1 eth1=192.168.1.1
enp3s0=192.168.2.2 eth2=192.168.2.2
enp4s0=192.168.3.3 eth3=192.168.3.3
[DISPLAY] [DISPLAY]
; please refer to README.md for help ; please refer to README.md for help
line0=startup... startup_text=startup...|HOST|ADDR
line1=HOST: linse-box1
line2=ADDR: 00:0d:b9:5b:26:5c