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 "zkey.h"
#define TAG "zkey"
static zkey_module_t *s_module; static bool s_inited;
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); } } }
void zkey_process_each(zkey_t *each) { /**
* @brief zkey_process_each */ each->keep_state_count++;
bool now_io_state = each->get_key_state(); 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) { each->after_filter_state = now_io_state; } each->last_real_state = now_io_state; zkey_process_each_after_filter(each, each->after_filter_state);
/**
* @brief 上报按键状态 */ } void zkey_do_loop_in_each_period(void *_null) { if (!s_inited) return; for (int i = 0; i < s_module->nkey; i++) { zkey_process_each(&s_module->keys[i]); } }
void zkey_init(zkey_module_t *module) { 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(); } }
|