From 4067f5216ecbe095b2b40bc442025322b9ba68c6 Mon Sep 17 00:00:00 2001 From: Mathias Lyngklip Kjeldgaard Date: Wed, 31 Jul 2019 13:34:28 +0200 Subject: [PATCH 1/3] Create DisplayRemainingTimeOnLCD.py Added a post-processing script that prints out the estimated time remaining generated by Cura. --- .../scripts/DisplayRemainingTimeOnLCD.py | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py diff --git a/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py new file mode 100644 index 0000000000..a943ca58f8 --- /dev/null +++ b/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py @@ -0,0 +1,86 @@ + +from ..Script import Script + +import re +import datetime + + +class DisplayRemainingTimeOnLCD(Script): + + def __init__(self): + super().__init__() + + + def getSettingDataString(self): + return """{ + "name":"Disaplay Remaining Time on LCD", + "key":"DisplayRemainingTimeOnLCD", + "metadata": {}, + "version": 2, + "settings": + { + "TurnOn": + { + "label": "Enable", + "description": "When enabled, It will write Time Left HHMMSS on the display", + "type": "bool", + "default_value": true + } + } + }""" + + def execute(self, data): + if self.getSettingValueByKey("TurnOn"): + TotalTime = 0 # Var for total time + TotalTimeString = "" # Var for the string we insert + for layer in data: + layer_index = data.index(layer) + lines = layer.split("\n") + for line in lines: + if line.startswith(";TIME:"): + # At this point, we have found a line in the GCODE with ";TIME:" + # which is the indication of TotalTime. Looks like: ";TIME:1337", where + # 1337 is the total print time in seconds. + line_index = lines.index(line) # We take a hold of that line + minString = re.split(":", line) # Then we split it, so we can get the number + + StringMedTal = "{}".format(minString[1]) # Here we insert that number from the + # list into a string. + + TotalTime = int(StringMedTal) # Only to contert it to a int. + + m, s = divmod(TotalTime, 60) # Math to calculate + h, m = divmod(m, 60) # hours, minutes and seconds. + TotalTimeString = "{:d}h{:02d}m{:02d}s".format(h, m, s) # Now we put it into the string + lines[line_index] = "M117 Time Left: {}".format(TotalTimeString) # And print that string instead of the original one + + + + + elif line.startswith(";TIME_ELAPSED:"): + + # As we didnt find the total time (";TIME:"), we have found a elapsed time mark + # This time represents the time the printer have printed. So with some math; + # totalTime - printTime = RemainingTime. + line_index = lines.index(line) # We get a hold of the line + myList = re.split(":", line) # Again, we split at ":" so we can get the number + StringMedTal = "{}".format(myList[1]) # Then we put that number from the list, into a string + + currentTime = float(StringMedTal) # This time we convert to a float, as the line looks something like: + # ;TIME_ELAPSED:1234.6789 + # which is total time in seconds + + timeLeft = TotalTime - currentTime # Here we calculate remaining time + + m1, s1 = divmod(timeLeft, 60) # And some math to get the total time in seconds into + h1, m1 = divmod(m1, 60) # the right format. (HH,MM,SS) + currentTimeString = "{:d}h{:2d}m{:2d}s".format(int(h1), int(m1), int(s1)) # Here we create the string holding our time + lines[line_index] = "M117 Time Left: {}".format(currentTimeString) # And now insert that into the GCODE + + + # Here we are OUT of the second for-loop + # Which means we have found and replaces all the occurences. + # Which also means we are ready to join the lines for that section of the GCODE file. + final_lines = "\n".join(lines) + data[layer_index] = final_lines + return data From fd3233dba59653101a349ad5dbe078e314f35dcd Mon Sep 17 00:00:00 2001 From: Mathias Lyngklip Kjeldgaard Date: Wed, 31 Jul 2019 23:29:35 +0200 Subject: [PATCH 2/3] updated variable names --- .../scripts/DisplayRemainingTimeOnLCD.py | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py index a943ca58f8..e5f61f7360 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py @@ -1,3 +1,13 @@ +# Cura PostProcessingPlugin +# Author: Mathias Lyngklip Kjeldgaard +# Date: July 31, 2019 +# Modified: --- + +# Description: This plugin displayes the remaining time on the LCD of the printer +# using the estimated print-time generated by Cura. + + + from ..Script import Script @@ -22,37 +32,36 @@ class DisplayRemainingTimeOnLCD(Script): "TurnOn": { "label": "Enable", - "description": "When enabled, It will write Time Left HHMMSS on the display", + "description": "When enabled, It will write Time Left: HHMMSS on the display", "type": "bool", - "default_value": true + "default_value": false } } }""" def execute(self, data): if self.getSettingValueByKey("TurnOn"): - TotalTime = 0 # Var for total time - TotalTimeString = "" # Var for the string we insert + total_time = 0 + total_time_string = "" for layer in data: layer_index = data.index(layer) lines = layer.split("\n") for line in lines: if line.startswith(";TIME:"): # At this point, we have found a line in the GCODE with ";TIME:" - # which is the indication of TotalTime. Looks like: ";TIME:1337", where + # which is the indication of total_time. Looks like: ";TIME:1337", where # 1337 is the total print time in seconds. - line_index = lines.index(line) # We take a hold of that line - minString = re.split(":", line) # Then we split it, so we can get the number + line_index = lines.index(line) # We take a hold of that line + split_string = re.split(":", line) # Then we split it, so we can get the number - StringMedTal = "{}".format(minString[1]) # Here we insert that number from the - # list into a string. + string_with_numbers = "{}".format(split_string[1]) # Here we insert that number from the + # list into a string. + total_time = int(string_with_numbers) # Only to contert it to a int. - TotalTime = int(StringMedTal) # Only to contert it to a int. - - m, s = divmod(TotalTime, 60) # Math to calculate - h, m = divmod(m, 60) # hours, minutes and seconds. - TotalTimeString = "{:d}h{:02d}m{:02d}s".format(h, m, s) # Now we put it into the string - lines[line_index] = "M117 Time Left: {}".format(TotalTimeString) # And print that string instead of the original one + m, s = divmod(total_time, 60) # Math to calculate + h, m = divmod(m, 60) # hours, minutes and seconds. + total_time_string = "{:d}h{:02d}m{:02d}s".format(h, m, s) # Now we put it into the string + lines[line_index] = "M117 Time Left: {}".format(total_time_string) # And print that string instead of the original one @@ -63,19 +72,18 @@ class DisplayRemainingTimeOnLCD(Script): # This time represents the time the printer have printed. So with some math; # totalTime - printTime = RemainingTime. line_index = lines.index(line) # We get a hold of the line - myList = re.split(":", line) # Again, we split at ":" so we can get the number - StringMedTal = "{}".format(myList[1]) # Then we put that number from the list, into a string + list_split = re.split(":", line) # Again, we split at ":" so we can get the number + string_with_numbers = "{}".format(list_split[1]) # Then we put that number from the list, into a string - currentTime = float(StringMedTal) # This time we convert to a float, as the line looks something like: - # ;TIME_ELAPSED:1234.6789 - # which is total time in seconds + current_time = float(string_with_numbers) # This time we convert to a float, as the line looks something like: + # ;TIME_ELAPSED:1234.6789 + # which is total time in seconds - timeLeft = TotalTime - currentTime # Here we calculate remaining time - - m1, s1 = divmod(timeLeft, 60) # And some math to get the total time in seconds into + time_left = total_time - current_time # Here we calculate remaining time + m1, s1 = divmod(time_left, 60) # And some math to get the total time in seconds into h1, m1 = divmod(m1, 60) # the right format. (HH,MM,SS) - currentTimeString = "{:d}h{:2d}m{:2d}s".format(int(h1), int(m1), int(s1)) # Here we create the string holding our time - lines[line_index] = "M117 Time Left: {}".format(currentTimeString) # And now insert that into the GCODE + current_time_string = "{:d}h{:2d}m{:2d}s".format(int(h1), int(m1), int(s1)) # Here we create the string holding our time + lines[line_index] = "M117 Time Left: {}".format(current_time_string) # And now insert that into the GCODE # Here we are OUT of the second for-loop From 4934d7a6e9d13de78fc20f0fa0376de2dfcfd784 Mon Sep 17 00:00:00 2001 From: Mathias Lyngklip Kjeldgaard Date: Thu, 8 Aug 2019 11:03:24 +0200 Subject: [PATCH 3/3] Fixed a bug caused by ":" I discovered the ":" I added caused the rest of the message to not be displayed when printing from a SD card, so I removed the ":". --- .../PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py index e5f61f7360..9152ab65f9 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayRemainingTimeOnLCD.py @@ -61,7 +61,7 @@ class DisplayRemainingTimeOnLCD(Script): m, s = divmod(total_time, 60) # Math to calculate h, m = divmod(m, 60) # hours, minutes and seconds. total_time_string = "{:d}h{:02d}m{:02d}s".format(h, m, s) # Now we put it into the string - lines[line_index] = "M117 Time Left: {}".format(total_time_string) # And print that string instead of the original one + lines[line_index] = "M117 Time Left {}".format(total_time_string) # And print that string instead of the original one @@ -83,7 +83,7 @@ class DisplayRemainingTimeOnLCD(Script): m1, s1 = divmod(time_left, 60) # And some math to get the total time in seconds into h1, m1 = divmod(m1, 60) # the right format. (HH,MM,SS) current_time_string = "{:d}h{:2d}m{:2d}s".format(int(h1), int(m1), int(s1)) # Here we create the string holding our time - lines[line_index] = "M117 Time Left: {}".format(current_time_string) # And now insert that into the GCODE + lines[line_index] = "M117 Time Left {}".format(current_time_string) # And now insert that into the GCODE # Here we are OUT of the second for-loop