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_time = self.getSettingValueByKey("time_remaining")
output_percentage = self.getSettingValueByKey("percentage") output_percentage = self.getSettingValueByKey("percentage")
line_set = {} line_set = {}
if (output_percentage or output_time) == True: if output_percentage or output_time:
total_time = -1 total_time = -1
previous_layer_end_percentage = 0 previous_layer_end_percentage = 0
for layer in data: for layer in data:
@ -72,35 +72,34 @@ class DisplayProgressOnLCD(Script):
total_time = self.getTimeValue(line) total_time = self.getTimeValue(line)
line_index = lines.index(line) line_index = lines.index(line)
if (output_time): if output_time:
self.outputTime(lines, line_index, total_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 # Emit 0 percent to sure Marlin knows we are overriding the completion percentage
lines.insert(line_index, "M73 P0") 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 # 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 # 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 # intermediate percentages before the line being processed. This can cause the current line to shift back and be
# encountered more than once # encountered more than once
if (line in line_set): if line in line_set:
continue continue
line_set[line] = True line_set[line] = True
# If total_time was not already found then noop # If total_time was not already found then noop
if (total_time == -1): if total_time == -1:
continue continue
current_time = self.getTimeValue(line) current_time = self.getTimeValue(line)
line_index = lines.index(line) line_index = lines.index(line)
if (output_time): if output_time:
# Here we calculate remaining time # Here we calculate remaining time
self.outputTime(lines, line_index, total_time - current_time) self.outputTime(lines, line_index, total_time - current_time)
if (output_percentage): if output_percentage:
# Calculate percentage value this layer ends at # Calculate percentage value this layer ends at
layer_end_percentage = int((current_time / total_time) * 100) 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 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 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 # Grab the index of the current line and figure out how many lines represent one percent
step = line_index / layer_percentage_delta step = line_index / layer_percentage_delta
@ -127,5 +126,5 @@ class DisplayProgressOnLCD(Script):
previous_layer_end_percentage = layer_end_percentage previous_layer_end_percentage = layer_end_percentage
# Join up the lines for this layer again and store them in the data array # 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 return data

View file

@ -122,14 +122,14 @@ class VersionUpgrade462to47(VersionUpgrade):
del script_parser["PauseAtHeight"]["redo_layers"] # Has been renamed to without the S. del script_parser["PauseAtHeight"]["redo_layers"] # Has been renamed to without the S.
# Migrate DisplayCompleteOnLCD to DisplayProgressOnLCD # Migrate DisplayCompleteOnLCD to DisplayProgressOnLCD
if script_id == "DisplayPercentCompleteOnLCD": if script_id == "DisplayRemainingTimeOnLCD":
was_enabled = script_parser[script_id]["TurnOn"] == "true" if "TurnOn" in script_parser[script_id] else False was_enabled = parseBool(script_parser[script_id]["TurnOn"]) if "TurnOn" in script_parser[script_id] else False
script_parser.remove_section(script_id) script_parser.remove_section(script_id)
script_id = "DisplayProgressOnLCD" script_id = "DisplayProgressOnLCD"
script_parser.add_section(script_id) script_parser.add_section(script_id)
if (was_enabled): if was_enabled:
script_parser.set(script_id, "time_remaining", "true") script_parser.set(script_id, "time_remaining", "True")
script_io = io.StringIO() script_io = io.StringIO()
script_parser.write(script_io) script_parser.write(script_io)