|
...
|
...
|
@@ -2,6 +2,10 @@ |
|
|
|
#include "JZ_TempControl.h"
|
|
|
|
#include "JZ_lamp.h"
|
|
|
|
#include "JZ_widget.h"
|
|
|
|
#include "JZ_speaker.h"
|
|
|
|
#include "wiringPi.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
/* Private constants ---------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* Private types -------------------------------------------------------------*/
|
|
...
|
...
|
@@ -9,11 +13,11 @@ |
|
|
|
/* Private values -------------------------------------------------------------*/
|
|
|
|
TempControlData *tempData;//存放温度、亮度数据
|
|
|
|
int InitialLumen;//最初亮度
|
|
|
|
int tempControlFlag = TEMP_NOTTRIGGER;//判断当前温度是否执行过温控
|
|
|
|
int tempControlFlag = TEMP_TRIGGER;//判断当前温度是否执行过温控
|
|
|
|
int light_mode = LIGHT_OFF; //探照灯模式
|
|
|
|
int tempMax = 70;//限制温度
|
|
|
|
int Initialflag = DEFAULT_STATUS;
|
|
|
|
|
|
|
|
static int delayThreadFlag = 0;
|
|
|
|
/* Private functions declaration ---------------------------------------------*/
|
|
|
|
|
|
|
|
/* Exported functions definition ---------------------------------------------*/
|
|
...
|
...
|
@@ -37,12 +41,12 @@ static void* TempControl_Task(void *arg) |
|
|
|
if(OutTime > 0)
|
|
|
|
{
|
|
|
|
//tempControlFlag = TEMP_TRIGGER;
|
|
|
|
printf("触发调控,输入温度%d,输入亮度%d,设置亮度%d,调控时间%d\n",tempData->InputTemp,tempData->InputLumen,InitialLumen,OutTime);
|
|
|
|
usleep(OutTime*1000);
|
|
|
|
printf("触发调控,输入温度%d,输入亮度%d,输出亮度%d,设置亮度%d,调控时间%d\n",tempData->InputTemp,tempData->InputLumen,tempData->OutLumen,InitialLumen,OutTime);
|
|
|
|
delay(OutTime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usleep(1*1000);
|
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
OutTime = 0;
|
|
|
|
|
|
...
|
...
|
@@ -60,13 +64,15 @@ static void* TempControl_Task(void *arg) |
|
|
|
int Jz_TempControlTaskCreate(void)
|
|
|
|
{
|
|
|
|
//需确保拿到亮度数据后再开启任务
|
|
|
|
usleep(1000*1000);
|
|
|
|
|
|
|
|
delay(1000);
|
|
|
|
printf("Jz_TempControlTaskCreate\n");
|
|
|
|
pthread_t pthread;
|
|
|
|
pthread_attr_t pthread_attr;
|
|
|
|
|
|
|
|
pthread_attr_init(&pthread_attr);
|
|
|
|
pthread_attr_setdetachstate(&pthread_attr, PTHREAD_CREATE_DETACHED); //设置线程分离属性
|
|
|
|
|
|
|
|
|
|
|
|
int ret = pthread_create(&pthread,&pthread_attr,TempControl_Task,NULL);
|
|
|
|
if(ret !=0)
|
|
|
|
{
|
|
...
|
...
|
@@ -82,7 +88,7 @@ int Jz_TempControlTaskCreate(void) |
|
|
|
printf("线程创建失败\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -102,7 +108,7 @@ int Jz_LampTempControl(float InputTemp, int InputLumen,int *InitialLumen,int *Ou |
|
|
|
{
|
|
|
|
|
|
|
|
int ControlFlag = DEFAULT_STATUS; //无变化为0, 升温为1,降温为2
|
|
|
|
|
|
|
|
|
|
|
|
//限制温度高于当前温度
|
|
|
|
if(tempMax >= InputTemp)
|
|
|
|
{
|
|
...
|
...
|
@@ -145,7 +151,7 @@ int Jz_LampTempControl(float InputTemp, int InputLumen,int *InitialLumen,int *Ou |
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/************************************
|
|
...
|
...
|
@@ -292,7 +298,7 @@ static void *TempControl_TempChangeTask(void *arg) |
|
|
|
tempData->OutLumen = 0;
|
|
|
|
}
|
|
|
|
Lumen = tempData->OutLumen;
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否超出温控范围了
|
|
|
|
if (tempData->InputTemp > tempMax +10) //超出最大温度10度
|
|
|
|
{
|
|
...
|
...
|
@@ -304,15 +310,19 @@ static void *TempControl_TempChangeTask(void *arg) |
|
|
|
Jz_LampLumenControl(Lumen,Lumen);
|
|
|
|
|
|
|
|
}
|
|
|
|
if(tempControlFlag == TEMP_NOTTRIGGER)//改变亮度后一定时间不触发温控
|
|
|
|
{
|
|
|
|
if(delayThreadFlag == 0)
|
|
|
|
{
|
|
|
|
delayThreadFlag = 1;
|
|
|
|
JZ_DelayThreadCreate(100);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(Lumen != lastLumen)//亮度改变
|
|
|
|
{
|
|
|
|
lastLumen = Lumen;
|
|
|
|
|
|
|
|
if(tempControlFlag == TEMP_NOTTRIGGER)//触发了温控
|
|
|
|
{
|
|
|
|
tempControlFlag = TEMP_TRIGGER;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Lumen != 0)
|
|
|
|
{
|
|
|
|
//重设亮度
|
|
...
|
...
|
@@ -322,6 +332,25 @@ static void *TempControl_TempChangeTask(void *arg) |
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
usleep(200*1000);
|
|
|
|
delay(200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************
|
|
|
|
*延时恢复温控
|
|
|
|
*函数名: JZ_TempControlFlag
|
|
|
|
*函数参数:
|
|
|
|
|
|
|
|
*返回值:
|
|
|
|
*函数作者:wzy
|
|
|
|
*************************************/
|
|
|
|
void *JZ_TempControlFlag(void *arg)
|
|
|
|
{
|
|
|
|
int delayTime = *(int *)arg;
|
|
|
|
//延时执行
|
|
|
|
usleep(delayTime*1000);
|
|
|
|
tempControlFlag = TEMP_TRIGGER; //温控标志位
|
|
|
|
delayThreadFlag = 0;
|
|
|
|
|
|
|
|
printf("延时恢复温控\n");
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|