You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include "key.h"
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);
void zkey_init(zkey_module_t *module) { /**
* @brief ������ʼ��������״̬�ij�ʼ����֮ǰ�ģ����ڵģ�֮���� * */ s_module = module; s_inited = true; //��־λ˵��������ʼ������
for (int i = 0; i < s_module->nkey; i++) { s_module->keys[i].cur_state = zks_keep; s_module->keys[i].last_io_state = s_module->keys[i].get_key_state(); s_module->keys[i].after_filter_state = s_module->keys[i].get_key_state(); } }
void zkey_do_loop_in_each_period(void *_null) { /**
* @brief ѭ����ѯ������״̬ * */ if (!s_inited) return; for (int i = 0; i < s_module->nkey; i++) //��ʼ��ÿ���������в�ѯ
{ zkey_process_each(&s_module->keys[i]); } }
void zkey_process_each(zkey_t *each) { /**
* @brief �����Ƿ������任��û�任��ʱ������ʱ����¼ * * @param each */ each->keep_state_count++;
bool now_io_state = each->get_key_state(); //��ȡ���ڵİ���io״̬
if (each->currentstatekeep_count < 1000) { each->currentstatekeep_count++; } if (now_io_state != each->last_real_state) //�����任
{ each->currentstatekeep_count = 0; } if (each->currentstatekeep_count >= 1) //����״̬����ʱ������20ms,���°���״̬
{ each->after_filter_state = now_io_state; } each->last_real_state = now_io_state; zkey_process_each_after_filter(each, each->after_filter_state); }
void zkey_process_each_after_filter(zkey_t *each, bool now_io_state) { if (now_io_state != each->last_io_state) { if (now_io_state) { each->keep_state_count = 0; each->hasProcessed = false; each->cur_state = zks_rising_edge; s_module->onkey(each, each->cur_state); } else { each->cur_state = zks_falling_edge; s_module->onkey(each, each->cur_state); each->keep_state_count = 0; } each->last_io_state = now_io_state; } else { each->cur_state = zks_keep; if (now_io_state) { s_module->onkey(each, each->cur_state); } } } //############################### ԭ����main�еķ��� ���¶���
//###############################//
extern uint32_t g_frequency; extern uint32_t g_duty[4]; extern int g_ozen_gears; extern uint32_t g_count_down_begin_sys_time; extern int time_key_press_frequency; //ÿ����4�ν�����0
extern uint32_t g_ozone_work_time; //##############�µ�############
extern pwm_message_t pwm_message; extern rgb_message_t rgb_message; shutdown_before_message_t shutdown_before_message; void process_switchkey(void) { static uint8_t switchkey_press_conut = 0; switchkey_press_conut++; switch (switchkey_press_conut) { case 1: //����������ģʽΪ�ػ�ǰ�Ĺ���ģʽ,��ʱ��Ъ
pwm_module_set_pwm_output_2( shutdown_before_message.hardware_frequency, shutdown_before_message.hardware_duty, shutdown_before_message.large_period, shutdown_before_message.large_duty); light_module_set_rgb_mode(rgb_message.turn_off_the_mode_before_rgb); port_fan_set(true); break; case 2: //�ػ�
switchkey_press_conut = 0; shutdown_before_message.hardware_duty=pwm_message.s_hardware_duty; shutdown_before_message.hardware_frequency=pwm_message.s_hardware_frequency; shutdown_before_message.large_duty=pwm_message.s_large_duty; shutdown_before_message.large_period=pwm_message.s_large_period; light_module_set_rgb_mode(RGB_CLOSE); light_module_set_timing_light_mode(CLOSE_ALL_LED); pwm_module_set_pwm_output_2(1,100,0,0); port_fan_set(false); break; } }
void onkey(zkey_t *key, zkey_state_t key_state) { /**
* @brief �ж�ÿ������������״̬ * * @param key * @param key_state */ if (get_ozone_starting_up_state()) { //������
if (key == &s_keys[0] && //��ʱ����
key->cur_state == zks_keep && //����
!key->hasProcessed && //û�б�������
key->keep_state_count >= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) //���³���ʱ������3s
{ key->hasProcessed = true; // printf("key0 zks_keep\r\n");
// stop_ozone_work();
} else if (key == &s_keys[0] && //��ʱ����
key->cur_state == zks_falling_edge && //�½��ش���
!key->hasProcessed && key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) //��3s
{ key->hasProcessed = true; printf("key0 zks_falling_edge\r\n"); // set_ozone_work_time();
// set_timing_time(running_time.timing_time_state);
} else if (key == &s_keys[1] && //�ߵ͵�λѡ��
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) { key->hasProcessed = true; // key_control_switch_gears(g_switch_gears);
printf("key1 zks_rising_edge\r\n"); // set_ozen_gears(g_ozen_gears);
} else if (key == &s_keys[2] && //��Ъʱ��ѡ��
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) { key->hasProcessed = true; printf("key2 zks_rising_edge\r\n"); // set_interval_time();
// set_interval_time(running_time.interval_time_state);
} // else if (key == &s_keys[3] && //����
// key->cur_state == zks_rising_edge && //
// !key->hasProcessed && //
// key->keep_state_count <=
// POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) {
// key->hasProcessed = true;
// printf("key3 zks_rising_edge\r\n");
// process_switch_key();
// // set_interval_time(running_time.interval_time_state);
// }
} // else {
if (key == &s_keys[3] && //����
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) { key->hasProcessed = true; printf("key zks_rising_edge\r\n"); // process_switch_key();
process_switchkey(); // set_interval_time(running_time.interval_time_state);
} // }
} void port_key_state(void) { static uint32_t keylastprocess = 0; if (port_haspassedms(keylastprocess) > 20) { keylastprocess = get_sys_ticket(); zkey_do_loop_in_each_period(NULL); } }
|