Skip to content

Commit

Permalink
Update DisplayInfoOnLCD.py
Browse files Browse the repository at this point in the history
Make M117 optional.
Combine M73 R and M73 P lines into a single line.
Add A and P parameters for M118 lines.
  • Loading branch information
GregValiant committed Apr 3, 2024
1 parent d478d05 commit 2e5cd5f
Showing 1 changed file with 102 additions and 43 deletions.
145 changes: 102 additions & 43 deletions plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def getSettingDataString(self):
"label": "Initial layer number:",
"description": "Choose which number you prefer for the initial layer, 0 or 1",
"type": "int",
"default_value": 0,
"default_value": 1,
"minimum_value": 0,
"maximum_value": 1,
"enabled": "display_option == 'filename_layer'"
Expand Down Expand Up @@ -125,33 +125,56 @@ def getSettingDataString(self):
"default_value": true,
"enabled": "display_option == 'display_progress'"
},
"add_m117_line":
{
"label": "Add M117 Line",
"description": "M117 sends a message to the LCD screen. Some screen firmware will not accept or display messages.",
"type": "bool",
"default_value": true
},
"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 like Octoprint or Pronterface is in use).",
"type": "bool",
"default_value": false
"default_value": true
},
"add_m118_a1":
{
"label": " Add A1 to M118 Line",
"description": "Adds A1 parameter. A1 adds a double foreslash '//' to the response. Octoprint may require this.",
"type": "bool",
"default_value": false,
"enabled": "add_m118_line"
},
"add_m118_p0":
{
"label": " Add P0 to M118 Line",
"description": "Adds P0 parameter. P0 has the printer send the response out through all it's ports. Octoprint may require this.",
"type": "bool",
"default_value": false,
"enabled": "add_m118_line"
},
"add_m73_line":
{
"label": "Add M73 Line(s)",
"description": "Adds M73 in addition to the M117. For some firmware this will set the printers time and or percentage.",
"description": "Adds M73 in addition to the M117. For some firmware this will set the printers time and or percentage. M75 is added to the beginning of the file and M77 is added to the end of the file. M73 will be added if one or both of the following options is chosen.",
"type": "bool",
"default_value": false,
"enabled": "display_option == 'display_progress'"
},
"add_m73_percent":
{
"label": " Add M73 Percentage",
"description": "Adds M73 with the P parameter. For some firmware this will set the printers 'percentage' of layers completed and it will count upward.",
"description": "Adds M73 with the P parameter to the start of each layer. For some firmware this will set the printers 'percentage' of layers completed and it will count upward.",
"type": "bool",
"default_value": false,
"enabled": "add_m73_line and display_option == 'display_progress'"
},
"add_m73_time":
{
"label": " Add M73 Time",
"description": "Adds M73 with the R parameter. For some firmware this will set the printers 'print time' and it will count downward.",
"description": "Adds M73 with the R parameter to the start of each layer. For some firmware this will set the printers 'print time' and it will count downward.",
"type": "bool",
"default_value": false,
"enabled": "add_m73_line and display_option == 'display_progress' and display_remaining_time"
Expand Down Expand Up @@ -179,15 +202,15 @@ def getSettingDataString(self):
"description": "This must run AFTER any script that adds a pause. Instead of the remaining print time the LCD will show the estimated time to the next layer that has a pause (TP).",
"type": "bool",
"default_value": false,
"enabled": "display_option == 'display_progress' and enable_countdown"
"enabled": "display_option == 'display_progress' and enable_countdown and display_remaining_time"
},
"pause_cmd":
{
"label": " What pause command(s) are used?",
"description": "This might be M0, or M25 or M600 if Filament Change is used. If you have mixed commands then delimit them with a comma ',' (Ex: M0,M600). Spaces are not allowed.",
"type": "str",
"default_value": "M0",
"enabled": "countdown_to_pause and enable_countdown"
"enabled": "countdown_to_pause and enable_countdown and display_remaining_time"
},
"enable_end_message":
{
Expand All @@ -211,28 +234,37 @@ def getSettingDataString(self):

def execute(self, data):
display_option = self.getSettingValueByKey("display_option")
add_m117_line = self.getSettingValueByKey("add_m117_line")
add_m118_line = self.getSettingValueByKey("add_m118_line")
add_m118_a1 = self.getSettingValueByKey("add_m118_a1")
add_m118_p0 = self.getSettingValueByKey("add_m118_p0")
add_m73_line = self.getSettingValueByKey("add_m73_line")
add_m73_time = self.getSettingValueByKey("add_m73_time")
add_m73_percent = self.getSettingValueByKey("add_m73_percent")
m73_str = ""

# This is Display Filename and Layer on LCD---------------------------------------------------------
if display_option == "filename_layer":
max_layer = 0
lcd_text = "M117 "
octo_text = "M118 "
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 "
octo_text += "Printing "
if not self.getSettingValueByKey("scroll"):
lcd_text += "Layer "
octo_text += "Layer "
else:
lcd_text += file_name + " - Layer "
octo_text += file_name + " - Layer "
i = self.getSettingValueByKey("startNum")
for layer in data:
display_text = lcd_text + str(i)
m118_text = octo_text + str(i)
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
Expand All @@ -243,18 +275,29 @@ def execute(self, data):
max_layer = str(int(max_layer) - 1)
if line.startswith(";LAYER:"):
if self.getSettingValueByKey("maxlayer"):
display_text = display_text + " of " + max_layer
display_text += " of " + max_layer
m118_text += " of " + max_layer
if not self.getSettingValueByKey("scroll"):
display_text = display_text + " " + file_name
display_text += " " + file_name
m118_text += " " + file_name
else:
if not self.getSettingValueByKey("scroll"):
display_text = display_text + " " + file_name + "!"
display_text += " " + file_name + "!"
m118_text += " " + file_name + "!"
else:
display_text = display_text + "!"
display_text += "!"
m118_text += "!"
line_index = lines.index(line)
lines.insert(line_index + 1, display_text)
if add_m117_line:
lines.insert(line_index + 1, display_text)
if add_m118_line:
lines.insert(line_index + 2, str(display_text.replace("M117", "M118", 1)))
if add_m118_a1 and not add_m118_p0:
m118_str = m118_text.replace("M118 ","M118 A1 ")
if add_m118_p0 and not add_m118_a1:
m118_str = m118_text.replace("M118 ","M118 P0 ")
if add_m118_p0 and add_m118_a1:
m118_str = m118_text.replace("M118 ","M118 A1 P0 ")
lines.insert(line_index + 2, m118_str)
i += 1
final_lines = "\n".join(lines)
data[layer_index] = final_lines
Expand Down Expand Up @@ -305,15 +348,15 @@ def execute(self, data):
orig_hr = round(orig_hhh // 1)
orig_mmm = math.floor((orig_hhh % 1) * 60)
if add_m118_line: lines.insert(tindex + 5,"M118 Adjusted Print Time " + str(hr) + "hr " + str(mmm) + "min")
lines.insert(tindex + 5,"M117 ET " + str(hr) + "hr " + str(mmm) + "min")
if add_m117_line: lines.insert(tindex + 5,"M117 ET " + str(hr) + "hr " + str(mmm) + "min")
## Add M73 line at beginning
mins = int(60 * hr + mmm)


if m73_time:
lines.insert(tindex + 4, "M73 R{}".format(mins))
if m73_percent:
lines.insert(tindex + 4, "M73 P0")
mins = int(60 * hr + mmm)
if add_m73_line and (add_m73_time or add_m73_percent):
if m73_time:
m73_str += " R{}".format(mins)
if m73_percent:
m73_str += " P0"
lines.insert(tindex + 4, "M73" + m73_str)
# If Countdown to pause is enabled then count the pauses
pause_str = ""
if bool(self.getSettingValueByKey("countdown_to_pause")):
Expand All @@ -334,8 +377,10 @@ def execute(self, data):
## This line goes in to convert seconds to hours and minutes
lines.insert(tindex + 5, f";Cura Time Estimate: {orig_hr}hr {orig_mmm}min {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 add_m117_line:
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:
Expand Down Expand Up @@ -403,16 +448,26 @@ def execute(self, data):
# 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_m117_line:
lines[l_index] += "\nM117 " + display_text
if add_m118_line:
lines[l_index] += "\nM118 " + display_text
a1_str = ""
p0_str = ""
if add_m118_a1:
a1_str = "A1 "
if add_m118_p0:
p0_str = "P0 "
lines[l_index] += "\nM118 " + a1_str + p0_str + display_text
# add M73 line
if display_remaining_time:
mins = int(60 * h + m)
if m73_time and display_remaining_time:
lines[l_index] += "\nM73 R{}".format(mins)
if m73_percent:
lines[l_index] += "\nM73 P" + str(round(int(current_layer) / int(number_of_layers) * 100))
if add_m73_line and (add_m73_time or add_m73_percent):
m73_str = ""
if m73_time and display_remaining_time:
m73_str += " R{}".format(mins)
if m73_percent:
m73_str += " P" + str(round(int(current_layer) / int(number_of_layers) * 100))
lines[l_index] += "\nM73" + m73_str
break
# overwrite the layer with the modified layer
data[layer_index] = "\n".join(lines)
Expand Down Expand Up @@ -447,21 +502,11 @@ def execute(self, data):
for line in lines:
try:
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
time_to_go = self.get_time_to_go(time_list[num])
M117_line = line.split("|")[0] + "| TP " + time_to_go
layer = layer.replace(line, M117_line)
if line.startswith("M118") and "|" in line and "P" in time_list[num]:
time_to_go = self.get_time_to_go(time_list[num])
M118_line = line.split("|")[0] + "| TP " + time_to_go
layer = layer.replace(line, M118_line)
except:
Expand Down Expand Up @@ -537,4 +582,18 @@ def message_to_user(self, speed_factor: float):
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
return finish_str, estimate_str, adjusted_str, print_start_str

def get_time_to_go(self, time_str: str):
alt_time = time_str[:-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"
return time_to_go

0 comments on commit 2e5cd5f

Please sign in to comment.