添加图标和delay

This commit is contained in:
RB 2025-05-04 23:49:39 +08:00
parent 927cafca66
commit af69d030fe
14 changed files with 133 additions and 26 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,5 +1,6 @@
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import sys
import os
import threading
@ -13,7 +14,11 @@ import xml.etree.ElementTree as ET
# 配置常量
REPO_DIR = "MRobot_repo"
REPO_URL = "http://gitea.qutrobot.top/robofish/MRobot.git"
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
if getattr(sys, 'frozen', False): # 检查是否为打包后的环境
CURRENT_DIR = os.path.dirname(sys.executable) # 使用可执行文件所在目录
else:
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) # 使用脚本所在目录
MDK_ARM_DIR = os.path.join(CURRENT_DIR, "MDK-ARM")
USER_DIR = os.path.join(CURRENT_DIR, "User")
@ -83,55 +88,60 @@ class MRobotApp:
self.log(f"找到项目文件:{project_file}")
return project_file
def add_groups_and_files(self):
"""添加 User 文件夹中的组和文件到 Keil 项目"""
"""添加 User 文件夹中的组和 .c 文件到 Keil 项目"""
project_file = self.find_uvprojx_file()
if not project_file:
return
tree = ET.parse(project_file)
root = tree.getroot()
groups_node = root.find(".//Groups")
if groups_node is None:
self.log("未找到 Groups 节点!")
return
existing_groups = {group.find("GroupName").text for group in groups_node.findall("Group")}
existing_files = {
file.text
for group in groups_node.findall("Group")
for file in group.findall(".//FileName")
}
# 获取现有组和文件信息
existing_groups = {group.find("GroupName").text: group for group in groups_node.findall("Group")}
for folder_name in os.listdir(USER_DIR):
folder_path = os.path.join(USER_DIR, folder_name)
if not os.path.isdir(folder_path):
continue
group_name = f"User/{folder_name}"
if group_name in existing_groups:
self.log(f"{group_name} 已存在,跳过...")
continue
group_node = ET.SubElement(groups_node, "Group")
ET.SubElement(group_node, "GroupName").text = group_name
files_node = ET.SubElement(group_node, "Files")
group_node = existing_groups[group_name]
self.log(f"{group_name} 已存在,检查文件...")
else:
group_node = ET.SubElement(groups_node, "Group")
ET.SubElement(group_node, "GroupName").text = group_name
ET.SubElement(group_node, "Files")
self.log(f"创建新组: {group_name}")
files_node = group_node.find("Files")
existing_files_in_group = {file.find("FileName").text for file in files_node.findall("File")}
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
if not os.path.isfile(file_path) or file_name in existing_files:
self.log(f"文件 {file_name} 已存在或无效,跳过...")
if not os.path.isfile(file_path) or not file_name.lower().endswith(".c"):
self.log(f"文件 {file_name} 无效,跳过...")
continue
if file_name in existing_files_in_group:
self.log(f"文件 {file_name} 已存在于组 {group_name},跳过...")
continue
file_node = ET.SubElement(files_node, "File")
ET.SubElement(file_node, "FileName").text = file_name
ET.SubElement(file_node, "FileType").text = "1"
relative_path = os.path.relpath(file_path, os.path.dirname(project_file)).replace("\\", "/")
ET.SubElement(file_node, "FilePath").text = relative_path
self.log(f"已添加文件: {file_name} 到组 {group_name}")
tree.write(project_file, encoding="utf-8", xml_declaration=True)
self.log("Keil 项目文件已更新!")
self.log("Keil 项目文件已更新,仅添加 .c 文件!")
def add_include_path(self, new_path):
"""添加新的 IncludePath 到 Keil 项目"""
@ -301,6 +311,7 @@ class MRobotApp:
root.title("MRobot 自动生成脚本")
root.geometry("800x600") # 调整窗口大小以适应布局
# 在窗口关闭时调用 on_closing 方法
root.protocol("WM_DELETE_WINDOW", lambda: self.on_closing(root))

View File

@ -3,7 +3,7 @@
更加高效快捷的 STM32 开发架构,诞生于 Robocon 和 Robomaster但绝不仅限于此。
<div align="center">
<img src="./image/MRobot.jpeg" height="100" alt="MRobot Logo">
<img src="./img/MRobot.png" height="100" alt="MRobot Logo">
<p>是时候使用更简洁的方式开发单片机了</p>
<p>
<!-- <img src="https://img.shields.io/github/license/xrobot-org/XRobot.svg" alt="License">

BIN
User/.DS_Store vendored

Binary file not shown.

34
User/bsp/delay.c Normal file
View File

@ -0,0 +1,34 @@
/* Includes ----------------------------------------------------------------- */
#include "bsp\delay.h"
#include <cmsis_os2.h>
#include <main.h>
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private typedef ---------------------------------------------------------- */
/* Private variables -------------------------------------------------------- */
/* Private function -------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
int8_t BSP_Delay(uint32_t ms) {
uint32_t tick_period = 1000u / osKernelGetTickFreq();
uint32_t ticks = ms / tick_period;
switch (osKernelGetState()) {
case osKernelError:
case osKernelReserved:
case osKernelLocked:
case osKernelSuspended:
return BSP_ERR;
case osKernelRunning:
osDelay(ticks ? ticks : 1);
break;
case osKernelInactive:
case osKernelReady:
HAL_Delay(ms);
break;
}
return BSP_OK;
}

20
User/bsp/delay.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ----------------------------------------------------------------- */
#include <stdint.h>
#include "bsp/bsp.h"
/* Exported constants ------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */
/* Exported functions prototypes -------------------------------------------- */
int8_t BSP_Delay(uint32_t ms);
#ifdef __cplusplus
}
#endif

BIN
img/.DS_Store vendored Normal file

Binary file not shown.

BIN
img/M.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
img/M.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

BIN
img/MR.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
img/MR.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

BIN
img/MRobot.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
img/MRobot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

42
pngico.py Normal file
View File

@ -0,0 +1,42 @@
from PIL import Image
import os
def crop_transparent_background(input_path, output_path):
"""
裁切 PNG 图片的透明背景并保存
:param input_path: 输入图片路径
:param output_path: 输出图片路径
"""
try:
# 打开图片
img = Image.open(input_path)
# 确保图片是 RGBA 模式
if img.mode != "RGBA":
img = img.convert("RGBA")
# 获取图片的 alpha 通道
bbox = img.getbbox()
if bbox:
# 裁切图片
cropped_img = img.crop(bbox)
# 保存裁切后的图片
cropped_img.save(output_path, format="PNG")
print(f"图片已保存到: {output_path}")
else:
print("图片没有透明背景或为空。")
except Exception as e:
print(f"处理图片时出错: {e}")
if __name__ == "__main__":
# 示例:输入和输出路径
input_file = "C:\Mac\Home\Desktop\MRobot\img\M.png" # 替换为你的输入图片路径
output_file = "C:\Mac\Home\Desktop\MRobot\img\M.png" # 替换为你的输出图片路径
# 检查文件是否存在
if os.path.exists(input_file):
crop_transparent_background(input_file, output_file)
else:
print(f"输入文件不存在: {input_file}")