릴레이 동작 추가

main
Imbis 5 months ago
parent efb86b3cb5
commit 94c0d7e670

File diff suppressed because one or more lines are too long

@ -148,24 +148,7 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN2 -FF0A31G12x_series_FLASH -FS00 -FL010000 -FF1A31G12x_series_CFG -FS11FFFF200 -FL1600 -FP0($$Device:A31G123$A31G12x\Flashloader\A31G12x_series_FLASH.FLM) -FP1($$Device:A31G123$A31G12x\Flashloader\A31G12x_series_CFG.FLM))</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>403</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>2750</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Application\action_process.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\S_DustSensorView\Application/action_process.c\403</Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>

@ -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;

@ -18,7 +18,7 @@ typedef enum
void Action_Initialization(void);
void Action_Set_MaxMin_Value(uint16_t MaxValue, uint16_t MinValue);

@ -8,3 +8,9 @@ void Gpio_Sensor_PWR_Initialization(void)
GPIO_SENSOR_PWR_OFF;
}
void Gpio_Relay_Initialization(void)
{
HAL_GPIO_ConfigOutput(GPIO_RELAY_PORT, GPIO_RELAY_PIN_NUM, PUSH_PULL_OUTPUT);
HAL_GPIO_ConfigPullup(GPIO_RELAY_PORT, GPIO_RELAY_PIN_NUM, PUPDx_EnablePU);
GPIO_RELAY_OFF;
}

@ -11,8 +11,17 @@
#define GPIO_SENSOR_PWR_OFF HAL_GPIO_ClearPin(GPIO_SENSOR_PWR_PORT, _BIT(GPIO_SENSOR_PWR_PIN_NUM))
#define GPIO_SENSOR_PWR_T HAL_GPIO_TogglePin(GPIO_SENSOR_PWR_PORT, _BIT(GPIO_SENSOR_PWR_PIN_NUM))
void Gpio_Sensor_PWR_Initialization(void);
#define GPIO_RELAY_PORT (Pn_Type*)PD
#define GPIO_RELAY_PIN_NUM 5
#define GPIO_RELAY_ON HAL_GPIO_SetPin(GPIO_RELAY_PORT, _BIT(GPIO_RELAY_PIN_NUM))
#define GPIO_RELAY_OFF HAL_GPIO_ClearPin(GPIO_RELAY_PORT, _BIT(GPIO_RELAY_PIN_NUM))
#define GPIO_RELAY_T HAL_GPIO_TogglePin(GPIO_RELAY_PORT, _BIT(GPIO_RELAY_PIN_NUM))
void Gpio_Sensor_PWR_Initialization(void);
void Gpio_Relay_Initialization(void);
#endif

@ -22,7 +22,7 @@
void timer_test(void)
{
// GPIO_RELAY_T;
}
@ -45,6 +45,7 @@ int main(void)
Buzzer_Initialization();
Gpio_Sensor_PWR_Initialization();
Gpio_Relay_Initialization();
Gpio_Switch_Port_Initialization();
Gpio_StateLed_Initialization();
@ -61,7 +62,7 @@ int main(void)
__enable_irq();
//SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 1000, timer_test);
//SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 100, timer_test);
while(true)

@ -3,6 +3,7 @@
#include "uart1.h"
#include "driver_ds3231_basic.h"
#include "buzzer.h"
#include "action_process.h"
#define PACKET_BUFF_SIZE 100
@ -125,6 +126,22 @@ static void Uart_Packet_Process(uint8_t* pRxBuff)
Buzzer_On(100);
}
else if(cmd == UART_CMD_SET_THRESHOLD && DataLen == 4)
{
uint16_t Max_Threshold;
uint16_t Min_Threshold;
uint8_t index = 0;
Max_Threshold = pRxBuff[PACK_INDEX_DATA + index++] << 8;
Max_Threshold += pRxBuff[PACK_INDEX_DATA + index++];
Min_Threshold = pRxBuff[PACK_INDEX_DATA + index++] << 8;
Min_Threshold += pRxBuff[PACK_INDEX_DATA + index++];
Action_Set_MaxMin_Value(Max_Threshold, Min_Threshold);
Buzzer_On(100);
}

@ -22,6 +22,7 @@ typedef enum
typedef enum
{
UART_CMD_SET_TIME = 0x00,
UART_CMD_SET_THRESHOLD = 0x01,
UART_CMD_MAX,
}UART_CMD;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save