[17] | 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 | |
---|
| 8 | button_state_t buttonState; |
---|
| 9 | uint32_t longPressCounterButtonOn; |
---|
| 10 | uint32_t longPressCounterButtonOff; |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | // Diese funktion muss regelmäßig aufgerufen werden um die Taster abzufragen. |
---|
| 14 | // 1ms |
---|
| 15 | button_state_t BUTTON_Exec(void) |
---|
| 16 | { |
---|
| 17 | |
---|
| 18 | if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_SET) |
---|
| 19 | { |
---|
| 20 | //Taste On wird gedrückt |
---|
| 21 | longPressCounterButtonOn++; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | if (longPressCounterButtonOn > LONG_PRESS_TIME) |
---|
| 26 | { |
---|
| 27 | |
---|
| 28 | if (buttonState != BUTTON_MANUAL_ON) |
---|
| 29 | { |
---|
| 30 | printf("BUTTON: Auto Mode Manual On\n"); |
---|
| 31 | buttonState = BUTTON_MANUAL_ON; |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | else if ( (longPressCounterButtonOn > MIN_PRESS_TIME) && (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_RESET)) |
---|
| 35 | { |
---|
| 36 | //Taste On wurde for 10m gesdrückt und losgelassen |
---|
| 37 | if (buttonState != BUTTON_AUTO) |
---|
| 38 | { |
---|
| 39 | printf("BUTTON: Auto Mode\n"); |
---|
| 40 | buttonState = BUTTON_AUTO; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_ON_GPIO_Port, GPIO_INPUT_BTN_ON_Pin) == GPIO_PIN_RESET) |
---|
| 47 | { |
---|
| 48 | longPressCounterButtonOn = 0; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | // ------ Taste OFF ----- |
---|
| 53 | if (HAL_GPIO_ReadPin(GPIO_INPUT_BTN_OFF_GPIO_Port, GPIO_INPUT_BTN_OFF_Pin) == GPIO_PIN_SET) |
---|
| 54 | { |
---|
| 55 | //Taste Off wird gedrückt |
---|
| 56 | longPressCounterButtonOff++; |
---|
| 57 | if (longPressCounterButtonOff > MIN_PRESS_TIME) |
---|
| 58 | { |
---|
| 59 | if (buttonState != BUTTON_OFF) |
---|
| 60 | { |
---|
| 61 | printf("BUTTON: Off Mode\n"); |
---|
| 62 | buttonState = BUTTON_OFF; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | else |
---|
| 67 | { |
---|
| 68 | longPressCounterButtonOff = 0; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | return buttonState; |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | button_state_t BUTTON_GetMode(void) |
---|
| 77 | { |
---|
| 78 | return buttonState; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | void BUTTON_SetModeOff(void) |
---|
| 82 | { |
---|
| 83 | buttonState = BUTTON_OFF; |
---|
| 84 | } |
---|