|
@@ -987,6 +987,84 @@ uint8_t ctr_lamp(uint8_t status_lamp, uint8_t lamp_num)
|
|
|
return device_status.lamp_status;
|
|
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)
|
|
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 --;
|
|
time_out --;
|
|
|
}
|
|
}
|
|
|
rt_pin_write(Motor_EN, OFF);
|
|
rt_pin_write(Motor_EN, OFF);
|
|
|
|
|
+ #if LAMP_EN == 0
|
|
|
if(device_status.autotakepic==0)
|
|
if(device_status.autotakepic==0)
|
|
|
ctr_lamp(OFF, 1);
|
|
ctr_lamp(OFF, 1);
|
|
|
|
|
+ #endif
|
|
|
|
|
+ /* LAMP_EN==1:灯管由 Lamp_Cycle 轮换管理,电机动作结束后不再并入关灯动作,
|
|
|
|
|
+ * 避免每轮电机动作都把工作中灯管熄灭再重新起弧 */
|
|
|
beep_set(0, 0); //200kzh - 50%
|
|
beep_set(0, 0); //200kzh - 50%
|
|
|
}
|
|
}
|
|
|
/*************************************************
|
|
/*************************************************
|
|
@@ -1895,8 +1977,12 @@ void HardWare_Init(uint8_t boot)
|
|
|
ctr_cangmen_down(OFF);
|
|
ctr_cangmen_down(OFF);
|
|
|
}
|
|
}
|
|
|
//关闭镇流器
|
|
//关闭镇流器
|
|
|
|
|
+ #if LAMP_EN == 1
|
|
|
|
|
+ Lamp_Cycle_Off(); //上电/初始化:关闭3只灯管并复位轮换
|
|
|
|
|
+ #else
|
|
|
if(device_status.autotakepic==0)
|
|
if(device_status.autotakepic==0)
|
|
|
ctr_lamp(OFF,1);
|
|
ctr_lamp(OFF,1);
|
|
|
|
|
+ #endif
|
|
|
|
|
|
|
|
//关闭震动电机
|
|
//关闭震动电机
|
|
|
ctr_shake(OFF,0);
|
|
ctr_shake(OFF,0);
|
|
@@ -1963,7 +2049,11 @@ void SunTest(void)
|
|
|
if(Read_Light_Voltage()>500)
|
|
if(Read_Light_Voltage()>500)
|
|
|
{
|
|
{
|
|
|
device_status.sun_status = 1;
|
|
device_status.sun_status = 1;
|
|
|
|
|
+ #if LAMP_EN == 1
|
|
|
|
|
+ Lamp_Cycle_Off(); //天亮:关闭3只灯管并复位轮换
|
|
|
|
|
+ #else
|
|
|
ctr_lamp(OFF,1);
|
|
ctr_lamp(OFF,1);
|
|
|
|
|
+ #endif
|
|
|
}
|
|
}
|
|
|
HMI_WRITE("sysTest.switchSun.val=%d",0);
|
|
HMI_WRITE("sysTest.switchSun.val=%d",0);
|
|
|
device_status.sun_test = 0;
|
|
device_status.sun_test = 0;
|
|
@@ -2006,10 +2096,10 @@ void ResetInit(void)
|
|
|
//2.打开相机供电
|
|
//2.打开相机供电
|
|
|
ctr_photo(ON);
|
|
ctr_photo(ON);
|
|
|
//3.关闭镇流器
|
|
//3.关闭镇流器
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
#if LAMP_EN == 1
|
|
#if LAMP_EN == 1
|
|
|
- ctr_lamp(OFF,2);
|
|
|
|
|
- ctr_lamp(OFF,3);
|
|
|
|
|
|
|
+ Lamp_Cycle_Off(); //关闭3只灯管并复位轮换计时
|
|
|
|
|
+ #else
|
|
|
|
|
+ ctr_lamp(OFF,1);
|
|
|
#endif
|
|
#endif
|
|
|
//4.关闭震动电机
|
|
//4.关闭震动电机
|
|
|
ctr_shake(OFF, 0);
|
|
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-屏幕或指令下发手动自检
|
|
//出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
|
|
|
void HardWare_Check(uint8_t boot)
|
|
void HardWare_Check(uint8_t boot)
|
|
|
{
|
|
{
|
|
@@ -2242,7 +2256,9 @@ static uint32_t prework_timer = 0;
|
|
|
static uint8_t clean_count = 0;
|
|
static uint8_t clean_count = 0;
|
|
|
void WorkCheck(void)
|
|
void WorkCheck(void)
|
|
|
{
|
|
{
|
|
|
|
|
+ #if LAMP_EN == 0
|
|
|
static rt_uint32_t light_timeout = 3600;
|
|
static rt_uint32_t light_timeout = 3600;
|
|
|
|
|
+ #endif
|
|
|
while(device_status.ds == 1 &&
|
|
while(device_status.ds == 1 &&
|
|
|
device_status.rain_status == 0 &&
|
|
device_status.rain_status == 0 &&
|
|
|
device_status.temp_status == 0 &&
|
|
device_status.temp_status == 0 &&
|
|
@@ -2255,6 +2271,9 @@ void WorkCheck(void)
|
|
|
{
|
|
{
|
|
|
// 开始结束时间相同则24小时模式
|
|
// 开始结束时间相同则24小时模式
|
|
|
device_status.work_status = 1;
|
|
device_status.work_status = 1;
|
|
|
|
|
+ #if LAMP_EN == 1
|
|
|
|
|
+ Lamp_Cycle_Update(); //三灯管轮换
|
|
|
|
|
+ #endif
|
|
|
rt_thread_delay(10000);
|
|
rt_thread_delay(10000);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -2328,11 +2347,40 @@ void WorkCheck(void)
|
|
|
device_status.work_status ? "工作" : "待机",
|
|
device_status.work_status ? "工作" : "待机",
|
|
|
now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
|
|
now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
|
|
|
device_status.startBar, device_status.stopBar);
|
|
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);
|
|
rt_thread_delay(10000);
|
|
|
}
|
|
}
|
|
|
else // 光控模式
|
|
else // 光控模式
|
|
|
{
|
|
{
|
|
|
LOG_I("光控定时模式!");
|
|
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)
|
|
if(device_status.sun_status == 0 && device_status.light_over_tim > 0)
|
|
|
{
|
|
{
|
|
|
// 夜晚且有剩余时间:工作
|
|
// 夜晚且有剩余时间:工作
|
|
@@ -2364,12 +2412,16 @@ void WorkCheck(void)
|
|
|
light_timeout = 3600; // 重置防止负数
|
|
light_timeout = 3600; // 重置防止负数
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ #endif
|
|
|
}
|
|
}
|
|
|
rt_thread_delay(1000);
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
}
|
|
|
// 异常状态处理while之外
|
|
// 异常状态处理while之外
|
|
|
device_status.work_status = 0;
|
|
device_status.work_status = 0;
|
|
|
prework_state = 0;
|
|
prework_state = 0;
|
|
|
|
|
+ #if LAMP_EN == 1
|
|
|
|
|
+ Lamp_Cycle_Off(); //退出工作(雨控/欠压/高温/天黑等):全部灯管关闭
|
|
|
|
|
+ #endif
|
|
|
rt_thread_delay(1000);
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2672,22 +2724,13 @@ void WorkTask(void)
|
|
|
}
|
|
}
|
|
|
//1.打开灯管
|
|
//1.打开灯管
|
|
|
#if LAMP_EN == 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
|
|
#else
|
|
|
ctr_lamp(ON,1);
|
|
ctr_lamp(ON,1);
|
|
|
if(device_status.version_type==12)
|
|
if(device_status.version_type==12)
|
|
@@ -2914,7 +2957,9 @@ static void Work_status_thread_entry(void *parameter)
|
|
|
rt_thread_delay(1000);
|
|
rt_thread_delay(1000);
|
|
|
rt_kprintf("开机光控检测:%d\n",sun_status_num);
|
|
rt_kprintf("开机光控检测:%d\n",sun_status_num);
|
|
|
}
|
|
}
|
|
|
|
|
+ #if LAMP_EN == 0
|
|
|
device_status.light_over_tim = device_status.sunBar * 3600;
|
|
device_status.light_over_tim = device_status.sunBar * 3600;
|
|
|
|
|
+ #endif
|
|
|
device_status.test_flag = 0;
|
|
device_status.test_flag = 0;
|
|
|
}
|
|
}
|
|
|
while(1)
|
|
while(1)
|