Skip to content

Commit

Permalink
Unify Buddy platform error codes
Browse files Browse the repository at this point in the history
BFW-4999
  • Loading branch information
CZDanol-prusa authored and CZDanol committed Feb 21, 2024
1 parent 98cd187 commit 4d9bab2
Show file tree
Hide file tree
Showing 9 changed files with 977 additions and 2,631 deletions.
406 changes: 0 additions & 406 deletions 12_MINI/error-codes.yaml

This file was deleted.

544 changes: 0 additions & 544 deletions 13_MK4/error-codes.yaml

This file was deleted.

579 changes: 0 additions & 579 deletions 16_iX/error-codes.yaml

This file was deleted.

606 changes: 0 additions & 606 deletions 17_XL/error-codes.yaml

This file was deleted.

468 changes: 0 additions & 468 deletions 23_MK3.5/error-codes.yaml

This file was deleted.

43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,24 @@
## Error code format <ErrorCode>

XXYZZ

- XX - number of printer according to USB PID
- Y - error category (common for all printers)
- ZZ - specific error code

Example: 12201

12 - printer number 12: Original Prusa MINI+

2 - error category: temperature error

01 - specific error code: Heatbed heating failed
* 12 - printer number 12: Original Prusa MINI+
* 2 - error category: temperature error
* 01 - specific error code: Heatbed heating failed

## Printer number
04 - Original Prusa MMU

10 - Original Prusa SL1/SL1S
* 04 `MMU` - Original Prusa MMU
* 10 `SL1` - Original Prusa SL1/SL1S
* 12 `MINI` - Original Prusa MINI/MINI+
* 13 `MK4` - Original Prusa MK4
* 16 `iX` - AFS IX
* 17 `XL` - Original Prusa XL
* 23 `MK3.5` - Original Prusa MK3.5

12 - Original Prusa MINI/MINI+

13 - Original Prusa MK4

17 - Original Prusa XL

23 - Original Prusa MK3.5
## Error categories
1. Mechanical - XYZ motors, tower, axis range
2. Temperature - thermistors/heating
Expand All @@ -43,3 +36,19 @@ Example: 12201

More information about the error codes can be found at:
[prusa.io/error-codes](https://prusa.io/error-codes)


## YAML files structure (Buddy)
The `.yaml` format structure is as follows:

* Root [dict]
* `Errors` [list of dict]: Specific error codes
* `printers` (optional) [list of string]: same as root-level printer filter
* `code` [string]: Error code in the format `XXYZZ`
* Leave `XX` as `XX`, the code applies to multiple printers.
* For example `XX101`
* `title` [string]: Error message title
* `text` [string]: Error message string
* `id` [string]: Error identifier used for referencing the error in the code
* For example `BED_MINTEMP_ERROR`
* `approved` [bool]: Not really good for anything
22 changes: 11 additions & 11 deletions generate_buddy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,22 @@
}};
"""

def generate_header_file(yaml_file_name, header_file_name, mmu, list, includes):
def generate_header_file(yaml_file_name, header_file_name, printer_id, printer_code, mmu, list, includes):
with open(yaml_file_name, "r") as yaml_file:
parsed_file = yaml.safe_load(yaml_file)

printer_code = None

err_id_cache = set()
err_dict = {}

for err in parsed_file["Errors"]:
if ("printers" in err) and (printer_id not in err["printers"]):
continue

code = err["code"]
assert len(code) == 5, f"Error code {code} is not five digits."
assert code[0:2] == "XX" or code[0:2] == printer_code, f"Code '{code}' has conflicting prefix, expected 'XX' or '{printer_code}'"

curr_printer_code = int(code[0:2])
if printer_code is None:
printer_code = curr_printer_code
else:
assert curr_printer_code == printer_code, \
f"Printer code {curr_printer_code} of error code {code} is not " + \
f"the same as previously specified printer code {printer_code}."
code = f"{printer_code}{code[2:]}"

err_class = int(code[2:3])
assert err_class in err_class_mapping, f"Unknown error class {err_class} in error code {code}."
Expand Down Expand Up @@ -196,7 +192,7 @@ def generate_header_file(yaml_file_name, header_file_name, mmu, list, includes):
else:
template = buddy_template

content = template.format(printer_code=printer_code, enum_items=enum_items, list_items=list_items, include_items=include_items)
content = template.format(printer_code=int(printer_code), enum_items=enum_items, list_items=list_items, include_items=include_items)

with open(header_file_name, 'w') as f:
f.write(content)
Expand All @@ -205,13 +201,17 @@ def generate_header_file(yaml_file_name, header_file_name, mmu, list, includes):
def main(args):
generate_header_file(getattr(args, "yaml-file"),
getattr(args, "output-file"),
getattr(args, "printer-id"),
getattr(args, "printer-code"),
args.mmu, args.list, args.include)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('yaml-file', type=Path)
parser.add_argument('output-file', type=Path)
parser.add_argument('printer-id', type=str)
parser.add_argument('printer-code', type=str)
parser.add_argument('--mmu', default=False, action='store_true', help='Generate mmu error codes')
parser.add_argument('--list', default=False, action='store_true', help='Generate error list, requires translations')
parser.add_argument('--include', default=[], action='append', help='List of files to include')
Expand Down
Loading

0 comments on commit 4d9bab2

Please sign in to comment.