Rev 4 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4 | Rev 5 | ||
|---|---|---|---|
| Line 21... | Line 21... | ||
| 21 | #include "main.h" |
21 | #include "main.h" |
| 22 | 22 | ||
| 23 | /* Private includes ----------------------------------------------------------*/ |
23 | /* Private includes ----------------------------------------------------------*/ |
| 24 | /* USER CODE BEGIN Includes */ |
24 | /* USER CODE BEGIN Includes */ |
| 25 | #include "sendLeds.h" |
25 | #include "sendLeds.h" |
| - | 26 | #include "libLog/log.h" |
|
| 26 | /* USER CODE END Includes */ |
27 | /* USER CODE END Includes */ |
| 27 | 28 | ||
| 28 | /* Private typedef -----------------------------------------------------------*/ |
29 | /* Private typedef -----------------------------------------------------------*/ |
| 29 | /* USER CODE BEGIN PTD */ |
30 | /* USER CODE BEGIN PTD */ |
| 30 | 31 | ||
| Line 101... | Line 102... | ||
| 101 | int origin = 0; |
102 | int origin = 0; |
| 102 | 103 | ||
| 103 | void moveGauge(int target) { |
104 | void moveGauge(int target) { |
| 104 | 105 | ||
| 105 | unsigned const fast = 10; |
106 | unsigned const fast = 10; |
| 106 | unsigned const slow = 30; |
107 | unsigned const slow = 20; |
| 107 | unsigned const range = slow - fast; |
108 | unsigned const range = slow - fast; |
| 108 | unsigned del = fast; |
109 | unsigned del = fast; |
| 109 | int step = 1; |
110 | int step = 1; |
| 110 | while (count != target) { |
111 | while (count != target) { |
| 111 | 112 | ||
| Line 167... | Line 168... | ||
| 167 | moveGauge(-600); |
168 | moveGauge(-600); |
| 168 | count = 0; |
169 | count = 0; |
| 169 | origin = 0; |
170 | origin = 0; |
| 170 | } |
171 | } |
| 171 | 172 | ||
| - | 173 | ||
| - | 174 | uint16_t getADC(){ |
|
| - | 175 | uint16_t mean = 0; |
|
| - | 176 | for (int i =0; i< NUM_SAMPLES; i++) |
|
| - | 177 | { |
|
| - | 178 | mean+=ADC_Samples[i]; |
|
| - | 179 | } |
|
| - | 180 | return mean/NUM_SAMPLES; |
|
| - | 181 | } |
|
| - | 182 | ||
| - | 183 | ||
| - | 184 | ||
| 172 | /* USER CODE END 0 */ |
185 | /* USER CODE END 0 */ |
| 173 | 186 | ||
| 174 | /** |
187 | /** |
| 175 | * @brief The application entry point. |
188 | * @brief The application entry point. |
| 176 | * @retval int |
189 | * @retval int |
| Line 232... | Line 245... | ||
| 232 | /* USER CODE BEGIN WHILE */ |
245 | /* USER CODE BEGIN WHILE */ |
| 233 | while (1) { |
246 | while (1) { |
| 234 | sendLeds(); |
247 | sendLeds(); |
| 235 | HAL_Delay(10); |
248 | HAL_Delay(10); |
| 236 | 249 | ||
| - | 250 | ||
| - | 251 | uint16_t val = log2fix ( getADC(), 8); |
|
| - | 252 | ||
| - | 253 | moveGauge(val * 4); |
|
| - | 254 | ||
| - | 255 | ||
| 237 | /* USER CODE END WHILE */ |
256 | /* USER CODE END WHILE */ |
| 238 | 257 | ||
| 239 | /* USER CODE BEGIN 3 */ |
258 | /* USER CODE BEGIN 3 */ |
| 240 | } |
259 | } |
| 241 | /* USER CODE END 3 */ |
260 | /* USER CODE END 3 */ |
| Line 532... | Line 551... | ||
| 532 | static void MX_GPIO_Init(void) |
551 | static void MX_GPIO_Init(void) |
| 533 | { |
552 | { |
| 534 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
553 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| 535 | 554 | ||
| 536 | /* GPIO Ports Clock Enable */ |
555 | /* GPIO Ports Clock Enable */ |
| 537 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
- | |
| 538 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
556 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 539 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
557 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 540 | 558 | ||
| 541 | /*Configure GPIO pin Output Level */ |
559 | /*Configure GPIO pin Output Level */ |
| 542 | HAL_GPIO_WritePin(GPIOA, enableCurrent_Pin|step2N_Pin|step1N_Pin|step1P_Pin, GPIO_PIN_RESET); |
560 | HAL_GPIO_WritePin(GPIOA, enableCurrent_Pin|step2N_Pin|step1N_Pin|step1P_Pin, GPIO_PIN_RESET); |