mirror of
https://github.com/goldenfishs/MRobot.git
synced 2025-06-16 06:46:38 +08:00
Compare commits
No commits in common. "3788e901b5a32b9c7362be3f19481bc46a874e24" and "c037044124ebafde938feeb49b77d618e0afd3a2" have entirely different histories.
3788e901b5
...
c037044124
30
MRobot.py
30
MRobot.py
@ -262,7 +262,6 @@ 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,21 +270,20 @@ 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 # 默认频率
|
||||
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}")
|
||||
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}")
|
||||
|
||||
# 自动添加已存在的任务名和频率
|
||||
new_task_var = tk.StringVar(value=file_base)
|
||||
@ -312,7 +310,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}")
|
||||
|
@ -1,2 +0,0 @@
|
||||
i2c,I2C
|
||||
uart,USART,UART
|
|
Loading…
Reference in New Issue
Block a user