zhunk 1 месяц назад
Родитель
Сommit
efcd7e5cc9

+ 139 - 94
Application_CBD/applications/control.c

@@ -987,6 +987,84 @@ uint8_t ctr_lamp(uint8_t status_lamp, uint8_t lamp_num)
     return device_status.lamp_status;
 }
 
+#if LAMP_EN == 1
+/* ==================== 三灯管轮换(李新定制) ====================
+ * 工作开始后 3 只灯管依次循环点亮,每只连续工作 LAMP_ROTATE_SEC(默认1小时),
+ * 顺序:灯管1 -> 灯管2 -> 灯管3 -> 灯管1 ... 循环,与屏幕/串口2配置的工作时长无关。
+ * 用 tick 计时,调用频率不影响轮换周期。 */
+static rt_tick_t s_lamp_cycle_tick  = 0;    //轮换起始 tick,0-未启动
+static uint8_t   s_lamp_cycle_active = 0;   //当前点亮的灯管号(1~3),0-全灭
+
+/* 工作开始:从当前时刻重新开始轮换 */
+void Lamp_Cycle_Start(void)
+{
+    s_lamp_cycle_tick   = rt_tick_get();
+    s_lamp_cycle_active = 0;
+}
+
+/* 关闭全部灯管并结束轮换 */
+void Lamp_Cycle_Off(void)
+{
+    /* 已经全灭则直接返回,避免每秒重复操作镇流器/刷屏 */
+    if(s_lamp_cycle_tick == 0 && s_lamp_cycle_active == 0 &&
+       device_status.lamp_status  == OFF &&
+       device_status.lamp1_status == OFF &&
+       device_status.lamp2_status == OFF)
+    {
+        return;
+    }
+
+    s_lamp_cycle_tick   = 0;
+    s_lamp_cycle_active = 0;
+    ctr_lamp(OFF,1);
+    ctr_lamp(OFF,2);
+    ctr_lamp(OFF,3);
+}
+
+/* 轮换刷新:需要在工作态每秒调用一次 */
+void Lamp_Cycle_Update(void)
+{
+    uint8_t  act;
+    uint32_t elapsed;
+    rt_tick_t now = rt_tick_get();
+
+    /* 手动测试/出厂自检期间不干预灯管状态,避免与测试指令互相抢占 */
+    if(device_status.test_flag != 0 || device_status.selfcheck_ws != 0)
+    {
+        return;
+    }
+
+    if(s_lamp_cycle_tick == 0)
+    {
+        s_lamp_cycle_tick = now;
+    }
+
+    elapsed = (uint32_t)((now - s_lamp_cycle_tick) / RT_TICK_PER_SECOND);
+    /* 每 LAMP_ROTATE_SEC 换一只,1->2->3 循环 */
+    act = (uint8_t)((elapsed / LAMP_ROTATE_SEC) % 3) + 1;
+
+    if(act == s_lamp_cycle_active)
+    {
+        /* 未到切换点:确认三路状态仍与轮换结果一致(测试/自检指令可能改动过),
+         * 一致则直接返回,避免每秒重复操作镇流器 */
+        if((act == 1 && device_status.lamp_status  == ON  && device_status.lamp1_status == OFF && device_status.lamp2_status == OFF) ||
+           (act == 2 && device_status.lamp_status  == OFF && device_status.lamp1_status == ON  && device_status.lamp2_status == OFF) ||
+           (act == 3 && device_status.lamp_status  == OFF && device_status.lamp1_status == OFF && device_status.lamp2_status == ON))
+        {
+            return;
+        }
+    }
+
+    /* 先全灭再点亮,避免多只镇流器同时冲击电源 */
+    ctr_lamp(OFF,1);
+    ctr_lamp(OFF,2);
+    ctr_lamp(OFF,3);
+    ctr_lamp(ON,act);
+    s_lamp_cycle_active = act;
+    LOG_I("三灯管轮换:光源%d 已工作%lu秒", act, elapsed);
+}
+#endif
+
 //震动电机
 uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec)
 {
@@ -1223,8 +1301,12 @@ void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_ou
         time_out --;
     }
     rt_pin_write(Motor_EN, OFF);
