|
|
|
@ -11,9 +11,6 @@
|
|
|
|
|
#include "rtc_process.h"
|
|
|
|
|
#include "save_file.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define KEY_POWER KEY_PUSH_SW1
|
|
|
|
|
#define KEY_MODE_SET KEY_PUSH_SW2
|
|
|
|
|
#define KEY_UP KEY_PUSH_SW3
|
|
|
|
@ -30,16 +27,11 @@ typedef enum _control_step
|
|
|
|
|
CONTROL_STEP_INIT_POWER_ON_KEY_SET,
|
|
|
|
|
CONTROL_STEP_INIT_COMPLETE,
|
|
|
|
|
CONTROL_STEP_ACTION_IDLE,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA,
|
|
|
|
|
CONTROL_STEP_ACTION_RUN_MAX_SENSOR_DATA,
|
|
|
|
|
CONTROL_STEP_ACTION_RUN_MIN_SENSOR_DATA,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CONTROL_STEP_ACTION_RUN_SET_MAX_SENSOR_DATA,
|
|
|
|
|
CONTROL_STEP_ACTION_RUN_SET_MIN_SENSOR_DATA,
|
|
|
|
|
|
|
|
|
|
CONTROL_STEP_ACTION_RUN_COMPLETE,
|
|
|
|
|
}CONTROL_STEP;
|
|
|
|
|
|
|
|
|
@ -48,18 +40,19 @@ typedef struct _control_info
|
|
|
|
|
{
|
|
|
|
|
bool isInitView;
|
|
|
|
|
bool isActionRun;
|
|
|
|
|
bool isRelayOn;
|
|
|
|
|
|
|
|
|
|
CONTROL_STEP Step;
|
|
|
|
|
uint32_t StartTickCount;
|
|
|
|
|
uint32_t GetSensorDataTickCount;
|
|
|
|
|
uint32_t returnMainViewTickCount;
|
|
|
|
|
uint16_t Co2_Now;
|
|
|
|
|
uint16_t Co2_SaveData;
|
|
|
|
|
uint16_t Co2_MaxValue;
|
|
|
|
|
uint16_t Co2_MinValue;
|
|
|
|
|
uint16_t Co2_TempValue;
|
|
|
|
|
SET_INDEX SetIndex;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t Co2_TempMax;
|
|
|
|
|
uint16_t Co2_TempMin;
|
|
|
|
|
}CONTROL_INFO;
|
|
|
|
@ -72,41 +65,28 @@ uint16_t SaveSensorCo2[100];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static CONTROL_INFO Control_Info;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Action_Process(void);
|
|
|
|
|
|
|
|
|
|
static void Action_PowerOn_Init_Process(void);
|
|
|
|
|
static void Action_PowerOn_Process(void);
|
|
|
|
|
|
|
|
|
|
static void Action_Get_SensorData(void);
|
|
|
|
|
static void Action_Get_SensorReadProcess(void);
|
|
|
|
|
static void Action_SaveSensorData(void);
|
|
|
|
|
|
|
|
|
|
static void Action_Power_On_Key_Set(void);
|
|
|
|
|
static void Action_Power_On_Key_Push_Callback(void);
|
|
|
|
|
static void Action_Power_Off_Key_Set(void);
|
|
|
|
|
static void Action_Power_Off_Key_Push_Callback(void);
|
|
|
|
|
|
|
|
|
|
static void Action_Mode_Key_Push(void);
|
|
|
|
|
static void Action_Set_Key_Push(void);
|
|
|
|
|
|
|
|
|
|
static void Action_Up_Key_Push(void);
|
|
|
|
|
static void Action_Down_Key_Push(void);
|
|
|
|
|
|
|
|
|
|
static void Action_ReturnMainViewCheck(void);
|
|
|
|
|
static void Action_Relay_Output_Check(void);
|
|
|
|
|
static void Action_RelayOn(void);
|
|
|
|
|
static void Action_RelayOff(void);
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
|
|
static void Action_PowerKey_Push(void);
|
|
|
|
|
static void Action_PowerKey_LongPush(void);
|
|
|
|
|
static void Action_Sensor_Read_Process(void);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void Action_Initialization(void)
|
|
|
|
|
{
|
|
|
|
@ -200,8 +180,11 @@ static void Action_PowerOn_Process(void)
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D1, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D2, GPIO_LED_MODE_ON, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D3, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
Action_RelayOff();
|
|
|
|
|
GPIO_SENSOR_PWR_ON;
|
|
|
|
|
SaveCheckSec = 0xFF;
|
|
|
|
|
Control_Info.Co2_Now = 0xFFFF;
|
|
|
|
|
Control_Info.Co2_SaveData = 0xFFFF;
|
|
|
|
|
Action_Get_SensorData();
|
|
|
|
|
if(EEPROM_Read_SettingValue(&Control_Info.Co2_MaxValue, &Control_Info.Co2_MinValue) == false)
|
|
|
|
|
{
|
|
|
|
@ -212,7 +195,7 @@ static void Action_PowerOn_Process(void)
|
|
|
|
|
Control_Info.Co2_TempMax = 0;
|
|
|
|
|
Control_Info.Co2_TempMin = 0xFFFF;
|
|
|
|
|
|
|
|
|
|
printf("Data, Time, Average(Now)_Co2, Max_Co2, Min_Co2\r\n");
|
|
|
|
|
printf("Data, Time, Average(Now)_Co2, Max_Co2, Min_Co2, Relay\r\n");
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA:
|
|
|
|
@ -242,6 +225,7 @@ static void Action_PowerOn_Process(void)
|
|
|
|
|
GPIO_SENSOR_PWR_OFF;
|
|
|
|
|
Action_Power_On_Key_Set();
|
|
|
|
|
Segment_All_Set_Data(0x00);
|
|
|
|
|
Action_RelayOff();
|
|
|
|
|
EEPROM_Write_SettingValue(Control_Info.Co2_MaxValue, Control_Info.Co2_MinValue);
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_IDLE;
|
|
|
|
|
Control_Info.isActionRun = false;
|
|
|
|
@ -287,6 +271,7 @@ static void Action_Get_SensorData(void)
|
|
|
|
|
KCD_HP100_Tx_Get_MeasurmentData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Action_Get_SensorReadProcess(void)
|
|
|
|
|
{
|
|
|
|
|
KCD_HP100_STATE nowSensorState = KCD_HP100_GetState();
|
|
|
|
@ -294,6 +279,16 @@ static void Action_Get_SensorReadProcess(void)
|
|
|
|
|
if(nowSensorState == KCD_HP100_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
KCD_HP100_Get_Co2((uint16_t *)&Control_Info.Co2_Now);
|
|
|
|
|
Control_Info.Co2_SaveData = Control_Info.Co2_Now;
|
|
|
|
|
|
|
|
|
|
if(Control_Info.Co2_Now >= Control_Info.Co2_MaxValue)
|
|
|
|
|
{
|
|
|
|
|
Action_RelayOff();
|
|
|
|
|
}
|
|
|
|
|
else if(Control_Info.Co2_Now <= Control_Info.Co2_MinValue)
|
|
|
|
|
{
|
|
|
|
|
Action_RelayOn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(nowSensorState == KCD_HP100_ERROR_TIMEOUT)
|
|
|
|
|
{
|
|
|
|
@ -313,7 +308,7 @@ static void Action_Get_SensorReadProcess(void)
|
|
|
|
|
if(Control_Info.Co2_TempMin > Control_Info.Co2_Now)
|
|
|
|
|
Control_Info.Co2_TempMin = Control_Info.Co2_Now;
|
|
|
|
|
|
|
|
|
|
printf("Now, %04d-%02d-%02d %02d:%02d:%02d, %d, %d, %d\r\n", nowTime.rtc_Year, nowTime.rtc_Month, nowTime.rtc_Date, nowTime.rtc_Hour, nowTime.rtc_Min, nowTime.rtc_Sec, Control_Info.Co2_Now, Control_Info.Co2_TempMax, Control_Info.Co2_TempMin);
|
|
|
|
|
printf("Now, %04d-%02d-%02d %02d:%02d:%02d, %d, %d, %d, %d\r\n", nowTime.rtc_Year, nowTime.rtc_Month, nowTime.rtc_Date, nowTime.rtc_Hour, nowTime.rtc_Min, nowTime.rtc_Sec, Control_Info.Co2_Now, Control_Info.Co2_TempMax, Control_Info.Co2_TempMin, Control_Info.isRelayOn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Action_Get_SensorData();
|
|
|
|
@ -331,12 +326,10 @@ static void Action_SaveSensorData(void)
|
|
|
|
|
SaveCheckSec = nowTime.rtc_Sec;
|
|
|
|
|
if(nowTime.rtc_Sec == 0)
|
|
|
|
|
{
|
|
|
|
|
if(Control_Info.Co2_Now != 0xFFFF){
|
|
|
|
|
SaveSensorCo2[SaveSensorIndex++] = Control_Info.Co2_Now;
|
|
|
|
|
if(Control_Info.Co2_SaveData != 0xFFFF){
|
|
|
|
|
SaveSensorCo2[SaveSensorIndex++] = Control_Info.Co2_SaveData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(nowTime.rtc_Min % 5 == 0)
|
|
|
|
|
{
|
|
|
|
|
if(SaveSensorIndex >= 5)
|
|
|
|
@ -364,10 +357,14 @@ static void Action_SaveSensorData(void)
|
|
|
|
|
Sum_Co2 -= Max_Co2;
|
|
|
|
|
Sum_Co2 -= Min_Co2;
|
|
|
|
|
Sum_Co2 /= (SaveSensorIndex - 2);
|
|
|
|
|
printf("Save, %04d-%02d-%02d %02d:%02d:%02d, %d, %d, %d\r\n", nowTime.rtc_Year, nowTime.rtc_Month, nowTime.rtc_Date, nowTime.rtc_Hour, nowTime.rtc_Min, nowTime.rtc_Sec, Sum_Co2, Max_Co2, Min_Co2);
|
|
|
|
|
if(Save_SensorData_SDCard(Sum_Co2, Max_Co2, Min_Co2, 0xFF) == false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(Save_SensorData_SDCard(Sum_Co2, Max_Co2, Min_Co2, Control_Info.isRelayOn ? 0xFF : 0x00) == false)
|
|
|
|
|
{
|
|
|
|
|
printf("Save fail, %04d-%02d-%02d %02d:%02d:%02d, %d, %d, %d, %d\r\n", nowTime.rtc_Year, nowTime.rtc_Month, nowTime.rtc_Date, nowTime.rtc_Hour, nowTime.rtc_Min, nowTime.rtc_Sec, Sum_Co2, Max_Co2, Min_Co2, Control_Info.isRelayOn);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("Save, %04d-%02d-%02d %02d:%02d:%02d, %d, %d, %d, %d\r\n", nowTime.rtc_Year, nowTime.rtc_Month, nowTime.rtc_Date, nowTime.rtc_Hour, nowTime.rtc_Min, nowTime.rtc_Sec, Sum_Co2, Max_Co2, Min_Co2, Control_Info.isRelayOn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SaveSensorIndex = 0;
|
|
|
|
@ -381,10 +378,8 @@ static void Action_SaveSensorData(void)
|
|
|
|
|
|
|
|
|
|
static void Action_ReturnMainViewCheck(void)
|
|
|
|
|
{
|
|
|
|
|
if(Control_Info.Step != CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA)
|
|
|
|
|
{
|
|
|
|
|
if(millis() - Control_Info.returnMainViewTickCount >= ACTION_RETURN_MAINVIEW_TIME)
|
|
|
|
|
{
|
|
|
|
|
if(Control_Info.Step != CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA){
|
|
|
|
|
if(millis() - Control_Info.returnMainViewTickCount >= ACTION_RETURN_MAINVIEW_TIME){
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D1, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D2, GPIO_LED_MODE_ON, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D3, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
@ -394,9 +389,30 @@ static void Action_ReturnMainViewCheck(void)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_RelayOn(void)
|
|
|
|
|
{
|
|
|
|
|
if(Control_Info.isRelayOn == false){
|
|
|
|
|
Control_Info.isRelayOn = true;
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D4, GPIO_LED_MODE_ON, 0, 0);
|
|
|
|
|
GPIO_RELAY_ON;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_RelayOff(void)
|
|
|
|
|
{
|
|
|
|
|
if(Control_Info.isRelayOn == true){
|
|
|
|
|
Control_Info.isRelayOn = false;
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D4, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
GPIO_RELAY_OFF;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Action_Set_MaxMin_Value(uint16_t MaxValue, uint16_t MinValue)
|
|
|
|
|
{
|
|
|
|
|
Control_Info.Co2_MaxValue = MaxValue;
|
|
|
|
|
Control_Info.Co2_MinValue = MinValue;
|
|
|
|
|
EEPROM_Write_SettingValue(Control_Info.Co2_MaxValue, Control_Info.Co2_MinValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -456,7 +472,6 @@ static void Action_Set_Key_Push(void)
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_RUN_SET_MAX_SENSOR_DATA;
|
|
|
|
|
}
|
|
|
|
|
else if(Control_Info.Step == CONTROL_STEP_ACTION_RUN_MIN_SENSOR_DATA){
|
|
|
|
|
|
|
|
|
|
Buzzer_On(DEFAULT_KEY_PUSH_BUZZER_TIME_COUNT);
|
|
|
|
|
Control_Info.Co2_TempValue = Control_Info.Co2_MinValue;
|
|
|
|
|
Control_Info.SetIndex = SET_1000;
|
|
|
|
|