mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Incorperate percentage and time remaining scripts
This commit is contained in:
parent
63b4c47095
commit
1519b05cdb
2 changed files with 81 additions and 143 deletions
|
@ -1,93 +0,0 @@
|
||||||
# Cura PostProcessingPlugin
|
|
||||||
# Author: Alexander Gee
|
|
||||||
# Date: May 3, 2020
|
|
||||||
# Modified: May 3, 2020
|
|
||||||
|
|
||||||
# Description: This plugin will write the percent of time complete on the LCD using Marlin's M73 command.
|
|
||||||
|
|
||||||
|
|
||||||
from ..Script import Script
|
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
class DisplayPercentCompleteOnLCD(Script):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
def getSettingDataString(self):
|
|
||||||
return """{
|
|
||||||
"name":"Display Percent Complete on LCD",
|
|
||||||
"key":"DisplayPercentCompleteOnLCD",
|
|
||||||
"metadata": {},
|
|
||||||
"version": 2,
|
|
||||||
"settings":
|
|
||||||
{
|
|
||||||
"TurnOn":
|
|
||||||
{
|
|
||||||
"label": "Enable",
|
|
||||||
"description": "When enabled, It will write the percent of time complete on the LCD using Marlin's M73 command.",
|
|
||||||
"type": "bool",
|
|
||||||
"default_value": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}"""
|
|
||||||
|
|
||||||
# Get the time value from a line as a float.
|
|
||||||
# Example line ;TIME_ELAPSED:1234.6789 or ;TIME:1337
|
|
||||||
def getTimeValue(self, line):
|
|
||||||
list_split = re.split(":", line) # Split at ":" so we can get the numerical value
|
|
||||||
return float(list_split[1]) # Convert the numerical portion to a float
|
|
||||||
|
|
||||||
def execute(self, data):
|
|
||||||
if self.getSettingValueByKey("TurnOn"):
|
|
||||||
total_time = -1
|
|
||||||
previous_layer_end_percentage = 0
|
|
||||||
for layer in data:
|
|
||||||
layer_index = data.index(layer)
|
|
||||||
lines = layer.split("\n")
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
if line.startswith(";TIME:") and total_time == -1:
|
|
||||||
# This line represents the total time required to print the gcode
|
|
||||||
total_time = self.getTimeValue(line)
|
|
||||||
# Emit 0 percent to sure Marlin knows we are overriding the completion percentage
|
|
||||||
lines.insert(lines.index(line),"M73 P0")
|
|
||||||
|
|
||||||
elif line.startswith(";TIME_ELAPSED:"):
|
|
||||||
# We've found one of the time elapsed values which are added at the end of layers
|
|
||||||
|
|
||||||
# If total_time was not already found then noop
|
|
||||||
if (total_time == -1):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Calculate percentage value this layer ends at
|
|
||||||
layer_end_percentage = int((self.getTimeValue(line) / total_time) * 100)
|
|
||||||
|
|
||||||
# Figure out how many percent of the total time is spent in this layer
|
|
||||||
layer_percentage_delta = layer_end_percentage - previous_layer_end_percentage
|
|
||||||
|
|
||||||
# If this layer represents less than 1 percent then we don't need to emit anything, continue to the next layer
|
|
||||||
if (layer_percentage_delta == 0):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Grab the index of the current line and figure out how many lines represent one percent
|
|
||||||
step = lines.index(line) / layer_percentage_delta
|
|
||||||
|
|
||||||
for percentage in range(1, layer_percentage_delta + 1):
|
|
||||||
# We add the percentage value here as while processing prior lines we will have inserted
|
|
||||||
# percentage lines before the current one. Failing to do this will upset the spacing
|
|
||||||
line_index = int((percentage * step) + percentage)
|
|
||||||
|
|
||||||
# Due to integer truncation of the total time value in the gcode the percentage we
|
|
||||||
# calculate may slightly exceed 100, as that is not valid we cap the value here
|
|
||||||
output = min(percentage + previous_layer_end_percentage, 100)
|
|
||||||
|
|
||||||
# Now insert the sanitized percentage into the GCODE
|
|
||||||
lines.insert(line_index, "M73 P{}".format(output))
|
|
||||||
|
|
||||||
previous_layer_end_percentage = layer_end_percentage
|
|
||||||
|
|
||||||
# Join up the lines for this layer again and store them in the data array
|
|
||||||
data[layer_index] = "\n".join(lines)
|
|
||||||
return data
|
|
|
@ -3,92 +3,123 @@
|
||||||
# Date: July 31, 2019
|
# Date: July 31, 2019
|
||||||
# Modified: May 13, 2020
|
# Modified: May 13, 2020
|
||||||
|
|
||||||
# Description: This plugin displayes the remaining time on the LCD of the printer
|
# Description: This plugin displays progress on the LCD. It can output the estimated time remaining and the completion percentage.
|
||||||
# using the estimated print-time generated by Cura.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from ..Script import Script
|
from ..Script import Script
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
class DisplayPercentCompleteOnLCD(Script):
|
||||||
class DisplayProgressOnLCD(Script):
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
def getSettingDataString(self):
|
def getSettingDataString(self):
|
||||||
return """{
|
return """{
|
||||||
"name":"Display Progress on LCD",
|
"name":"Display Percent Complete on LCD",
|
||||||
"key":"DisplayProgressOnLCD",
|
"key":"DisplayPercentCompleteOnLCD",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"settings":
|
"settings":
|
||||||
{
|
{
|
||||||
"TurnOn":
|
"TimeRemaining":
|
||||||
{
|
{
|
||||||
"label": "Enable",
|
"label": "Enable",
|
||||||
"description": "When enabled, It will write Time Left: HHMMSS on the display. This is updated every layer.",
|
"description": "When enabled, write Time Left: HHMMSS on the display using M117. This is updated every layer.",
|
||||||
|
"type": "bool",
|
||||||
|
"default_value": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"Percentage":
|
||||||
|
{
|
||||||
|
"label": "Enable",
|
||||||
|
"description": "When enabled, set the completion bar percentage on the LCD using Marlin's M73 command.",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"default_value": false
|
"default_value": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
# Get the time value from a line as a float.
|
||||||
|
# Example line ;TIME_ELAPSED:1234.6789 or ;TIME:1337
|
||||||
|
def getTimeValue(self, line):
|
||||||
|
list_split = re.split(":", line) # Split at ":" so we can get the numerical value
|
||||||
|
return float(list_split[1]) # Convert the numerical portion to a float
|
||||||
|
|
||||||
def execute(self, data):
|
def execute(self, data):
|
||||||
if self.getSettingValueByKey("TurnOn"):
|
output_time = self.getSettingValueByKey("TimeRemaining")
|
||||||
total_time = 0
|
output_percentage = self.getSettingValueByKey("Percentage")
|
||||||
total_time_string = ""
|
if (output_percentage or output_time) == True:
|
||||||
|
total_time = -1
|
||||||
|
previous_layer_end_percentage = 0
|
||||||
for layer in data:
|
for layer in data:
|
||||||
layer_index = data.index(layer)
|
layer_index = data.index(layer)
|
||||||
lines = layer.split("\n")
|
lines = layer.split("\n")
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith(";TIME:"):
|
if line.startswith(";TIME:") and total_time == -1:
|
||||||
# At this point, we have found a line in the GCODE with ";TIME:"
|
# This line represents the total time required to print the gcode
|
||||||
# which is the indication of total_time. Looks like: ";TIME:1337", where
|
total_time = self.getTimeValue(line)
|
||||||
# 1337 is the total print time in seconds.
|
line_index = lines.index(line)
|
||||||
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
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
if (output_time):
|
||||||
|
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.insert(line_index, "M117 Time Left {}".format(total_time_string)) # And print that string instead of the original one
|
||||||
|
if (output_percentage):
|
||||||
|
# Emit 0 percent to sure Marlin knows we are overriding the completion percentage
|
||||||
|
lines.insert(line_index,"M73 P0")
|
||||||
|
|
||||||
|
|
||||||
elif line.startswith(";TIME_ELAPSED:"):
|
elif line.startswith(";TIME_ELAPSED:"):
|
||||||
|
# We've found one of the time elapsed values which are added at the end of layers
|
||||||
|
|
||||||
# As we didnt find the total time (";TIME:"), we have found a elapsed time mark
|
# If total_time was not already found then noop
|
||||||
# This time represents the time the printer have printed. So with some math;
|
if (total_time == -1):
|
||||||
# totalTime - printTime = RemainingTime.
|
continue
|
||||||
line_index = lines.index(line) # We get a hold of the line
|
|
||||||
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
|
|
||||||
|
|
||||||
current_time = float(string_with_numbers) # This time we convert to a float, as the line looks something like:
|
current_time = self.getTimeValue(line)
|
||||||
# ;TIME_ELAPSED:1234.6789
|
line_index = lines.index(line)
|
||||||
# which is total time in seconds
|
|
||||||
|
if (output_time):
|
||||||
|
# Here we calculate remaining time and do some math to get the total time in seconds into the right format. (HH,MM,SS)
|
||||||
|
time_left = total_time - current_time
|
||||||
|
m1, s1 = divmod(time_left, 60)
|
||||||
|
h1, m1 = divmod(m1, 60)
|
||||||
|
# Here we create the string holding our time
|
||||||
|
current_time_string = "{:d}h{:2d}m{:2d}s".format(int(h1), int(m1), int(s1))
|
||||||
|
# And now insert that into the GCODE
|
||||||
|
lines.insert(line_index, "M117 Time Left {}".format(current_time_string))
|
||||||
|
|
||||||
time_left = total_time - current_time # Here we calculate remaining time
|
if (output_percentage):
|
||||||
m1, s1 = divmod(time_left, 60) # And some math to get the total time in seconds into
|
# Calculate percentage value this layer ends at
|
||||||
h1, m1 = divmod(m1, 60) # the right format. (HH,MM,SS)
|
layer_end_percentage = int((current_time / total_time) * 100)
|
||||||
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
|
|
||||||
|
|
||||||
|
# Figure out how many percent of the total time is spent in this layer
|
||||||
|
layer_percentage_delta = layer_end_percentage - previous_layer_end_percentage
|
||||||
|
|
||||||
|
# If this layer represents less than 1 percent then we don't need to emit anything, continue to the next layer
|
||||||
|
if (layer_percentage_delta != 0):
|
||||||
|
# Grab the index of the current line and figure out how many lines represent one percent
|
||||||
|
step = line_index / layer_percentage_delta
|
||||||
|
|
||||||
# Here we are OUT of the second for-loop
|
for percentage in range(1, layer_percentage_delta + 1):
|
||||||
# Which means we have found and replaces all the occurences.
|
# We add the percentage value here as while processing prior lines we will have inserted
|
||||||
# Which also means we are ready to join the lines for that section of the GCODE file.
|
# percentage lines before the current one. Failing to do this will upset the spacing
|
||||||
final_lines = "\n".join(lines)
|
percentage_line_index = int((percentage * step) + percentage)
|
||||||
data[layer_index] = final_lines
|
|
||||||
|
# Due to integer truncation of the total time value in the gcode the percentage we
|
||||||
|
# calculate may slightly exceed 100, as that is not valid we cap the value here
|
||||||
|
output = min(percentage + previous_layer_end_percentage, 100)
|
||||||
|
|
||||||
|
# Now insert the sanitized percentage into the GCODE
|
||||||
|
lines.insert(percentage_line_index, "M73 P{}".format(output))
|
||||||
|
|
||||||
|
previous_layer_end_percentage = layer_end_percentage
|
||||||
|
|
||||||
|
# Join up the lines for this layer again and store them in the data array
|
||||||
|
data[layer_index] = "\n".join(lines)
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue