Git Product home page Git Product logo

ry_key's Introduction

ry_key

概述

嵌入式领域,C语言编写的按键驱动。

  • 两种类型
    • 独立按键
    • 组合键
  • 4种状态
    按下弹起空闲
  • 9类事件
    组合键按压弹起单击双击三击长按超长按无事件

系统结构

数据结构

独立按键

独立按键结构

组合键

组合键结构

独立按键的状态机

状态转移图

独立按键扫描状态机

按键扫描的具体流程

按键扫描的具体流程

如何使用

建议使用一个定时器外设,配置成系统时基,定时调用ry_key_scan

#include "ry_key.h"

static ry_key_t __keyPower;              /* 电源按键 */
static ry_key_t __keyCtr;                /* 控制按键 */
static ry_key_compound_t __compoundKey1; /* 组合键 */


extern uint8_t key_power_get_level(void);
extern uint8_t key_ctr_get_level(void);

void key_power_long_press_callback(ry_key_t *key)
{
	printf("key_power_long_press_callback");
}
void key_ctr_single_click_callback(ry_key_t *key)
{
	printf("key_ctr_single_click_callback");
}
void compound_key1_callback(ry_key_t *key)
{
	printf("compound_key1_callback");
}

void user_key_init(void)
{
	ry_key_reg(&__keyPower, 1, 5, 50, 300, 900, key_power_get_level);
	ry_key_reg(&__keyCtr,   1, 5, 50, 300, 900, key_ctr_get_level);
	ry_key_compound_reg(&__compoundKey1, compound_key1_callback);
	
	RY_KEY_CALLBACK_CFG(__keyPower, KEY_LONG_PRESS_EVENT, key_power_long_press_callback);
	RY_KEY_CALLBACK_CFG(__keyCtr, KEY_SINGLE_CLICK_EVENT, key_ctr_single_click_callback);
	
	ry_key_compound_insert_key_sn(&__compoundKey1, __keyPower.sn);
	ry_key_compound_insert_key_sn(&__compoundKey1, __keyCtr.sn);
}

int main(void)
{
	//system_init();
	user_key_init();
	while(1)
	{
		/* 配置定时器,定时扫描按键效果更好 */
		ry_key_scan();
	}
}

ry_key's People

Contributors

l231 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.