1 | #include <stdio.h> |
---|
2 | #include "button.h" |
---|
3 | #include "main.h" |
---|
4 | #include "buzzer.h" |
---|
5 | |
---|
6 | #define LONG_PRESS_TIME 5000 |
---|
7 | #define MIN_PRESS_TIME 10 |
---|
8 | |
---|
9 | button_state_t buttonState; |
---|
10 | uint32_t longPressCounterButtonOn; |
---|
11 | uint32_t longPressCounterButtonOff; |
---|
12 | |
---|
13 | |
---|
14 | // Diese funktion muss regelmäßig aufgerufen werden um die Taster abzufragen. |
---|
15 | // 1ms |
---|
16 | button_state_t BUTTON_Exec(void) |
---|
17 | { |
---|
18 | |
---|
19 | if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_SET) |
---|
20 | { |
---|
21 | //Taste On wird gedrückt |
---|
22 | longPressCounterButtonOn++; |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | if (longPressCounterButtonOn > LONG_PRESS_TIME) |
---|
27 | { |
---|
28 | |
---|
29 | if (buttonState != BUTTON_MANUAL_ON) |
---|
30 | { |
---|
31 | printf("BUTTON: Auto Mode Manual On\n"); |
---|
32 | BUZZER_Alarm_Start(200,1000); |
---|
33 | buttonState = BUTTON_MANUAL_ON; |
---|
34 | } |
---|
35 | } |
---|
36 | else if ( (longPressCounterButtonOn > MIN_PRESS_TIME) && (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_RESET)) |
---|
37 | { |
---|
38 | //Taste On wurde for 10m gesdrückt und losgelassen |
---|
39 | if (buttonState != BUTTON_AUTO) |
---|
40 | { |
---|
41 | printf("BUTTON: Auto Mode\n"); |
---|
42 | BUZZER_Beep(200); |
---|
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 | BUZZER_Alarm_Stop(); //Falls noch im AlarmModus, dann ausschalten |
---|
65 | BUZZER_Beep(200); |
---|
66 | printf("BUTTON: Off Mode\n"); |
---|
67 | buttonState = BUTTON_OFF; |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | longPressCounterButtonOff = 0; |
---|
74 | } |
---|
75 | |
---|
76 | return buttonState; |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | button_state_t BUTTON_GetMode(void) |
---|
82 | { |
---|
83 | return buttonState; |
---|
84 | } |
---|
85 | |
---|