+    #if LAMP_EN == 0
     if(device_status.autotakepic==0)
     ctr_lamp(OFF, 1);
+    #endif
+    /* LAMP_EN==1:灯管由 Lamp_Cycle 轮换管理,电机动作结束后不再并入关灯动作,
+     * 避免每轮电机动作都把工作中灯管熄灭再重新起弧 */
     beep_set(0, 0);      //200kzh - 50%
 }
 /*************************************************
@@ -1895,8 +1977,12 @@ void HardWare_Init(uint8_t boot)
         ctr_cangmen_down(OFF);
     }
     //关闭镇流器
+    #if LAMP_EN == 1
+    Lamp_Cycle_Off();       //上电/初始化:关闭3只灯管并复位轮换
+    #else
     if(device_status.autotakepic==0)
     ctr_lamp(OFF,1);
+    #endif
 
     //关闭震动电机
     ctr_shake(OFF,0);
@@ -1963,7 +2049,11 @@ void SunTest(void)
     if(Read_Light_Voltage()>500)
     {
         device_status.sun_status = 1;
+        #if LAMP_EN == 1
+        Lamp_Cycle_Off();       //天亮:关闭3只灯管并复位轮换
+        #else
         ctr_lamp(OFF,1);
+        #endif
     }
     HMI_WRITE("sysTest.switchSun.val=%d",0);
     device_status.sun_test = 0;
@@ -2006,10 +2096,10 @@ void ResetInit(void)
            //2.打开相机供电
            ctr_photo(ON);
            //3.关闭镇流器
-           ctr_lamp(OFF,1);
            #if LAMP_EN == 1
-           ctr_lamp(OFF,2);
-           ctr_lamp(OFF,3);
+           Lamp_Cycle_Off();    //关闭3只灯管并复位轮换计时
+           #else
+           ctr_lamp(OFF,1);
            #endif
            //4.关闭震动电机
            ctr_shake(OFF, 0);
@@ -2110,83 +2200,7 @@ void ResetInit(void)
         }
     }
 }
-/*三色光源*/
-void Led_Check(uint8_t tp)
-{
-    if(tp==3)
-    {
-        if(device_status.light_over_tim>2*3600)
-        {
-            device_status.work_status = 1;
-            device_status.lamp_status = 1;
-            device_status.lamp1_status = 0;
-            device_status.lamp2_status = 0;
-            LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
-        }
-        else if (device_status.light_over_tim>3600&&device_status.light_over_tim<7200) {
-            device_status.work_status = 1;
-            device_status.lamp_status = 0;
-            device_status.lamp1_status = 1;
-            device_status.lamp2_status = 0;
-            LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
-        }
-        else if (device_status.light_over_tim<1*3600) {
-            device_status.work_status = 1;
-            device_status.lamp_status = 0;
-            device_status.lamp1_status = 0;
-            device_status.lamp2_status = 1;
-            LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
-        }
-    }
-    else if (tp==6) {
-        if(device_status.light_over_tim>4*3600)
-        {
-            device_status.work_status = 1;
-            device_status.lamp_status = 1;
-            device_status.lamp1_status = 0;
-            device_status.lamp2_status = 0;
-            LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
-        }
-        else if (device_status.light_over_tim<14400&&device_status.light_over_tim>7200) {
-            device_status.work_status = 1;
-            device_status.lamp_status = 0;
-            device_status.lamp1_status = 1;
-            device_status.lamp2_status = 0;
-            LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
-        }
-        else if (device_status.light_over_tim<7200) {
-            device_status.work_status = 1;
-            device_status.lamp_status = 0;
-            device_status.lamp1_status = 0;
-            device_status.lamp2_status = 1;
-            LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
-        }
-    }
-    else if (tp==9) {
-        if(device_status.light_over_tim>6*3600)
-        {
-            device_status.work_status = 1;
-            device_status.lamp_status = 1;
-            device_status.lamp1_status = 0;
-            device_status.lamp2_status = 0;
-            LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
-        }
-        else if (device_status.light_over_tim<6*3600&&device_status.light_over_tim>3*3600) {
-            device_status.work_status = 1;
-            device_status.lamp_status = 0;
-            device_status.lamp1_status = 1;
-            device_status.lamp2_status = 0;
-            LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
-        }
-        else if (device_status.light_over_tim<3*3600) {
-            device_status.work_status = 1;
-            device_status.lamp_status = 0;
-            device_status.lamp1_status = 0;
-            device_status.lamp2_status = 1;
-            LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
-        }
-    }
-}
+
 //出厂前自检 0-开机自检  1-屏幕或指令下发手动自检
 void HardWare_Check(uint8_t boot)
 {
@@ -2242,7 +2256,9 @@ static uint32_t prework_timer = 0;
 static uint8_t clean_count = 0;
 void WorkCheck(void)
 {
+    #if LAMP_EN == 0
     static rt_uint32_t light_timeout = 3600;
+    #endif
     while(device_status.ds == 1 &&
           device_status.rain_status == 0 &&
           device_status.temp_status == 0 &&
@@ -2255,6 +2271,9 @@ void WorkCheck(void)
             {
                 // 开始结束时间相同则24小时模式
                 device_status.work_status = 1;
+                #if LAMP_EN == 1
+                Lamp_Cycle_Update();        //三灯管轮换
+                #endif
                 rt_thread_delay(10000);
                 continue;
             }
@@ -2328,11 +2347,40 @@ void WorkCheck(void)
                   device_status.work_status ? "工作" : "待机",
                   now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
                   device_status.startBar, device_status.stopBar);
+            #if LAMP_EN == 1
+            if(device_status.work_status == 1)
+            {
+                Lamp_Cycle_Update();        //三灯管轮换
+            }
+            else if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
+            {
+                Lamp_Cycle_Off();           //待机:全部灯管关闭
+            }
+            #endif
             rt_thread_delay(10000);
         }
         else // 光控模式
         {
             LOG_I("光控定时模式!");
+            #if LAMP_EN == 1
+            /* 三灯管定制:工作时长不再受屏幕/串口2下发的 sunBar 限制,
+             * 天黑(光控)即工作,天亮即停;工作期间由 Lamp_Cycle_Update 按
+             * LAMP_ROTATE_SEC(默认1小时)依次轮换3只灯管。 */
+            if(device_status.sun_status == 0)
+            {
+                device_status.work_status = 1;
+                Lamp_Cycle_Update();    //按 LAMP_ROTATE_SEC 轮换光源1/2/3
+            }
+            else
+            {
+                device_status.work_status = 0;
+                //没有在测试并且没有在自检
+                if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
+                {
+                    Lamp_Cycle_Off();
+                }
+            }
+            #else
             if(device_status.sun_status == 0 && device_status.light_over_tim > 0)
             {
                 // 夜晚且有剩余时间:工作
@@ -2364,12 +2412,16 @@ void WorkCheck(void)
                     light_timeout = 3600;  // 重置防止负数
                 }
             }
+            #endif
         }
         rt_thread_delay(1000);
     }
     // 异常状态处理while之外
     device_status.work_status = 0;
     prework_state = 0;
