zhunk 3 месяцев назад
Родитель
Сommit
2094627677

+ 1 - 1
Application_cbd_apm32f1/.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-426458338030839847" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-475015324938722023" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>

+ 62 - 173
Application_cbd_apm32f1/applications/hmi.c

@@ -240,35 +240,6 @@ typedef struct {
 
 static auto_focus_t g_af;
 
-/* ========== 景深融合(Depth of Field Fusion)控制块 ========== */
-typedef struct {
-    rt_bool_t enabled;            /* 景深融合功能使能 */
-    int       best_pos;           /* 最佳对焦位置 */
-    int       move_count;         /* 当前移动次数 (0-5: 前后各3次) */
-    int       total_moves;        /* 总移动次数 (默认6次: 前后各3次) */
-    int       move_step;          /* 每次移动的步长(脉冲数) */
-    int       current_capture;    /* 当前拍照序号 */
-    int       total_captures;     /* 总拍照数 (对焦1次 + 前后各3次 = 7次) */
-    rt_bool_t is_last_capture;    /* 是否是最后一次拍照 */
-    rt_bool_t capture_done;       /* 当前拍照完成标志 */
-    volatile rt_bool_t in_progress; /* 融合流程进行中 */
-} depth_fusion_t;
-
-static depth_fusion_t g_fusion;
-
-/* 景深融合步骤名称 */
-static const char* fusion_step_name(int step) {
-    switch(step) {
-        case 0: return "focus_ok";           /* 对焦完成基准拍照 */
-        case 1: return "back_1";            /* 向后1 */
-        case 2: return "back_2";            /* 向后2 */
-        case 3: return "back_3";            /* 向后3 */
-        case 4: return "forward_1";         /* 向前1 */
-        case 5: return "forward_2";         /* 向前2 */
-        case 6: return "forward_3";         /* 向前3 */
-        default: return "unknown";
-    }
-}
 
 /* 轻量级信号处理程序:仅存储清晰度值,不阻塞 */
 void thread1_signal_handler(int sig)
@@ -311,151 +282,77 @@ static void auto_focus_move(void)
     rt_timer_start(timer_takephoto);
 }
 
-/* 初始化景深融合状态 */
-static void depth_fusion_init(int best_pos)
-{
-    memset(&g_fusion, 0, sizeof(g_fusion));
-    g_fusion.enabled = RT_TRUE;
-    g_fusion.best_pos = best_pos;
-    g_fusion.move_count = 0;
-    g_fusion.total_moves = 6;      /* 前后各移动3次 */
-    g_fusion.move_step = 30;       /* 每次移动30脉冲(可根据景深需求调整) */
-    g_fusion.current_capture = 0;
-    g_fusion.total_captures = 7;   /* 1次对焦 + 6次移动 = 7次 */
-    g_fusion.is_last_capture = RT_FALSE;
-    g_fusion.capture_done = RT_FALSE;
-    g_fusion.in_progress = RT_TRUE;
-
-    LOG_I("[景深融合] 初始化完成! 最佳位置:%d 步长:%d", best_pos, g_fusion.move_step);
-}
 
