|
|
@@ -16,6 +16,7 @@
|
|
|
#include "control.h"
|
|
|
#include "hmi.h"
|
|
|
#include "math.h"
|
|
|
+#include "sys_monitor.h"
|
|
|
#define DBG_ENABLE
|
|
|
#define DBG_COLOR
|
|
|
#define DBG_TAG "control"
|
|
|
@@ -44,7 +45,7 @@
|
|
|
|
|
|
|
|
|
Device_Status_typedef device_status;
|
|
|
-
|
|
|
+System_stats_t system_status;
|
|
|
|
|
|
rt_device_t serial_485; /*串口设备句柄*/
|
|
|
struct serial_configure uart_config_485 = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
|
|
|
@@ -125,51 +126,25 @@ int UART_485_INIT(void)
|
|
|
}
|
|
|
|
|
|
/* 入口函数 */
|
|
|
-static void sht30_collect_thread_entry(void *parameter)
|
|
|
+static void adc_collect_thread_entry(void *parameter)
|
|
|
{
|
|
|
-
|
|
|
- sht3x_device_t sht3x_device;
|
|
|
static int checklightnum = 0;
|
|
|
static int checknightnum = 0;
|
|
|
- sht3x_device = sht3x_init("i2c1", 0x44);
|
|
|
- //此处需要短暂的延时,否则会出现连续读取失败的问题
|
|
|
- rt_thread_mdelay(150);
|
|
|
+ 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)
|
|
|
{
|
|
|
- if(sht3x_device)
|
|
|
- {
|
|
|
- if(RT_EOK == sht3x_read_singleshot(sht3x_device))
|
|
|
- {
|
|
|
- hum_value = sht3x_device->humidity;
|
|
|
- tem_value = sht3x_device->temperature;
|
|
|
- if(hum_value!=0)
|
|
|
- {
|
|
|
- rt_sprintf(device_status.humidity,"%d.%d",(int)sht3x_device->humidity, (uint)(sht3x_device->humidity * 10) % 10);
|
|
|
- rt_sprintf(device_status.tempture,"%d.%d",(int)sht3x_device->temperature, (uint)(sht3x_device->temperature * 10) % 10);
|
|
|
- }
|
|
|
- else {
|
|
|
- rt_kprintf("sht3x_read_singleshot eRR:%d",hum_value);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- sht3x_softreset(sht3x_device);
|
|
|
- }
|
|
|
-//// rt_kprintf("sht30 humidity : %d.%d ", (int)sht3x_device->humidity, (int)(sht3x_device->humidity * 10) % 10);
|
|
|
-//// rt_kprintf("temperature: %d.%d\n", (int)sht3x_device->temperature, (int)(sht3x_device->temperature * 10) % 10);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- rt_kprintf("read sht3x fail.\r\n");
|
|
|
- //重新初始化
|
|
|
- sht3x_deinit(sht3x_device);
|
|
|
- sht3x_device = sht3x_init("i2c1", 0x44);
|
|
|
- rt_thread_mdelay(150);
|
|
|
- }
|
|
|
- if(Read_Light_Voltage()>500||atoi(device_status.lux)>500)
|
|
|
+ log_cnt ++;
|
|
|
+ rain_value= Read_Rain_Voltage();
|
|
|
+ light_value= Read_Light_Voltage();
|
|
|
+ if(light_value>500||atoi(device_status.lux)>500)
|
|
|
{
|
|
|
checklightnum++;
|
|
|
- if(checklightnum==20)
|
|
|
+ if(checklightnum==1000) //100s
|
|
|
{
|
|
|
device_status.sun_status = 1;
|
|
|
checklightnum =0;
|
|
|
@@ -180,7 +155,7 @@ static void sht30_collect_thread_entry(void *parameter)
|
|
|
{
|
|
|
checknightnum ++;
|
|
|
}
|
|
|
- if(checknightnum==20)
|
|
|
+ if(checknightnum==1000) //100s
|
|
|
{
|
|
|
device_status.sun_status = 0;
|
|
|
checknightnum = 0;
|
|
|
@@ -194,13 +169,43 @@ static void sht30_collect_thread_entry(void *parameter)
|
|
|
else if(atoi(device_status.tempture)>=(device_status.tpl+5)&&atoi(device_status.tempture)<=(device_status.tph-10)) {
|
|
|
device_status.temp_status = 0;
|
|
|
}
|
|
|
- LOG_I("光控计数:%d-%d",checklightnum,checknightnum);
|
|
|
- rt_thread_mdelay(5000);
|
|
|
+ //雨控
|
|
|
+ if(rain_value>250&&device_status.selfcheck_ws==0)
|
|
|
+ {
|
|
|
+ checkrain_num++;
|
|
|
+ if(checkrain_num>=10){
|
|
|
+ system_status.rain_value = rain_value;
|
|
|
+ system_status.rain_control_triggers +=1;
|
|
|
+ device_status.rain_status = 1;
|
|
|
+ ctr_lamp(OFF,1);
|
|
|
+ ctr_lamp(OFF,2);
|
|
|
+ ctr_lamp(OFF,3);
|
|
|
+ device_status.ctr_up_motor = 2; //关闭上仓门
|
|
|
+ checkrain_num = 0;
|
|
|
+ checkrain_unlock = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ checkrain_unlock++;
|
|
|
+ checkrain_num = 0;
|
|
|
+ //雨控消抖,5分钟
|
|
|
+ if(checkrain_unlock==10*60*60)
|
|
|
+ {
|
|
|
+ checkrain_unlock = 0;
|
|
|
+ device_status.rain_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);
|
|
|
+ }
|
|
|
+ rt_thread_mdelay(log_freq);
|
|
|
}
|
|
|
}
|
|
|
static void Power_ReadCheck(void *parameter)
|
|
|
{
|
|
|
- rt_uint32_t rain_cnt = 0;
|
|
|
int bat_cnt = 0;
|
|
|
int RV;
|
|
|
MovingAverageFilter* filter = moving_average_filter_init(10);
|
|
|
@@ -286,26 +291,6 @@ static void Power_ReadCheck(void *parameter)
|
|
|
device_status.heattem = 25;
|
|
|
}
|
|
|
}
|
|
|
- //雨控
|
|
|
- if(Read_Rain_Voltage()>250&&device_status.selfcheck_ws==0)
|
|
|
- {
|
|
|
- device_status.rain_status = 1;
|
|
|
- ctr_lamp(OFF,1);
|
|
|
- ctr_lamp(OFF,2);
|
|
|
- ctr_lamp(OFF,3);
|
|
|
- device_status.ctr_up_motor = 2; //关闭上仓门
|
|
|
- rain_cnt = 0;
|
|
|
- }
|
|
|
- else {
|
|
|
- rain_cnt++;
|
|
|
- //雨控消抖,5分钟
|
|
|
- if(rain_cnt>3000*6&&Read_Rain_Voltage()<250)
|
|
|
- {
|
|
|
- LOG_D("雨控触发:%d",Read_Rain_Voltage());
|
|
|
- rain_cnt = 0;
|
|
|
- device_status.rain_status = 0;
|
|
|
- }
|
|
|
- }
|
|
|
//LOG_D("rain_cnt:%d-value:%d",rain_cnt,Read_Rain_Voltage());
|
|
|
}
|
|
|
if(bat_cnt>=100){ //持续10s
|
|
|
@@ -427,7 +412,7 @@ int Read_Light_Voltage(void)
|
|
|
adc10_rain = rt_adc_read(adc_dev,ADC_DEV_CHANNLE_2);
|
|
|
rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_2);
|
|
|
HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
|
|
|
- LOG_I("read light value:%d",adc10_rain);
|
|
|
+// LOG_I("read light value:%d",adc10_rain);
|
|
|
return adc10_rain;
|
|
|
}
|
|
|
//获取内部温度传感器值
|
|
|
@@ -554,7 +539,7 @@ int Read_Ntc_Voltage(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);
|
|
|
/* 如果获得线程控制块,启动这个线程 */
|
|
|
if (tid1 != RT_NULL)
|