+    #if LAMP_EN == 1
+    Lamp_Cycle_Off();       //退出工作(雨控/欠压/高温/天黑等):全部灯管关闭
+    #endif
     rt_thread_delay(1000);
 }
 
@@ -2672,22 +2724,13 @@ void WorkTask(void)
         }
         //1.打开灯管
         #if LAMP_EN == 1
-        if(device_status.lamp_status==1&&device_status.sun_status==0)   //光控状态不亮灯
+        /* 三灯管定制:首次进入工作流程时启动轮换计时(此后跨轮次保持相位),
+         * 由 Lamp_Cycle_Update 按 LAMP_ROTATE_SEC 依次点亮 光源1/2/3 */
+        if(s_lamp_cycle_tick == 0)
         {
-            ctr_lamp(ON,1);
-            ctr_lamp(OFF,2);
-            ctr_lamp(OFF,3);
-        }
-        else if (device_status.lamp1_status==1&&device_status.sun_status==0) {
-            ctr_lamp(OFF,1);
-            ctr_lamp(ON,2);
-            ctr_lamp(OFF,3);
-        }
-        else if (device_status.lamp2_status==1&&device_status.sun_status==0) {
-            ctr_lamp(OFF,1);
-            ctr_lamp(OFF,2);
-            ctr_lamp(ON,3);
+            Lamp_Cycle_Start();
         }
