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.
 
 
 
 

69 lines
2.0 KiB

#pragma once
#include "port.h"
#include "ozone_work.h"
#include "pwm.h"
#define POWER_KEY_TRIGGER_TIME 3000
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define ZKEY_INIT(_name, _get_key_state) \
{ .name = _name, .get_key_state = _get_key_state }
#define ZMODULE_INIT(_keys, _onkey) /**/ \
{ /**/ \
.keys = _keys, /**/ \
.nkey = ARRAY_SIZE(_keys), /**/ \
.onkey = _onkey /**/ \
}
typedef enum {
// mode1
zks_keep,
zks_rising_edge, //上升沿按键按下从0-1
zks_falling_edge, //下降沿按键抬起1-0
// mode2
zks_trigger_event, //触发
zks_longtime_trigger_event, //长时间触发
} zkey_event_t;
typedef zkey_event_t zkey_state_t;
typedef bool (*get_key_state_t)(void);
typedef struct {
const char *name;
get_key_state_t get_key_state;
bool last_io_state;
zkey_state_t cur_state; //当前的状态
uint32_t keep_state_count; /*按键当前状态保持了多久*/
bool hasProcessed; /*useful for user*/
bool after_filter_state;
uint32_t currentstatekeep_count; //消抖使用
bool last_real_state; //消抖使用
} zkey_t;
static uint16_t s_key_press_state;
static uint16_t s_key_long_press_time_ms = 3000; //长按判断时间
#define KEY_SCAN_PERIOD 20 //扫描周期20ms
typedef struct {
zkey_t *keys;
int nkey;
void (*onkey)(zkey_t *key, zkey_state_t key_state);
} zkey_module_t;
static zkey_module_t *s_module;
static bool s_inited;
void zkey_init(zkey_module_t *module);
void zkey_do_loop_in_each_period(void *_null);
void zkey_process_each(zkey_t *each);
void zkey_process_each_after_filter(zkey_t *each, bool now_io_state);
void read_key_state(void);
void onkey(zkey_t *key, zkey_state_t key_state);
void port_key_state(void);