Compare commits
1
Commits
Dev
..
014094f337
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
014094f337 |
+2
-6
@@ -7,10 +7,6 @@
|
||||
#include "stm32g0xx_hal.h"
|
||||
#endif
|
||||
|
||||
#ifdef STM32G0B1xx
|
||||
#include "stm32g0xx_hal.h"
|
||||
#endif
|
||||
|
||||
#ifdef STM32F030xx
|
||||
#include "stm32f0xx_hal.h"
|
||||
#endif
|
||||
@@ -20,7 +16,7 @@ typedef struct DS_Button
|
||||
{
|
||||
GPIO_TypeDef* Port;
|
||||
uint16_t Pin;
|
||||
bool Pressed, Released, PressedLong, PressedLongLong;
|
||||
bool Presed, Released, PresedLong, PresedLongLong;
|
||||
uint32_t PrevTick, PressStartTick, PressStartTickLong;
|
||||
uint8_t Storage;
|
||||
|
||||
@@ -42,6 +38,6 @@ bool DS_ButtonPressedLongLong(DS_Button* Button);
|
||||
|
||||
bool DS_ButtonRisingEdge(DS_Button* Button);
|
||||
|
||||
bool DS_ButtonFallingEdge(DS_Button* Button);
|
||||
bool DS_ButtonFalingEdge(DS_Button* Button);
|
||||
|
||||
#endif //DS_BUTTON_H
|
||||
+22
-20
@@ -1,22 +1,24 @@
|
||||
#include "../inc/DS_Button.h"
|
||||
|
||||
void DS_ButtonInit(DS_Button *Button, GPIO_TypeDef *Port, uint16_t Pin) {
|
||||
void DS_ButtonInit(DS_Button* Button, GPIO_TypeDef *Port, uint16_t Pin)
|
||||
{
|
||||
Button->Port = Port;
|
||||
Button->Pin = Pin;
|
||||
Button->Pressed = false;
|
||||
Button->PressedLong = false;
|
||||
Button->PressedLongLong = false;
|
||||
Button->Presed = false;
|
||||
Button->PresedLong = false;
|
||||
Button->PresedLongLong = false;
|
||||
Button->Released = false;
|
||||
Button->PrevTick = 0;
|
||||
Button->PressStartTick = 0;
|
||||
Button->PressStartTickLong = 0;
|
||||
Button->Storage = 5; // Начальное среднее положение для стабилизации
|
||||
Button->Storage = 5;
|
||||
|
||||
Button->FallingEdge = false;
|
||||
Button->RisingEdge = false;
|
||||
}
|
||||
|
||||
void DS_ButtonUpdate(DS_Button * Button) {
|
||||
void DS_ButtonUpdate(DS_Button *Button)
|
||||
{
|
||||
uint32_t CurrentTick = HAL_GetTick();
|
||||
if ((CurrentTick - Button->PrevTick) < 10)
|
||||
return;
|
||||
@@ -29,19 +31,19 @@ void DS_ButtonInit(DS_Button *Button, GPIO_TypeDef *Port, uint16_t Pin) {
|
||||
{
|
||||
if (Button->Storage == 0)
|
||||
Button->Storage +=5;
|
||||
else if (Button->Storage < 10)
|
||||
else if (Button->Storage <= 10)
|
||||
Button->Storage +=1;
|
||||
|
||||
|
||||
if (Button->PressStartTick == 0)
|
||||
Button->PressStartTick = CurrentTick;
|
||||
else if ((CurrentTick-Button->PressStartTick)>1000)
|
||||
Button->PressedLong = true;
|
||||
Button->PresedLong = true;
|
||||
|
||||
if (Button->PressStartTickLong == 0)
|
||||
Button->PressStartTickLong = CurrentTick;
|
||||
else if ((CurrentTick-Button->PressStartTickLong)>5000)
|
||||
Button->PressedLongLong = true;
|
||||
Button->PresedLongLong = true;
|
||||
|
||||
|
||||
|
||||
@@ -55,10 +57,10 @@ void DS_ButtonInit(DS_Button *Button, GPIO_TypeDef *Port, uint16_t Pin) {
|
||||
Button->Storage -=1;
|
||||
|
||||
Button->PressStartTick = 0;
|
||||
Button->PressedLong = false;
|
||||
Button->PresedLong = false;
|
||||
|
||||
Button->PressStartTickLong = 0;
|
||||
Button->PressedLongLong = false;
|
||||
Button->PresedLongLong = false;
|
||||
}
|
||||
|
||||
switch (Button->Storage)
|
||||
@@ -68,16 +70,16 @@ void DS_ButtonInit(DS_Button *Button, GPIO_TypeDef *Port, uint16_t Pin) {
|
||||
{
|
||||
Button->FallingEdge = true;
|
||||
}
|
||||
Button->Pressed = false;
|
||||
Button->Presed = false;
|
||||
Button->Released = true;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
if (Button->Pressed == false)
|
||||
if (Button->Presed == false)
|
||||
{
|
||||
Button->RisingEdge = true;
|
||||
}
|
||||
Button->Pressed = true;
|
||||
Button->Presed = true;
|
||||
Button->Released = false;
|
||||
break;
|
||||
|
||||
@@ -89,7 +91,7 @@ void DS_ButtonInit(DS_Button *Button, GPIO_TypeDef *Port, uint16_t Pin) {
|
||||
|
||||
bool DS_ButtonPressed(DS_Button *Button)
|
||||
{
|
||||
if (Button->Pressed)
|
||||
if (Button->Presed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -107,9 +109,9 @@ bool DS_ButtonReleased(DS_Button *Button)
|
||||
|
||||
bool DS_ButtonPressedLong(DS_Button *Button)
|
||||
{
|
||||
if (Button->PressedLong)
|
||||
if (Button->PresedLong)
|
||||
{
|
||||
Button->PressedLong = false;
|
||||
Button->PresedLong = false;
|
||||
Button->PressStartTick = Button->PressStartTick + 500;
|
||||
return true;
|
||||
}
|
||||
@@ -118,10 +120,10 @@ bool DS_ButtonPressedLong(DS_Button *Button)
|
||||
|
||||
bool DS_ButtonPressedLongLong(DS_Button *Button)
|
||||
{
|
||||
if (Button->PressedLongLong)
|
||||
if (Button->PresedLongLong)
|
||||
{
|
||||
Button->PressStartTick = 0;
|
||||
Button->PressedLongLong = false;
|
||||
Button->PresedLongLong = false;
|
||||
Button->PressStartTickLong = Button->PressStartTickLong+500;
|
||||
return true;
|
||||
}
|
||||
@@ -138,7 +140,7 @@ bool DS_ButtonRisingEdge(DS_Button *Button)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DS_ButtonFallingEdge(DS_Button *Button)
|
||||
bool DS_ButtonFalingEdge(DS_Button *Button)
|
||||
{
|
||||
if (Button->FallingEdge)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user