diff --git a/library/lcd/lcd_comm.py b/library/lcd/lcd_comm.py index 06ab44a2..f12f07f9 100644 --- a/library/lcd/lcd_comm.py +++ b/library/lcd/lcd_comm.py @@ -357,13 +357,17 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value: # Crop bitmap to keep only the progress bar background bar_image = bar_image.crop(box=(x, y, x + width, y + height)) - # Draw progress bar + # Draw progress bar. Fill has to be computed from the offset + # into [min_value, max_value], not the raw value; otherwise a + # bar with min_value > 0 (e.g. a 25..95 temperature bar) is + # filled by the wrong fraction. DisplayRadialProgressBar below + # already does this correctly. See issue #954. if width > height: - bar_filled_width = (value / (max_value - min_value) * width) - 1 + bar_filled_width = ((value - min_value) / (max_value - min_value) * width) - 1 if bar_filled_width < 0: bar_filled_width = 0 else: - bar_filled_height = (value / (max_value - min_value) * height) - 1 + bar_filled_height = ((value - min_value) / (max_value - min_value) * height) - 1 if bar_filled_height < 0: bar_filled_height = 0 draw = ImageDraw.Draw(bar_image)