|
@@ -16,7 +16,7 @@
|
|
|
#include "hmi.h"
|
|
#include "hmi.h"
|
|
|
#include "math.h"
|
|
#include "math.h"
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
-
|
|
|
|
|
|
|
+#include "sys_monitor.h"
|
|
|
#define DBG_ENABLE
|
|
#define DBG_ENABLE
|
|
|
#define DBG_COLOR
|
|
#define DBG_COLOR
|
|
|
#define DBG_TAG "control"
|
|
#define DBG_TAG "control"
|
|
@@ -46,7 +46,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
Device_Status_typedef device_status;
|
|
Device_Status_typedef device_status;
|
|
|
-
|
|
|
|
|
|
|
+System_stats_t system_status;
|
|
|
|
|
|
|
|
rt_device_t serial_485; /*串口设备句柄*/
|
|
rt_device_t serial_485; /*串口设备句柄*/
|
|
|
struct serial_configure uart_config_485 = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
|
|
struct serial_configure uart_config_485 = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
|
|
@@ -143,84 +143,88 @@ int UART_485_INIT(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/* 入口函数 */
|
|
/* 入口函数 */
|
|
|
-static void sht30_collect_thread_entry(void *parameter)
|
|
|
|
|
|
|
+static void adc_collect_thread_entry(void *parameter)
|
|
|
{
|
|
{
|
|
|
static int checklightnum = 0;
|
|
static int checklightnum = 0;
|
|
|
static int checknightnum = 0;
|
|
static int checknightnum = 0;
|
|
|
- static int rain_on_num = 0;
|
|
|
|
|
- static int rain_off_num = 0;
|
|
|
|
|
|
|
+ static int checkrain_num = 0;
|
|
|
|
|
+ static int checkrain_unlock = 0;
|
|
|
|
|
+ static unsigned int rain_value = 0;
|
|
|
|
|
+ static unsigned int light_value = 0;
|
|
|
|
|
+ const unsigned int log_freq = 100; //100ms
|
|
|
|
|
+ static unsigned log_cnt = 0;
|
|
|
while (1)
|
|
while (1)
|
|
|
{
|
|
{
|
|
|
- if(Read_Light_Voltage()>500)
|
|
|
|
|
|
|
+ log_cnt ++;
|
|
|
|
|
+ rain_value= Read_Rain_Voltage();
|
|
|
|
|
+ light_value= Read_Light_Voltage();
|
|
|
|
|
+ if(light_value>500)
|
|
|
{
|
|
{
|
|
|
|
|
+ checknightnum = 0;
|
|
|
checklightnum++;
|
|
checklightnum++;
|
|
|
- if(checklightnum==1000)
|
|
|
|
|
|
|
+ if(checklightnum==1000) //100s
|
|
|
{
|
|
{
|
|
|
device_status.sun_status = 1;
|
|
device_status.sun_status = 1;
|
|
|
- device_status.C01 |= (1<<6);
|
|
|
|
|
checklightnum =0;
|
|
checklightnum =0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
|
|
+ light_value = 0;
|
|
|
checknightnum ++;
|
|
checknightnum ++;
|
|
|
- if(checknightnum==1000)
|
|
|
|
|
|
|
+ if(checknightnum==1000) //100s
|
|
|
{
|
|
{
|
|
|
- device_status.C01 &= ~(1<<6);
|
|
|
|
|
device_status.sun_status = 0;
|
|
device_status.sun_status = 0;
|
|
|
checknightnum = 0;
|
|
checknightnum = 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- //LOG_I("光控计数:%d-%d",checklightnum,checknightnum);
|
|
|
|
|
|
|
+#if WENKONG==1
|
|
|
|
|
+ //温控
|
|
|
|
|
+ if(atoi(device_status.tempture)>=device_status.tph||atoi(device_status.tempture)<=device_status.tpl)
|
|
|
|
|
+ {
|
|
|
|
|
+ device_status.temp_status = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if(atoi(device_status.tempture)>=(device_status.tpl+5)&&atoi(device_status.tempture)<=(device_status.tph-10)) {
|
|
|
|
|
+ device_status.temp_status = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
//雨控
|
|
//雨控
|
|
|
- if(Read_Rain_Voltage()>250&&device_status.selfcheck_ws==0)
|
|
|
|
|
|
|
+ if(rain_value>250&&device_status.selfcheck_ws==0)
|
|
|
{
|
|
{
|
|
|
- rain_on_num ++;
|
|
|
|
|
- if(rain_on_num==1)
|
|
|
|
|
- {
|
|
|
|
|
- LOG_W("雨控触发值:%d",Read_Rain_Voltage());
|
|
|
|
|
- device_status.C01 |= (1<<5);
|
|
|
|
|
|
|
+ checkrain_num++;
|
|
|
|
|
+ if(checkrain_num>=10){
|
|
|
|
|
+ system_status.rain_value = rain_value;
|
|
|
|
|
+ system_status.rain_control_triggers +=1;
|
|
|
device_status.rain_status = 1;
|
|
device_status.rain_status = 1;
|
|
|
- device_status.ctr_up_motor = 2; //关闭上仓门
|
|
|
|
|
ctr_lamp(OFF,1);
|
|
ctr_lamp(OFF,1);
|
|
|
ctr_lamp(OFF,2);
|
|
ctr_lamp(OFF,2);
|
|
|
ctr_lamp(OFF,3);
|
|
ctr_lamp(OFF,3);
|
|
|
- rain_on_num = 0;
|
|
|
|
|
- rain_off_num = 0;
|
|
|
|
|
|
|
+ device_status.ctr_up_motor = 2; //关闭上仓门
|
|
|
|
|
+ checkrain_num = 0;
|
|
|
|
|
+ checkrain_unlock = 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- rain_off_num ++;
|
|
|
|
|
- if(rain_off_num==35000){ //1个小时后解除雨控
|
|
|
|
|
|
|
+ checkrain_unlock++;
|
|
|
|
|
+ checkrain_num = 0;
|
|
|
|
|
+ //雨控消抖,5分钟
|
|
|
|
|
+ if(checkrain_unlock==10*60*60)
|
|
|
|
|
+ {
|
|
|
|
|
+ checkrain_unlock = 0;
|
|
|
device_status.rain_status = 0;
|
|
device_status.rain_status = 0;
|
|
|
- device_status.C01 &= ~(1<<5);
|
|
|
|
|
- rain_on_num = 0;
|
|
|
|
|
- rain_off_num = 0;
|
|
|
|
|
- }
|
|
|
|
|
- if(rain_off_num%100==0){
|
|
|
|
|
- LOG_I("雨控解除计数:35000-%d",rain_off_num);
|
|
|
|
|
- LOG_I("光控计数:%d-%d",checklightnum,checknightnum);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- //温控
|
|
|
|
|
- #if WENKONG==1
|
|
|
|
|
- if(atoi(device_status.tempture)>=device_status.tph||atoi(device_status.tempture)<=device_status.tpl)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.C01 |= (1<<7);
|
|
|
|
|
- device_status.temp_status = 1;
|
|
|
|
|
- }
|
|
|
|
|
- else if(atoi(device_status.tempture)>=(device_status.tpl+5)&&atoi(device_status.tempture)<=(device_status.tph-10))
|
|
|
|
|
- {
|
|
|
|
|
- device_status.C01 &= ~(1<<7);
|
|
|
|
|
- device_status.temp_status = 0;
|
|
|
|
|
|
|
+ if(log_cnt==50){ //每5s打印
|
|
|
|
|
+ log_cnt = 0;
|
|
|
|
|
+ LOG_I("光控计数:light:%d-night:%d",checklightnum,checknightnum);
|
|
|
|
|
+ LOG_I("雨控计数:有:%d-无:%d",checkrain_num,checkrain_unlock);
|
|
|
|
|
+ LOG_I("雨控ADC值:%d 光控ADC值:%d",rain_value,light_value);
|
|
|
}
|
|
}
|
|
|
- #endif
|
|
|
|
|
- rt_thread_mdelay(100);
|
|
|
|
|
|
|
+ rt_thread_mdelay(log_freq);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
static void Power_ReadCheck(void *parameter)
|
|
static void Power_ReadCheck(void *parameter)
|
|
|
{
|
|
{
|
|
|
int bat_cnt = 0;
|
|
int bat_cnt = 0;
|
|
@@ -561,7 +565,7 @@ int Read_Ntc_Voltage(void)
|
|
|
int sht30_collect(void)
|
|
int sht30_collect(void)
|
|
|
{
|
|
{
|
|
|
/* 创建线程*/
|
|
/* 创建线程*/
|
|
|
- tid1 = rt_thread_create("sht30_collect_thread",sht30_collect_thread_entry, RT_NULL,THREAD_STACK_SIZE,THREAD_PRIORITY, THREAD_TIMESLICE);
|
|
|
|
|
|
|
+ tid1 = rt_thread_create("adc_thread",adc_collect_thread_entry, RT_NULL,THREAD_STACK_SIZE,THREAD_PRIORITY, THREAD_TIMESLICE);
|
|
|
tid2 = rt_thread_create("Power Check thread", Power_ReadCheck, RT_NULL, P_THREAD_STACK_SIZE, P_THREAD_PRIORITY, P_THREAD_TIMESCLICE);
|
|
tid2 = rt_thread_create("Power Check thread", Power_ReadCheck, RT_NULL, P_THREAD_STACK_SIZE, P_THREAD_PRIORITY, P_THREAD_TIMESCLICE);
|
|
|
/* 如果获得线程控制块,启动这个线程 */
|
|
/* 如果获得线程控制块,启动这个线程 */
|
|
|
if (tid1 != RT_NULL)
|
|
if (tid1 != RT_NULL)
|