|
6 | 6 | from octoprint_mrbeam.iobeam.iobeam_handler import IoBeamValueEvents |
7 | 7 |
|
8 | 8 | LASERHEAD_MAX_TEMP_FALLBACK = 55.0 |
| 9 | +LASERHEAD_MAX_DUST_FACTOR_FALLBACK = 3.0 # selected the highest factor |
9 | 10 |
|
10 | 11 | # singleton |
11 | 12 | _instance = None |
@@ -34,6 +35,7 @@ def __init__(self, plugin): |
34 | 35 | self._event_bus = plugin._event_bus |
35 | 36 | self._plugin_version = plugin.get_plugin_version() |
36 | 37 | self._iobeam = None |
| 38 | + self._laserhead_properties = {} |
37 | 39 |
|
38 | 40 | self._lh_cache = {} |
39 | 41 | self._last_used_lh_serial = None |
@@ -443,7 +445,7 @@ def current_laserhead_max_temperature(self): |
443 | 445 | float: Laser head max temp |
444 | 446 |
|
445 | 447 | """ |
446 | | - current_laserhead_properties = self._load_current_laserhead_properties() |
| 448 | + current_laserhead_properties = self._get_laserhead_properties() |
447 | 449 |
|
448 | 450 | # Handle the exceptions |
449 | 451 | if((isinstance(current_laserhead_properties, dict) is False) or |
@@ -472,7 +474,7 @@ def default_laserhead_max_temperature(self): |
472 | 474 |
|
473 | 475 | def _load_current_laserhead_properties(self): |
474 | 476 | """ |
475 | | - Loads the current detected laser head related properties and return them |
| 477 | + Loads the current detected laser head related properties from the laser head profile files and return them |
476 | 478 |
|
477 | 479 | Returns: |
478 | 480 | dict: current laser head properties, None: otherwise |
@@ -505,7 +507,65 @@ def _load_current_laserhead_properties(self): |
505 | 507 | e, lh_properties_file_path)) |
506 | 508 | return None |
507 | 509 |
|
| 510 | + def _get_laserhead_properties(self): |
| 511 | + """ |
| 512 | + returns the current saved laser head properties or load new if the laser head id changed |
| 513 | +
|
| 514 | + Returns: |
| 515 | + dict: current laser head properties, None: otherwise |
| 516 | +
|
| 517 | + """ |
| 518 | + # 1. get the ID of the current laser head |
| 519 | + laserhead_id = self.get_current_used_lh_model_id() |
| 520 | + self._logger.debug("laserhead id compare {} - {}".format(laserhead_id, self._laserhead_properties.get("laserhead_id", None))) |
| 521 | + if laserhead_id != self._laserhead_properties.get("laserhead_id", None): |
| 522 | + self._logger.debug("new laserhead_id -> load current laserhead porperties") |
| 523 | + # 2. Load the corresponding yaml file and return it's content |
| 524 | + self._laserhead_properties = self._load_current_laserhead_properties() |
| 525 | + if self._laserhead_properties is not None: |
| 526 | + self._laserhead_properties.update({'laserhead_id': laserhead_id}) |
| 527 | + else: |
| 528 | + self._logger.debug("no new laserhead_id -> return current laserhead_properties") |
| 529 | + |
| 530 | + self._logger.debug( |
| 531 | + "_laserhead_properties - {}".format(self._laserhead_properties)) |
| 532 | + return self._laserhead_properties |
| 533 | + |
| 534 | + @property |
| 535 | + def current_laserhead_max_dust_factor(self): |
| 536 | + """ |
| 537 | + Return the current laser head max dust factor |
| 538 | +
|
| 539 | + Returns: |
| 540 | + float: Laser head max dust factor |
| 541 | +
|
| 542 | + """ |
| 543 | + current_laserhead_properties = self._get_laserhead_properties() |
| 544 | + |
| 545 | + # Handle the exceptions |
| 546 | + if ((isinstance(current_laserhead_properties, dict) is False) or |
| 547 | + ("max_dust_factor" not in current_laserhead_properties) or |
| 548 | + (isinstance(current_laserhead_properties["max_dust_factor"], float) is False)): |
| 549 | + # Apply fallback |
| 550 | + self._logger.debug("Current laserhead properties: {}".format(current_laserhead_properties)) |
| 551 | + self._logger.exception( |
| 552 | + "Current Laserhead max dust factor couldn't be retrieved, fallback to the factor value of: {}".format( |
| 553 | + self.default_laserhead_max_dust_factor)) |
| 554 | + return self.default_laserhead_max_dust_factor |
| 555 | + # Reaching here means, everything looks good |
| 556 | + self._logger.debug("Current Laserhead max dust factor:{}".format(current_laserhead_properties["max_dust_factor"])) |
| 557 | + return current_laserhead_properties["max_dust_factor"] |
| 558 | + |
| 559 | + @property |
| 560 | + def default_laserhead_max_dust_factor(self): |
| 561 | + """ |
| 562 | + Default max dust factor for laser head. to be used by other modules at init time |
| 563 | +
|
| 564 | + Returns: |
| 565 | + float: Laser head default max dust factor |
| 566 | + """ |
508 | 567 |
|
| 568 | + return LASERHEAD_MAX_DUST_FACTOR_FALLBACK |
509 | 569 |
|
510 | 570 |
|
511 | 571 |
|
0 commit comments