|
|
|
@ -9,9 +9,56 @@
|
|
|
|
|
#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
|
|
|
|
|
#define KEY_DOWN KEY_PUSH_SW4
|
|
|
|
|
|
|
|
|
|
typedef enum _control_step
|
|
|
|
|
{
|
|
|
|
|
CONTROL_STEP_INIT,
|
|
|
|
|
CONTROL_STEP_INIT_BUZZER_ON,
|
|
|
|
|
CONTROL_STEP_INIT_ALL_LED_ON,
|
|
|
|
|
CONTROL_STEP_INIT_ALL_LED_ON_WAIT,
|
|
|
|
|
CONTROL_STEP_INIT_VERSION_ON,
|
|
|
|
|
CONTROL_STEP_INIT_VERSION_ON_WAIT,
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _control_info
|
|
|
|
|
{
|
|
|
|
|
bool isInitView;
|
|
|
|
|
bool isActionRun;
|
|
|
|
|
CONTROL_STEP Step;
|
|
|
|
|
uint32_t StartTickCount;
|
|
|
|
|
uint32_t Co2_Now;
|
|
|
|
|
uint32_t Co2_MaxValue;
|
|
|
|
|
uint32_t Co2_MinValue;
|
|
|
|
|
}CONTROL_INFO;
|
|
|
|
@ -25,12 +72,36 @@ 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_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);
|
|
|
|
|
|
|
|
|
|
#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)
|
|
|
|
|
{
|
|
|
|
|
Control_Info.isInitView = false;
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gpio_Swtich_Set_Callback(KEY_MODE_SET, Action_Mode_Key_Push, Action_Set_Key_Push, NULL);
|
|
|
|
|
Gpio_Swtich_Set_Callback(KEY_UP, Action_Up_Key_Push, NULL, NULL);
|
|
|
|
|
Gpio_Swtich_Set_Callback(KEY_DOWN, Action_Down_Key_Push, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 1, Action_Process);
|
|
|
|
|
}
|
|
|
|
@ -38,13 +109,187 @@ void Action_Initialization(void)
|
|
|
|
|
|
|
|
|
|
static void Action_Process(void)
|
|
|
|
|
{
|
|
|
|
|
if(Control_Info.isInitView == false)
|
|
|
|
|
{
|
|
|
|
|
Action_PowerOn_Init_Process();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(Control_Info.isActionRun == true)
|
|
|
|
|
Action_PowerOn_Process();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_PowerOn_Init_Process(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t i;
|
|
|
|
|
switch(Control_Info.Step)
|
|
|
|
|
{
|
|
|
|
|
case CONTROL_STEP_INIT:
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT_BUZZER_ON;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_INIT_BUZZER_ON:
|
|
|
|
|
Buzzer_On(500);
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT_ALL_LED_ON;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_INIT_ALL_LED_ON:
|
|
|
|
|
Segment_All_Set_Data(0xFF);
|
|
|
|
|
for(i = 0 ; i < GPIO_LED_MAX ; i++)
|
|
|
|
|
{
|
|
|
|
|
Gpio_Led_OutputSet(i, GPIO_LED_MODE_ON, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
Control_Info.StartTickCount = millis();
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT_ALL_LED_ON_WAIT;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_INIT_ALL_LED_ON_WAIT:
|
|
|
|
|
if((millis() - Control_Info.StartTickCount) >= ACTION_INIT_LED_ON_WAIT_TIME)
|
|
|
|
|
{
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT_VERSION_ON;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_INIT_VERSION_ON:
|
|
|
|
|
Segment_Show_Version();
|
|
|
|
|
Control_Info.StartTickCount = millis();
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT_VERSION_ON_WAIT;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_INIT_VERSION_ON_WAIT:
|
|
|
|
|
if((millis() - Control_Info.StartTickCount) >= ACTION_INIT_LED_ON_WAIT_TIME)
|
|
|
|
|
{
|
|
|
|
|
Segment_All_Set_Data(0x00);
|
|
|
|
|
for(i = 0 ; i < GPIO_LED_MAX ; i++)
|
|
|
|
|
{
|
|
|
|
|
Gpio_Led_OutputSet(i, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT_POWER_ON_KEY_SET;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_INIT_POWER_ON_KEY_SET:
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_LE1, GPIO_LED_MODE_TOGGLE, ACTION_LE1_IDLE_ON_TIME, ACTION_LE1_IDLE_OFF_TIME);
|
|
|
|
|
Action_Power_On_Key_Set();
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT_COMPLETE;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_INIT_COMPLETE:
|
|
|
|
|
Control_Info.isInitView = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_PowerOn_Process(void)
|
|
|
|
|
{
|
|
|
|
|
switch (Control_Info.Step)
|
|
|
|
|
{
|
|
|
|
|
case CONTROL_STEP_INIT:
|
|
|
|
|
Action_Power_Off_Key_Set();
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_LE1, GPIO_LED_MODE_TOGGLE, ACTION_LE1_RUN_ON_TIME, ACTION_LE1_RUN_OFF_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);
|
|
|
|
|
if(EEPROM_Read_SettingValue(&Control_Info.Co2_MaxValue, &Control_Info.Co2_MinValue) == false)
|
|
|
|
|
{
|
|
|
|
|
Control_Info.Co2_MaxValue = DEFAULT_SENSOR_MAX_DATA;
|
|
|
|
|
Control_Info.Co2_MinValue = DEFAULT_SENSOR_MIN_DATA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA:
|
|
|
|
|
Segment_Show_Time();
|
|
|
|
|
Segment_Show_SensorData(Control_Info.Co2_Now);
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_MAX_SENSOR_DATA:
|
|
|
|
|
Segment_Show_Time();
|
|
|
|
|
Segment_Show_SensorData(Control_Info.Co2_MaxValue);
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_MIN_SENSOR_DATA:
|
|
|
|
|
Segment_Show_Time();
|
|
|
|
|
Segment_Show_SensorData(Control_Info.Co2_MinValue);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_SET_MAX_SENSOR_DATA:
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_SET_MIN_SENSOR_DATA:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_COMPLETE:
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_LE1, GPIO_LED_MODE_TOGGLE, ACTION_LE1_IDLE_ON_TIME, ACTION_LE1_IDLE_OFF_TIME);
|
|
|
|
|
Action_Power_On_Key_Set();
|
|
|
|
|
Segment_All_Set_Data(0x00);
|
|
|
|
|
EEPROM_Write_SettingValue(Control_Info.Co2_MaxValue, Control_Info.Co2_MinValue);
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT;
|
|
|
|
|
Control_Info.isActionRun = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_Power_On_Key_Set(void)
|
|
|
|
|
{
|
|
|
|
|
Gpio_Swtich_Set_PushCount(KEY_POWER, DEFAULT_KEY_PUSH_COUNT, KEY_POWER_ON_CHECK_PUSH_COUNT);
|
|
|
|
|
Gpio_Swtich_Set_Callback(KEY_POWER, NULL, Action_Power_On_Key_Push_Callback, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_Power_Off_Key_Set(void)
|
|
|
|
|
{
|
|
|
|
|
Gpio_Swtich_Set_PushCount(KEY_POWER, DEFAULT_KEY_PUSH_COUNT, KEY_POWER_OFF_CHECK_PUSH_COUNT);
|
|
|
|
|
Gpio_Swtich_Set_Callback(KEY_POWER, NULL, Action_Power_Off_Key_Push_Callback, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Action_Power_On_Key_Push_Callback(void)
|
|
|
|
|
{
|
|
|
|
|
Buzzer_On(DEFAULT_KEY_PUSH_BUZZER_TIME_COUNT);
|
|
|
|
|
Control_Info.isActionRun = true;
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_INIT;
|
|
|
|
|
dbg_printf("power on\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_Power_Off_Key_Push_Callback(void)
|
|
|
|
|
{
|
|
|
|
|
Buzzer_On(DEFAULT_KEY_PUSH_BUZZER_TIME_COUNT);
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_RUN_COMPLETE;
|
|
|
|
|
dbg_printf("power off\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_Mode_Key_Push(void)
|
|
|
|
|
{
|
|
|
|
|
switch(Control_Info.Step)
|
|
|
|
|
{
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA:
|
|
|
|
|
Buzzer_On(DEFAULT_KEY_PUSH_BUZZER_TIME_COUNT);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D1, GPIO_LED_MODE_ON, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D2, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D3, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_RUN_MAX_SENSOR_DATA;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_MAX_SENSOR_DATA:
|
|
|
|
|
Buzzer_On(DEFAULT_KEY_PUSH_BUZZER_TIME_COUNT);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D1, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D2, GPIO_LED_MODE_OFF, 0, 0);
|
|
|
|
|
Gpio_Led_OutputSet(GPIO_LED_D3, GPIO_LED_MODE_ON, 0, 0);
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_RUN_MIN_SENSOR_DATA;
|
|
|
|
|
break;
|
|
|
|
|
case CONTROL_STEP_ACTION_RUN_MIN_SENSOR_DATA:
|
|
|
|
|
Buzzer_On(DEFAULT_KEY_PUSH_BUZZER_TIME_COUNT);
|
|
|
|
|
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);
|
|
|
|
|
Control_Info.Step = CONTROL_STEP_ACTION_RUN_NOW_SENSOR_DATA;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_Set_Key_Push(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Action_Up_Key_Push(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Action_Down_Key_Push(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|