From c05eb73fb6dc87b23a19eea23deb1ac07bc0812c 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:21:34 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.py1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/main.py1 | 62 +++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/bin/main.py1 b/bin/main.py1 index 59fd76c..8e2ed15 100644 --- a/bin/main.py1 +++ b/bin/main.py1 @@ -218,39 +218,37 @@ def Partial_refresh():#局刷函数 draw.text((129,108),power_battery(),font = font04,fill =255) #显示当前电量百分比 power_str=power_str1 Local_strong_brush() #局部强刷 -# logging.info("电源电量局部刷新") -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() -except OSError as e: - logging.info(e) -except KeyboardInterrupt: - logging.info("检测到键盘中断,正在清理并退出") - epd.init() - epd.Clear(0xFF) # 清除屏幕内容 - epd.sleep() # 使屏幕进入休眠状态 - epd2in13_V4.epdconfig.module_exit() # 清理资源 - exit() +# logging.info("电池电量局部刷新") -except Exception as e: - logging.error("发生了意外的错误: %s", e) - epd.init() - epd.Clear(0xFF) # 清除屏幕内容 - epd.sleep() # 使屏幕进入休眠状态 - epd2in13_V4.epdconfig.module_exit() # 清理资源 - exit() +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()