Update code to use xatLabs Cheetah display controller

This commit is contained in:
Julian Metzler 2024-03-17 13:58:03 +01:00
parent d476f2ccd9
commit f32241ab5c
4 changed files with 17 additions and 84 deletions

Binary file not shown.

1
TYPM.JSN Normal file

File diff suppressed because one or more lines are too long

68
run.py
View File

@ -1,6 +1,5 @@
from deutschebahn import DBInfoscreen
from pyfis.krone import Krone8200Display
from pyfis.krone.exceptions import CommunicationError
from pyfis.xatlabs import xatLabsCheetah
from pyfis.utils import get_vias
from util import timeout, TimeoutError
@ -169,69 +168,18 @@ def update_display(display, dbi):
def main():
ctrl = Krone8200Display(SERIAL_PORT, address=(0x41, 0x49), debug=True)
ctrl.port.timeout=5.0
ctrl = xatLabsCheetah("http://typ-m-zza.local")
display = ctrl.get_splitflap_display()
dbi = DBInfoscreen(DBI_HOST)
display = TypMZZA(ctrl)
display.clear()
last_update = 0
last_heartbeat = 0
while True:
now = time.time()
if now - last_heartbeat >= 10:
print("\n" + "=" * 60 + "\n")
print("Sending heartbeat")
ctrl.send_end_comm()
last_heartbeat = now
continue
if now - last_update < 60:
time.sleep(1)
continue
print("\n" + "=" * 60 + "\n")
try:
display_id = update_display(display, dbi)
try:
with open("/tmp/m-zza-status.json", 'r') as f:
status = json.load(f)
except (FileNotFoundError, ValueError):
status = {'displayHash': None}
display_hash = hashlib.sha256(bytes(display_id, 'utf-8')).hexdigest()
update = True
if status['displayHash'] == display_hash:
print("No need to update display.")
update = False
else:
status['displayHash'] = display_hash
if update:
num_tries = 10
for i in range(num_tries):
try:
display.update()
break
except CommunicationError:
print("Communication error! Retrying... {}/{}".format(i+1, num_tries))
time.sleep(5)
with open("/tmp/m-zza-status.json", 'w') as f:
json.dump(status, f)
except:
traceback.print_exc()
last_update = now
display.update()
try:
display_id = update_display(display, dbi)
display.update()
except:
traceback.print_exc()
if __name__ == "__main__":

View File

@ -2,23 +2,6 @@ from pyfis.splitflap_display import SplitFlapDisplay, TextField, CustomMapField,
from pyfis.utils import vias_from_csv, map_from_csv
def _load_map(file):
_map = {}
with open(file, 'r') as f:
lines = f.readlines()
for line in lines:
line = line.strip()
if not line:
continue
parts = line.split(maxsplit=1)
pos = int(parts[0])
if len(parts) > 1:
text = parts[1]
_map[pos] = text
return _map
SERIAL_PORT = "/dev/serial/by-path/platform-3f980000.usb-usb-0:1.5:1.0-port0"
DBI_HOST = "trains.xatlabs.com"
STATION_CODE = "MH"
STATION_NAME = "München Hbf"
@ -176,14 +159,15 @@ VIA_WEIGHTS = {
}
# Wird nur noch gebraucht, um neue JSON-Datei zu erstellen
class TypMZZA(SplitFlapDisplay):
hour = CustomMapField(MAP_HOUR, start_address=1, x=0, y=0, module_width=12, module_height=2, home_pos=99)
minute = CustomMapField(MAP_MINUTE, start_address=2, x=12, y=0, module_width=4, module_height=2, home_pos=99)
info_1 = CustomMapField(MAP_INFO_1, start_address=4, x=0, y=2, module_width=16, module_height=2, home_pos=99)
info_2 = CustomMapField(MAP_INFO_2, start_address=5, x=0, y=4, module_width=16, module_height=2, home_pos=99)
via_1 = CustomMapField(MAP_VIA_1, start_address=6, x=16, y=2, module_width=16, module_height=2, home_pos=99)
via_2 = CustomMapField(MAP_VIA_2, start_address=7, x=16, y=4, module_width=16, module_height=2, home_pos=99)
destination = TextField(start_address=8, length=16, x=0, y=6, module_width=2, module_height=2, display_mapping=MAP_ALNUM, home_pos=99)
hour = CustomMapField(MAP_HOUR, start_address=1, x=0, y=0, module_width=12, module_height=2, home_pos=127)
minute = CustomMapField(MAP_MINUTE, start_address=2, x=12, y=0, module_width=4, module_height=2, home_pos=127)
info_1 = CustomMapField(MAP_INFO_1, start_address=4, x=0, y=2, module_width=16, module_height=2, home_pos=127)
info_2 = CustomMapField(MAP_INFO_2, start_address=5, x=0, y=4, module_width=16, module_height=2, home_pos=127)
via_1 = CustomMapField(MAP_VIA_1, start_address=6, x=16, y=2, module_width=16, module_height=2, home_pos=127)
via_2 = CustomMapField(MAP_VIA_2, start_address=7, x=16, y=4, module_width=16, module_height=2, home_pos=127)
destination = TextField(start_address=8, length=16, x=0, y=6, module_width=2, module_height=2, display_mapping=MAP_ALNUM, home_pos=127)
hour_b = MirrorField(hour, start_address=24, x=0, y=10)
minute_b = MirrorField(minute, start_address=25, x=12, y=10)