-/* 景深融合移动电机一步 */
-static void depth_fusion_move(void)
+/* 景深融合:步进10次后再回到最清晰位置 */
+static void depth_of_field_fusion(void)
 {
-    int offset;
-    int dir;
-
-    /* 计算偏移量: 先向负方向移动3次,再向正方向移动3次 */
-    if (g_fusion.move_count < 3) {
-        /* 向后(负方向)移动 */
-        dir = 0;
-        offset = -(g_fusion.move_count + 1) * g_fusion.move_step;
-    } else {
-        /* 向前(正方向)移动 */
-        dir = 1;
-        offset = (g_fusion.move_count - 2) * g_fusion.move_step;
-    }
-
-    /* 计算绝对位置: 最佳位置 + 偏移量 */
-    int target_pos = g_fusion.best_pos + offset;
-
-    LOG_I("[景深融合] 移动#%d/%d 方向:%s 目标位置:%d",
-           g_fusion.move_count + 1, g_fusion.total_moves,
-           dir ? "前" : "后", target_pos);
-
-    slide_para.pulse_period = mapSpeed(1);
-    slide_para.ystep = target_pos;
-    slide_para.ydir = dir;
-    slide_para.ydis = g_fusion.move_step;
-    slide_para.en_slide = 6;
-
-    while (slide_para.en_slide != 0) {
-        rt_thread_delay(100);
-    }
-
-    LOG_I("[景深融合] 电机到位,准备拍照");
-    rt_timer_start(timer_takephoto);
-}
-
-/* 景深融合拍照完成回调 - 由定时器或信号处理调用 */
-void depth_fusion_on_capture_ready(void)
-{
-    if (!g_fusion.in_progress || g_fusion.capture_done) {
-        return;
-    }
-
-    g_fusion.current_capture++;
-    g_fusion.capture_done = RT_TRUE;
-
-    /* 发送拍照指令,标记是否最后一次 */
-    char *cmd = makeJson_Warn("fusion_capture", fusion_step_name(g_fusion.current_capture));
-    if (cmd != RT_NULL) {
-        DTU_Write("%s", cmd);
-        rt_free(cmd);
-        LOG_I("[景深融合] 发送拍照指令[%d/%d]: %s",
-               g_fusion.current_capture, g_fusion.total_captures,
-               fusion_step_name(g_fusion.current_capture));
-    }
-}
-
-/* 景深融合拍照完成回调 - 内部使用 */
-static void depth_fusion_capture_done(void)
-{
-    depth_fusion_on_capture_ready();
-}
-
-/* 景深融合流程处理(在接收端通知保存完成后调用) */
-static void depth_fusion_process(void)
-{
-    g_fusion.capture_done = RT_FALSE;
-
-    if (g_fusion.current_capture == 0) {
-        /* 第一次: 对焦完成后的基准位置拍照 */
-        LOG_I("[景深融合] 执行对焦基准位置拍照");
-        depth_fusion_capture_done();
-        return;
+    int i;
+    int best_pos = g_af.best_pos;
+    int step_size = g_af.step_size;
+    
+    LOG_I("[景深融合] 开始: 最佳位置=%d", best_pos);
+    
+    /* 往 dir=1 方向步进 10 次 */
+    g_af.dir = 1;
+    for (i = 0; i < 10; i++) {
+        g_af.current_pos += step_size;
+        LOG_I("[景深融合] 正向步进[%d/10]: 位置=%d", i + 1, g_af.current_pos);
+        
+        slide_para.pulse_period = mapSpeed(1);
+        slide_para.ystep = step_size;
+        slide_para.ydir = g_af.dir;
+        slide_para.ydis = step_size;
+        slide_para.en_slide = 6;
+        
+        while (slide_para.en_slide != 0) {
+            rt_thread_delay(100);
+        }
+        rt_thread_delay(50);  // 短暂延迟确保稳定
     }
-
-    g_fusion.move_count++;
-
-    if (g_fusion.move_count > g_fusion.total_moves) {
-        /* 全部移动完成,执行融合 */
-        g_fusion.in_progress = RT_FALSE;
-        g_fusion.enabled = RT_FALSE;
-        LOG_I("[景深融合] 全部拍照完成,执行融合!");
-        char *cmd = makeJson_Warn("fusion_start", "do_fusion");
-        if (cmd != RT_NULL) {
-            DTU_Write("%s", cmd);
-            rt_free(cmd);
+    
+    LOG_I("[景深融合] 正向步进完成: 位置=%d", g_af.current_pos);
+    
+    /* 回到最清晰位置 */
+    if (g_af.current_pos > best_pos) {
+        g_af.dir = 0;  // 反向移动
+        int steps_back = (g_af.current_pos - best_pos) / step_size;
+        if ((g_af.current_pos - best_pos) % step_size != 0) {
+            steps_back++;  // 向上取整
+        }
+        for (i = 0; i < steps_back && g_af.current_pos > best_pos; i++) {
+            g_af.current_pos -= step_size;
+            LOG_I("[景深融合] 返回最佳位置[%d/%d]: 位置=%d", i + 1, steps_back, g_af.current_pos);
+            
+            slide_para.pulse_period = mapSpeed(1);
+            slide_para.ystep = step_size;
+            slide_para.ydir = g_af.dir;
+            slide_para.ydis = step_size;
+            slide_para.en_slide = 6;
+            
+            while (slide_para.en_slide != 0) {
+                rt_thread_delay(100);
+            }
+            rt_thread_delay(50);
         }
-        return;
     }
-
-    /* 继续移动到下一个位置,移动完成后自动拍照 */
-    depth_fusion_move();
-}
-
-/* 设置景深融合使能(由外部调用) */
-void depth_fusion_set_enabled(rt_bool_t enable)
-{
-    g_fusion.enabled = enable;
-    LOG_I("[景深融合] 功能%s", enable ? "使能" : "禁用");
-}
-
-/* 获取景深融合是否在进行中 */
-rt_bool_t depth_fusion_is_active(void)
-{
-    return g_fusion.in_progress;
+    
+    g_af.current_pos = best_pos;
+    LOG_I("[景深融合] 完成: 已回到最佳位置=%d", g_af.current_pos);
+    
+    /* 发送景深融合完成消息 */
+    char *c0 = makeJson_Warn("auto_focus","auto_focus");
+    DTU_Write("%s",c0);
+    rt_free(c0);
+    device_status.autotakepic = 0;
 }
 
-/* 完成对焦 - 触发景深融合流程 */
+/* 完成对焦 */
 static void auto_focus_done(void)
 {
     LOG_I("[对焦] 完成! 最佳位置:%d 清晰度:%.2f", g_af.best_pos, g_af.best_sharpness);
-
-    if (g_fusion.enabled) {
-        /* 启动景深融合流程 */
-        LOG_I("[景深融合] 对焦完成,启动景深融合流程");
-        depth_fusion_init(g_af.best_pos);
-        depth_fusion_process();  /* 执行第一次拍照 */
-    } else {
-        /* 原有逻辑: 发送对焦完成消息 */
-        char *c0 = makeJson_Warn("auto_focus","auto_focus");
-        DTU_Write("%s",c0);
-        rt_free(c0);
-    }
-
-    device_status.autotakepic = 0;
+    
+    /* 执行景深融合 */
+    depth_of_field_fusion();
 }
 
 /* 处理一次清晰度值,执行对焦算法 */
@@ -770,15 +667,7 @@ static void Ctr_Mortor_entry(void* parameter)
             calibrate_init();
             slide_para.ystep = 0;
         }
-        /* 景深融合: 拍照保存完成后继续下一步 */
-        if(device_status.autotakepic == 5)
-        {
-            if (depth_fusion_is_active()) {
-                LOG_I("[景深融合] 收到保存完成,继续下一步");
-                depth_fusion_process();
-            }
-            device_status.autotakepic = 0;
-        }
+
         if(device_status.fsl_sw==1)
         {
             ctr_Petroleum_jelly(10);

+ 0 - 6
Application_cbd_apm32f1/applications/selfcheck.c

@@ -38,12 +38,6 @@ static int calculate_average(int arr[], int n) {
 
 static void t_takephoto_callback(void *parameter)
 {
-    /* 景深融合模式下,触发拍照指令 */
-    if (depth_fusion_is_active()) {
-        depth_fusion_on_capture_ready();
-        return;
-    }
-
     device_status.autotakepic = 0;
     LOG_E("t_takephoto_callback");
     //关闭补光灯

+ 2 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,5 @@
+# 2026-07-27 更新说明
+	1、到达清晰度位置后往胶带后方再移动10个步进后返回最清晰位置;
 # 2026-07-15 更新说明
 	#define VERSION_BZY         "3.10.4"                //孢子仪V1.3
 	1、增加对bKp分区的读写,用于升级过程的异常处理,app启动失败可以恢复升级前的版本;