Skip to content

Commit

Permalink
🐛 Fix printer lock behaviour
Browse files Browse the repository at this point in the history
Finally, figured out a good way to do it I think. The crucial M115 command is sent after we thought the printer.

Closes #50
  • Loading branch information
cp2004 committed Dec 24, 2021
1 parent dfb03e6 commit 156013c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
11 changes: 6 additions & 5 deletions octoprint_eeprom_marlin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ def comm_protocol_gcode_received(self, comm, line, *args, **kwargs):
self.collecting_eeprom = False
self.collecting_stats = False

elif "printer locked" in line.lower():
self._logger.info("Printer locked, aborting data collection")
self.send_message("locked", {})
self.collecting_eeprom = False
self.collecting_stats = False
if "printer locked" in line.lower():
self.send_message("locked", {})
self._firmware_info.locked = True
# Disable data collection
self.collecting_eeprom = False
self.collecting_stats = False

if self.collecting_eeprom:
parsed = self._parser.parse_eeprom_data(line)
Expand Down
6 changes: 6 additions & 0 deletions octoprint_eeprom_marlin/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def on_api_command(self, command, data):
commands = ["M503" if self._settings.get(["use_m503"]) else "M501"]
if self._settings.get_boolean(["m78"]):
commands += ["M78"]
if self._firmware_info.locked:
# If the printer was locked on startup, we will need to check the name using M115 first.
commands = ["M115"] + commands
# Assume the user unlocked the printer - if they didn't, the locked state will return as soon as we
# send these commands.
self._firmware_info.locked = False
self._printer.commands(commands)

elif command == CMD_SAVE:
Expand Down
2 changes: 2 additions & 0 deletions octoprint_eeprom_marlin/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class FirmwareInfo:
is_marlin = False # type: bool
additional_info = {} # type: dict
capabilities = {} # type: dict
locked = False

def additional_info_from_dict(self, data):
self.additional_info = {}
Expand All @@ -304,6 +305,7 @@ def to_dict(self):
"is_marlin": self.is_marlin,
"additional": self.additional_info,
"capabilities": self.capabilities,
"locked": self.locked,
}


Expand Down
7 changes: 6 additions & 1 deletion octoprint_eeprom_marlin/static/js/eeprom_marlin.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ $(function () {

self.info.is_marlin(data.info.is_marlin);
self.info.name(data.info.name);
self.printer_locked(data.info.locked);
};

self.stats = (function () {
Expand Down Expand Up @@ -221,7 +222,7 @@ $(function () {
return (
!self.loading() &&
!self.initialLoad() &&
self.info.is_marlin() &&
(self.info.is_marlin() || self.printer_locked()) && // Allow refresh button when locked
!self.printerState.isBusy() &&
self.printerState.isReady()
);
Expand Down Expand Up @@ -463,6 +464,10 @@ $(function () {
self.loading(false);
self.printer_locked(true);
}
if (data.type === "unlocked") {
self.loading(false);
self.printer_locked(false);
}
};

self.onAllBound = self.onEventConnected = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</strong>
</p>
<p>
{{ _("Unlock the printer to use the EEPROM editor") }}
{{ _("Unlock the printer and then press 'Load' to use the EEPROM editor") }}
</p>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<div class="eeprom-notconnected" data-bind="visible: !initialLoad() && !(info.name().length > 0)">
<div class="eeprom-notconnected" data-bind="visible: !initialLoad() && !(info.name().length > 0) && !printer_locked()">
<p>
<span class="fa-stack fa-3x">
<i class="fas fa-plug fa-stack-2x text-info"></i>
Expand Down

0 comments on commit 156013c

Please sign in to comment.