1 | /** |
---|
2 | ****************************************************************************** |
---|
3 | * @file led.c |
---|
4 | * @author ECS, Falko Jahn |
---|
5 | * @version V1.0.0 |
---|
6 | * @date 29-Jan-2021 |
---|
7 | * @brief LED Modul |
---|
8 | * Beschreibung in Header |
---|
9 | ****************************************************************************** |
---|
10 | */ |
---|
11 | |
---|
12 | // --- INCLUDES ---------------------------------------------------------------- |
---|
13 | #include "led.h" |
---|
14 | #include "main.h" |
---|
15 | |
---|
16 | //--- GGF. EXTERNE VARIABLEN --------------------------------------------------- |
---|
17 | |
---|
18 | //--- LOKALE DEFINES - bitte hier dokumentieren -------------------------------- |
---|
19 | #define LED_OFF 0 |
---|
20 | #define LED_ON (!LED_OFF) |
---|
21 | //--- LOKALE TYPE DEFS - bitte hier dokumentieren------------------------------- |
---|
22 | typedef struct |
---|
23 | { |
---|
24 | uint32_t onTime; |
---|
25 | uint32_t offTime; |
---|
26 | uint32_t counter; |
---|
27 | uint32_t currentState; |
---|
28 | } LED_TypeDef; |
---|
29 | |
---|
30 | //--- DEFINATIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ---------- |
---|
31 | |
---|
32 | //--- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------ |
---|
33 | LED_TypeDef ledError; |
---|
34 | LED_TypeDef ledFunction; |
---|
35 | |
---|
36 | //--- LOKALE FUNKTIONS PROTOTYPEN ---------------------------------------------- |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | //--- LOKALE FUNKTIONEN - bitte hier dokumentieren ----------------------------- |
---|
41 | |
---|
42 | //--- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------ |
---|
43 | void LED_Init(void) |
---|
44 | { |
---|
45 | |
---|
46 | } |
---|
47 | |
---|
48 | void LED_ErrorOn() |
---|
49 | { |
---|
50 | HAL_GPIO_WritePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin,GPIO_PIN_SET); |
---|
51 | HAL_GPIO_WritePin(BUZZER_GPIO_Port, BUZZER_Pin,GPIO_PIN_SET); |
---|
52 | ledError.currentState = LED_ON; |
---|
53 | ledError.counter = 0; |
---|
54 | } |
---|
55 | |
---|
56 | void LED_ErrorOff() |
---|
57 | { |
---|
58 | HAL_GPIO_WritePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin,GPIO_PIN_RESET); |
---|
59 | HAL_GPIO_WritePin(BUZZER_GPIO_Port, BUZZER_Pin,GPIO_PIN_RESET); |
---|
60 | ledError.currentState = LED_OFF; |
---|
61 | ledError.counter = 0; |
---|
62 | } |
---|
63 | |
---|
64 | void LED_ErrorToggle() |
---|
65 | { |
---|
66 | HAL_GPIO_TogglePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin); |
---|
67 | HAL_GPIO_TogglePin(BUZZER_GPIO_Port, BUZZER_Pin); |
---|
68 | |
---|
69 | ledError.currentState = !ledError.currentState; |
---|
70 | ledError.counter = 0; |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | void LED_ErrorStartBlink(int ontime, int offtime) |
---|
75 | { |
---|
76 | ledError.onTime = ontime; |
---|
77 | ledError.offTime = offtime; |
---|
78 | HAL_GPIO_TogglePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin); |
---|
79 | HAL_GPIO_TogglePin(BUZZER_GPIO_Port, BUZZER_Pin); |
---|
80 | ledError.currentState = !ledError.currentState; |
---|
81 | |
---|
82 | if (ledError.currentState == LED_ON) ledError.counter = ontime; |
---|
83 | if (ledError.currentState == LED_OFF) ledError.counter = offtime; |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | void LED_ErrorExec() |
---|
88 | { |
---|
89 | if (ledError.counter > 0) |
---|
90 | { |
---|
91 | ledError.counter--; |
---|
92 | if (ledError.counter == 0) |
---|
93 | { |
---|
94 | if (ledError.currentState == LED_ON) |
---|
95 | { |
---|
96 | HAL_GPIO_WritePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin,GPIO_PIN_RESET); |
---|
97 | HAL_GPIO_WritePin(BUZZER_GPIO_Port, BUZZER_Pin,GPIO_PIN_RESET); |
---|
98 | ledError.currentState = LED_OFF; |
---|
99 | ledError.counter = ledError.offTime; |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | HAL_GPIO_WritePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin,GPIO_PIN_SET); |
---|
104 | HAL_GPIO_WritePin(BUZZER_GPIO_Port, BUZZER_Pin,GPIO_PIN_SET); |
---|
105 | ledError.currentState = LED_ON; |
---|
106 | ledError.counter = ledError.onTime; |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | // ----- LED FUNCTION ------ |
---|
113 | |
---|
114 | void LED_FunctionOn() |
---|
115 | { |
---|
116 | HAL_GPIO_WritePin(LED_FUNC_GPIO_Port, LED_FUNC_Pin,GPIO_PIN_SET); |
---|
117 | ledFunction.currentState = LED_ON; |
---|
118 | ledFunction.counter = 0; |
---|
119 | } |
---|
120 | |
---|
121 | void LED_FunctionOff() |
---|
122 | { |
---|
123 | HAL_GPIO_WritePin(LED_FUNC_GPIO_Port, LED_FUNC_Pin,GPIO_PIN_RESET); |
---|
124 | ledFunction.currentState = LED_OFF; |
---|
125 | ledFunction.counter = 0; |
---|
126 | } |
---|
127 | |
---|
128 | void LED_FunctionToggle() |
---|
129 | { |
---|
130 | HAL_GPIO_TogglePin(LED_FUNC_GPIO_Port, LED_FUNC_Pin); |
---|
131 | ledFunction.currentState = !ledFunction.currentState; |
---|
132 | ledFunction.counter = 0; |
---|
133 | } |
---|
134 | |
---|
135 | void LED_FunctionStartBlink(int ontime, int offtime) |
---|
136 | { |
---|
137 | ledFunction.onTime = ontime; |
---|
138 | ledFunction.offTime = offtime; |
---|
139 | HAL_GPIO_TogglePin(LED_FUNC_GPIO_Port, LED_FUNC_Pin); |
---|
140 | ledFunction.currentState = !ledFunction.currentState; |
---|
141 | |
---|
142 | if (ledFunction.currentState == LED_ON) ledFunction.counter = ontime; |
---|
143 | if (ledFunction.currentState == LED_OFF) ledFunction.counter = offtime; |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | void LED_FunctionSetTimes(int ontime, int offtime) |
---|
148 | { |
---|
149 | ledFunction.onTime = ontime; |
---|
150 | ledFunction.offTime = offtime; |
---|
151 | } |
---|
152 | |
---|
153 | void LED_FunctionExec() |
---|
154 | { |
---|
155 | if (ledFunction.counter > 0) |
---|
156 | { |
---|
157 | ledFunction.counter--; |
---|
158 | if (ledFunction.counter == 0) |
---|
159 | { |
---|
160 | if (ledFunction.currentState == LED_ON) |
---|
161 | { |
---|
162 | HAL_GPIO_WritePin(LED_FUNC_GPIO_Port, LED_FUNC_Pin,GPIO_PIN_RESET); |
---|
163 | ledFunction.currentState = LED_OFF; |
---|
164 | ledFunction.counter = ledFunction.offTime; |
---|
165 | } |
---|
166 | else |
---|
167 | { |
---|
168 | HAL_GPIO_WritePin(LED_FUNC_GPIO_Port, LED_FUNC_Pin,GPIO_PIN_SET); |
---|
169 | ledFunction.currentState = LED_ON; |
---|
170 | ledFunction.counter = ledFunction.onTime; |
---|
171 | } |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | void LED_Test() |
---|
179 | { |
---|
180 | LED_ErrorOn(); |
---|
181 | HAL_Delay(1000); |
---|
182 | LED_ErrorOff(); |
---|
183 | HAL_Delay(1000); |
---|
184 | |
---|
185 | } |
---|
186 | |
---|
187 | void LED_Exec() |
---|
188 | { |
---|
189 | LED_ErrorExec(); |
---|
190 | LED_FunctionExec(); |
---|
191 | } |
---|
192 | |
---|