+        Lamp_Cycle_Update();
         #else
             ctr_lamp(ON,1);
             if(device_status.version_type==12)
@@ -2914,7 +2957,9 @@ static void Work_status_thread_entry(void *parameter)
             rt_thread_delay(1000);
             rt_kprintf("开机光控检测:%d\n",sun_status_num);
         }
+        #if LAMP_EN == 0
         device_status.light_over_tim = device_status.sunBar * 3600;
+        #endif
         device_status.test_flag = 0;
      }
      while(1)

+ 11 - 3
Application_CBD/applications/control.h

@@ -17,6 +17,10 @@
 /* 清扫/卷带电机驱动方式:0-普通IO(H桥双高刹车),1-PWM(pwm8) */
 #define PWM_EN           1
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
+/* 三灯管轮换:工作开始后,3只灯管依次循环点亮,每只连续工作时间(s)。
+ * 该周期与屏幕/串口2下发的"工作时间"(sunBar/时控时段)无关,仅本宏决定。 */
+#define LAMP_ROTATE_SEC  (1*3600)      //每只灯管连续工作1小时
+
 #define SENSOR_EN        0              //温湿度:0关闭,1打开
 #define ROBOT_EN         0              //机器人
 #define Color_EN         0              //定制色诱
@@ -27,8 +31,8 @@
 #define DZ_260917_1      0              //resetinit中执行5次清扫;
 ////////////////////////////////////////////////////////////////
 #if LAMP_EN == 1
-    #define VERSION_HK          "1.(3ledV9).41(HK)"      //4.0海康-三色光源
-    #define VERSION_HK_2000W    "1.3led0.40(2000W)"       //水稻
+    #define VERSION_HK          "1.3Lv1.41(HK)"      //4.0海康-三色光源
+    #define VERSION_HK_2000W    "1.3Lv1.40(2000W)"       //水稻
 #else
 #if DZ_260630_1 == 0
      #define VERSION_HK          "1.82.41(HK)"            //4.0海康-1200W
@@ -53,7 +57,6 @@
 #define VERSION_GK          "1.82.1(GK)"                //1.0高空
 
 #define VERSION_XCT         "1.13.6(HK)"                //吸虫塔-海康
-#define VERSION_Robot       "1.0(robot)"                //展厅机器人
 #define VERSION_BZY         "2.70"                      //孢子仪
 
 #define CompileTime         sprintf(device_status.driver_compile,"%s-%s",__DATE__,__TIME__)              //编译时间,每次更新代码修改
@@ -347,6 +350,11 @@ uint8_t ctr_Heat(uint8_t status_heat);          //加热
 uint8_t ctr_cangmen_up(uint8_t status_up);      //上仓门
 uint8_t ctr_cangmen_down(uint8_t status_down);  //下仓门
 uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num);            //镇流器
+#if LAMP_EN == 1
+void    Lamp_Cycle_Start(void);     //工作开始:复位三灯管轮换计时
+void    Lamp_Cycle_Update(void);    //轮换刷新(1s周期调用):到点切下一只灯管
+void    Lamp_Cycle_Off(void);       //关闭全部灯管并清轮换状态
+#endif
 uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec);        //震动
 uint8_t ctr_clear(uint16_t status_clear);       //清扫
 void ctr_TG_Clear(uint16_t clear_timeout);      //清扫2

+ 6 - 30
Application_CBD/applications/dtu_uart2.c

