| 1 | #include <stdio.h>
|
|---|
| 2 | #include "button.h"
|
|---|
| 3 | #include "main.h"
|
|---|
| 4 | #include "buzzer.h"
|
|---|
| 5 | #include "leds.h"
|
|---|
| 6 |
|
|---|
| 7 | #define LONG_PRESS_TIME 5000
|
|---|
| 8 | #define MIN_PRESS_TIME 10
|
|---|
| 9 |
|
|---|
| 10 | button_state_t buttonState;
|
|---|
| 11 | uint32_t longPressCounterButtonOn;
|
|---|
| 12 | uint32_t longPressCounterButtonOff;
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | // Diese funktion muss regelmäßig aufgerufen werden um die Taster abzufragen.
|
|---|
| 16 | // 1ms
|
|---|
| 17 | button_state_t BUTTON_Exec(void)
|
|---|
| 18 | {
|
|---|
| 19 |
|
|---|
| 20 | if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_SET)
|
|---|
| 21 | {
|
|---|
| 22 | //Taste On wird gedrückt
|
|---|
| 23 | longPressCounterButtonOn++;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | if (longPressCounterButtonOn > LONG_PRESS_TIME)
|
|---|
| 28 | {
|
|---|
| 29 |
|
|---|
| 30 | if (buttonState != BUTTON_MANUAL_ON)
|
|---|
| 31 | {
|
|---|
| 32 | printf("BUTTON: Auto Mode Manual On\n");
|
|---|
| 33 | BUZZER_Alarm_Start(200,1000);
|
|---|
| 34 | LEDS_GN_On();
|
|---|
| 35 | buttonState = BUTTON_MANUAL_ON;
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | else if ( (longPressCounterButtonOn > MIN_PRESS_TIME) && (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_RESET))
|
|---|
| 39 | {
|
|---|
| 40 | //Taste On wurde for 10m gesdrückt und losgelassen
|
|---|
| 41 | if (buttonState != BUTTON_AUTO)
|
|---|
| 42 | {
|
|---|
| 43 | printf("BUTTON: Auto Mode\n");
|
|---|
| 44 | BUZZER_Beep(200);
|
|---|
| 45 | LEDS_GN_Blink_Start(100, 1000);
|
|---|
| 46 | buttonState = BUTTON_AUTO;
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_RESET)
|
|---|
| 53 | {
|
|---|
| 54 | longPressCounterButtonOn = 0;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | // ------ Taste OFF -----
|
|---|
| 59 | if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_OFF_GPIO_Port, GPIO_INPUT_BTN_OFF_Pin) == GPIO_PIN_SET)
|
|---|
| 60 | {
|
|---|
| 61 | //Taste Off wird gedrückt
|
|---|
| 62 | longPressCounterButtonOff++;
|
|---|
| 63 | if (longPressCounterButtonOff > MIN_PRESS_TIME)
|
|---|
| 64 | {
|
|---|
| 65 | if (buttonState != BUTTON_OFF)
|
|---|
| 66 | {
|
|---|
| 67 | BUZZER_Alarm_Stop(); //Falls noch im AlarmModus, dann ausschalten
|
|---|
| 68 | BUZZER_Beep(200);
|
|---|
| 69 | LEDS_GN_Off();
|
|---|
| 70 | printf("BUTTON: Off Mode\n");
|
|---|
| 71 | buttonState = BUTTON_OFF;
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 | else
|
|---|
| 76 | {
|
|---|
| 77 | longPressCounterButtonOff = 0;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | return buttonState;
|
|---|
| 81 |
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | button_state_t BUTTON_GetMode(void)
|
|---|
| 86 | {
|
|---|
| 87 | return buttonState;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | void BUTTON_SetModeOff(void)
|
|---|
| 91 | {
|
|---|
| 92 | LEDS_GN_Off();
|
|---|
| 93 | BUZZER_Alarm_Stop(); //Falls wir im Manual on Mode waren, soll jetzt auch der buzzer wieder ausgehen.
|
|---|
| 94 | buttonState = BUTTON_OFF;
|
|---|
| 95 | }
|
|---|