From 1583d87d7e686b6ca48b8241a91841980221b1e7 Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 6 Jul 2024 18:23:19 +0200 Subject: [PATCH] Update display only if percentage has changed and print X when mail sent --- src/program.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/program.py b/src/program.py index 8ba5970..449896b 100644 --- a/src/program.py +++ b/src/program.py @@ -240,7 +240,7 @@ def display_site_measure(epd, titel, titel_pos, val): draw.text((156, 110), "Abbrechen", font = font_label, fill = 0) epd.display(epd.getbuffer(dp)) -def display_site_main(epd, cl, ph): +def display_site_main(epd, cl, ph, clm, phm): dp = Image.new('1', (epd.height, epd.width), 255) newimage = Image.open(os.path.join(picdir, 'tankgrafik.bmp')) dp.paste(newimage, (0,0)) @@ -255,9 +255,11 @@ def display_site_main(epd, cl, ph): draw.rectangle((10, 78, 114, 85), outline = 1, fill = 1) if cl < 20: draw.rectangle((10, 90, 114, 97), outline = 1, fill = 1) - if cl < ALARM_LEVEL_CM: #todo and email - draw.rectangle((10, 54, 114, 109), outline = 1, fill = 1) - draw.text((37, 53), "X", font = font_huge, fill = 0) + if cl < ALARM_LEVEL_CM: + if clm == 1: + draw.text((37, 53), "X", font = font_huge, fill = 0) + else: + draw.rectangle((10, 54, 114, 109), outline = 1, fill = 1) if ph < 80: draw.rectangle((135, 54, 239, 61), outline = 1, fill = 1) if ph < 60: @@ -266,9 +268,11 @@ def display_site_main(epd, cl, ph): draw.rectangle((135, 78, 239, 85), outline = 1, fill = 1) if ph < 20: draw.rectangle((135, 90, 239, 97), outline = 1, fill = 1) - if ph < ALARM_LEVEL_CM: #todo and email - draw.rectangle((135, 54, 239, 109), outline = 1, fill = 1) - draw.text((164, 53), "X", font = font_huge, fill = 0) + if ph < ALARM_LEVEL_CM: + if phm == 1: + draw.text((164, 53), "X", font = font_huge, fill = 0) + else: + draw.rectangle((135, 54, 239, 109), outline = 1, fill = 1) epd.display(epd.getbuffer(dp)) if __name__ == '__main__': @@ -283,7 +287,7 @@ if __name__ == '__main__': font_label = ImageFont.truetype(os.path.join(picdir, 'squarea.ttf'), 15) font_huge = ImageFont.truetype(os.path.join(picdir, 'squarea.ttf'), 74) - display_site_main(epd, 0, 0) + display_site_main(epd, 0, 0, 0, 0) print("Lese config.ini...") config = configparser.ConfigParser() @@ -318,6 +322,8 @@ if __name__ == '__main__': print("Starte Hauptprogramm...") mavg_cl = MovingAverage(AVG_WINDOWSIZE) mavg_ph = MovingAverage(AVG_WINDOWSIZE) + clp_prev = -1 + php_prev = -1 while True: try: state = buttons.get_state() @@ -406,9 +412,14 @@ if __name__ == '__main__': ph_status = False clp = get_percent(cl_leer, cl_voll, cl) php = get_percent(ph_leer, ph_voll, ph) - display_site_main(epd, clp, php) print("Chlor: {:10.2f} cm, pH-Minus: {:10.2f} cm".format(cl, ph)) print("Chlor: {:10.2f} %, pH-Minus: {:10.2f} %".format(clp, php)) + clp = round(clp, 0) + php = round(php, 0) + if clp != clp_prev or php != php_prev: + display_site_main(epd, clp, php, cl_mail, ph_mail) + clp_prev = clp + php_prev = php if cl_status and abs(cl_leer - ALARM_LEVEL_CM) < cl: print(f"{Fore.RED}Chlor-Tank fast leer!{Style.RESET_ALL}") if cl_mail == 0: @@ -431,4 +442,4 @@ if __name__ == '__main__': config.write(configfile) time.sleep(0.5) except KeyboardInterrupt: - shutdown(epd) + shutdown(epd) \ No newline at end of file