当前位置: 首页 > news >正文

做红包网站是犯法的吗正规培训机构有哪些

做红包网站是犯法的吗,正规培训机构有哪些,泰安网签查询系统,网络运维和网站开发哪个好MultiButton 简介 MultiButton 是一个小巧简单易用的事件驱动型按键驱动模块,可无限量扩展按键,按键事件的回调异步处理方式可以简化你的程序结构,去除冗余的按键处理硬编码,让你的按键业务逻辑更清晰。 使用方法 1.先申请一个…

MultiButton

简介

MultiButton 是一个小巧简单易用的事件驱动型按键驱动模块,可无限量扩展按键,按键事件的回调异步处理方式可以简化你的程序结构,去除冗余的按键处理硬编码,让你的按键业务逻辑更清晰。

使用方法

1.先申请一个按键结构

struct Button button1;

2.初始化按键对象,绑定按键的GPIO电平读取接口read_button_pin() ,后一个参数设置有效触发电平

button_init(&button1, read_button_pin, 0, 0);

3.注册按键事件

button_attach(&button1, SINGLE_CLICK, Callback_SINGLE_CLICK_Handler);
button_attach(&button1, DOUBLE_CLICK, Callback_DOUBLE_Click_Handler);
...

4.启动按键

button_start(&button1);

5.设置一个5ms间隔的定时器循环调用后台处理函数

while(1) {...if(timer_ticks == 5) {timer_ticks = 0;button_ticks();}
}

特性

MultiButton 使用C语言实现,基于面向对象方式设计思路,每个按键对象单独用一份数据结构管理:

struct Button {uint16_t ticks;uint8_t  repeat: 4;uint8_t  event : 4;uint8_t  state : 3;uint8_t  debounce_cnt : 3;uint8_t  active_level : 1;uint8_t  button_level : 1;uint8_t  button_id;uint8_t  (*hal_button_Level)(uint8_t  button_id_);BtnCallback  cb[number_of_event];struct Button* next;
};

这样每个按键使用单向链表相连,依次进入 button_handler(struct Button* handle) 状态机处理,所以每个按键的状态彼此独立。

按键事件

事件说明
PRESS_DOWN按键按下,每次按下都触发
PRESS_UP按键弹起,每次松开都触发
PRESS_REPEAT重复按下触发,变量repeat计数连击次数
SINGLE_CLICK单击按键事件
DOUBLE_CLICK双击按键事件
LONG_PRESS_START达到长按时间阈值时触发一次
LONG_PRESS_HOLD长按期间一直触发

Examples

#include "button.h"unit8_t btn1_id = 0;struct Button btn1;uint8_t read_button_GPIO(uint8_t button_id)
{// you can share the GPIO read function with multiple Buttonsswitch(button_id){case btn1_id:return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);break;default:return 0;break;}
}
void BTN1_PRESS_DOWN_Handler(void* btn)
{//do something...
}void BTN1_PRESS_UP_Handler(void* btn)
{//do something...
}...int main()
{button_init(&btn1, read_button_GPIO, 0, btn1_id);button_attach(&btn1, PRESS_DOWN,       BTN1_PRESS_DOWN_Handler);button_attach(&btn1, PRESS_UP,         BTN1_PRESS_UP_Handler);button_attach(&btn1, PRESS_REPEAT,     BTN1_PRESS_REPEAT_Handler);button_attach(&btn1, SINGLE_CLICK,     BTN1_SINGLE_Click_Handler);button_attach(&btn1, DOUBLE_CLICK,     BTN1_DOUBLE_Click_Handler);button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler);button_attach(&btn1, LONG_PRESS_HOLD,  BTN1_LONG_PRESS_HOLD_Handler);button_start(&btn1);//make the timer invoking the button_ticks() interval 5ms.//This function is implemented by yourself.__timer_start(button_ticks, 0, 5);while(1){}
}

开源移植 STM32

源文件 main.c

#include "stm32f10x.h"
#include "Delay.h"
#include "LED.h"
#include "KEY.h"
#include "multi_button.h"int main()
{LED_Init(); // LED初始化KEY_Init(); // 按键初始化while (1){Delay_ms(5);button_ticks();// 按键运行}
}

源文件multi_button.c

