zhunk 1 год назад
Родитель
Сommit
1dca10d873

+ 21 - 77
Application_cbd_apm32f1/applications/control.c

@@ -1592,7 +1592,6 @@ void HardWare_Check(uint8_t boot)
 
 }
 
-
 void WorkCheck(void)
 {
     static rt_uint32_t light_timeout = 3600;
@@ -1604,86 +1603,38 @@ void WorkCheck(void)
         if(device_status.timeSwitch == 1) // 时控模式
         {
             LOG_I("***********时控*****************");
-            if(device_status.startBar == device_status.stopBar &&
-               device_status.startBar == 0)
+            if(device_status.startBar == device_status.stopBar)
             {
-                // 24小时模式处理
-                #if LAMP_EN == 1
-                device_status.lamp_status = (device_status.sun_status == 0) ? 1 : 0;
-                device_status.lamp1_status = 0;
-                device_status.lamp2_status = 0;
-                #endif
+                // 开始结束时间相同则24小时模式
                 device_status.work_status = 1;
-                rt_thread_delay(1000);
+                rt_thread_delay(10000);
                 continue;
             }
 
             time_t now;
             time(&now);
             struct tm now_tm = *localtime(&now);
-            struct tm start_tm = *localtime(&now);
-            struct tm end_tm = *localtime(&now);
-
-            // 设置开始时间
-            now_tm.tm_hour = now_tm.tm_hour-8;
-            time_t now_time = mktime(&now_tm);
-
-            // 设置开始时间
-            start_tm.tm_hour = device_status.startBar-8;
-            start_tm.tm_min = 0;
-            start_tm.tm_sec = 0;
-            time_t start_time = mktime(&start_tm);
-
-            // 设置结束时间(自动处理跨天)
-            end_tm.tm_hour = device_status.stopBar-8;
-            end_tm.tm_min = 0;
-            end_tm.tm_sec = 0;
-            if(device_status.startBar >= device_status.stopBar) {
-                end_tm.tm_mday += 1; // 结束时间+1天
-            }
-            time_t end_time = mktime(&end_tm);
+            rt_uint32_t curr_sec = now_tm.tm_hour*3600 + now_tm.tm_min*60 + now_tm.tm_sec;
+            rt_uint32_t start_sec = device_status.startBar * 3600;
+            rt_uint32_t end_sec = device_status.stopBar * 3600;
 
-            // 工作时间判断
-            if(now_time >= start_time && now_time < end_time)
+            // 修复跨天判断逻辑
+            if (start_sec < end_sec)
             {
-                device_status.work_status = 1;
-                LOG_I("时控工作模式:现在:%d- 开始:%d-结束:%d",now_time,start_time,end_time);
-                rt_thread_delay(10000);
-                #if LAMP_EN == 1
-                // 统一灯控制逻辑
-                int hours = now_tm.tm_hour;
-                if (hours >= 20 && hours < 21) {
-                    device_status.lamp_status = 1;
-                    device_status.lamp1_status = 0;
-                    device_status.lamp2_status = 0;
-                } else if (hours >= 21 && hours < 22) {
-                    device_status.lamp_status = 0;
-                    device_status.lamp1_status = 1;
-                    device_status.lamp2_status = 0;
-                } else if (hours >= 22 && hours < 23) {
-                    device_status.lamp_status = 0;
-                    device_status.lamp1_status = 0;
-                    device_status.lamp2_status = 1;
-                } else {
-                    // 非20-23点默认状态
-                    device_status.lamp_status = 1;
-                    device_status.lamp1_status = 0;
-                    device_status.lamp2_status = 0;
-                }
-                #endif
+                // 不跨天模式
+                device_status.work_status = (curr_sec >= start_sec && curr_sec < end_sec) ? 1 : 0;
             }
             else
             {
-                device_status.work_status = 0;
-                LOG_I("时控待机模式:现在:%d- 开始:%d-结束:%d",now_time,start_time,end_time);
-                rt_thread_delay(10000);
-                #if LAMP_EN == 1
-                // 非工作时间关灯
-                device_status.lamp_status = 0;
-                device_status.lamp1_status = 0;
-                device_status.lamp2_status = 0;
-                #endif
+                // 跨天模式
+                device_status.work_status = (curr_sec >= start_sec || curr_sec < end_sec) ? 1 : 0;
             }
+
+            LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
+                  device_status.work_status ? "工作" : "待机",
+                  now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
+                  device_status.startBar, device_status.stopBar);
+            rt_thread_delay(10000);
         }
         else // 光控模式
         {
@@ -1692,12 +1643,8 @@ void WorkCheck(void)
             {
                 device_status.light_over_tim--;
                 light_timeout = 3600;  // 重置超时计数器
-                #if LAMP_EN == 1
-                Led_Check(device_status.sunBar);
-                #else
                 device_status.work_status = 1;
                 LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
-                #endif
             }
             else
             {
@@ -1709,13 +1656,9 @@ void WorkCheck(void)
                 device_status.work_status = 0;
 
                 //没有在测试并且没有在自检
-                if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
+                if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
                 {
                     ctr_lamp(OFF,1);
-                    #if LAMP_EN == 1
-                    ctr_lamp(OFF,2);
-                    ctr_lamp(OFF,3);
-                    #endif
                 }
 
                 // 连续1小时白天后重置
@@ -1734,11 +1677,12 @@ void WorkCheck(void)
         }
         rt_thread_delay(1000);
     }
-
     // 异常状态处理
     device_status.work_status = 0;
     rt_thread_delay(1000);
 }
+
+
 #if 0
 //工作状态检测
 void WorkCheck(void)

+ 2 - 2
Application_cbd_apm32f1/applications/control.h

@@ -18,7 +18,7 @@
 
 
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
-#define PCB_V1           1             //1-旧PCB,0-新PCB(模块化)
+#define PCB_V1           0             //1-旧PCB,0-新PCB(模块化)
 #define MATCH_DEVICE     0             //比赛设备
 #define SENSOR_EN        1             //温湿度:0关闭,1打开
 
@@ -33,7 +33,7 @@
     #define VERSION_HK_2000W    "1.3led.40(2000W)"       //水稻
 #else
     #define VERSION_HK          "2.5.41(HK)"            //4.0海康-1200W
-    #define VERSION_HK_2000W    "2.17.4(2000W)"         //4.0水稻
+    #define VERSION_HK_2000W    "2.18.4(2000W)"         //4.0水稻
 #endif
 
 #define VERSION_ZP          "1.45.1(ZP)"            //1.0转盘

+ 6 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,9 @@
+
+	光控损坏的处理
+# 2025-06-03 更新说明
+#define VERSION_HK_2000W    "2.18.4(2000W)"         //4.0水稻
+1. 修复时控逻辑BUG,设置跨天工作到0点会结束工作问题;
+
 # 2025-05-30 更新说明
 #define VERSION_HK_2000W    "2.17.4(2000W)"         //4.0水稻
 1. 增加调试上报功能