按钮驱动

This commit is contained in:
2021-09-18 11:01:32 +08:00
parent adc745e2a7
commit 3a77ca9988
13 changed files with 4711 additions and 4159 deletions
+62
View File
@@ -0,0 +1,62 @@
/*
* button.c
*
* Created on: Sep 18, 2021
* Author: wuwenfeng
*/
#include "button.h"
void GEI_BUTTON_CODE(struct button *bt,uint8_t in)
{
#define t 250
bt->code=0;
if(in==1)
{
if(bt->lock==0)
{
if(HAL_GetTick()<bt->time+t)
{
bt->times++;
bt->time=HAL_GetTick();
bt->lock=1;
}else
{
bt->times=1;
bt->time=HAL_GetTick();
bt->lock=1;
}
}
if(bt->lock==1)
{
if(HAL_GetTick()>bt->time+t)
{
bt->code=255;
bt->times=255;
}
}
}
if(in==0)
{
if(bt->lock==1)
{
if(bt->code==255)
{
}else
{
bt->code=bt->times;
}
bt->lock=0;
}
}
}