Apply suggestions from code review

Co-authored-by: Konstantinos Karmas <konskarm@gmail.com>
This commit is contained in:
Alexander Gee 2020-07-08 00:30:19 -05:00 committed by GitHub
parent 18098ae893
commit 0a97511d3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 14 deletions

View file

@ -59,7 +59,7 @@ class DisplayProgressOnLCD(Script):
output_time = self.getSettingValueByKey("time_remaining")
output_percentage = self.getSettingValueByKey("percentage")
line_set = {}
if (output_percentage or output_time) == True:
if output_percentage or output_time:
total_time = -1
previous_layer_end_percentage = 0
for layer in data:
@ -72,35 +72,34 @@ class DisplayProgressOnLCD(Script):
total_time = self.getTimeValue(line)
line_index = lines.index(line)
if (output_time):
if output_time:
self.outputTime(lines, line_index, total_time)
if (output_percentage):
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:"):
# 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):
if line in line_set:
continue
line_set[line] = True
# If total_time was not already found then noop
if (total_time == -1):
if total_time == -1:
continue
current_time = self.getTimeValue(line)
line_index = lines.index(line)
if (output_time):
if output_time:
# Here we calculate remaining time
self.outputTime(lines, line_index, total_time - current_time)
if (output_percentage):
if output_percentage:
# Calculate percentage value this layer ends at
layer_end_percentage = int((current_time / total_time) * 100)
@ -108,7 +107,7 @@ class DisplayProgressOnLCD(Script):
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):
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
@ -127,5 +126,5 @@ class DisplayProgressOnLCD(Script):
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)
data[layer_index] = "\n".join(lines)
return data