source: trunk/firmware_v4/SES/src/button.c@ 42

Last change on this file since 42 was 42, checked in by f.jahn, 5 days ago
File size: 1.9 KB
RevLine 
[42]1#include <stdio.h>
2#include "button.h"
3#include "main.h"
4
5#define LONG_PRESS_TIME 5000
6#define MIN_PRESS_TIME 10
7
8button_state_t buttonState;
9uint32_t longPressCounterButtonOn;
10uint32_t longPressCounterButtonOff;
11
12
13// Diese funktion muss regelmäßig aufgerufen werden um die Taster abzufragen.
14// 1ms
15button_state_t BUTTON_Exec(void)
16{
17 if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_SET)
18 {
19 //Taste On wird gedrückt
20 longPressCounterButtonOn++;
21 }
22
23
24 if (longPressCounterButtonOn > LONG_PRESS_TIME)
25 {
26
27 if (buttonState != BUTTON_MANUAL_ON)
28 {
29#ifdef DEBUG
30 printf("BUTTON: Auto Mode Manual On\n");
31#endif
32 buttonState = BUTTON_MANUAL_ON;
33 }
34 }
35 else if ( (longPressCounterButtonOn > MIN_PRESS_TIME) && (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_RESET))
36 {
37 //Taste On wurde for 10m gesdrückt und losgelassen
38 if (buttonState != BUTTON_AUTO)
39 {
40#ifdef DEBUG
41 printf("BUTTON: Auto Mode\n");
42#endif
43 buttonState = BUTTON_AUTO;
44 }
45 }
46
47
48
49 if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_RESET)
50 {
51 longPressCounterButtonOn = 0;
52 }
53
54
55 // ------ Taste OFF -----
56 if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_OFF_GPIO_Port, GPIO_INPUT_BTN_OFF_Pin) == GPIO_PIN_SET)
57 {
58 //Taste Off wird gedrückt
59 longPressCounterButtonOff++;
60 if (longPressCounterButtonOff > MIN_PRESS_TIME)
61 {
62 if (buttonState != BUTTON_OFF)
63 {
64#ifdef DEBUG
65 printf("BUTTON: Off Mode\n");
66#endif
67 buttonState = BUTTON_OFF;
68 }
69 }
70 }
71 else
72 {
73 longPressCounterButtonOff = 0;
74 }
75
76 return buttonState;
77
78}
79
80
81button_state_t BUTTON_GetMode(void)
82{
83 return buttonState;
84}
85
86void BUTTON_SetModeOff(void)
87{
88 buttonState = BUTTON_OFF;
89}
90
91void BUTTON_SetModeAuto(void)
92{
93 buttonState = BUTTON_AUTO;
94}
Note: See TracBrowser for help on using the repository browser.