|
|
@@ -19,7 +19,6 @@
|
|
|
#include "string.h"
|
|
|
#include "sht30_collect.h"
|
|
|
#include "beep.h"
|
|
|
-#include "easyflash.h"
|
|
|
#include "sound.h"
|
|
|
#include "ymodem.h"
|
|
|
#include <shell.h>
|
|
|
@@ -143,38 +142,6 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
|
|
|
}
|
|
|
|
|
|
|
|
|
-/*入口函数*/
|
|
|
-static void Hmi_thread_entry(void *parameter)
|
|
|
-{
|
|
|
-
|
|
|
- struct rx_msg msg;
|
|
|
- rt_err_t result;
|
|
|
- rt_uint32_t rx_length;
|
|
|
- if(device_status.dtype==3){
|
|
|
- device_status.collt_box_sta = 0;
|
|
|
- device_status.run_sta = 0;
|
|
|
- }
|
|
|
- device_status.camsta = 1;
|
|
|
- while(1)
|
|
|
- {
|
|
|
-
|
|
|
- rt_memset(&msg, 0, sizeof(msg));
|
|
|
- /* 从消息队列中读取消息*/
|
|
|
- result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 50);
|
|
|
- if (result == RT_EOK)
|
|
|
- {
|
|
|
-
|
|
|
- rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
|
|
|
- rx_buffer[rx_length] = '\0';
|
|
|
- //LOG_I("%s",rx_buffer);
|
|
|
- //\r 对应的hex为0x0d,0x0a,占两个字节,屏幕发送的数据都以\r结尾
|
|
|
- //HMI_Decode();
|
|
|
- }
|
|
|
- /*********************************************************************************************************************/
|
|
|
- //rt_kprintf("%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
- //rt_kprintf("workSta.vbat.txt=%c%d.%02d%c\n",hmi_str,voltage/100,voltage%100,hmi_str);
|
|
|
- }
|
|
|
-}
|
|
|
/*******************************************************************************************/
|
|
|
static void t_uart2_callback(void *parameter)
|
|
|
{
|
|
|
@@ -217,213 +184,310 @@ void send_signal(int sig)
|
|
|
{
|
|
|
rt_thread_kill(ctr_motor, sig);
|
|
|
}
|
|
|
+/* ========== 自动对焦(Auto Focus)控制块 ========== */
|
|
|
+#define AF_FOCUS_TIMEOUT_MS 5000 /* 等待 focus 回复超时时间(ms) */
|
|
|
+#define AF_FOCUS_RETRY_MAX 3 /* 等待 focus 超时补发指令次数上限 */
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ float best_sharpness; /* 全局最佳清晰度 */
|
|
|
+ int best_pos; /* 全局最佳位置 */
|
|
|
+ float last_sharpness; /* 上一次移动后的清晰度 */
|
|
|
+ int dir; /* 行进方向: 1=正向, 0=反向 */
|
|
|
+ int step_size; /* 步进电机脉冲数 */
|
|
|
+ int current_pos; /* 当前位置 */
|
|
|
+ int peak_counter; /* 连续上升后下降的峰值计数 */
|
|
|
+ int reduce_counter; /* 清晰度连续降低计数 */
|
|
|
+ int diff_counter; /* 清晰度变化微小累计次数 */
|
|
|
+ bool last_rising; /* 上次是否上升 */
|
|
|
+ int max_iterations; /* 最大迭代次数 */
|
|
|
+ bool initial_move; /* 初始方向判断标志 */
|
|
|
+ volatile bool sharpness_updated; /* 信号处理程序置位: 有新清晰度值 */
|
|
|
+ float new_sharpness; /* 信号处理程序写入的新清晰度值 */
|
|
|
+ bool active; /* 对焦进行中标志(用于超时重试判定) */
|
|
|
+ rt_tick_t wait_start_tick; /* 开始等待 focus 回复的时间 */
|
|
|
+ int retry_cnt; /* 已连续超时补发指令次数 */
|
|
|
+} auto_focus_t;
|
|
|
+
|
|
|
+static auto_focus_t g_af;
|
|
|
+/* 轻量级信号处理程序:仅存储清晰度值,不阻塞 */
|
|
|
+void thread1_signal_handler(int sig)
|
|
|
+{
|
|
|
+ rt_timer_stop(timer_takephoto);
|
|
|
+ g_af.sharpness_updated = true;
|
|
|
+ g_af.new_sharpness = device_status.focus_value;
|
|
|
+}
|
|
|
|
|
|
-// 全局状态变量(需在合适位置初始化)
|
|
|
-static float g_best_sharpness = -FLT_MAX; // 全局最佳清晰度
|
|
|
-static int g_best_pos = 0; // 全局最佳位置
|
|
|
-static float g_last_sharpness = 0.0; // 上一次移动后的清晰度
|
|
|
-static bool g_initial_move = true; // 初始方向判断标志
|
|
|
-static bool focus_done = false;
|
|
|
-int maxIterations = 100;
|
|
|
-uint8_t dir = 1;
|
|
|
-uint8_t stepSize = 20; // 初始步长(单位:步进电机脉冲数)
|
|
|
-int current_pos = 0; // 根据实际类型修改(int/float等)
|
|
|
-static int g_peak_counter = 0; // 连续上升后下降的计数器
|
|
|
-static bool g_last_rising = false; // 记录上次是否上升
|
|
|
-static int counter_sharpness_reduce = 0; //清晰度降低累计
|
|
|
-static int counter_sharpness_diff = 0; //清晰度累计插值 次数变化
|
|
|
-#define MAX(a, b) ((a) > (b) ? (a) : (b)) // 手动定义宏
|
|
|
+/* 初始化自动对焦状态 */
|
|
|
+static void auto_focus_init(void)
|
|
|
+{
|
|
|
+ memset(&g_af, 0, sizeof(g_af));
|
|
|
+ g_af.best_sharpness = -FLT_MAX;
|
|
|
+ g_af.last_sharpness = 0.0f;
|
|
|
+ g_af.initial_move = true;
|
|
|
+ g_af.last_rising = false;
|
|
|
+ g_af.dir = 1;
|
|
|
+ g_af.step_size = 20;
|
|
|
+ g_af.current_pos = 0;
|
|
|
+ g_af.max_iterations = 100;
|
|
|
+ g_af.peak_counter = 0;
|
|
|
+ g_af.best_pos = 0;
|
|
|
+ g_af.reduce_counter = 0;
|
|
|
+ /* 超时重试状态 */
|
|
|
+ g_af.active = true;
|
|
|
+ g_af.wait_start_tick = rt_tick_get();
|
|
|
+ g_af.retry_cnt = 0;
|
|
|
+}
|
|
|
|
|
|
-void thread1_signal_handler(int sig)
|
|
|
+/* 移动电机一步 */
|
|
|
+static void auto_focus_move(void)
|
|
|
{
|
|
|
- if(timer_takephoto){
|
|
|
- rt_timer_stop(timer_takephoto);
|
|
|
+ g_af.current_pos += g_af.dir ? g_af.step_size : -g_af.step_size;
|
|
|
+ LOG_I("[对焦] 移动:方向=%d 步长=%d 位置=%d", g_af.dir, g_af.step_size, g_af.current_pos);
|
|
|
+
|
|
|
+ slide_para.pulse_period = mapSpeed(1);
|
|
|
+ slide_para.ystep = g_af.step_size;
|
|
|
+ slide_para.ydir = g_af.dir;
|
|
|
+ slide_para.ydis = g_af.step_size;
|
|
|
+ slide_para.en_slide = 6;
|
|
|
+
|
|
|
+ while (slide_para.en_slide != 0) {
|
|
|
+ rt_thread_delay(100);
|
|
|
}
|
|
|
- LOG_I("[对焦] 清晰度值更新:%.2f", device_status.focus_value);
|
|
|
- slide_para.pulse_period = mapSpeed(1); // 更新电机速度参数
|
|
|
- maxIterations--;
|
|
|
-
|
|
|
- if (device_status.autotakepic == 2 && maxIterations >= 0) {
|
|
|
- float current_sharpness = device_status.focus_value;
|
|
|
-
|
|
|
- /* 更新全局最佳状态 */
|
|
|
- if (current_sharpness > g_best_sharpness) {
|
|
|
- g_best_sharpness = current_sharpness;
|
|
|
- g_best_pos = current_pos;
|
|
|
- LOG_I("[对焦] 发现更佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
|
|
|
- }
|
|
|
|
|
|
- /* 初始方向判断(首步移动后) */
|
|
|
- if (g_initial_move) {
|
|
|
- if (current_sharpness > g_last_sharpness) {
|
|
|
- LOG_I("[对焦] 初始方向正确,保持方向:%d", dir);
|
|
|
- } else {
|
|
|
- dir = !dir; // 反转方向
|
|
|
- LOG_I("[对焦] 初始方向错误,反转方向:%d", dir);
|
|
|
- }
|
|
|
- g_initial_move = false;
|
|
|
- } else {
|
|
|
+ LOG_I("[对焦] 电机到位");
|
|
|
+ g_af.wait_start_tick = rt_tick_get(); /* 移动完成,开始等待 focus 回复 */
|
|
|
+ rt_timer_start(timer_takephoto);
|
|
|
+}
|
|
|
|
|
|
- double diff_sharpness = fabs(current_sharpness-g_last_sharpness);
|
|
|
- if(diff_sharpness<1.0)
|
|
|
- {
|
|
|
- counter_sharpness_diff++;
|
|
|
- if(counter_sharpness_diff>=10){ //持续10次
|
|
|
- stepSize = 20;
|
|
|
- }
|
|
|
- }
|
|
|
+/* 完成对焦 */
|
|
|
+static void auto_focus_done(void)
|
|
|
+{
|
|
|
+ LOG_I("[对焦] 完成! 最佳位置:%d 清晰度:%.2f", g_af.best_pos, g_af.best_sharpness);
|
|
|
+ g_af.active = false; /* 对焦完成,停止超时重试检测 */
|
|
|
+ char *c0 = makeJson_Warn("auto_focus","auto_focus");
|
|
|
+ DTU_Write("%s",c0);
|
|
|
+ rt_free(c0);
|
|
|
+}
|
|
|
|
|
|
- if(diff_sharpness > 3.5) //动态调整,发生明显变化,降低步进幅度
|
|
|
- {
|
|
|
- counter_sharpness_diff = 0;
|
|
|
- stepSize = 4;
|
|
|
- }
|
|
|
- LOG_I("[对焦] 清晰度变化累计%d次小于1.0",counter_sharpness_diff);
|
|
|
-
|
|
|
- if(current_sharpness< (g_last_sharpness-0.3f)){ //持续3次清晰度降低,调整行进方向
|
|
|
- counter_sharpness_reduce++;
|
|
|
- LOG_I("[对焦] 清晰度下降,次数:%d", counter_sharpness_reduce);
|
|
|
- if(counter_sharpness_reduce>=3){
|
|
|
- counter_sharpness_reduce = 0;
|
|
|
- dir = !dir; // 清晰度下降,反转方向
|
|
|
- LOG_I("[对焦] 连续清晰度下降,调转行进方向!");
|
|
|
- }
|
|
|
- }else {
|
|
|
- counter_sharpness_reduce = 0;
|
|
|
- }
|
|
|
+/* 处理一次清晰度值,执行对焦算法 */
|
|
|
+static void auto_focus_process(void)
|
|
|
+{
|
|
|
+ float current_sharpness = g_af.new_sharpness;
|
|
|
+ g_af.sharpness_updated = false;
|
|
|
+ g_af.max_iterations--;
|
|
|
+ g_af.retry_cnt = 0; /* 收到 focus 回复,清零超时重试计数 */
|
|
|
+ g_af.wait_start_tick = rt_tick_get(); /* 重置等待计时 */
|
|
|
+
|
|
|
+ LOG_I("[对焦] 清晰度:%.2f 位置:%d 剩余:%d",
|
|
|
+ current_sharpness, g_af.current_pos, g_af.max_iterations);
|
|
|
+
|
|
|
+ /* 更新最佳位置 */
|
|
|
+ if (current_sharpness > g_af.best_sharpness) {
|
|
|
+ g_af.best_sharpness = current_sharpness;
|
|
|
+ g_af.best_pos = g_af.current_pos;
|
|
|
+ LOG_I("[对焦] 新最佳:位置%d 清晰度%.2f", g_af.best_pos, g_af.best_sharpness);
|
|
|
+ }
|
|
|
|
|
|
- /* 方向策略调整,检测到清晰度变大 */
|
|
|
- if (current_sharpness > (g_last_sharpness - 3.5f)) { // 噪声容忍阈值3.0
|
|
|
- // 保持方向,当接近峰值时自动减小步长
|
|
|
- LOG_I("保持方向,当接近峰值时自动减小步长...");
|
|
|
- g_last_rising = true;
|
|
|
- stepSize += 2; //动态调整步幅
|
|
|
- } else {
|
|
|
- if(g_last_rising){
|
|
|
- g_peak_counter++;
|
|
|
- LOG_I("[对焦] 检测到清晰度波动[%d/3]", g_peak_counter);
|
|
|
- stepSize = 2;
|
|
|
- }else {
|
|
|
- g_peak_counter = 0; // 连续下降则重置
|
|
|
- }
|
|
|
- g_last_rising = false;
|
|
|
- dir = !dir; // 清晰度下降,反转方向
|
|
|
- LOG_I("[对焦] 清晰度下降,反转方向:%d 步长:%d", dir, stepSize);
|
|
|
- }
|
|
|
+ /* 初始方向判断:比较首次移动前后的清晰度 */
|
|
|
+ if (g_af.initial_move) {
|
|
|
+ g_af.initial_move = false;
|
|
|
+ if (current_sharpness > g_af.last_sharpness + 0.5f) {
|
|
|
+ LOG_I("[对焦] 初始方向正确");
|
|
|
+ } else {
|
|
|
+ g_af.dir = !g_af.dir;
|
|
|
+ LOG_I("[对焦] 初始方向错误,反转");
|
|
|
}
|
|
|
+ g_af.last_sharpness = current_sharpness;
|
|
|
+ auto_focus_move();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- /* 记录本次清晰度值 */
|
|
|
- g_last_sharpness = current_sharpness;
|
|
|
-
|
|
|
- /* 计算并执行下一步移动 */
|
|
|
- current_pos += dir ? stepSize : -stepSize;
|
|
|
- LOG_I("[对焦] 方向:%d 移动步长:%d 新位置:%d", dir, stepSize, current_pos);
|
|
|
+ /* 计算清晰度变化 */
|
|
|
+ float diff = current_sharpness - g_af.last_sharpness;
|
|
|
+
|
|
|
+ /* 动态调整步长 */
|
|
|
+ if (fabs(diff) > 3.0f) {
|
|
|
+ /* 清晰度大幅变化 -> 缩小步长精细搜索 */
|
|
|
+ g_af.step_size = 4;
|
|
|
+ g_af.diff_counter = 0;
|
|
|
+ LOG_I("[对焦] 大幅变化,步长=%d", g_af.step_size);
|
|
|
+ } else if (fabs(diff) < 1.0f) {
|
|
|
+ /* 清晰度变化微小 -> 累计平坦区域 */
|
|
|
+ g_af.diff_counter++;
|
|
|
+ if (g_af.diff_counter >= 10) {
|
|
|
+ g_af.step_size = 20;
|
|
|
+ }
|
|
|
+ LOG_I("[对焦] 平坦[%d/10] 步长=%d", g_af.diff_counter, g_af.step_size);
|
|
|
+ } else {
|
|
|
+ g_af.diff_counter = 0;
|
|
|
+ }
|
|
|
|
|
|
- if(counter_sharpness_diff>=30){
|
|
|
- dir = !dir;
|
|
|
- stepSize += 10; //增大步幅
|
|
|
- counter_sharpness_diff = 0;
|
|
|
+ /* 方向判断 */
|
|
|
+ bool need_reverse = false;
|
|
|
+ if (diff > 0.5f) {
|
|
|
+ /* 上升:保持方向,缩小步长逼近峰值 */
|
|
|
+ g_af.reduce_counter = 0;
|
|
|
+ g_af.last_rising = true;
|
|
|
+ if (g_af.step_size > 4) g_af.step_size -= 2;
|
|
|
+ LOG_I("[对焦] 上升↑ 步长=%d", g_af.step_size);
|
|
|
+ } else if (diff < -0.3f) {
|
|
|
+ /* 下降:累计,超过阈值反转方向 */
|
|
|
+ g_af.reduce_counter++;
|
|
|
+ g_af.last_rising = false;
|
|
|
+ LOG_I("[对焦] 下降↓[%d/3]", g_af.reduce_counter);
|
|
|
+ if (g_af.reduce_counter >= 3) {
|
|
|
+ need_reverse = true;
|
|
|
+ g_af.reduce_counter = 0;
|
|
|
+ g_af.peak_counter++;
|
|
|
+ LOG_I("[对焦] 峰值检测[%d/3]", g_af.peak_counter);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ g_af.reduce_counter = 0;
|
|
|
+ LOG_I("[对焦] 平稳=");
|
|
|
+ }
|
|
|
|
|
|
- LOG_I("[对焦] 最佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
|
|
|
+ g_af.last_sharpness = current_sharpness;
|
|
|
|
|
|
+ if (need_reverse) {
|
|
|
+ g_af.dir = !g_af.dir;
|
|
|
+ LOG_I("[对焦] 反转方向");
|
|
|
+ }
|
|
|
|
|
|
- if(g_peak_counter>=3&¤t_sharpness>g_best_sharpness*0.95){
|
|
|
- focus_done = true;
|
|
|
- }else{
|
|
|
- focus_done = false;
|
|
|
- g_best_sharpness -= 2.0f; //降低阈值,防止找不到
|
|
|
- }
|
|
|
+ /* 平坦区域超时:强制反转并增大步长 */
|
|
|
+ if (g_af.diff_counter >= 30) {
|
|
|
+ g_af.dir = !g_af.dir;
|
|
|
+ g_af.step_size += 10;
|
|
|
+ g_af.diff_counter = 0;
|
|
|
+ LOG_I("[对焦] 平坦超时,增大步长=%d", g_af.step_size);
|
|
|
+ }
|
|
|
|
|
|
- /* 终止条件检测 */
|
|
|
- if (counter_sharpness_diff>=100||maxIterations <= 0 || focus_done==true) {
|
|
|
- counter_sharpness_reduce = 0;
|
|
|
- maxIterations = 100;
|
|
|
- LOG_I("[对焦] 完成搜索,最佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
|
|
|
- if (g_peak_counter >= 3) {
|
|
|
- LOG_I("[对焦] 连续三次波动确认峰值");
|
|
|
- }
|
|
|
- focus_done = false;
|
|
|
- LOG_I("[对焦] 已到达最佳对焦位置");
|
|
|
- if(maxIterations==0)
|
|
|
- {
|
|
|
- stepSize = 20;
|
|
|
- dir = !dir;
|
|
|
- current_pos = 0;
|
|
|
- }else{
|
|
|
- counter_sharpness_diff = 0;
|
|
|
- char *c0 = makeJson_Warn("auto_focus","auto_focus");
|
|
|
- DTU_Write("%s",c0);
|
|
|
- rt_free(c0);
|
|
|
- device_status.autotakepic = 0; // 退出自动对焦模式
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- slide_para.ystep = stepSize;
|
|
|
- slide_para.ydir = dir;
|
|
|
- slide_para.ydis = stepSize;
|
|
|
- slide_para.en_slide = 6; // 触发移动
|
|
|
- while (slide_para.en_slide != 0) {
|
|
|
- rt_thread_delay(50); // 等待移动完成
|
|
|
- }
|
|
|
+ LOG_I("[对焦] 最佳:位置%d 清晰度%.2f", g_af.best_pos, g_af.best_sharpness);
|
|
|
+
|
|
|
+ /* 终止条件 */
|
|
|
+ bool done = false;
|
|
|
+ if (g_af.peak_counter >= 3 && current_sharpness > g_af.best_sharpness * 0.95f) {
|
|
|
+ done = true;
|
|
|
+ LOG_I("[对焦] 峰值确认完成");
|
|
|
+ g_af.max_iterations = 100;
|
|
|
+ g_af.reduce_counter = 0;
|
|
|
+ g_af.diff_counter = 0;
|
|
|
+ }
|
|
|
+ if (g_af.max_iterations <= 0) {
|
|
|
+ done = true;
|
|
|
+ g_af.step_size = 20;
|
|
|
+ g_af.dir = !g_af.dir;
|
|
|
+ g_af.current_pos = 0;
|
|
|
+ LOG_I("[对焦] 迭代次数耗尽");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (done) {
|
|
|
+ auto_focus_done();
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ /* 移动电机 */
|
|
|
+ auto_focus_move();
|
|
|
}
|
|
|
|
|
|
+/* ========== Y轴校准(Calibration)控制块 ========== */
|
|
|
+typedef struct {
|
|
|
+ float best_sharpness;
|
|
|
+ float last_sharpness;
|
|
|
+ int diff_counter;
|
|
|
+ bool initial_move;
|
|
|
+ int dir;
|
|
|
+ int ystep;
|
|
|
+ volatile bool sharpness_updated;
|
|
|
+ float new_sharpness;
|
|
|
+} calibrate_t;
|
|
|
+
|
|
|
+static calibrate_t g_cal;
|
|
|
+
|
|
|
+
|
|
|
+/* 轻量级信号处理程序:仅存储清晰度值,不阻塞 */
|
|
|
void thread2_signal_handler(int sig)
|
|
|
{
|
|
|
rt_timer_stop(timer_takephoto);
|
|
|
- maxIterations--;
|
|
|
- LOG_I("[Y] 清晰度值更新:%.2f", device_status.focus_value);
|
|
|
- slide_para.pulse_period = mapSpeed(50); // 更新电机速度参数
|
|
|
- if(device_status.calibrate_slide==20&& maxIterations >= 0){
|
|
|
- float current_sharpness = device_status.focus_value;
|
|
|
- /* 更新全局最佳状态 */
|
|
|
- if (current_sharpness > g_best_sharpness) {
|
|
|
- g_best_sharpness = current_sharpness;
|
|
|
- LOG_I("[Y] 发现更佳位置(清晰度:%.2f)",g_best_sharpness);
|
|
|
- }
|
|
|
- /* 初始方向判断(首步移动后) */
|
|
|
- if (g_initial_move) {
|
|
|
- if (current_sharpness > g_last_sharpness) {
|
|
|
- LOG_I("[对焦] 初始方向正确,保持方向:%d", dir);
|
|
|
- }
|
|
|
- g_initial_move = false;
|
|
|
- }else{
|
|
|
- double diff_sharpness = fabs(current_sharpness-g_last_sharpness);
|
|
|
- if(diff_sharpness<1.0)
|
|
|
- {
|
|
|
- counter_sharpness_diff++;
|
|
|
- }
|
|
|
+ g_cal.sharpness_updated = true;
|
|
|
+ g_cal.new_sharpness = device_status.focus_value;
|
|
|
+}
|
|
|
|
|
|
- LOG_I("[Y] 清晰度变化累计%d次小于1.0",counter_sharpness_diff);
|
|
|
- if(counter_sharpness_diff>1&&diff_sharpness>100.0){
|
|
|
- //停止,保存当前位置
|
|
|
- device_status.calibrate_slide = 0;
|
|
|
- device_status.y_init_dis = slide_para.ystep;
|
|
|
- LOG_I("设置Y轴初始位置:%d",slide_para.ystep);
|
|
|
- ef_set_env_blob("y_init_dis", &device_status.y_init_dis, sizeof(device_status.y_init_dis));
|
|
|
- return;
|
|
|
- }
|
|
|
- /* 记录本次清晰度值 */
|
|
|
- g_last_sharpness = current_sharpness;
|
|
|
- }
|
|
|
+/* 初始化校准状态 */
|
|
|
+static void calibrate_init(void)
|
|
|
+{
|
|
|
+ memset(&g_cal, 0, sizeof(g_cal));
|
|
|
+ g_cal.best_sharpness = -FLT_MAX;
|
|
|
+ g_cal.last_sharpness = 0.0f;
|
|
|
+ g_cal.initial_move = true;
|
|
|
+ g_cal.dir = 1;
|
|
|
+ g_cal.ystep = 0;
|
|
|
+}
|
|
|
|
|
|
- /* 终止条件检测 */
|
|
|
- if (maxIterations <= 0) {
|
|
|
- device_status.calibrate_slide = 0;
|
|
|
- return;
|
|
|
- }
|
|
|
- slide_para.ydir = dir;
|
|
|
- slide_para.ydis = 80;
|
|
|
- slide_para.ystep += 80;
|
|
|
- slide_para.en_slide = 6; // 触发移动
|
|
|
- while (slide_para.en_slide != 0) {
|
|
|
- rt_thread_delay(50); // 等待移动完成
|
|
|
- }
|
|
|
+/* 移动电机一步 */
|
|
|
+static void calibrate_move(void)
|
|
|
+{
|
|
|
+ g_cal.ystep += 80;
|
|
|
+ slide_para.pulse_period = mapSpeed(50);
|
|
|
+ slide_para.ydir = g_cal.dir;
|
|
|
+ slide_para.ydis = 80;
|
|
|
+ slide_para.ystep = g_cal.ystep;
|
|
|
+ slide_para.en_slide = 6;
|
|
|
+
|
|
|
+ while (slide_para.en_slide != 0) {
|
|
|
+ rt_thread_delay(500);
|
|
|
}
|
|
|
|
|
|
+ LOG_I("[Y] 电机到位 位置:%d", g_cal.ystep);
|
|
|
+ rt_timer_start(timer_takephoto);
|
|
|
}
|
|
|
|
|
|
+/* 处理一次校准清晰度值 */
|
|
|
+static void calibrate_process(void)
|
|
|
+{
|
|
|
+ float current_sharpness = g_cal.new_sharpness;
|
|
|
+ g_cal.sharpness_updated = false;
|
|
|
+
|
|
|
+ LOG_I("[Y] 清晰度值:%.2f 位置:%d", current_sharpness, g_cal.ystep);
|
|
|
+
|
|
|
+ /* 更新最佳位置 */
|
|
|
+ if (current_sharpness > g_cal.best_sharpness) {
|
|
|
+ g_cal.best_sharpness = current_sharpness;
|
|
|
+ LOG_I("[Y] 更佳位置(清晰度:%.2f) 位置:%d", g_cal.best_sharpness, g_cal.ystep);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 初始方向判断 */
|
|
|
+ if (g_cal.initial_move) {
|
|
|
+ g_cal.initial_move = false;
|
|
|
+ if (current_sharpness > g_cal.last_sharpness) {
|
|
|
+ LOG_I("[Y] 初始方向正确");
|
|
|
+ }
|
|
|
+ g_cal.last_sharpness = current_sharpness;
|
|
|
+ calibrate_move();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 计算变化 */
|
|
|
+ double diff_sharpness = fabs(current_sharpness - g_cal.last_sharpness);
|
|
|
+ if (diff_sharpness < 1.0) {
|
|
|
+ g_cal.diff_counter++;
|
|
|
+ }
|
|
|
+
|
|
|
+ LOG_I("[Y] 平坦累计:%d 变化量:%.2f", g_cal.diff_counter, diff_sharpness);
|
|
|
+
|
|
|
+ /* 从平坦区域到突变 -> 特征点,保存当前位置 */
|
|
|
+ if (g_cal.diff_counter > 1 && diff_sharpness > 100.0) {
|
|
|
+ device_status.calibrate_slide = 0;
|
|
|
+ device_status.y_init_dis = g_cal.ystep;
|
|
|
+ LOG_I("设置Y轴初始位置:%d", g_cal.ystep);
|
|
|
+ ef_set_env_blob("y_init_dis", &device_status.y_init_dis, sizeof(device_status.y_init_dis));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ g_cal.last_sharpness = current_sharpness;
|
|
|
+
|
|
|
+ /* 继续移动 */
|
|
|
+ calibrate_move();
|
|
|
+}
|
|
|
|
|
|
//入口函数-电机控制及
|
|
|
static void Ctr_Mortor_entry(void* parameter)
|
|
|
@@ -444,11 +508,42 @@ static void Ctr_Mortor_entry(void* parameter)
|
|
|
if(device_status.autotakepic==2)
|
|
|
{
|
|
|
t_takephoto++;
|
|
|
- if(t_takephoto==36000)
|
|
|
+ if(t_takephoto==360000)
|
|
|
{
|
|
|
t_takephoto = 0;
|
|
|
device_status.autotakepic = 0;
|
|
|
}
|
|
|
+ /* 自动对焦:等待 focus 回复超时则补发指令(最多重试3次),
|
|
|
+ * 防止串口乱码导致 focus 帧丢失而对焦中断 */
|
|
|
+ if (g_af.active &&
|
|
|
+ (rt_tick_get() - g_af.wait_start_tick) >
|
|
|
+ rt_tick_from_millisecond(AF_FOCUS_TIMEOUT_MS))
|
|
|
+ {
|
|
|
+ if (g_af.retry_cnt < AF_FOCUS_RETRY_MAX) {
|
|
|
+ g_af.retry_cnt++;
|
|
|
+ g_af.wait_start_tick = rt_tick_get(); /* 重新计时,等待下一个5s */
|
|
|
+ LOG_W("[对焦] 等待focus超时,补发指令(%d/%d)",
|
|
|
+ g_af.retry_cnt, AF_FOCUS_RETRY_MAX);
|
|
|
+ char *p1 = makeJson_Warn("movy", "4");
|
|
|
+ DTU_Write("%s", p1);
|
|
|
+ rt_free(p1);
|
|
|
+ DTU_Write("{\"cmd\": \"takephoto\" }");
|
|
|
+ } else {
|
|
|
+ LOG_E("[对焦] focus超时,重试%d次无回复,中止对焦", AF_FOCUS_RETRY_MAX);
|
|
|
+ g_af.active = false;
|
|
|
+ device_status.autotakepic = 0;
|
|
|
+ ctr_led(OFF);
|
|
|
+ slidelock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 自动对焦:有新清晰度值时处理 */
|
|
|
+ if (g_af.sharpness_updated) {
|
|
|
+ auto_focus_process();
|
|
|
+ }
|
|
|
+ /* Y轴校准:有新清晰度值时处理 */
|
|
|
+ if (g_cal.sharpness_updated) {
|
|
|
+ calibrate_process();
|
|
|
+ }
|
|
|
}else {
|
|
|
t_takephoto = 0;
|
|
|
}
|
|
|
@@ -507,7 +602,6 @@ static void Ctr_Mortor_entry(void* parameter)
|
|
|
DTU_Write("%s",photo);
|
|
|
rt_free(photo);
|
|
|
device_status.autotakepic = 4;
|
|
|
- rt_thread_delay(1000);
|
|
|
rt_timer_start(timer_takephoto);
|
|
|
}
|
|
|
}
|
|
|
@@ -535,26 +629,19 @@ static void Ctr_Mortor_entry(void* parameter)
|
|
|
DTU_Write("%s",photo);
|
|
|
rt_free(photo);
|
|
|
device_status.autotakepic = 4;
|
|
|
- rt_thread_delay(1000);
|
|
|
rt_timer_start(timer_takephoto);
|
|
|
}
|
|
|
if(device_status.autotakepic == 4)
|
|
|
{
|
|
|
- device_status.autotakepic = 2;
|
|
|
- g_best_sharpness = 0.0; // 全局最佳清晰度
|
|
|
- g_best_pos = 0; // 全局最佳位置
|
|
|
- g_last_sharpness = 0.0; // 上一次移动后的清晰度
|
|
|
- g_initial_move = true; // 初始方向判断标志
|
|
|
- maxIterations = 100;
|
|
|
- counter_sharpness_diff = 0;
|
|
|
- dir = 1;
|
|
|
- stepSize = 20; // 初始步长(单位:步进电机脉冲数)
|
|
|
- current_pos = 0; // 根据实际类型修改(int/float等)
|
|
|
+ /* 根据当前模式只初始化对应的状态机:
|
|
|
+ * 校准模式(custom calibrate_slide!=0)下不应激活自动对焦的重试检测 */
|
|
|
+ if (device_status.calibrate_slide == 0) {
|
|
|
+ auto_focus_init();
|
|
|
+ } else {
|
|
|
+ calibrate_init();
|
|
|
+ }
|
|
|
slide_para.ystep = 0;
|
|
|
- g_peak_counter = 0;
|
|
|
- g_last_rising = false;
|
|
|
- focus_done = false;
|
|
|
- //启动超时检测定时器
|
|
|
+ device_status.autotakepic = 2;
|
|
|
}
|
|
|
if(device_status.fsl_sw==1)
|
|
|
{
|
|
|
@@ -589,36 +676,6 @@ static void Ctr_Mortor_entry(void* parameter)
|
|
|
/*屏幕写数据*/
|
|
|
int Hmi_Fresh(void)
|
|
|
{
|
|
|
- #if 0
|
|
|
- //初始化串口4
|
|
|
- HMI_uart4_init();
|
|
|
- rt_err_t ret = RT_EOK;
|
|
|
- /* 初始化消息队列 */
|
|
|
- rt_mq_init(&rx_mq, "rx_mq",
|
|
|
- msg_pool, /* 存放消息的缓冲区 */
|
|
|
- sizeof(struct rx_msg), /* 一条消息的最大长度 */
|
|
|
- sizeof(msg_pool), /* 存放消息的缓冲区大小 */
|
|
|
- RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
|
|
- /* 设置接收回调函数 */
|
|
|
- rt_device_set_rx_indicate(serial, uart_input);
|
|
|
- /* 创建线程*/
|
|
|
- hmi1 = rt_thread_create("Hmi_Fresh_thread",
|
|
|
- Hmi_thread_entry,
|
|
|
- RT_NULL,
|
|
|
- HMI_THREAD_STACK_SIZE,
|
|
|
- HMI_THREAD_PRIORITY,
|
|
|
- HMI_THREAD_TIMESLICE);
|
|
|
- /* 如果获得线程控制块,启动这个线程 */
|
|
|
- if (hmi1 != RT_NULL)
|
|
|
- {
|
|
|
- rt_thread_startup(hmi1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LOG_E("rt_thread_startup hmi1 failed!");
|
|
|
- }
|
|
|
- #endif
|
|
|
-
|
|
|
/*部分控制的线程*/
|
|
|
ctr_motor = rt_thread_create("Ctr motor",
|
|
|
Ctr_Mortor_entry,
|
|
|
@@ -646,8 +703,11 @@ void Check_ParamConfig(void)
|
|
|
static struct tm tm;
|
|
|
gmtime_r(&now, &tm);
|
|
|
|
|
|
- if(easyflash_init()==EF_NO_ERR) //初始化成功
|
|
|
+ /*初始化FlashDB(含fal),所有参数统一存放在KVDB,替代原EasyFlash*/
|
|
|
+ uint32_t t_start = rt_tick_get();
|
|
|
+ if(app_flashdb_init()==0) //初始化成功
|
|
|
{
|
|
|
+ LOG_I("app_flashdb_init cost %dms", rt_tick_from_millisecond(rt_tick_get() - t_start));
|
|
|
ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
|
|
|
ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
|
|
|
ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
|
|
|
@@ -656,7 +716,7 @@ void Check_ParamConfig(void)
|
|
|
LOG_I("REBOOT_TIME:%d-%d-%d",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
|
|
|
}
|
|
|
else {
|
|
|
- LOG_E("easyflash init ERRPR!!!");
|
|
|
+ LOG_E("app_flashdb init ERRPR!!!");
|
|
|
}
|
|
|
//保存默认配置
|
|
|
if(device_status.iSave!=FLASH_FLAG)
|
|
|
@@ -666,20 +726,8 @@ void Check_ParamConfig(void)
|
|
|
device_status.dtype = 7;
|
|
|
device_status.version_type = 7; //4.0
|
|
|
device_status.Power_Type = 0; //0-交流供电;1-直流供电
|
|
|
- device_status.clt_time = 10; //收集时间
|
|
|
- device_status.heattime = 10; //加热时间
|
|
|
- device_status.heatvalue=100; //加热温度
|
|
|
- device_status.thsp = 300; //默认熄屏时间5分钟
|
|
|
- device_status.sunBar = 9; //光控定时时长
|
|
|
- device_status.startBar = 20; //定时开始时间
|
|
|
- device_status.stopBar = 0; //定时结束时间
|
|
|
device_status.tph = 60; //高温保护阈值
|
|
|
device_status.tpl = 10; //低温保护阈值
|
|
|
- device_status.shake_ws = 1; //震动开关,默认开
|
|
|
- device_status.shake_sec = 1; //震动时间,s
|
|
|
- device_status.vol = 7; //音量
|
|
|
- device_status.timeSwitch = 0; //工作模式:光控
|
|
|
- device_status.passWord = 8888; //屏幕密码
|
|
|
device_status.dattim = 10; //数据上传间隔
|
|
|
device_status.ds = 1; //设备状态
|
|
|
device_status.update_flag = 0;
|
|
|
@@ -710,13 +758,6 @@ void Check_ParamConfig(void)
|
|
|
device_status.y_init_dis = 0;
|
|
|
ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
|
|
|
ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
|
|
|
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
|
|
|
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
|
|
|
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
|
|
|
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
|
|
|
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
|
|
|
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
|
|
|
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
|
|
|
ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
|
|
|
ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
|
|
|
ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
|
|
|
@@ -747,36 +788,14 @@ void Check_ParamConfig(void)
|
|
|
ef_set_env_blob("collt_min_sh3", &device_status.collt_min_sh3, sizeof(device_status.collt_min_sh3));
|
|
|
ef_set_env_blob("collt_min_eh3", &device_status.collt_min_eh3, sizeof(device_status.collt_min_eh3));
|
|
|
LOG_I("SOFTWARE VERSION:%s",device_status.driver);
|
|
|
- LOG_I("Default paramconf is:");
|
|
|
- LOG_I("stime:%d",device_status.iSave);
|
|
|
- LOG_I("stime:%d",device_status.clt_time);
|
|
|
- LOG_I("startBar:%d",device_status.startBar);
|
|
|
- LOG_I("stopBar:%d",device_status.stopBar);
|
|
|
- LOG_I("timeSwitch:%d",device_status.timeSwitch);
|
|
|
- LOG_I("sunBar:%d",device_status.sunBar);
|
|
|
- LOG_I("jtime:%d",device_status.heattime);
|
|
|
- LOG_I("jheat:%d",device_status.heatvalue);
|
|
|
- LOG_I("thsp:%d", device_status.thsp);
|
|
|
- LOG_I("passwd:%d",device_status.passWord);
|
|
|
flash_flag = RT_FALSE;
|
|
|
- }//从easyflash读取参数配置
|
|
|
+ }//从FlashDB(KVDB)读取参数配置
|
|
|
else if (device_status.iSave==FLASH_FLAG) {
|
|
|
ef_get_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype),NULL); //设备类型
|
|
|
ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
|
|
|
- ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
|
|
|
- ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
|
|
|
- ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
|
|
|
- ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
|
|
|
- ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
|
|
|
- ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
|
|
|
- ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
|
|
|
- ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
|
|
|
- ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
|
|
|
ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
|
|
|
ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
|
|
|
ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
|
|
|
- ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
|
|
|
- ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
|
|
|
ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
|
|
|
ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
|
|
|
ef_get_env_blob("lat",&device_status.lat,sizeof(device_status.lat),NULL);
|
|
|
@@ -784,11 +803,8 @@ void Check_ParamConfig(void)
|
|
|
ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
|
|
|
ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL); //环境温度
|
|
|
ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL); //环境湿度
|
|
|
- ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL); //时间
|
|
|
- ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL); //重置
|
|
|
ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
|
|
|
ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
|
|
|
- ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL); //平台地址
|
|
|
/*孢子仪*/
|
|
|
ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL); //培养时间
|
|
|
ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL); //采集开始1
|
|
|
@@ -820,25 +836,10 @@ void Check_ParamConfig(void)
|
|
|
device_status.version_type = 7;
|
|
|
if (device_status.version_type==7) {
|
|
|
rt_sprintf(device_status.driver, "%s",VERSION_BZY);
|
|
|
- //异常处理:20230331,修复第一段开始时间等于第二段结束时间的情况
|
|
|
- if(device_status.collecting_eh1==device_status.collecting_eh2&&device_status.collecting_sh2!=device_status.collecting_eh2)
|
|
|
- {
|
|
|
- device_status.collecting_eh2 = device_status.collecting_sh2 + 2;
|
|
|
- }
|
|
|
}
|
|
|
- app_flashdb_init();
|
|
|
LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
|
|
|
LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
|
|
|
LOG_I("开机次数:%d",device_status.rebootcnt);
|
|
|
- LOG_I("收集时间:%d",device_status.clt_time);
|
|
|
- LOG_I("定时开始时间:%d",device_status.startBar);
|
|
|
- LOG_I("定时结束时间:%d",device_status.stopBar);
|
|
|
- LOG_I("timeSwitch:%d",device_status.timeSwitch);
|
|
|
- LOG_I("光控定时时长:%d",device_status.sunBar);
|
|
|
- LOG_I("收集时间:%d",device_status.heattime);
|
|
|
- LOG_I("加热温度:%d",device_status.heatvalue);
|
|
|
- LOG_I("震动开关:%d",device_status.shake_ws);
|
|
|
- LOG_I("震动时间:%d",device_status.shake_sec);
|
|
|
LOG_I("高温保护:%d",device_status.tph);
|
|
|
LOG_I("低温保护:%d",device_status.tpl);
|
|
|
LOG_I("thsp:%d", device_status.thsp);
|
|
|
@@ -872,18 +873,19 @@ void Check_ParamConfig(void)
|
|
|
sht30_collect();
|
|
|
slide_Fresh();
|
|
|
ctr_photo(ON);
|
|
|
-#if SENSOR_EN==1
|
|
|
- mb_master_samlpe();
|
|
|
-#endif
|
|
|
uint16_t connect_num=0;
|
|
|
- //等待联网,
|
|
|
+ //等待联网,500ms轮询一次,net由dtu线程收到同步JSON后更新
|
|
|
while(atoi(device_status.net)==1)
|
|
|
{
|
|
|
- rt_thread_delay(10000);
|
|
|
+ rt_thread_delay(500);
|
|
|
connect_num++;
|
|
|
- LOG_I("联网中......%d",connect_num);
|
|
|
+ //每2S打印一次,避免刷屏
|
|
|
+ if(connect_num%4==0)
|
|
|
+ {
|
|
|
+ LOG_I("联网中......%d",connect_num/4);
|
|
|
+ }
|
|
|
//超时时间为100S
|
|
|
- if(connect_num==10)
|
|
|
+ if(connect_num>=200)
|
|
|
{
|
|
|
LOG_W("Time not set:%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
break;
|
|
|
@@ -905,8 +907,6 @@ void Check_ParamConfig(void)
|
|
|
void ResetParamDefault(void)
|
|
|
{
|
|
|
device_status.ds = 1; //设备状态开机
|
|
|
- device_status.thsp = 300;
|
|
|
- device_status.passWord = 8888;
|
|
|
device_status.dattim = 10;
|
|
|
device_status.collecting_sh1 = 11;
|
|
|
device_status.collecting_eh1 = 16;
|
|
|
@@ -947,53 +947,25 @@ void ResetParamDefault(void)
|
|
|
ef_set_env_blob("collt_min_eh3", &device_status.collt_min_eh3, sizeof(device_status.collt_min_eh3));
|
|
|
}
|
|
|
ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
|
|
|
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
|
|
|
- ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
|
|
|
- DTU_Write("reset.mp3");
|
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
|
void ResetParamDefault_DC(void)
|
|
|
{
|
|
|
//将温度数据设置为-15摄氏度,以便上传的数据中包含温控数据
|
|
|
rt_sprintf(device_status.tempture,"%d",-15);
|
|
|
- device_status.clt_time = 10; //收集时间
|
|
|
device_status.dattim = 10; //数据上传间隔
|
|
|
- #if LAMP_EN == 0
|
|
|
- device_status.startBar = 20; //定时开始时间
|
|
|
- device_status.stopBar = 0; //定时结束时间
|
|
|
- #endif
|
|
|
- device_status.heattime = 10; //加热时间
|
|
|
- device_status.shake_ws = 1; //针对开关
|
|
|
- device_status.shake_sec = 1; //震动时间1-100ms
|
|
|
-
|
|
|
device_status.tph = 70; //高温保护阈值
|
|
|
device_status.tpl = 10; //低温保护阈值
|
|
|
- device_status.timeSwitch = 0; //定时模式
|
|
|
- device_status.heatvalue=100;
|
|
|
device_status.ds = 1; //设备状态开机
|
|
|
device_status.thsp = 300;
|
|
|
- device_status.passWord = 8888;
|
|
|
- device_status.timeSwitch = 0;
|
|
|
device_status.Power_Type = 1;
|
|
|
- device_status.handle_bugger = 0;
|
|
|
ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
|
|
|
- ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
|
|
|
ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
|
|
|
ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
|
|
|
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
|
|
|
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
|
|
|
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
|
|
|
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
|
|
|
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
|
|
|
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
|
|
|
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
|
|
|
ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
|
|
|
ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
|
|
|
- ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
|
|
|
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
|
|
|
ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
|
|
|
ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
|
|
|
- DTU_Write("reset.mp3");
|
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
|
//固件备份
|
|
|
@@ -1063,33 +1035,7 @@ void app_partion_backup(void)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-void Debug_log_ON(void)
|
|
|
-{
|
|
|
- rt_console_set_device("uart4");
|
|
|
- finsh_set_device("uart4");
|
|
|
-}
|
|
|
-void Debug_log_OFF(void)
|
|
|
-{
|
|
|
- rt_console_set_device("uart1");
|
|
|
- finsh_set_device("uart1");
|
|
|
- rt_mq_init(&rx_mq, "rx_mq",
|
|
|
- msg_pool, /* 存放消息的缓冲区 */
|
|
|
- sizeof(struct rx_msg), /* 一条消息的最大长度 */
|
|
|
- sizeof(msg_pool), /* 存放消息的缓冲区大小 */
|
|
|
- RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
|
|
- rt_device_set_rx_indicate(serial, uart_input);
|
|
|
- hmi1 = rt_thread_create("Hmi_Fresh_thread",
|
|
|
- Hmi_thread_entry,
|
|
|
- RT_NULL,
|
|
|
- HMI_THREAD_STACK_SIZE,
|
|
|
- HMI_THREAD_PRIORITY,
|
|
|
- HMI_THREAD_TIMESLICE);
|
|
|
- if (hmi1 != RT_NULL)
|
|
|
- {
|
|
|
- rt_thread_startup(hmi1);
|
|
|
- }
|
|
|
|
|
|
-}
|
|
|
int delete_thread_ctr_motor()
|
|
|
{
|
|
|
if(ctr_motor!=RT_NULL)
|
|
|
@@ -1097,8 +1043,7 @@ void Debug_log_OFF(void)
|
|
|
rt_thread_delete(ctr_motor);
|
|
|
}
|
|
|
}
|
|
|
-MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
|
|
|
-MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
|
|
|
+
|
|
|
MSH_CMD_EXPORT(ResetParamDefault,ResetParamDefault);
|
|
|
//
|
|
|
//INIT_BOARD_EXPORT(HMI_uart4_init);
|