From 54296e7bbe5fc7dd62270ebd9f7cae20f2068bbc Mon Sep 17 00:00:00 2001 From: Ronald Date: Sat, 9 Nov 2024 15:52:54 +0000 Subject: [PATCH] Updated code to clear the display --- main.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 12ee8f5..b91712e 100644 --- a/main.py +++ b/main.py @@ -236,9 +236,6 @@ def main(): display.Init() - logging.info("clearing display") - display.clear() - width = display.width height = display.height image = Image.new('1', (width, height)) @@ -261,7 +258,14 @@ def main(): display.ShowImage() def clear_display(): - display.clear() + buffer = Image.new('1', (width, height)) + draw = ImageDraw.Draw(image) + draw.rectangle((0, 0, width, height), outline=0, fill=0) # black rectangle to clear screen, without clearing buffer + display.getbuffer(buffer) + display.ShowImage() + + logging.info("clearing display") + clear_display() if "DISPLAY_IN_TERMINAL" in config['SCREEN']: if config['SCREEN']['DISPLAY_IN_TERMINAL'].lower() == "false": @@ -321,9 +325,6 @@ def main(): logging.error("the data returned from the API was not in an expected format") continue - if show_on_screen: - clear_display() - glucoseMeasurement = graph['connection']['glucoseMeasurement'] if show_in_terminal: @@ -336,6 +337,8 @@ def main(): print(f"Refresh rate: {delay} seconds") if show_on_screen: + clear_display() + draw.text((x, top), glucoseMeasurement['Timestamp'], font=font, fill=255) draw.text((x, top+8), "Glucose units: " + str(glucoseMeasurement['Value']), font=font, fill=255) # Don't know why these two need to have more spaces to line up with the line ebovee