From b9cd0bab9d5dbd00a625d41118e68597be1e9431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=85=89-k?= <36470587+kxgx@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:20:47 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/main.py | 59 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/bin/main.py b/bin/main.py index 5e9bc36..086fdd9 100644 --- a/bin/main.py +++ b/bin/main.py @@ -251,24 +251,41 @@ def Partial_refresh(): # 局刷函数 draw.text((129, 108), power_str1, font=font04, fill=255) # 显示当前电量百分比 power_str = power_str1 Local_strong_brush() # 局部强刷 - logging.debug("电源电量局部刷新") -try: - ##################屏幕初始化######################### - epd = epd2in13_V4.EPD() # 初始化 - epd.init() # 设定屏幕刷新模式 - logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) # 打印屏幕高度及宽度 - logging.info("初始化并清空显示屏") # 屏幕开始准备相关展示 - info_image = Image.new('1', (epd.height, epd.width), 255) # 画布创建准备 - draw = ImageDraw.Draw(info_image) - Basic_refresh() # 全局刷新 - Partial_refresh() # 局部刷新 -except OSError as e: - logging.info(e) -except KeyboardInterrupt: - logging.info("检测到键盘中断,正在清理并退出") -finally: - epd.init() - epd.Clear(0xFF) # 清除屏幕内容 - epd.sleep() # 使屏幕进入休眠状态 - epd2in13_V4.epdconfig.module_exit() # 清理资源 - exit() + logging.debug("电池电量局部刷新") + +retry_interval = 180 # 设置重试间隔时间(秒) +while True: + try: + ##################屏幕初始化######################### + epd = epd2in13_V4.EPD() #初始化 + epd.init()#设定屏幕刷新模式 + #epd.Clear(0xFF) #清除屏幕内容 + ##################屏幕初始化######################### + logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度 + logging.info("初始化并清空显示屏")#屏幕开始准备相关展示 + info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备 + draw = ImageDraw.Draw(info_image) + Basic_refresh() #全局刷新 + Partial_refresh() #局部刷新 + epd.init() + epd.Clear(0xFF) + epd.sleep() + time.sleep(300) + break # 如果脚本执行成功,则退出循环 + except (OSError, Exception) as e: # 捕获你提到的异常 + logging.error("发生了错误: %s", e) + time.sleep(retry_interval) # 等待一段时间后重试 + except KeyboardInterrupt: + logging.info("检测到键盘中断,正在清理并退出") + epd.init() + epd.Clear(0xFF) # 清除屏幕内容 + epd.sleep() # 使屏幕进入休眠状态 + epd2in13_V4.epdconfig.module_exit() # 清理资源 + exit() + +# 脚本正常结束后的清理操作 +epd.init() +epd.Clear(0xFF) # 清除屏幕内容 +epd.sleep() # 使屏幕进入休眠状态 +epd2in13_V4.epdconfig.module_exit() # 清理资源 +exit() \ No newline at end of file