From 3f6cf813a42be8b9b236b37ec2fb0bd0a980dc46 Mon Sep 17 00:00:00 2001 From: RB Date: Wed, 30 Apr 2025 11:25:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=BD=E5=A4=9F=E6=AD=A3=E7=A1=AE=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E9=A2=91=E7=8E=87=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes MRobot.py | 31 ++++++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.DS_Store b/.DS_Store index 93bd760b5e606d36b60741f1e74bc6c5b02ceab6..7bb6bf5697af0bd81ec61145bc8dd1c8a11c5879 100644 GIT binary patch delta 53 zcmZoMXfc@JFUrNhz`)4BAi&_6lb@WFlb;0S3v3qTSkBDIwb_hi2IFQHHfE-Y4GEjs IIsWnk06e)2wg3PC delta 134 zcmZoMXfc@JFU-Thz`)4BAi%(o;+d15oRpKFv{{g2C9^h2f|VhOp_Cz$AqOD|6a}hf zSP#T{|G|KPVKWcQ3`T8k2499ChJ2uwe1;MRJ%(b20)|wEWSFT?jgCNi-sYLCd`z3! IIsWnk0EHGH)c^nh diff --git a/MRobot.py b/MRobot.py index 0d18847..3897de5 100644 --- a/MRobot.py +++ b/MRobot.py @@ -11,7 +11,6 @@ import csv # 配置常量 REPO_DIR = "MRobot_repo" REPO_URL = "http://gitea.qutrobot.top/robofish/MRobot.git" -# REPO_URL = "https://github.com/goldenfishs/MRobot.git" # 使用 HTTPS 协议 class MRobotApp: def __init__(self): @@ -263,6 +262,7 @@ class MRobotApp: sys.stdout = TextRedirector(self.message_box) sys.stderr = TextRedirector(self.message_box) + # 修改 update_task_ui 方法 def update_task_ui(self): # 检查是否有已存在的任务文件 task_dir = os.path.join("User", "task") @@ -271,20 +271,21 @@ class MRobotApp: file_base, file_ext = os.path.splitext(file_name) # 忽略 init 和 user_task 文件 if file_ext == ".c" and file_base not in ["init", "user_task"] and file_base not in [task_var.get() for task_var, _ in self.task_vars]: - # 尝试从文件中读取频率信息 + # 尝试从 user_task.h 文件中读取频率信息 frequency = 100 # 默认频率 - file_path = os.path.join(task_dir, file_name) - try: - with open(file_path, "r", encoding="utf-8") as f: - content = f.read() - # 调试信息:打印文件内容 - print(f"读取任务文件 {file_name} 内容:\n{content}") - match = re.search(r"#define\s+TASK_FREQ_\w+\s*\((\d+)\)", content) - if match: - frequency = int(match.group(1)) - print(f"从文件 {file_name} 中读取到频率: {frequency}") - except Exception as e: - print(f"读取任务文件 {file_name} 时出错: {e}") + user_task_header_path = os.path.join("User", "task", "user_task.h") + if os.path.exists(user_task_header_path): + try: + with open(user_task_header_path, "r", encoding="utf-8") as f: + content = f.read() + # 匹配任务频率的宏定义 + pattern = rf"#define\s+TASK_FREQ_{file_base.upper()}\s*\((\d+)[uU]?\)" + match = re.search(pattern, content) + if match: + frequency = int(match.group(1)) + print(f"从 user_task.h 文件中读取到任务 {file_base} 的频率: {frequency}") + except Exception as e: + print(f"读取 user_task.h 文件时出错: {e}") # 自动添加已存在的任务名和频率 new_task_var = tk.StringVar(value=file_base) @@ -311,7 +312,7 @@ class MRobotApp: # 添加新任务按钮 add_task_button = tk.Button(self.task_frame, text="添加任务", command=self.add_task, bg="blue", fg="white") add_task_button.pack(pady=10) - + # 修改 add_task 方法 def add_task(self): new_task_var = tk.StringVar(value=f"Task_{len(self.task_vars) + 1}")