Skip to content

Commit

Permalink
fix: make the console lines for status updates during the job be info…
Browse files Browse the repository at this point in the history
…, not critical. also, streamline extractIndex
  • Loading branch information
L10nhunter committed Dec 16, 2024
1 parent 097246d commit f775dcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
19 changes: 11 additions & 8 deletions server/Classes/Fabricators/Printers/Printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def parseGcode(self, job: Job, isVerbose: bool = False):
prev_line = ""
# Replace file with the path to the file. "r" means read mode.
# now instead of reading from 'g', we are reading line by line
current_app.socketio.emit("console_update", {"message": "Starting Job", "level": "critical", "printerid": self.dbID})
current_app.socketio.emit("console_update", {"message": "Starting Job", "level": "info", "printerid": self.dbID})
for line in lines:
if self.status == "cancelled":
self.sendGcode(self.cancelCMD)
Expand Down Expand Up @@ -126,10 +126,12 @@ def parseGcode(self, job: Job, isVerbose: bool = False):

if len(line) == 0 or line.startswith(";"):
continue
if job.getTimeStarted() == 0 and ("M75" in line or self.startTimeCMD in line) :
if job.getTimeStarted() == 0 and ("M75" in line or self.startTimeCMD in line):
job.setTimeStarted(1)
job.setTime(job.calculateEta(), 1)
job.setTime(datetime.now(), 2)
if current_app:
current_app.socketio.emit("console_update", {"message": "Fabricating...", "level": "info", "printerid": self.dbID})

assert self.sendGcode(line), f"Failed to send {line}"

Expand Down Expand Up @@ -175,7 +177,7 @@ def parseGcode(self, job: Job, isVerbose: bool = False):
self.sendGcode(self.cancelCMD)
self.verdict = "cancelled"
if self.logger is not None: self.logger.debug("Job cancelled")
current_app.socketio.emit("console_update", {"message": "Job cancelled", "level": "critical", "printerid": self.dbID})
current_app.socketio.emit("console_update", {"message": "Job cancelled", "level": "info", "printerid": self.dbID})
return True
elif self.status == "printing":
self.resume()
Expand Down Expand Up @@ -209,18 +211,18 @@ def parseGcode(self, job: Job, isVerbose: bool = False):
if self.status == "complete":
self.verdict = "complete"
if self.logger is not None: self.logger.debug("Job complete")
current_app.socketio.emit("console_update", {"message": "Job complete", "level": "critical", "printerid": self.dbID})
current_app.socketio.emit("console_update", {"message": "Job complete", "level": "info", "printerid": self.dbID})
return True

if self.status == "error":
self.verdict = "error"
if self.logger is not None: self.logger.debug("Job error")
current_app.socketio.emit("console_update", {"message": "Job error", "level": "critical", "printerid": self.dbID})
current_app.socketio.emit("console_update", {"message": "Job error", "level": "info", "printerid": self.dbID})
return False
self.verdict = "complete"
self.status = "complete"
if self.logger is not None: self.logger.debug("Job complete")
current_app.socketio.emit("console_update", {"message": "Job complete", "level": "critical", "printerid": self.dbID})
current_app.socketio.emit("console_update", {"message": "Job complete", "level": "info", "printerid": self.dbID})
return True
except Exception as e:
# self.setStatus("error")
Expand Down Expand Up @@ -330,6 +332,7 @@ def handleTempLine(self, line: str) -> None:
pass
except Exception as e:
current_app.handle_errors_and_logging(e, self)

def extractIndex(self, gcode: bytes) -> str:
"""
Method to extract the index of the gcode for use in the callablesHashtable
Expand All @@ -341,12 +344,12 @@ def extractIndex(self, gcode: bytes) -> str:
if hashIndex == "M109" or hashIndex == "M190":
if self.logger is not None: self.logger.info("Waiting for temperature to stabilize...")
current_app.socketio.emit("console_update",
{"message": "Waiting for temperature to stabilize...", "level": "critical",
{"message": "Waiting for temperature to stabilize...", "level": "info",
"printerid": self.dbID})
elif hashIndex == "G28":
if self.logger is not None: self.logger.info("Homing...")
current_app.socketio.emit("console_update",
{"message": "Homing...", "level": "critical", "printerid": self.dbID})
{"message": "Homing...", "level": "info", "printerid": self.dbID})
return hashIndex

def pause(self):
Expand Down
13 changes: 3 additions & 10 deletions server/Classes/Fabricators/Printers/Prusa/PrusaPrinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,13 @@ class PrusaPrinter(Printer, hasEndingSequence, metaclass=ABCMeta):

callablesHashtable = {**Printer.callablesHashtable, **callablesHashtable}


def extractIndex(self, gcode: bytes) -> str:
hashIndex = gcode.decode().split("\n")[0].split(" ")[0]
if hashIndex == "M109" or hashIndex == "M190":
if self.logger is not None: self.logger.info("Waiting for temperature to stabilize...")
current_app.socketio.emit("console_update", {"message": "Waiting for temperature to stabilize...", "level": "critical", "printerid": self.dbID})
elif hashIndex == "G28":
if self.logger is not None: self.logger.info("Homing...")
current_app.socketio.emit("console_update", {"message": "Homing...", "level": "critical", "printerid": self.dbID})
elif hashIndex == "G29":
hashIndex = super().extractIndex(gcode)
if hashIndex == "G29":
try:
g29addon = gcode.decode().split("\n")[0].split(" ")[1]
hashIndex += ".01" if g29addon == "P1" else ".02"
except IndexError:
hashIndex += ".01"
current_app.socketio.emit("console_update", {"message": "Auto bed leveling...", "level": "critical", "printerid": self.dbID})
current_app.socketio.emit("console_update", {"message": "Auto bed leveling...", "level": "info", "printerid": self.dbID})
return hashIndex

0 comments on commit f775dcc

Please sign in to comment.