-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButton.c
67 lines (55 loc) · 1.87 KB
/
Button.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/******************************************************************************
*
* Module: Button
*
* File Name: Button.c
*
* Description: Source file for Button Module.
*
* Author: Mohamed Tarek
******************************************************************************/
#include "Dio.h"
#include "Port.h"
#include "Button.h"
/* Button Configurations Structure */
static Port_ConfigType g_Button_Config;
/* Global variable to hold the button state */
static uint8 g_button_state = BUTTON_RELEASED;
/*******************************************************************************************************************/
/*******************************************************************************************************************/
uint8 BUTTON_getState(void)
{
return g_button_state;
}
/*******************************************************************************************************************/
void BUTTON_refreshState(void)
{
uint8 state = Dio_ReadChannel(DioConf_SW1_CHANNEL_ID_INDEX);
/* Count the number of Pressed times increment if the switch pressed for 20 ms */
static uint8 g_Pressed_Count = 0;
/* Count the number of Released times increment if the switch released for 20 ms */
static uint8 g_Released_Count = 0;
if(state == BUTTON_PRESSED)
{
g_Pressed_Count++;
g_Released_Count = 0;
}
else
{
g_Released_Count++;
g_Pressed_Count = 0;
}
if(g_Pressed_Count == 3)
{
g_button_state = BUTTON_PRESSED;
g_Pressed_Count = 0;
g_Released_Count = 0;
}
else if(g_Released_Count == 3)
{
g_button_state = BUTTON_RELEASED;
g_Released_Count = 0;
g_Pressed_Count = 0;
}
}
/*******************************************************************************************************************/