mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Merge pull request #15866 from GregValiant/DisplayInfoOnLCD
Display Info on LCD
This commit is contained in:
commit
4f0840d7b5
3 changed files with 468 additions and 250 deletions
|
@ -3,21 +3,16 @@
|
|||
# Date: August 28, 2018
|
||||
# Modified: November 16, 2018 by Joshua Pope-Lewis
|
||||
|
||||
# Description: This plugin shows custom messages about your print on the Status bar...
|
||||
# Please look at the 5 options
|
||||
# - Scrolling (SCROLL_LONG_FILENAMES) if enabled in Marlin and you aren't printing a small item select this option.
|
||||
# - Name: By default it will use the name generated by Cura (EG: TT_Test_Cube) - Type a custom name in here
|
||||
# - Start Num: Choose which number you prefer for the initial layer, 0 or 1
|
||||
# - Max Layer: Enabling this will show how many layers are in the entire print (EG: Layer 1 of 265!)
|
||||
# - Add prefix 'Printing': Enabling this will add the prefix 'Printing'
|
||||
# Description: This plugin is now an option in 'Display Info on LCD'
|
||||
|
||||
from ..Script import Script
|
||||
from UM.Application import Application
|
||||
from UM.Message import Message
|
||||
|
||||
class DisplayFilenameAndLayerOnLCD(Script):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def initialize(self) -> None:
|
||||
Message(title = "[Display Filename and Layer on LCD]", text = "This script is now an option in 'Display Info on LCD'. This post processor no longer works.").show()
|
||||
|
||||
def getSettingDataString(self):
|
||||
return """{
|
||||
"name": "Display Filename And Layer On LCD",
|
||||
|
@ -26,40 +21,10 @@ class DisplayFilenameAndLayerOnLCD(Script):
|
|||
"version": 2,
|
||||
"settings":
|
||||
{
|
||||
"scroll":
|
||||
"enable_script":
|
||||
{
|
||||
"label": "Scroll enabled/Small layers?",
|
||||
"description": "If SCROLL_LONG_FILENAMES is enabled select this setting however, if the model is small disable this setting!",
|
||||
"type": "bool",
|
||||
"default_value": false
|
||||
},
|
||||
"name":
|
||||
{
|
||||
"label": "Text to display:",
|
||||
"description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.",
|
||||
"type": "str",
|
||||
"default_value": ""
|
||||
},
|
||||
"startNum":
|
||||
{
|
||||
"label": "Initial layer number:",
|
||||
"description": "Choose which number you prefer for the initial layer, 0 or 1",
|
||||
"type": "int",
|
||||
"default_value": 0,
|
||||
"minimum_value": 0,
|
||||
"maximum_value": 1
|
||||
},
|
||||
"maxlayer":
|
||||
{
|
||||
"label": "Display max layer?:",
|
||||
"description": "Display how many layers are in the entire print on status bar?",
|
||||
"type": "bool",
|
||||
"default_value": true
|
||||
},
|
||||
"addPrefixPrinting":
|
||||
{
|
||||
"label": "Add prefix 'Printing'?",
|
||||
"description": "This will add the prefix 'Printing'",
|
||||
"label": "Deprecated/Obsolete",
|
||||
"description": "This script is now included in 'Display Info on LCD'.",
|
||||
"type": "bool",
|
||||
"default_value": true
|
||||
}
|
||||
|
@ -67,43 +32,6 @@ class DisplayFilenameAndLayerOnLCD(Script):
|
|||
}"""
|
||||
|
||||
def execute(self, data):
|
||||
max_layer = 0
|
||||
lcd_text = "M117 "
|
||||
if self.getSettingValueByKey("name") != "":
|
||||
name = self.getSettingValueByKey("name")
|
||||
else:
|
||||
name = Application.getInstance().getPrintInformation().jobName
|
||||
if self.getSettingValueByKey("addPrefixPrinting"):
|
||||
lcd_text += "Printing "
|
||||
if not self.getSettingValueByKey("scroll"):
|
||||
lcd_text += "Layer "
|
||||
else:
|
||||
lcd_text += name + " - Layer "
|
||||
i = self.getSettingValueByKey("startNum")
|
||||
for layer in data:
|
||||
display_text = lcd_text + str(i)
|
||||
layer_index = data.index(layer)
|
||||
lines = layer.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith(";LAYER_COUNT:"):
|
||||
max_layer = line
|
||||
max_layer = max_layer.split(":")[1]
|
||||
if self.getSettingValueByKey("startNum") == 0:
|
||||
max_layer = str(int(max_layer) - 1)
|
||||
if line.startswith(";LAYER:"):
|
||||
if self.getSettingValueByKey("maxlayer"):
|
||||
display_text = display_text + " of " + max_layer
|
||||
if not self.getSettingValueByKey("scroll"):
|
||||
display_text = display_text + " " + name
|
||||
else:
|
||||
if not self.getSettingValueByKey("scroll"):
|
||||
display_text = display_text + " " + name + "!"
|
||||
else:
|
||||
display_text = display_text + "!"
|
||||
line_index = lines.index(line)
|
||||
lines.insert(line_index + 1, display_text)
|
||||
i += 1
|
||||
final_lines = "\n".join(lines)
|
||||
data[layer_index] = final_lines
|
||||
|
||||
Message(title = "[Display Filename and Layer on LCD]", text = "This post is now included in 'Display Info on LCD'. This script will exit.").show()
|
||||
data[0] += "; [Display Filename and Layer on LCD] Did not run. It is now included in 'Display Info on LCD'.\n"
|
||||
return data
|
||||
|
|
448
plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py
Normal file
448
plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py
Normal file
|
@ -0,0 +1,448 @@
|
|||
# Display Filename and Layer on the LCD by Amanda de Castilho on August 28, 2018
|
||||
# Modified: Joshua Pope-Lewis on November 16, 2018
|
||||
# Display Progress on LCD by Mathias Lyngklip Kjeldgaard, Alexander Gee, Kimmo Toivanen, Inigo Martinez on July 31, 2019
|
||||
# Show Progress was adapted from Display Progress by Louis Wooters on January 6, 2020. His changes are included here.
|
||||
#---------------------------------------------------------------
|
||||
# DisplayNameOrProgressOnLCD.py
|
||||
# Cura Post-Process plugin
|
||||
# Combines 'Display Filename and Layer on the LCD' with 'Display Progress'
|
||||
# Combined and with additions by: GregValiant (Greg Foresi)
|
||||
# Date: September 8, 2023
|
||||
# NOTE: This combined post processor will make 'Display Filename and Layer on the LCD' and 'Display Progress' obsolete
|
||||
# Description: Display Filename and Layer options:
|
||||
# Status messages sent to the printer...
|
||||
# - Scrolling (SCROLL_LONG_FILENAMES) if enabled in Marlin and you aren't printing a small item select this option.
|
||||
# - Name: By default it will use the name generated by Cura (EG: TT_Test_Cube) - You may enter a custom name here
|
||||
# - Start Num: Choose which number you prefer for the initial layer, 0 or 1
|
||||
# - Max Layer: Enabling this will show how many layers are in the entire print (EG: Layer 1 of 265!)
|
||||
# - Add prefix 'Printing': Enabling this will add the prefix 'Printing'
|
||||
# - Example Line on LCD: Printing Layer 0 of 395 3DBenchy
|
||||
# Display Progress options:
|
||||
# - Display Total Layer Count
|
||||
# - Disply Time Remaining for the print
|
||||
# - Time Fudge Factor % - Divide the Actual Print Time by the Cura Estimate. Enter as a percentage and the displayed time will be adjusted. This allows you to bring the displayed time closer to reality (Ex: Entering 87.5 would indicate an adjustment to 87.5% of the Cura estimate).
|
||||
# - Example line on LCD: 1/479 | ET 2h13m
|
||||
# - Time to Pauses changes the M117/M118 lines to countdown to the next pause as 1/479 | TP 2h36m
|
||||
# - 'Add M118 Line' is available with either option. M118 will bounce the message back to a remote print server through the USB connection.
|
||||
# - Enable 'Finish-Time' Message - when enabled, takes the Print Time, adds 15 minutes for print start-up, and calculates when the print will end. It takes into account the Time Fudge Factor. The user may enter a print start time. This is also available for Display Filename.
|
||||
|
||||
from ..Script import Script
|
||||
from UM.Application import Application
|
||||
from UM.Qt.Duration import DurationFormat
|
||||
import UM.Util
|
||||
import configparser
|
||||
from UM.Preferences import Preferences
|
||||
import time
|
||||
import datetime
|
||||
from UM.Message import Message
|
||||
|
||||
class DisplayInfoOnLCD(Script):
|
||||
|
||||
def getSettingDataString(self):
|
||||
return """{
|
||||
"name": "Display Info on LCD",
|
||||
"key": "DisplayInfoOnLCD",
|
||||
"metadata": {},
|
||||
"version": 2,
|
||||
"settings":
|
||||
{
|
||||
"display_option":
|
||||
{
|
||||
"label": "LCD display option...",
|
||||
"description": "Display Filename and Layer was formerly 'Display Filename and Layer on LCD' post-processor. The message format on the LCD is 'Printing Layer 0 of 15 3D Benchy'. Display Progress is similar to the former 'Display Progress on LCD' post-processor. The display format is '1/16 | ET 2hr28m'. Display Progress includes a fudge factor for the print time estimate.",
|
||||
"type": "enum",
|
||||
"options": {
|
||||
"display_progress": "Display Progress",
|
||||
"filename_layer": "Filename and Layer"
|
||||
},
|
||||
"default_value": "display_progress"
|
||||
},
|
||||
"format_option":
|
||||
{
|
||||
"label": "Scroll enabled/Small layers?",
|
||||
"description": "If SCROLL_LONG_FILENAMES is enabled in your firmware select this setting.",
|
||||
"type": "bool",
|
||||
"default_value": false,
|
||||
"enabled": "display_option == 'filename_layer'"
|
||||
},
|
||||
"file_name":
|
||||
{
|
||||
"label": "Text to display:",
|
||||
"description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.",
|
||||
"type": "str",
|
||||
"default_value": "",
|
||||
"enabled": "display_option == 'filename_layer'"
|
||||
},
|
||||
"startNum":
|
||||
{
|
||||
"label": "Initial layer number:",
|
||||
"description": "Choose which number you prefer for the initial layer, 0 or 1",
|
||||
"type": "int",
|
||||
"default_value": 0,
|
||||
"minimum_value": 0,
|
||||
"maximum_value": 1,
|
||||
"enabled": "display_option == 'filename_layer'"
|
||||
},
|
||||
"maxlayer":
|
||||
{
|
||||
"label": "Display max layer?:",
|
||||
"description": "Display how many layers are in the entire print on status bar?",
|
||||
"type": "bool",
|
||||
"default_value": true,
|
||||
"enabled": "display_option == 'filename_layer'"
|
||||
},
|
||||
"addPrefixPrinting":
|
||||
{
|
||||
"label": "Add prefix 'Printing'?",
|
||||
"description": "This will add the prefix 'Printing'",
|
||||
"type": "bool",
|
||||
"default_value": true,
|
||||
"enabled": "display_option == 'filename_layer'"
|
||||
},
|
||||
"display_total_layers":
|
||||
{
|
||||
"label": "Display total layers",
|
||||
"description": "This setting adds the 'Total Layers' to the LCD message as '17/234'.",
|
||||
"type": "bool",
|
||||
"default_value": true,
|
||||
"enabled": "display_option == 'display_progress'"
|
||||
},
|
||||
"display_remaining_time":
|
||||
{
|
||||
"label": "Display remaining time",
|
||||
"description": "This will add the remaining printing time to the LCD message.",
|
||||
"type": "bool",
|
||||
"default_value": true,
|
||||
"enabled": "display_option == 'display_progress'"
|
||||
},
|
||||
"add_m118_line":
|
||||
{
|
||||
"label": "Add M118 Line",
|
||||
"description": "Adds M118 in addition to the M117. It will bounce the message back through the USB port to a computer print server (if a printer server is enabled).",
|
||||
"type": "bool",
|
||||
"default_value": false
|
||||
},
|
||||
"speed_factor":
|
||||
{
|
||||
"label": "Time Fudge Factor %",
|
||||
"description": "When using 'Display Progress' tweak this value to get better estimates. ([Actual Print Time]/[Cura Estimate]) x 100 = Time Fudge Factor. If Cura estimated 9hr and the print actually took 10hr30min then enter 117 here to adjust any estimate closer to reality. This Fudge Factor is also used to calculate the time that the print will end if you were to start it 15 minutes after slicing.",
|
||||
"type": "float",
|
||||
"unit": "%",
|
||||
"default_value": 100,
|
||||
"enabled": "enable_end_message or display_option == 'display_progress'"
|
||||
},
|
||||
"countdown_to_pause":
|
||||
{
|
||||
"label": "Countdown to Pauses",
|
||||
"description": "When enabled - DisplayInfoOnLCD must run AFTER all PauseAtHeight and Filament Change scripts. Instead of layer number and remaining print time the LCD will show 'layers remaining before pause/filament change and the time to pause/filament change' (TP).",
|
||||
"type": "bool",
|
||||
"default_value": false,
|
||||
"enabled": "display_option == 'display_progress'"
|
||||
},
|
||||
"enable_end_message":
|
||||
{
|
||||
"label": "Enable 'Finish-Time' Message",
|
||||
"description": "Get a message when you save a fresh slice. It will show the estimated date and time that the print would finish (with a 15 minute lag from the end of slicing to the start of the print).",
|
||||
"type": "bool",
|
||||
"default_value": true,
|
||||
"enabled": true
|
||||
},
|
||||
"print_start_time":
|
||||
{
|
||||
"label": "Print Start Time (Ex 16:45)",
|
||||
"description": "Use 'Military' time. 16:45 would be 4:45PM. 09:30 would be 9:30AM. If you leave this blank it will be assumed that the print start will 15 minutes after slicing.",
|
||||
"type": "str",
|
||||
"default_value": "",
|
||||
"unit": "hrs ",
|
||||
"enabled": "enable_end_message"
|
||||
}
|
||||
|
||||
}
|
||||
}"""
|
||||
|
||||
def execute(self, data):
|
||||
display_option = self.getSettingValueByKey("display_option")
|
||||
add_m118_line = self.getSettingValueByKey("add_m118_line")
|
||||
|
||||
# This is Display Filename and Layer on LCD---------------------------------------------------------
|
||||
if display_option == "filename_layer":
|
||||
max_layer = 0
|
||||
lcd_text = "M117 "
|
||||
if self.getSettingValueByKey("file_name") != "":
|
||||
file_name = self.getSettingValueByKey("file_name")
|
||||
else:
|
||||
file_name = Application.getInstance().getPrintInformation().jobName
|
||||
if self.getSettingValueByKey("addPrefixPrinting"):
|
||||
lcd_text += "Printing "
|
||||
if not self.getSettingValueByKey("scroll"):
|
||||
lcd_text += "Layer "
|
||||
else:
|
||||
lcd_text += file_name + " - Layer "
|
||||
i = self.getSettingValueByKey("startNum")
|
||||
for layer in data:
|
||||
display_text = lcd_text + str(i)
|
||||
layer_index = data.index(layer)
|
||||
lines = layer.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith(";LAYER_COUNT:"):
|
||||
max_layer = line
|
||||
max_layer = max_layer.split(":")[1]
|
||||
if self.getSettingValueByKey("startNum") == 0:
|
||||
max_layer = str(int(max_layer) - 1)
|
||||
if line.startswith(";LAYER:"):
|
||||
if self.getSettingValueByKey("maxlayer"):
|
||||
display_text = display_text + " of " + max_layer
|
||||
if not self.getSettingValueByKey("scroll"):
|
||||
display_text = display_text + " " + file_name
|
||||
else:
|
||||
if not self.getSettingValueByKey("scroll"):
|
||||
display_text = display_text + " " + file_name + "!"
|
||||
else:
|
||||
display_text = display_text + "!"
|
||||
line_index = lines.index(line)
|
||||
lines.insert(line_index + 1, display_text)
|
||||
if add_m118_line:
|
||||
lines.insert(line_index + 2, str(display_text.replace("M117", "M118", 1)))
|
||||
i += 1
|
||||
final_lines = "\n".join(lines)
|
||||
data[layer_index] = final_lines
|
||||
if bool(self.getSettingValueByKey("enable_end_message")):
|
||||
message_str = self.message_to_user(self.getSettingValueByKey("speed_factor") / 100)
|
||||
Message(title = "Display Info on LCD - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show()
|
||||
return data
|
||||
|
||||
# Display Progress (from 'Show Progress' and 'Display Progress on LCD')---------------------------------------
|
||||
elif display_option == "display_progress":
|
||||
# get settings
|
||||
display_total_layers = self.getSettingValueByKey("display_total_layers")
|
||||
display_remaining_time = self.getSettingValueByKey("display_remaining_time")
|
||||
speed_factor = self.getSettingValueByKey("speed_factor") / 100
|
||||
# initialize global variables
|
||||
first_layer_index = 0
|
||||
time_total = 0
|
||||
number_of_layers = 0
|
||||
time_elapsed = 0
|
||||
# if at least one of the settings is disabled, there is enough room on the display to display "layer"
|
||||
first_section = data[0]
|
||||
lines = first_section.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith(";TIME:"):
|
||||
tindex = lines.index(line)
|
||||
cura_time = int(line.split(":")[1])
|
||||
print_time = cura_time * speed_factor
|
||||
hhh = print_time/3600
|
||||
hr = round(hhh // 1)
|
||||
mmm = round((hhh % 1) * 60)
|
||||
orig_hhh = cura_time/3600
|
||||
orig_hr = round(orig_hhh // 1)
|
||||
orig_min = int((cura_time - (orig_hr * 3600))/60) # Not rounded up
|
||||
orig_mmm = round((orig_hhh % 1) * 60) # Rounded up
|
||||
orig_sec = round(cura_time - orig_hr * 3600 - orig_min * 60)
|
||||
if add_m118_line: lines.insert(tindex + 3,"M118 Adjusted Print Time " + str(hr) + "hr " + str(mmm) + "min")
|
||||
lines.insert(tindex + 3,"M117 ET " + str(hr) + "hr " + str(mmm) + "min")
|
||||
# If Countdown to pause is enabled then count the pauses and/or filament changes
|
||||
pause_str = ""
|
||||
if bool(self.getSettingValueByKey("countdown_to_pause")):
|
||||
pause_count = 0
|
||||
filament_change_count = 0
|
||||
for num in range(2,len(data) - 1, 1):
|
||||
if "PauseAtHeight.py" in data[num]:
|
||||
pause_count += 1
|
||||
if "M600" in data[num]:
|
||||
filament_change_count += 1
|
||||
if pause_count > 0:
|
||||
pause_str = f" with {pause_count} pause(s)"
|
||||
if filament_change_count > 0:
|
||||
pause_str += f" and {filament_change_count} filament change(s)"
|
||||
# This line goes in to convert seconds to hours and minutes
|
||||
lines.insert(tindex + 3, f";Cura Time Estimate: {cura_time}sec = {orig_hr}hr {orig_min}min {orig_sec}sec {pause_str}")
|
||||
data[0] = "\n".join(lines)
|
||||
data[len(data)-1] += "M117 Orig Cura Est " + str(orig_hr) + "hr " + str(orig_mmm) + "min\n"
|
||||
if add_m118_line: data[len(data)-1] += "M118 Est w/FudgeFactor " + str(speed_factor * 100) + "% was " + str(hr) + "hr " + str(mmm) + "min\n"
|
||||
if not display_total_layers or not display_remaining_time:
|
||||
base_display_text = "layer "
|
||||
else:
|
||||
base_display_text = ""
|
||||
layer = data[len(data)-1]
|
||||
data[len(data)-1] = layer.replace(";End of Gcode" + "\n", "")
|
||||
data[len(data)-1] += ";End of Gcode" + "\n"
|
||||
# Search for the number of layers and the total time from the start code
|
||||
for index in range(len(data)):
|
||||
data_section = data[index]
|
||||
# We have everything we need, save the index of the first layer and exit the loop
|
||||
if ";LAYER:" in data_section:
|
||||
first_layer_index = index
|
||||
break
|
||||
else:
|
||||
for line in data_section.split("\n"):
|
||||
if line.startswith(";LAYER_COUNT:"):
|
||||
number_of_layers = int(line.split(":")[1])
|
||||
elif line.startswith(";TIME:"):
|
||||
time_total = int(line.split(":")[1])
|
||||
# for all layers...
|
||||
current_layer = 0
|
||||
for layer_counter in range(len(data)-2):
|
||||
current_layer += 1
|
||||
layer_index = first_layer_index + layer_counter
|
||||
display_text = base_display_text
|
||||
display_text += str(current_layer)
|
||||
# create a list where each element is a single line of code within the layer
|
||||
lines = data[layer_index].split("\n")
|
||||
if not ";LAYER:" in data[layer_index]:
|
||||
current_layer -= 1
|
||||
continue
|
||||
# add the total number of layers if this option is checked
|
||||
if display_total_layers:
|
||||
display_text += "/" + str(number_of_layers)
|
||||
# if display_remaining_time is checked, it is calculated in this loop
|
||||
if display_remaining_time:
|
||||
time_remaining_display = " | ET " # initialize the time display
|
||||
m = (time_total - time_elapsed) // 60 # estimated time in minutes
|
||||
m *= speed_factor # correct for printing time
|
||||
m = int(m)
|
||||
h, m = divmod(m, 60) # convert to hours and minutes
|
||||
# add the time remaining to the display_text
|
||||
if h > 0: # if it's more than 1 hour left, display format = xhxxm
|
||||
time_remaining_display += str(h) + "h"
|
||||
if m < 10: # add trailing zero if necessary
|
||||
time_remaining_display += "0"
|
||||
time_remaining_display += str(m) + "m"
|
||||
else:
|
||||
time_remaining_display += str(m) + "m"
|
||||
display_text += time_remaining_display
|
||||
# find time_elapsed at the end of the layer (used to calculate the remaining time of the next layer)
|
||||
if not current_layer == number_of_layers:
|
||||
for line_index in range(len(lines) - 1, -1, -1):
|
||||
line = lines[line_index]
|
||||
if line.startswith(";TIME_ELAPSED:"):
|
||||
# update time_elapsed for the NEXT layer and exit the loop
|
||||
time_elapsed = int(float(line.split(":")[1]))
|
||||
break
|
||||
# insert the text AFTER the first line of the layer (in case other scripts use ";LAYER:")
|
||||
for l_index, line in enumerate(lines):
|
||||
if line.startswith(";LAYER:"):
|
||||
lines[l_index] += "\nM117 " + display_text
|
||||
if add_m118_line:
|
||||
lines[l_index] += "\nM118 " + display_text
|
||||
break
|
||||
# overwrite the layer with the modified layer
|
||||
data[layer_index] = "\n".join(lines)
|
||||
|
||||
# If enabled then change the ET to TP for 'Time To Pause'
|
||||
if bool(self.getSettingValueByKey("countdown_to_pause")):
|
||||
time_list = []
|
||||
time_list.append("0")
|
||||
time_list.append("0")
|
||||
this_time = 0
|
||||
pause_index = 1
|
||||
|
||||
# Get the layer times
|
||||
for num in range(2,len(data) - 1):
|
||||
layer = data[num]
|
||||
lines = layer.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith(";TIME_ELAPSED:"):
|
||||
this_time = (float(line.split(":")[1]))*speed_factor
|
||||
time_list.append(str(this_time))
|
||||
if "PauseAtHeight.py" in layer or "M600" in layer:
|
||||
for qnum in range(num - 1, pause_index, -1):
|
||||
time_list[qnum] = str(float(this_time) - float(time_list[qnum])) + "P"
|
||||
pause_index = num-1
|
||||
|
||||
# Make the adjustments to the M117 (and M118) lines that are prior to a pause
|
||||
for num in range (2, len(data) - 1,1):
|
||||
layer = data[num]
|
||||
lines = layer.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith("M117") and "|" in line and "P" in time_list[num]:
|
||||
M117_line = line.split("|")[0] + "| TP "
|
||||
alt_time = time_list[num][:-1]
|
||||
hhh = int(float(alt_time) / 3600)
|
||||
if hhh > 0:
|
||||
hhr = str(hhh) + "h"
|
||||
else:
|
||||
hhr = ""
|
||||
mmm = ((float(alt_time) / 3600) - (int(float(alt_time) / 3600))) * 60
|
||||
sss = int((mmm - int(mmm)) * 60)
|
||||
mmm = str(round(mmm)) + "m"
|
||||
time_to_go = str(hhr) + str(mmm)
|
||||
if hhr == "": time_to_go = time_to_go + str(sss) + "s"
|
||||
M117_line = M117_line + time_to_go
|
||||
layer = layer.replace(line, M117_line)
|
||||
if line.startswith("M118") and "|" in line and "P" in time_list[num]:
|
||||
M118_line = line.split("|")[0] + "| TP " + time_to_go
|
||||
layer = layer.replace(line, M118_line)
|
||||
data[num] = layer
|
||||
setting_data = ""
|
||||
if bool(self.getSettingValueByKey("enable_end_message")):
|
||||
message_str = self.message_to_user(speed_factor)
|
||||
Message(title = "[Display Info on LCD] - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show()
|
||||
return data
|
||||
|
||||
def message_to_user(self, speed_factor: float):
|
||||
# Message the user of the projected finish time of the print (figuring a 15 minute delay from end-of-slice to start-of-print
|
||||
print_time = Application.getInstance().getPrintInformation().currentPrintTime.getDisplayString(DurationFormat.Format.ISO8601)
|
||||
print_start_time = self.getSettingValueByKey("print_start_time")
|
||||
# If the user entered a print start time make sure it is in the correct format or ignore it.
|
||||
if print_start_time == "" or print_start_time == "0" or len(print_start_time) != 5 or not ":" in print_start_time:
|
||||
print_start_time = ""
|
||||
# Change the print start time to proper time format, or, use the current time
|
||||
if print_start_time != "":
|
||||
hr = int(print_start_time.split(":")[0])
|
||||
min = int(print_start_time.split(":")[1])
|
||||
sec = 0
|
||||
fifteen_minute_delay = 0
|
||||
else:
|
||||
hr = int(time.strftime("%H"))
|
||||
min = int(time.strftime("%M"))
|
||||
sec = int(time.strftime("%S"))
|
||||
fifteen_minute_delay = 900
|
||||
|
||||
#Get the current data/time info
|
||||
yr = int(time.strftime("%Y"))
|
||||
day = int(time.strftime("%d"))
|
||||
mo = int(time.strftime("%m"))
|
||||
|
||||
date_and_time = datetime.datetime(yr, mo, day, hr, min, sec)
|
||||
#Split the Cura print time
|
||||
pr_hr = int(print_time.split(":")[0])
|
||||
pr_min = int(print_time.split(":")[1])
|
||||
pr_sec = int(print_time.split(":")[2])
|
||||
#Adjust the print time if none was entered
|
||||
print_seconds = pr_hr*3600 + pr_min*60 + pr_sec + fifteen_minute_delay
|
||||
#Adjust the total seconds by the Fudge Factor
|
||||
adjusted_print_time = print_seconds * speed_factor
|
||||
#Break down the adjusted seconds back into hh:mm:ss
|
||||
adj_hr = int(adjusted_print_time/3600)
|
||||
print_seconds = adjusted_print_time - (adj_hr * 3600)
|
||||
adj_min = int(print_seconds) / 60
|
||||
adj_sec = int(print_seconds - (adj_min * 60))
|
||||
#Get the print time to add to the start time
|
||||
time_change = datetime.timedelta(hours=adj_hr, minutes=adj_min, seconds=adj_sec)
|
||||
new_time = date_and_time + time_change
|
||||
#Get the day of the week that the print will end on
|
||||
week_day = str(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][int(new_time.strftime("%w"))])
|
||||
#Get the month that the print will end in
|
||||
mo_str = str(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][int(new_time.strftime("%m"))-1])
|
||||
#Make adjustments from 24hr time to 12hr time
|
||||
if int(new_time.strftime("%H")) > 12:
|
||||
show_hr = str(int(new_time.strftime("%H")) - 12) + ":"
|
||||
show_ampm = " PM"
|
||||
elif int(new_time.strftime("%H")) == 0:
|
||||
show_hr = "12:"
|
||||
show_ampm = " AM"
|
||||
else:
|
||||
show_hr = str(new_time.strftime("%H")) + ":"
|
||||
show_ampm = " AM"
|
||||
if print_start_time == "":
|
||||
start_str = "and a 15 minute lag between saving the file and starting the print."
|
||||
else:
|
||||
start_str = "and your entered 'print start time' of " + print_start_time + "hrs."
|
||||
if print_start_time != "":
|
||||
print_start_str = "Print Start Time................." + str(print_start_time) + "hrs"
|
||||
else:
|
||||
print_start_str = "Print Start Time.................15 minutes from now."
|
||||
estimate_str = "Cura Time Estimate.........." + str(print_time)
|
||||
adjusted_str = "Adjusted Time Estimate..." + str(time_change)
|
||||
finish_str = week_day + " " + str(mo_str) + " " + str(new_time.strftime("%d")) + ", " + str(new_time.strftime("%Y")) + " at " + str(show_hr) + str(new_time.strftime("%M")) + str(show_ampm)
|
||||
return finish_str, estimate_str, adjusted_str, print_start_str
|
|
@ -9,12 +9,13 @@ from ..Script import Script
|
|||
|
||||
import re
|
||||
import datetime
|
||||
from UM.Message import Message
|
||||
|
||||
class DisplayProgressOnLCD(Script):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def initialize(self) -> None:
|
||||
Message(title = "[Display Progress on LCD]", text = "This script is now an option in 'Display Info on LCD'. This post processor no longer works.").show()
|
||||
|
||||
def getSettingDataString(self):
|
||||
return """{
|
||||
"name": "Display Progress On LCD",
|
||||
|
@ -23,176 +24,17 @@ class DisplayProgressOnLCD(Script):
|
|||
"version": 2,
|
||||
"settings":
|
||||
{
|
||||
"time_remaining":
|
||||
"enable_script":
|
||||
{
|
||||
"label": "Time Remaining",
|
||||
"description": "Select to write remaining time to the display.Select to write remaining time on the display using M117 status line message (almost all printers) or using M73 command (Prusa and Marlin 2 if enabled).",
|
||||
"label": "Deprecated/Obsolete",
|
||||
"description": "This script is now included in 'Display Info on LCD'.",
|
||||
"type": "bool",
|
||||
"default_value": false
|
||||
},
|
||||
"time_remaining_method":
|
||||
{
|
||||
"label": "Time Reporting Method",
|
||||
"description": "How should remaining time be shown on the display? It could use a generic message command (M117, almost all printers), or a specialised time remaining command (M73, Prusa and Marlin 2).",
|
||||
"type": "enum",
|
||||
"options": {
|
||||
"m117":"M117 - All printers",
|
||||
"m73":"M73 - Prusa, Marlin 2",
|
||||
"m118":"M118 - Octoprint"
|
||||
},
|
||||
"enabled": "time_remaining",
|
||||
"default_value": "m117"
|
||||
},
|
||||
"update_frequency":
|
||||
{
|
||||
"label": "Update frequency",
|
||||
"description": "Update remaining time for every layer or periodically every minute or faster.",
|
||||
"type": "enum",
|
||||
"options": {"0":"Every layer","15":"Every 15 seconds","30":"Every 30 seconds","60":"Every minute"},
|
||||
"default_value": "0",
|
||||
"enabled": "time_remaining"
|
||||
},
|
||||
"percentage":
|
||||
{
|
||||
"label": "Percentage",
|
||||
"description": "When enabled, set the completion bar percentage on the LCD using Marlin's M73 command.",
|
||||
"type": "bool",
|
||||
"default_value": false
|
||||
"default_value": true
|
||||
}
|
||||
}
|
||||
}"""
|
||||
|
||||
# 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 outputTime(self, lines, line_index, time_left, mode):
|
||||
# Do some math to get the time left in seconds into the right format. (HH,MM,SS)
|
||||
time_left = max(time_left, 0)
|
||||
m, s = divmod(time_left, 60)
|
||||
h, m = divmod(m, 60)
|
||||
# Create the string
|
||||
if mode == "m117":
|
||||
current_time_string = "{:d}h{:02d}m{:02d}s".format(int(h), int(m), int(s))
|
||||
# And now insert that into the GCODE
|
||||
lines.insert(line_index, "M117 Time Left {}".format(current_time_string))
|
||||
elif mode == "m118":
|
||||
current_time_string = "{:d}h{:02d}m{:02d}s".format(int(h), int(m), int(s))
|
||||
# And now insert that into the GCODE
|
||||
lines.insert(line_index, "M118 A1 P0 action:notification Time Left {}".format(current_time_string))
|
||||
else:
|
||||
mins = int(60 * h + m + s / 30)
|
||||
lines.insert(line_index, "M73 R{}".format(mins))
|
||||
|
||||
def execute(self, data):
|
||||
output_time = self.getSettingValueByKey("time_remaining")
|
||||
output_time_method = self.getSettingValueByKey("time_remaining_method")
|
||||
output_frequency = int(self.getSettingValueByKey("update_frequency"))
|
||||
output_percentage = self.getSettingValueByKey("percentage")
|
||||
line_set = {}
|
||||
if output_percentage or output_time:
|
||||
total_time = -1
|
||||
previous_layer_end_percentage = 0
|
||||
previous_layer_end_time = 0
|
||||
for layer in data:
|
||||
layer_index = data.index(layer)
|
||||
lines = layer.split("\n")
|
||||
|
||||
for line in lines:
|
||||
if (line.startswith(";TIME:") or line.startswith(";PRINT.TIME:")) and total_time == -1:
|
||||
# This line represents the total time required to print the gcode
|
||||
total_time = self.getTimeValue(line)
|
||||
line_index = lines.index(line)
|
||||
|
||||
# In the beginning we may have 2 M73 lines, but it makes logic less complicated
|
||||
if output_time:
|
||||
self.outputTime(lines, line_index, total_time, output_time_method)
|
||||
|
||||
if output_percentage:
|
||||
# Emit 0 percent to sure Marlin knows we are overriding the completion percentage
|
||||
if output_time_method == "m118":
|
||||
lines.insert(line_index, "M118 A1 P0 action:notification Data Left 0/100")
|
||||
else:
|
||||
lines.insert(line_index, "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 we have seen this line before then skip processing it. We can see lines multiple times because we are adding
|
||||
# intermediate percentages before the line being processed. This can cause the current line to shift back and be
|
||||
# encountered more than once
|
||||
if line in line_set:
|
||||
continue
|
||||
line_set[line] = True
|
||||
|
||||
# If total_time was not already found then noop
|
||||
if total_time == -1:
|
||||
continue
|
||||
|
||||
current_time = self.getTimeValue(line)
|
||||
line_index = lines.index(line)
|
||||
|
||||
if output_time:
|
||||
if output_frequency == 0:
|
||||
# Here we calculate remaining time
|
||||
self.outputTime(lines, line_index, total_time - current_time, output_time_method)
|
||||
else:
|
||||
# Here we calculate remaining time and how many outputs are expected for the layer
|
||||
layer_time_delta = int(current_time - previous_layer_end_time)
|
||||
layer_step_delta = int((current_time - previous_layer_end_time) / output_frequency)
|
||||
# If this layer represents less than 1 step then we don't need to emit anything, continue to the next layer
|
||||
if layer_step_delta != 0:
|
||||
# Grab the index of the current line and figure out how many lines represent one second
|
||||
step = line_index / layer_time_delta
|
||||
# Move new lines further as we add new lines above it
|
||||
lines_added = 1
|
||||
# Run through layer in seconds
|
||||
for seconds in range(1, layer_time_delta + 1):
|
||||
# Time from start to decide when to update
|
||||
line_time = int(previous_layer_end_time + seconds)
|
||||
# Output every X seconds and after last layer
|
||||
if line_time % output_frequency == 0 or line_time == total_time:
|
||||
# Line to add the output
|
||||
time_line_index = int((seconds * step) + lines_added)
|
||||
|
||||
# Insert remaining time into the GCODE
|
||||
self.outputTime(lines, time_line_index, total_time - line_time, output_time_method)
|
||||
# Next line will be again lower
|
||||
lines_added = lines_added + 1
|
||||
|
||||
previous_layer_end_time = int(current_time)
|
||||
|
||||
if output_percentage:
|
||||
# Calculate percentage value this layer ends at
|
||||
layer_end_percentage = int((current_time / 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:
|
||||
# Grab the index of the current line and figure out how many lines represent one percent
|
||||
step = line_index / 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
|
||||
percentage_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
|
||||
if output_time_method == "m118":
|
||||
lines.insert(percentage_line_index, "M118 A1 P0 action:notification Data Left {}/100".format(output))
|
||||
else:
|
||||
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)
|
||||
Message(title = "[Display Progress on LCD]", text = "This post is now included in 'Display Info on LCD'. This script will exit.").show()
|
||||
data[0] += "; [Display Progress on LCD] Did not run. It is now included in 'Display Info on LCD'.\n"
|
||||
return data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue