Skip to content

Commit

Permalink
SL1SW-2381: sla: select printer prefix according to detected model
Browse files Browse the repository at this point in the history
- yaml file moved to common `yaml` forlder
- all prefixes changed to XX and compatible printers set to both SL1 and M1 models
  • Loading branch information
filipkotoucek committed Aug 13, 2024
1 parent c71dff0 commit a0a91e1
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 123 deletions.
1 change: 1 addition & 0 deletions prusaerrors/shared/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Printer(IntEnum):
XL = 0x0011
MK35 = 0x0017
MK39 = 0x0015
M1 = 0x001D


@unique
Expand Down
58 changes: 57 additions & 1 deletion prusaerrors/sl1/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,70 @@

import builtins
from pathlib import Path
from re import compile as re_compile

from prusaerrors.shared.codes import unique_codes, Codes, yaml_codes
import yaml

from prusaerrors.shared.codes import Category, Code, Printer, unique_codes, Codes

if "_" not in vars(builtins):

def _(value):
return value

def yaml_codes(src_path: Path):
"""
Add code definitions from YAML source
"""

def decor(cls):
with src_path.open("r") as src_file:
data = yaml.safe_load(src_file)
assert "Errors" in data

printer = Printer.SL1
path = Path("/run/model")
model = [x.name for x in path.iterdir() if x.is_file()]
if len(model) == 1:
a = Printer.M1.name.lower()
if a in model:
printer = Printer.M1
else:
raise KeyError("None or multiple model files found. Check /run/model folder.")

re = re_compile(
r"^(?P<printer>([0-9][0-9]|XX))"
r"(?P<category>[0-9])"
r"(?P<error>[0-9][0-9])$"
)
for entry in data["Errors"]:
code_parts = re.match(entry["code"]).groupdict()
category = Category(int(code_parts["category"]))
error = int(code_parts["error"])
printers = entry.get("printers")
action = entry.get("action", [])

if code_parts["printer"] == 'XX':
if printer.name in printers:
setattr(
cls,
entry["id"],
Code(
printer,
category,
error,
entry["title"],
entry["text"],
entry.get("approved", False),
action
)
)
else:
raise KeyError("current code has specific prefix. It has to be XX...")
return cls

return decor


@unique_codes
@yaml_codes(Path(__file__).parent / "errors.yaml")
Expand Down
2 changes: 1 addition & 1 deletion prusaerrors/sl1/errors.yaml
Loading

0 comments on commit a0a91e1

Please sign in to comment.