1 Star 0 Fork 23

学渣集中营/keil_development_assistant

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
only_run_by_file.cpp 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
AGeek 提交于 2023-07-22 17:51 . 添加打包脚本
#include "only_run_by_file.h"
only_run_by_file::only_run_by_file(QObject *parent) : QObject(parent),
runFileName("run"),
closeFileName("close")
{
// 如果 run 文件已经存在,则删除
if (QFile::exists(runFileName)) {
QFile::remove(runFileName);
// 检测 close 文件是否存在的定时器
closeTimer = new QTimer(this);
connect(closeTimer, &QTimer::timeout, this, &only_run_by_file::checkCloseFile);
closeTimer->start(300); // 每 300 毫秒执行一次检测
}else
createRunFile();
// 检测 run 文件是否存在的定时器
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &only_run_by_file::checkRunFile);
timer->start(800); // 每 800 毫秒执行一次检测
}
void only_run_by_file::createCloseFile()
{
// 创建 close 文件
QFile file(closeFileName);
file.open(QIODevice::WriteOnly);
file.close();
}
void only_run_by_file::createRunFile()
{
// 创建 run 文件
QFile file(runFileName);
file.open(QIODevice::WriteOnly);
file.close();
}
void only_run_by_file::deleteCloseFile()
{
// 如果 close 文件已经存在,则删除
if (QFile::exists(closeFileName)) {
QFile::remove(closeFileName);
}
}
void only_run_by_file::deleteRunFile()
{
// 如果 run 文件已经存在,则删除
if (QFile::exists(runFileName)) {
QFile::remove(runFileName);
}
}
void only_run_by_file::checkRunFile()
{
// 检测 run 文件是否存在
if (!QFile::exists(runFileName)) {
// 文件不存在,采集关闭操作并创建 close 文件
deleteCloseFile();
// 创建 close 文件
createCloseFile();
emit runFileDeleted();
}
}
void only_run_by_file::checkCloseFile()
{
static uint8_t cnt=0;
if(cnt<3)
{
cnt++;
// 检测 close 文件是否存在
if (QFile::exists(closeFileName)) {
// 发出信号,通知检测到 close 文件
closeTimer->stop();
// 如果 close 文件已经存在,则删除
deleteCloseFile();
// 创建 run 文件
createRunFile();
emit closeFileDetected();
}
}else
{
cnt=0;
// 如果 close 文件已经存在,则删除
deleteCloseFile();
// 创建 run 文件
createRunFile();
emit closeFileDetected();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/itexp/keil_development_assistant.git
git@gitee.com:itexp/keil_development_assistant.git
itexp
keil_development_assistant
keil_development_assistant
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385