/** Copyright (c) 2016 Zibin Zheng <znbin@qq.com>* All rights reserved*/#include "multi_button.h"#define EVENT_CB(ev)   if(handle->cb[ev])handle->cb[ev]((void*)handle)
#define PRESS_REPEAT_MAX_NUM  15 /*!< The maximum value of the repeat counter *///button handle list head.
static struct Button* head_handle = NULL;static void button_handler(struct Button* handle);/*** @brief  Initializes the button struct handle.* @param  handle: the button handle struct.* @param  pin_level: read the HAL GPIO of the connected button level.* @param  active_level: pressed GPIO level.* @param  button_id: the button id.* @retval None*/
void button_init(struct Button* handle, u8(*pin_level)(u8), u8 active_level, u8 button_id)
{memset(handle, 0, sizeof(struct Button));handle->event = (u8)NONE_PRESS;handle->hal_button_Level = pin_level;handle->button_level = handle->hal_button_Level(button_id);handle->active_level = active_level;handle->button_id = button_id;
}//  /*button1 init*/
//  button_init(&btn1, read_button_GPIO, 0, KEY1_id);                      // 初始化按键结构体
//  button_attach(&btn1, SINGLE_CLICK, BTN1_SINGLE_CLICK_Handler);         // 添加单击事件
//  button_attach(&btn1, DOUBLE_CLICK, BTN1_DOUBLE_CLICK_Handler);         // 添加双击事件
//  button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler); // 添加长按事件
//  button_start(&btn1);                                                   // 启动按键  /*** @brief  Attach the button event callback function.* @param  handle: the button handle struct.* @param  event: trigger event type.* @param  cb: callback function.* @retval None*/
void button_attach(struct Button* handle, PressEvent event, BtnCallback7 cb)
{handle->cb[event] = cb;
}/*** @brief  Inquire the button event happen.* @param  handle: the button handle struct.* @retval button event.*/
PressEvent get_button_event(struct Button* handle)
{return (PressEvent)(handle->event);
}/*** @brief  Button driver core function, driver state machine.* @param  handle: the button handle struct.* @retval None*/
static void button_handler(struct Button* handle)
{u8 read_gpio_level = handle->hal_button_Level(handle->button_id);//ticks counter working..4if((handle->state) > 0) handle->ticks++;/*------------button debounce handle---------------*/if(read_gpio_level != handle->button_level) { //not equal to prev one//continue read 3 times same new level changeif(++(handle->debounce_cnt) >= DEBOUNCE_TICKS) {handle->button_level = read_gpio_level;handle->debounce_cnt = 0;}} else { //level not change ,counter reset.handle->debounce_cnt = 0;}/*-----------------State machine-------------------*/switch (handle->state) {case 0:if(handle->button_level == handle->active_level) {	//start press downhandle->event = (u8)PRESS_DOWN;EVENT_CB(PRESS_DOWN);handle->ticks = 0;handle->repeat = 1;handle->state = 1;} else {handle->event = (u8)NONE_PRESS;}break;case 1:if(handle->button_level != handle->active_level) { //released press uphandle->event = (u8)PRESS_UP;EVENT_CB(PRESS_UP);handle->ticks = 0;handle->state = 2;} else if(handle->ticks > LONG_TICKS) {handle->event = (u8)LONG_PRESS_START;EVENT_CB(LONG_PRESS_START);handle->state = 5;}break;case 2:if(handle->button_level == handle->active_level) { //press down againhandle->event = (u8)PRESS_DOWN;EVENT_CB(PRESS_DOWN);if(handle->repeat != PRESS_REPEAT_MAX_NUM) {handle->repeat++;}EVENT_CB(PRESS_REPEAT); // repeat hithandle->ticks = 0;handle->state = 3;} else if(handle->ticks > SHORT_TICKS) { //released timeoutif(handle->repeat == 1) {handle->event = (u8)SINGLE_CLICK;EVENT_CB(SINGLE_CLICK);} else if(handle->repeat == 2) {handle->event = (u8)DOUBLE_CLICK;EVENT_CB(DOUBLE_CLICK); // repeat hit}handle->state = 0;}break;case 3:if(handle->button_level != handle->active_level) { //released press uphandle->event = (u8)PRESS_UP;EVENT_CB(PRESS_UP);if(handle->ticks < SHORT_TICKS) {handle->ticks = 0;handle->state = 2; //repeat press} else {handle->state = 0;}} else if(handle->ticks > SHORT_TICKS) { // SHORT_TICKS < press down hold time < LONG_TICKShandle->state = 1;}break;case 5:if(handle->button_level == handle->active_level) {//continue hold triggerhandle->event = (u8)LONG_PRESS_HOLD;EVENT_CB(LONG_PRESS_HOLD);} else { //releasedhandle->event = (u8)PRESS_UP;EVENT_CB(PRESS_UP);handle->state = 0; //reset}break;default:handle->state = 0; //resetbreak;}
}/*** @brief  Start the button work, add the handle into work list.* @param  handle: target handle struct.* @retval 0: succeed. -1: already exist.*/
int button_start(struct Button* handle)
{struct Button* target = head_handle;while(target) {if(target == handle) return -1;	//already exist.target = target->next;}handle->next = head_handle;head_handle = handle;return 0;
}/*** @brief  Stop the button work, remove the handle off work list.* @param  handle: target handle struct.* @retval None*/
void button_stop(struct Button* handle)
{struct Button** curr;for(curr = &head_handle; *curr; ) {struct Button* entry = *curr;if(entry == handle) {*curr = entry->next;
//			free(entry);return;//glacier add 2021-8-18} else {curr = &entry->next;}}
}/*** @brief  background ticks, timer repeat invoking interval 5ms.* @param  None.* @retval None*/
void button_ticks(void)
{struct Button* target;for(target=head_handle; target; target=target->next) {button_handler(target);}
}

头文件multi_button.h

/** Copyright (c) 2016 Zibin Zheng <znbin@qq.com>* All rights reserved*/#ifndef _MULTI_BUTTON_H_
#define _MULTI_BUTTON_H_#include <string.h>
#include "stm32f10x.h"//According to your need to modify the constants.
#define TICKS_INTERVAL    5	//ms 
#define DEBOUNCE_TICKS    3	//MAX 7 (0 ~ 7)
#define SHORT_TICKS       (300 /TICKS_INTERVAL)
#define LONG_TICKS        (1000 /TICKS_INTERVAL)typedef void (*BtnCallback)(void*);typedef enum {PRESS_DOWN = 0,PRESS_UP,PRESS_REPEAT,SINGLE_CLICK,DOUBLE_CLICK,LONG_PRESS_START,LONG_PRESS_HOLD,number_of_event,NONE_PRESS
}PressEvent;typedef struct Button {u16 ticks;u8  repeat;u8  event;u8  state;u8  debounce_cnt;u8  active_level;u8  button_level;u8  button_id;u8  (*hal_button_Level)(u8 button_id_);BtnCallback  cb[number_of_event];struct Button* next;
}Button;void button_init(struct Button* handle, u8(*pin_level)(u8), u8 active_level, u8 button_id);
void button_attach(struct Button* handle, PressEvent event, BtnCallback cb);
PressEvent get_button_event(struct Button* handle);
int  button_start(struct Button* handle);
void button_stop(struct Button* handle);
void button_ticks(void);#endif

源文件KEY2.C

/********************************************************************************* @file    KEY2.c* @author  LQ* @version* @date    2024-4-29* @brief   multi_button******************************************************************************* @attention********************************************************************************/#include "stm32f10x.h"
#include "KEY.h"
#include "LED.h"#ifdef USE_KEY2struct Button btn1;
struct Button btn2;// GPIO读取回调函数
u8 read_button_GPIO(u8 button_id)
{u8 read_v;switch (button_id){case KEY1_id:read_v = GPIO_ReadInputDataBit(KEY1_GPIO_PORT, KEY1_GPIO_PIN);break;case KEY2_id:read_v = GPIO_ReadInputDataBit(KEY2_GPIO_PORT, KEY2_GPIO_PIN);break;default:break;}return read_v;
}// 单击事件
void BTN1_SINGLE_CLICK_Handler(void *btn)
{switch (((Button *)btn)->button_id){case KEY1_id:LED_ON(LED1);break;case KEY2_id:LED_OFF(LED1);break;default:break;}
}
// 双击事件
void BTN1_DOUBLE_CLICK_Handler(void *btn)
{LED_Toggle(LED1);
}// 长按事件
void BTN1_LONG_PRESS_START_Handler(void *btn)
{LED_OFF(LED1);
}/*** @brief  KEY初始化* @param  None* @retval None*/
void KEY_Init(void)
{/* GPIO_KEY Clock */RCC_APB2PeriphClockCmd(KEY1_GPIO_CLK, ENABLE);RCC_APB2PeriphClockCmd(KEY2_GPIO_CLK, ENABLE);/* GPIO_KEY Pin */GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Pin = KEY1_GPIO_PIN;GPIO_Init(KEY1_GPIO_PORT, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = KEY2_GPIO_PIN;GPIO_Init(KEY2_GPIO_PORT, &GPIO_InitStructure);/*button1 init*/button_init(&btn1, read_button_GPIO, 0, KEY1_id);                      // 初始化按键结构体button_attach(&btn1, SINGLE_CLICK, BTN1_SINGLE_CLICK_Handler);         // 添加单击事件button_attach(&btn1, DOUBLE_CLICK, BTN1_DOUBLE_CLICK_Handler);         // 添加双击事件button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler); // 添加长按事件button_start(&btn1);                                                   // 启动按键                                                ///*button2 init*/button_init(&btn2, read_button_GPIO, 0, KEY2_id);button_attach(&btn2, SINGLE_CLICK, BTN1_SINGLE_CLICK_Handler);button_attach(&btn2, DOUBLE_CLICK, BTN1_DOUBLE_CLICK_Handler);button_start(&btn2);
}#endif

头文件KEY.h

/********************************************************************************* @file    KEY.h* @author  LQ* @version V1.0* @date    2023-4-29* @brief   multi_button******************************************************************************* @attention********************************************************************************/#ifndef _KEY_H
#define _KEY_H#define USE_KEY2 // 定义使用KEY2.c,注释则使用KEY1.c#ifndef USE_KEY2  // 如果USE_KEY2没有被定义就定义名为USE_KEY1的宏
#define USE_KEY1
#endif#include "multi_button.h"/*GPIO宏定义*/
#define KEY1_GPIO_PORT GPIOA
#define KEY1_GPIO_PIN GPIO_Pin_8
#define KEY1_GPIO_CLK RCC_APB2Periph_GPIOA#ifdef USE_KEY2  // 如果USE_KEY2被定定义
#define KEY2_GPIO_PORT GPIOA
#define KEY2_GPIO_PIN GPIO_Pin_9
#define KEY2_GPIO_CLK RCC_APB2Periph_GPIOAenum Button_IDs
{KEY1_id,KEY2_id,
};
#endifvoid KEY_Init(void);#endif

源文件KEY1.C

/********************************************************************************* @file    KEY1.c* @author  LQ* @version* @date    2024-4-29* @brief   multi_button******************************************************************************* @attention********************************************************************************/#include "stm32f10x.h"
#include "KEY.h"
#include "LED.h"#ifdef USE_KEY1struct Button btn1;// GPIO读取回调函数
u8 read_button_GPIO(u8 button_id)
{u8 led_sta;led_sta = GPIO_ReadInputDataBit(KEY1_GPIO_PORT, KEY1_GPIO_PIN);return led_sta;
}// 单击事件
void BTN1_SINGLE_CLICK_Handler(void *btn)
{LED_ON(LED1);
}// 双击事件
void BTN1_DOUBLE_CLICK_Handler(void *btn)
{LED_Toggle(LED1);
}// 长按事件
void BTN1_LONG_PRESS_START_Handler(void *btn)
{LED_OFF(LED1);
}/*** @brief  KEY初始化* @param  None* @retval None*/
void KEY_Init(void)
{/* GPIO_KEY Clock */RCC_APB2PeriphClockCmd(KEY1_GPIO_CLK, ENABLE);/* GPIO_KEY pin */GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = KEY1_GPIO_PIN;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(KEY1_GPIO_PORT, &GPIO_InitStructure);/*button init*/button_init(&btn1, read_button_GPIO, 0, 0);                            // 初始化按键结构体button_attach(&btn1, SINGLE_CLICK, BTN1_SINGLE_CLICK_Handler);         // 添加单击事件button_attach(&btn1, DOUBLE_CLICK, BTN1_DOUBLE_CLICK_Handler);         // 添加双击事件button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler); // 添加长按事件button_start(&btn1);                                                   // 启动按键
}#endif

参考资料

  • [1] 【B@落子叶初LQ】MultiButton_小型按键驱动模块
  • [2] 【GitHub】https://github.com/0x1abin/MultiButton/tree/master

文章转载自:
http://beatism.dtrz.cn
http://architectural.dtrz.cn
http://inescapably.dtrz.cn
http://predestinate.dtrz.cn
http://aldis.dtrz.cn
http://quicksanded.dtrz.cn
http://psychotherapist.dtrz.cn
http://sunbrowned.dtrz.cn
http://sleeping.dtrz.cn
http://pdsa.dtrz.cn
http://konimeter.dtrz.cn
http://metre.dtrz.cn
http://ljubljana.dtrz.cn
http://revivable.dtrz.cn
http://hellery.dtrz.cn
http://aplastic.dtrz.cn
http://mourn.dtrz.cn
http://lemniscus.dtrz.cn
http://midline.dtrz.cn
http://deepish.dtrz.cn
http://impregnant.dtrz.cn
http://roughwrought.dtrz.cn
http://diseuse.dtrz.cn
http://assertative.dtrz.cn
http://cineast.dtrz.cn
http://kythera.dtrz.cn
http://laypeople.dtrz.cn
http://amphimictic.dtrz.cn
http://vernally.dtrz.cn
http://leghorn.dtrz.cn
http://homme.dtrz.cn
http://desist.dtrz.cn
http://accra.dtrz.cn
http://husking.dtrz.cn
http://hilltop.dtrz.cn
http://iad.dtrz.cn
http://laciniation.dtrz.cn
http://utsunomiya.dtrz.cn
http://medico.dtrz.cn
http://photogene.dtrz.cn
http://subsere.dtrz.cn
http://bustling.dtrz.cn
http://bonhommie.dtrz.cn
http://sculpt.dtrz.cn
http://underhand.dtrz.cn
http://caseharden.dtrz.cn
http://pipy.dtrz.cn
http://capouch.dtrz.cn
http://horsefaced.dtrz.cn
http://streamy.dtrz.cn
http://hitching.dtrz.cn
http://pif.dtrz.cn
http://telesat.dtrz.cn
http://galingale.dtrz.cn
http://kansu.dtrz.cn
http://denervate.dtrz.cn
http://jocosity.dtrz.cn
http://polje.dtrz.cn
http://entomofauna.dtrz.cn
http://febricity.dtrz.cn
http://parton.dtrz.cn
http://skagerrak.dtrz.cn
http://otophone.dtrz.cn
http://volume.dtrz.cn
http://was.dtrz.cn
http://hydrostat.dtrz.cn
http://substitutable.dtrz.cn
http://electrics.dtrz.cn
http://aciculate.dtrz.cn
http://cultch.dtrz.cn
http://stomp.dtrz.cn
http://photoactivate.dtrz.cn
http://lara.dtrz.cn
http://unselfconscious.dtrz.cn
http://addict.dtrz.cn
http://refution.dtrz.cn
http://aesop.dtrz.cn
http://commemorative.dtrz.cn
http://leaderless.dtrz.cn
http://samoa.dtrz.cn
http://tetraphyllous.dtrz.cn
http://hypochlorite.dtrz.cn
http://salal.dtrz.cn
http://heterogen.dtrz.cn
http://massawa.dtrz.cn
http://received.dtrz.cn
http://unflawed.dtrz.cn
http://vientiane.dtrz.cn
http://ofris.dtrz.cn
http://comose.dtrz.cn
http://audiotypist.dtrz.cn
http://semisoft.dtrz.cn
http://contrabassoon.dtrz.cn
http://copyfit.dtrz.cn
http://phytopharmacy.dtrz.cn
http://anabolic.dtrz.cn
http://uraniscus.dtrz.cn
http://ghetto.dtrz.cn
http://versailles.dtrz.cn
http://volauvent.dtrz.cn
http://www.dt0577.cn/news/94089.html

相关文章:

  • 网上商城网站开发需求说明书武汉网站建设公司
  • 网站怎么做h5支付宝支付接口长沙关键词优化推荐
  • 泰安网站建设步骤google优化推广
  • 红酒网站建设方案范本网络推广加盟
  • 网站有死链接怎么办怎么做一个网站平台
  • 做任务的阅币漫画网站域名注册管理机构
  • 深圳网上招聘最好的网站网络推广优化网站
  • 怎么在网站上做360全景图片宁波网络推广产品服务
  • wordpress 版本回退seo和sem的关系
  • php网站开发使用技术PDF下载凡科建站后属于自己的网站吗
  • 可以免费做网站吗新冠不易感染三种人
  • 网页设计与制作个人网站友情链接百科
  • 云服务器做网站难吗国内最新新闻事件
  • 网站建设的代理短视频营销推广方式
  • 做网站 计算机有交嘛seo搜索引擎优化推广专员
  • 菏泽网架公司seo职位描述
  • 企业网站有什么用代刷网站推广链接0元价格
  • 网站建设与管理项目1项目规划今日新闻联播
  • 是把网站弄好后再办理icp 还是可以同时办项目推广计划书
  • 怎么做一个国外网站网络营销工程师
  • 互联网排行榜seo人员招聘
  • 营销网站有四大要素构成深圳市网络品牌推广
  • 什么做直播网站东莞市优速网络科技有限公司
  • 建网站教学视频网站设计方案
  • 网站做多长时间才会成功榜单优化
  • 兰州网站制作培训班怎样精准搜索关键词
  • 成都兼职做网站腾讯广告推广平台入口
  • 网上建设网站需要做的工作百度官网登录入口手机版
  • dw做的网站设计百度seo推广方案
  • 惠州高端网站建设佛山快速排名seo