Skip to content

Commit

Permalink
Fix PrintTimeGenius issue (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
crysxd authored Jul 6, 2024
1 parent 9fca47a commit 5f374b8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
25 changes: 21 additions & 4 deletions octoapp/layerutils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@

class LayerUtils:

LayerChangeCommand = "OCTOAPP_LAYER_CHANGE"
DisableLegacyLayerCommand = "OCTOAPP_DISABLE_LAYER_MAGIC"
# Version of layer change commands we used.
# The 0 index is the currently used ones, below are older variations
LayerChangeCommands = [
"M118 E1 OCTOAPP_LAYER_CHANGE",
"OCTOAPP_LAYER_CHANGE"
]

# Version of disable legacy layer commands we used.
# The 0 index is the currently used ones, below are older variations
DisableLegacyLayerCommands = [
"M118 E1 OCTOAPP_DISABLE_LAYER_MAGIC",
"OCTOAPP_DISABLE_LAYER_MAGIC"
]


@staticmethod
def CreateLayerChangeCommand(layer):
return LayerUtils.LayerChangeCommand + " LAYER=" + str(layer)
def CreateLayerChangeCommands(layer):
return list(map(lambda x: x + " LAYER=" + str(layer), LayerUtils.LayerChangeCommands))

@staticmethod
def IsOctoAppCommand(cmd):
return cmd.startswith("M118 E1 OCTOAPP_") or cmd.startswith("OCTOAPP_")


@staticmethod
def IsLayerChange(line, context):
if line.startswith("; generated by PrusaSlicer") or line.startswith("; generated by OrcaSlicer") or line.startswith("; generated by SuperSlicer"):
Expand Down
2 changes: 1 addition & 1 deletion octoapp/notificationutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def removeQuotes(s):
return s

base = NotificationUtils.CreateNotificationCommand("")
commands = [ base, ";" + base, "; " + base]
commands = [ base, ";" + base, "; " + base, "M118 E1 " + base]

for command in commands:
if line.startswith(command):
Expand Down
12 changes: 8 additions & 4 deletions octoprint_octoapp/layerprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ def __init__(self, input_stream):
super().__init__(input_stream)
self.LayerCounter = 0
self.FirstLine = True
self.Disabled = False
self.Context = {}

def process_line(self, line):
try:
decodedLine = line.decode()

if decodedLine.startswith(LayerUtils.LayerChangeCommand) or decodedLine.startswith(LayerUtils.DisableLegacyLayerCommand):
return None
if decodedLine.replace('\n', '').replace('\r', '') in LayerUtils.DisableLegacyLayerCommands:
self.Disabled = True

if self.Disabled is True:
return line

if LayerUtils.IsLayerChange(decodedLine, self.Context):
result = (decodedLine + LayerUtils.CreateLayerChangeCommand(self.LayerCounter) + "\r\n").encode()
result = (decodedLine + LayerUtils.CreateLayerChangeCommands(self.LayerCounter)[0] + "\r\n").encode()
self.LayerCounter += 1
return result

if self.FirstLine:
self.FirstLine = False
return (LayerUtils.DisableLegacyLayerCommand + "\r\n" + decodedLine).encode()
return (LayerUtils.DisableLegacyLayerCommands[0] + "\r\n" + decodedLine).encode()

return line
except Exception as e:
Expand Down
13 changes: 8 additions & 5 deletions octoprint_octoapp/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def __init__(self, parent, notification_handler: NotificationsHandler):
self.Progress = 0
self.GcodeSentCount = 0
self.LayerMagicDisabledAt = datetime.fromtimestamp(0)
self.FirstLayerDoneCommand = LayerUtils.CreateLayerChangeCommand(1)
self.ThirdLayerDoneCommand = LayerUtils.CreateLayerChangeCommand(3)
self.FirstLayerDoneCommands = LayerUtils.CreateLayerChangeCommands(1)
self.ThirdLayerDoneCommands = LayerUtils.CreateLayerChangeCommands(3)
self.ScheduledNotifications = None
self.ScheduledNotificationsThread = {}
self.LastFilePos = 0
Expand Down Expand Up @@ -125,16 +125,16 @@ def OnEvent(self, event, payload):

def OnGcodeQueued(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
# Check for our layer commands
if cmd == LayerUtils.DisableLegacyLayerCommand:
if cmd in LayerUtils.DisableLegacyLayerCommands:
Sentry.Info("NOTIFICATION", "Layer magic disabled")
self.LayerMagicDisabledAt = datetime.now()
return False

if cmd == self.FirstLayerDoneCommand and self.NotificationHandler:
if cmd in self.FirstLayerDoneCommands and self.NotificationHandler:
self.NotificationHandler.OnFirstLayerDone()
return False

if cmd == self.ThirdLayerDoneCommand and self.NotificationHandler:
if cmd in self.ThirdLayerDoneCommands and self.NotificationHandler:
self.NotificationHandler.OnThirdLayerDone()
return False

Expand All @@ -143,6 +143,9 @@ def OnGcodeQueued(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwa
self.NotificationHandler.OnCustomNotification(message)
return False

if LayerUtils.IsOctoAppCommand(cmd):
return False

return True


Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
plugin_identifier = "octoapp"

# The plugin's python package, should be "octoprint_<plugin identifier>", has to be unique
plugin_package = "octoprint_octoapp"

# The plugin's human readable name. Can be overwritten within OctoPrint's internal data via __plugin_name__ in the
# plugin module
plugin_name = "OctoApp"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
# Note that this is also parsed by the moonraker module to pull the version, so the string and format must remain the same!
plugin_version = "2.1.1"
plugin_version = "2.1.2"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 5f374b8

Please sign in to comment.