|
|
#include "main.h"
#include <stdbool.h> //���岼��
#include "board.h"
/***********************************************************************************************************************
* =====================================================��������====================================================== * ***********************************************************************************************************************/ void onkey(zkey_t *key, zkey_state_t key_state); /***********************************************************************************************************************
* =====================================================ȫ�ֱ���====================================================== * ***********************************************************************************************************************/
static zkey_t s_keys[] = { ZKEY_INIT("timerkey", port_gpio_get_timer_key_state), ZKEY_INIT("gearskey", port_gpio_get_gears_key_state), ZKEY_INIT("intervalkey", port_gpio_get_interval_key_state), ZKEY_INIT("switchkey", port_gpio_get_switch_key_state), }; zkey_module_t key_module = ZMODULE_INIT(s_keys, onkey);
/***********************************************************************************************************************
* =====================================================ȫ��״̬====================================================== * ***********************************************************************************************************************/ static bool error_even_trigger_after_stop_ozone_work_state; //�����¼�������ֹͣ����������־λ
// ����
bool g_setting_interval_work_flag = false; //���ڵĵ�λ
WORK_LEVEL_T g_setting_level = WORK_LEVEL_LOW; //�ػ�ǰ�ĵ�λ
//��־λ
bool g_power_flag = false; //���ػ���־λ
static int g_error_num; bool g_auto_shutdown_flag = false; //��ʱ����ʹ�ܱ�־λ
static uint32_t g_auto_shutdown_countdown_s; //��ʱʱ��
//����
static bool pwm_modble_enable_falg; //Ӳ��pwmʹ�ܱ�־λ
/***********************************************************************************************************************
* =======================================================HOOK======================================================== * ***********************************************************************************************************************/ void HOOK_pwm_module_set_pwm_duty(uint32_t frequency, uint32_t duty) { set_pwm_modbul_freq_duty(frequency, duty); port_fan_set(true); //����
pwm_modble_enable_falg = true; printf("work\r\n"); } void HOOK_pwm_stop(void) { set_pwm_modbul_freq_duty(1, 0); //�ر�PWM����
port_fan_set(false); //���Ƚ�������
pwm_modble_enable_falg = false; printf("rest\r\n"); } bool HOOK_pwm_is_enable(void) { return pwm_modble_enable_falg; } int hook_get_autoshutdown_timecount() { return g_auto_shutdown_countdown_s; }
/***********************************************************************************************************************
* =================================================INTERNAL_FUNCTION================================================= * ***********************************************************************************************************************/ /**
* @brief ���ݵ�λ����pwm������rgb����ɫ * * @param gears */ void update_ozone_work_level(bool interval_work, WORK_LEVEL_T level) { printf("update_ozone_work_level(interval_work:%d,level:%d)\n", interval_work, level); rgb_light_mode_t lightmode; int duty = 0;
if (level == WORK_LEVEL_CLOSE) { duty = 0; lightmode = RGB_CLOSE; } else if (level == WORK_LEVEL_LOW) { duty = 25; lightmode = RGB_COLOR_GERRN; } else if (level == WORK_LEVEL_MIDDLE) { duty = 50; lightmode = RGB_COLOR_BLUE; } else if (level == WORK_LEVEL_HIGHT) { duty = 100; lightmode = RGB_COLOR_RED; }
if (interval_work) { ozone_pwm_control_module_set_pwm_output_2(1, 0, INTERVAL_WORK_PERIOD_MS,INTERVAL_WORK_DUTY); } else { set_pwm_modbul_freq_duty(1, duty); } light_module_set_rgb_mode(lightmode); light_module_set_rgb_flicker_mode(interval_work); }
/**
* @brief �ػ� */ void shutdown(void) { printf("shutdown\n"); g_power_flag = false; g_error_num = 0; g_auto_shutdown_flag = false; g_auto_shutdown_countdown_s = 0;
update_ozone_work_level(false, WORK_LEVEL_CLOSE); port_fan_set(false); //�رշ���
light_module_close_all_light(); } /***********************************************************************************************************************
* ======================================================����======================================================= * ***********************************************************************************************************************/ void iwdt_init(void) { /**
* @brief ���Ź����ܣ���������0ʱ�����ڼ�����+1 * �����ڼ���Ϊ��2����ʱ�����ж� * �����ڼ�����Ϊ��4����֮ǰû�н���ι��������������λ */ IWDT_InitStruType x;
x.WDT_Tms = 4000; x.WDT_IE = Enable; /* IWDT�ж�ʹ�� */ x.WDT_Rst = Enable; /* IWDT��λʹ�� */ x.WDT_Clock = IWDT_CLOCK_WDT; /* LRC */ IWDT_Init(&x); /* ʹ��IWDT */ IWDT_Enable(); } void feed_iwdt(void) { //ι��
if (0x01 == IWDT_GetFlagStatus()) { IWDT_Clear(); // printf("�\r\n");
} }
void onkey(zkey_t *key, zkey_state_t key_state) { if (key->hasProcessed) return; /**
* @brief �ػ�ʱ��ֻ������Դ���� */ if (!g_power_flag) { if (key == &s_keys[3] && key->cur_state == zks_falling_edge) { key->hasProcessed = true; printf("key zks_rising_edge\r\n"); /**
* @brief ���� * 1.���ñ�־λ * 2.���� * 3.������������Ӧ��ָʾ�� */
g_power_flag = true; //���ػ���־λ
g_error_num = 0; g_auto_shutdown_flag = false; //��ʱ����ʹ�ܱ�־λ
g_auto_shutdown_countdown_s = 0; //��ʱʱ��
port_fan_set(true); //����������
update_ozone_work_level(g_setting_interval_work_flag, g_setting_level); } return; }
/**
* @brief �����쳣ʱ�����˵�Դ�����⣬���а���ʧЧ�� */ if (g_error_num != 0) { //�豸�����쳣
if (key == &s_keys[3] && key->cur_state == zks_falling_edge) { key->hasProcessed = true; printf("process key[2] event\r\n"); /**
* @brief �ػ� */ shutdown(); } return; }
if (key == &s_keys[0] && key->cur_state == zks_falling_edge) //��3s
{ printf("process key[0] event\r\n"); /**
* @brief ������ʱ�����¼� */ if (!g_auto_shutdown_flag) { g_auto_shutdown_flag = true; g_auto_shutdown_countdown_s = 0; } g_auto_shutdown_countdown_s += AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S; } else if (key == &s_keys[1] && key->cur_state == zks_falling_edge) { /**
* @brief �����ȼ����� */ printf("process key[1] event\r\n"); if (g_setting_level == WORK_LEVEL_HIGHT) { update_ozone_work_level(g_setting_interval_work_flag, WORK_LEVEL_LOW); } else if (g_setting_level == WORK_LEVEL_MIDDLE) { update_ozone_work_level(g_setting_interval_work_flag, WORK_LEVEL_HIGHT); } else if (g_setting_level == WORK_LEVEL_LOW) { update_ozone_work_level(g_setting_interval_work_flag, WORK_LEVEL_MIDDLE); } } else if (key == &s_keys[2] && key->cur_state == zks_falling_edge) { printf("process key[2] event\r\n"); /**
* @brief ������Ъ�����¼� */ g_setting_interval_work_flag = !g_setting_interval_work_flag; update_ozone_work_level(g_setting_interval_work_flag, g_setting_level); } else if (key == &s_keys[3] && key->cur_state == zks_falling_edge) { printf("process key[2] event\r\n"); /**
* @brief �ػ� */ shutdown(); } } /***********************************************************************************************************************
* ======================================================������======================================================= ***********************************************************************************************************************/ int main(void) { HRC_Config(Enable, SCU_HRC_48M, Enable); //ʱ��ԴSCU_CLK_HRC
SystemInit(); DeviceClockAllEnable(); //������������ʱ��
User_SysTickInit(); //�δ���ʱ����ʼ��Ϊ(����Ϊ1ms�ж�)
SysTick_Enable(); //Ӳ����ʼ��
unused_gpio_init(); gpio_init(); uart0_init(); t16_pa4_init();
//ģ����ʼ��
zkey_init(&key_module);
//�ϵ�Ĭ�Ϲػ�
shutdown();
//��������
printf("Initialization completed\r\n");
while (true) { /*******************************************************************************************************************
* ==================================================����ָʾ��=================================================== * *******************************************************************************************************************/ port_do_debug_light_state();
/***********************************************************************************************************************
* =================================================����ģ�����ȴ���================================================== * ***********************************************************************************************************************/ { static uint32_t keylastprocess = 0; if (port_haspassedms(keylastprocess) > KEY_PERIOD) { keylastprocess = get_sys_ticket(); zkey_do_loop_in_each_period(NULL); } } /***********************************************************************************************************************
* ===============================================�ƹ�����ģ�����ȴ���================================================ * ***********************************************************************************************************************/ light_module_schedule();
/***********************************************************************************************************************
* ===============================================��������ģ�����ȴ���================================================ * ***********************************************************************************************************************/ ozone_pwm_control_module_loop();
/***********************************************************************************************************************
* ===================================================�Զ��ػ���==================================================== * ***********************************************************************************************************************/ //
if (g_power_flag && g_auto_shutdown_flag) { static uint32_t ticket = 0; ticket = get_sys_ticket(); //
if (port_haspassedms(ticket) > 1000) { ticket = get_sys_ticket(); if (g_auto_shutdown_countdown_s > 0) { g_auto_shutdown_countdown_s -= 1; } else { g_auto_shutdown_flag = false; /**
* @brief ������ʱ�ػ� */ shutdown(); } } //
} /***********************************************************************************************************************
* ===================================================�쳣������==================================================== ***********************************************************************************************************************/ { static uint32_t ticket = 0; if (port_haspassedms(ticket) > EXCEPTION_CHECK_PERIOD) { ticket = get_sys_ticket();
/**
* @brief * ��������ADC����ֵ�Ƿ��涨��Χ */ if (false) { } } } // End..................................
} }
|