@@ -3258,23 +3258,11 @@ int parseDtu(char *json_string)
                               {
                                   if(tt->valueint>=1&&tt->valueint<=10)
                                   {
-                                      #if LAMP_EN == 0
+                                      /* LAMP_EN==1(三灯管)时工作时长由灯管轮换(LAMP_ROTATE_SEC)决定,
+                                       * 该值仅做记录,不再限制灯管实际工作时间 */
                                       device_status.sunBar = tt->valueint;
                                       ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                      rt_kprintf("光控定时tt:%d\n",tt->valueint);
-                                      #else
-                                      if(tt->valueint==3||tt->valueint==6||tt->valueint==9)
-                                      {
-                                          device_status.sunBar = tt->valueint;
-                                          ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                          rt_kprintf("光控定时tt:%d\n",tt->valueint);
-                                      }
-                                      else
-                                      {
-                                          device_status.sunBar = 3;
-                                          rt_kprintf("三光源模式,禁止设置定时时长!!!\n");
-                                      }
-                                      #endif
+                                      LOG_I("光控定时tt:%d",tt->valueint);
                                   }
                                   else {
                                       rt_kprintf("光控定时tt设置失败参数错误!!!\n");
@@ -3283,23 +3271,11 @@ int parseDtu(char *json_string)
                               else if (tt->type==cJSON_String) {
                                   if(atoi(tt->valuestring)>=1&&atoi(tt->valuestring)<=10)
                                   {
-                                      #if LAMP_EN == 0
+                                      /* LAMP_EN==1(三灯管)时工作时长由灯管轮换(LAMP_ROTATE_SEC)决定,
+                                       * 该值仅做记录,不再限制灯管实际工作时间 */
                                       device_status.sunBar = atoi(tt->valuestring);
                                       ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                      rt_kprintf("光控定时tt:%d\n",atoi(tt->valuestring));
-                                      #else
-                                      if(atoi(tt->valuestring)%3==0)
-                                      {
-                                          device_status.sunBar = atoi(tt->valuestring);
-                                          ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                          LOG_I("光控定时tt:%d",atoi(tt->valuestring));
-                                      }
-                                      else
-                                      {
-                                          device_status.sunBar = 3;
-                                          LOG_W("三光源模式,禁止设置定时时长!!!");
-                                      }
-                                      #endif
+                                      LOG_I("光控定时tt:%d",atoi(tt->valuestring));
                                   }
                                   else {
                                       LOG_E("光控定时tt设置失败参数错误!!!");

+ 4 - 20
Application_CBD/applications/hmi.c

@@ -1982,16 +1982,6 @@ static void hmi_switch_version(const char *frame)
             param_mirror_sync();
         }
     }
-    else if (strstr(frame,"SwversionV30")!=NULL) {
-        if(device_status.version_type != 30)
-        {
-            device_status.version_type = 30;
-            sprintf(device_status.driver, "%s",VERSION_Robot);
-            ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));        //版本类型
-            MA_save();
-            param_mirror_sync();
-        }
-    }
     else if((strstr(frame,"SwversionV7")!=NULL)) {
         if(device_status.dtype!=7)
         {
@@ -2513,9 +2503,8 @@ static void HMI_Decode(void)
         {
             if(device_status.version_type!=6)
             {
-                #if LAMP_EN == 1
-                if(device_status.sunBar%3==0)
-                #endif
+                /* 注:LAMP_EN==1(三灯管)时工作时长不再由 sunBar 决定
+                 * (灯管按 LAMP_ROTATE_SEC 每小时轮换),此处值仅做记录 */
                 device_status.sunBar=atoi(value_str);
                 ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
             }
@@ -3413,15 +3402,10 @@ void Check_ParamConfig(void)
                 device_status.collecting_eh2 = device_status.collecting_sh2 + 2;
             }
         }
-        else if (device_status.version_type==30) {
-            rt_sprintf(device_status.driver, "%s",VERSION_Robot);
-        }
         /*定制三色光源*/
         #if LAMP_EN == 1
-            if(device_status.sunBar%3!=0)
-            {
-                device_status.sunBar = 3;
-            }
+            /* 三灯管模式下工作时长由 Lamp_Cycle(每只灯管轮换 LAMP_ROTATE_SEC)决定,
+             * sunBar 不再限制实际工作时间,仅按参数记录,不再强制改写为3 */
 //            device_status.timeSwitch = 1;
 //            device_status.startBar = 20;
 //            device_status.stopBar = 23;