Rev 63 | Rev 66 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 63 | Rev 65 | ||
---|---|---|---|
Line 26... | Line 26... | ||
26 | #include "libPLX/plx.h" |
26 | #include "libPLX/plx.h" |
27 | #include "libSerial/serial.H" |
27 | #include "libSerial/serial.H" |
28 | #include "libSmallPrintf/small_printf.h" |
28 | #include "libSmallPrintf/small_printf.h" |
29 | #include "libNMEA/nmea.h" |
29 | #include "libNMEA/nmea.h" |
30 | #include "switches.h" |
30 | #include "switches.h" |
31 | #include<string.h> |
31 | #include <string.h> |
32 | 32 | ||
33 | /* USER CODE END Includes */ |
33 | /* USER CODE END Includes */ |
34 | 34 | ||
35 | /* Private typedef -----------------------------------------------------------*/ |
35 | /* Private typedef -----------------------------------------------------------*/ |
36 | /* USER CODE BEGIN PTD */ |
36 | /* USER CODE BEGIN PTD */ |
Line 45... | Line 45... | ||
45 | /* USER CODE BEGIN PM */ |
45 | /* USER CODE BEGIN PM */ |
46 | 46 | ||
47 | /* USER CODE END PM */ |
47 | /* USER CODE END PM */ |
48 | 48 | ||
49 | /* Private variables ---------------------------------------------------------*/ |
49 | /* Private variables ---------------------------------------------------------*/ |
- | 50 | I2C_HandleTypeDef hi2c1; |
|
- | 51 | ||
50 | SPI_HandleTypeDef hspi1; |
52 | SPI_HandleTypeDef hspi1; |
51 | 53 | ||
52 | TIM_HandleTypeDef htim2; |
54 | TIM_HandleTypeDef htim2; |
53 | TIM_HandleTypeDef htim3; |
55 | TIM_HandleTypeDef htim3; |
54 | TIM_HandleTypeDef htim9; |
56 | TIM_HandleTypeDef htim9; |
Line 64... | Line 66... | ||
64 | context_t contexts[MAX_DISPLAYS]; |
66 | context_t contexts[MAX_DISPLAYS]; |
65 | 67 | ||
66 | /* timeout when the ignition is switched off */ |
68 | /* timeout when the ignition is switched off */ |
67 | #define IGNITION_OFF_TIMEOUT 30000UL |
69 | #define IGNITION_OFF_TIMEOUT 30000UL |
68 | 70 | ||
69 | // 500mS per logger period. |
71 | // 500mS per logger period. |
70 | #define LOGGER_INTERVAL 500UL |
72 | #define LOGGER_INTERVAL 500UL |
71 | 73 | ||
72 | const int DialTimeout = 10000; // about 10 seconds after twiddle, save the dial position. |
74 | const int DialTimeout = 10000; // about 10 seconds after twiddle, save the dial position. |
73 | 75 | ||
74 | nvram_info_t dial_nvram[MAX_DISPLAYS] __attribute__((section(".NVRAM_Data"))); |
76 | nvram_info_t dial_nvram[MAX_DISPLAYS] __attribute__((section(".NVRAM_Data"))); |
Line 96... | Line 98... | ||
96 | static void MX_USART3_UART_Init(void); |
98 | static void MX_USART3_UART_Init(void); |
97 | static void MX_TIM3_Init(void); |
99 | static void MX_TIM3_Init(void); |
98 | static void MX_TIM9_Init(void); |
100 | static void MX_TIM9_Init(void); |
99 | static void MX_TIM2_Init(void); |
101 | static void MX_TIM2_Init(void); |
100 | static void MX_UART4_Init(void); |
102 | static void MX_UART4_Init(void); |
- | 103 | static void MX_I2C1_Init(void); |
|
101 | /* USER CODE BEGIN PFP */ |
104 | /* USER CODE BEGIN PFP */ |
102 | 105 | ||
103 | // the dial is the switch number we are using. |
106 | // the dial is the switch number we are using. |
104 | // suppress is the ItemIndex we wish to suppress on this display |
107 | // suppress is the ItemIndex we wish to suppress on this display |
105 | int DisplayCurrent(int dial, int suppress) |
108 | int DisplayCurrent(int dial, int suppress) |
Line 137... | Line 140... | ||
137 | rmc_length = length < sizeof(rmc_buff) ? length : sizeof(rmc_buff); |
140 | rmc_length = length < sizeof(rmc_buff) ? length : sizeof(rmc_buff); |
138 | memcpy(rmc_buff, data, length); |
141 | memcpy(rmc_buff, data, length); |
139 | return 0; |
142 | return 0; |
140 | } |
143 | } |
141 | 144 | ||
142 | - | ||
143 | // check if bluetooth connected |
145 | // check if bluetooth connected |
144 | uint8_t btConnected() |
146 | uint8_t btConnected() |
145 | { |
147 | { |
146 | return HAL_GPIO_ReadPin(BT_STATE_GPIO_Port, BT_STATE_Pin) == GPIO_PIN_SET; |
148 | return HAL_GPIO_ReadPin(BT_STATE_GPIO_Port, BT_STATE_Pin) == GPIO_PIN_SET; |
147 | } |
149 | } |
148 | 150 | ||
149 | /* USER CODE END PFP */ |
151 | /* USER CODE END PFP */ |
150 | 152 | ||
151 | /* Private user code ---------------------------------------------------------*/ |
153 | /* Private user code ---------------------------------------------------------*/ |
Line 198... | Line 200... | ||
198 | MX_USART3_UART_Init(); |
200 | MX_USART3_UART_Init(); |
199 | MX_TIM3_Init(); |
201 | MX_TIM3_Init(); |
200 | MX_TIM9_Init(); |
202 | MX_TIM9_Init(); |
201 | MX_TIM2_Init(); |
203 | MX_TIM2_Init(); |
202 | MX_UART4_Init(); |
204 | MX_UART4_Init(); |
- | 205 | MX_I2C1_Init(); |
|
203 | /* USER CODE BEGIN 2 */ |
206 | /* USER CODE BEGIN 2 */ |
204 | 207 | ||
205 | /* Turn on USART1 IRQ */ |
208 | /* Turn on USART1 IRQ */ |
206 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
209 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
207 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
210 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
Line 244... | Line 247... | ||
244 | cc_init(); |
247 | cc_init(); |
245 | 248 | ||
246 | int i; |
249 | int i; |
247 | for (i = 0; i < 2; i++) |
250 | for (i = 0; i < 2; i++) |
248 | { |
251 | { |
249 | dial_pos[i] = 0; // default to items 0 and 1 |
252 | dial_pos[i] = 0; // default to items 0 and 1 |
250 | contexts[i].knobPos = -1; |
253 | contexts[i].knobPos = -1; // set the knob position |
- | 254 | contexts[i].dial_timer = 1; // timeout immediately |
|
251 | } |
255 | } |
252 | 256 | ||
253 | /* reset the display timeout, latch on power from accessories */ |
257 | /* reset the display timeout, latch on power from accessories */ |
254 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
258 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
255 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
259 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
Line 287... | Line 291... | ||
287 | char PLXPacket = 0; |
291 | char PLXPacket = 0; |
288 | for (i = 0; i < MAXRDG; i++) |
292 | for (i = 0; i < MAXRDG; i++) |
289 | { |
293 | { |
290 | Info[i].Max = 0; |
294 | Info[i].Max = 0; |
291 | Info[i].Min = 0xFFF; // 12 bit max value |
295 | Info[i].Min = 0xFFF; // 12 bit max value |
292 | Info[i].sum = 0; // |
296 | Info[i].sum = 0; // |
293 | Info[i].count=0; |
297 | Info[i].count = 0; |
294 | } |
298 | } |
295 | 299 | ||
296 | int PLXPtr = 0; |
300 | int PLXPtr = 0; |
297 | 301 | ||
298 | while (1) |
302 | while (1) |
Line 310... | Line 314... | ||
310 | rmc_length = 0; |
314 | rmc_length = 0; |
311 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
315 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
312 | logCount = 0; |
316 | logCount = 0; |
313 | log = 1; |
317 | log = 1; |
314 | } |
318 | } |
315 | 319 | ||
316 | // time several counted logger intervals after RMC recieved, enable logger each timeout. |
320 | // time several counted logger intervals after RMC recieved, enable logger each timeout. |
317 | if (logCount < ((1000 / LOGGER_INTERVAL)-1) && HAL_GetTick() > nextTick) |
321 | if (logCount < ((1000 / LOGGER_INTERVAL) - 1) && HAL_GetTick() > nextTick) |
318 | { |
322 | { |
319 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
323 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
320 | ++logCount; |
324 | ++logCount; |
321 | log = 1; |
325 | log = 1; |
322 | } |
326 | } |
Line 349... | Line 353... | ||
349 | 353 | ||
350 | // do turn off screen |
354 | // do turn off screen |
351 | } |
355 | } |
352 | } |
356 | } |
353 | 357 | ||
354 | - | ||
355 | for (chr = 0; chr < cc; chr++) |
358 | for (chr = 0; chr < cc; chr++) |
356 | { |
359 | { |
357 | char c = GetCharSerial(&uc1); |
360 | char c = GetCharSerial(&uc1); |
358 | 361 | ||
359 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
362 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
Line 384... | Line 387... | ||
384 | } |
387 | } |
385 | if (Info[i].data < Info[i].Min) |
388 | if (Info[i].data < Info[i].Min) |
386 | { |
389 | { |
387 | Info[i].Min = Info[i].data; |
390 | Info[i].Min = Info[i].data; |
388 | } |
391 | } |
389 | // take an avarage |
392 | // take an avarage |
390 | Info[i].sum += Info[i].data; |
393 | Info[i].sum += Info[i].data; |
391 | Info[i].count ++; |
394 | Info[i].count++; |
392 | 395 | ||
393 | // Send items to BT if it is in connected state |
396 | // Send items to BT if it is in connected state |
394 | if (log && btConnected()) |
397 | if (log && btConnected()) |
395 | { |
398 | { |
396 | 399 | ||
Line 399... | Line 402... | ||
399 | int cnt = small_sprintf(outbuff, |
402 | int cnt = small_sprintf(outbuff, |
400 | "$PLLOG,%d,%d,%d,%ld", |
403 | "$PLLOG,%d,%d,%d,%ld", |
401 | logCount, |
404 | logCount, |
402 | Info[i].observation, |
405 | Info[i].observation, |
403 | Info[i].instance, |
406 | Info[i].instance, |
404 | Info[i].count==0? 0: Info[i].sum/Info[i].count); |
407 | Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count); |
405 | 408 | ||
406 | // NMEA style checksum |
409 | // NMEA style checksum |
407 | int ck; |
410 | int ck; |
408 | int sum = 0; |
411 | int sum = 0; |
409 | for (ck = 1; ck < cnt; ck++) |
412 | for (ck = 1; ck < cnt; ck++) |
Line 411... | Line 414... | ||
411 | cnt += small_sprintf(outbuff + cnt, "*%02X\n", |
414 | cnt += small_sprintf(outbuff + cnt, "*%02X\n", |
412 | sum & 0xFF); |
415 | sum & 0xFF); |
413 | sendString(&uc3, outbuff, cnt); |
416 | sendString(&uc3, outbuff, cnt); |
414 | } |
417 | } |
415 | } |
418 | } |
416 | log = 0; |
419 | log = 0; |
417 | // now to display the information |
420 | // now to display the information |
418 | int suppress = DisplayCurrent(0, -1); |
421 | int suppress = DisplayCurrent(0, -1); |
419 | DisplayCurrent(1, suppress); |
422 | DisplayCurrent(1, suppress); |
420 | } |
423 | } |
421 | PLXPtr = 0; |
424 | PLXPtr = 0; |
422 | PLXPacket = 0; |
425 | PLXPacket = 0; |
Line 500... | Line 503... | ||
500 | Error_Handler(); |
503 | Error_Handler(); |
501 | } |
504 | } |
502 | } |
505 | } |
503 | 506 | ||
504 | /** |
507 | /** |
- | 508 | * @brief I2C1 Initialization Function |
|
- | 509 | * @param None |
|
- | 510 | * @retval None |
|
- | 511 | */ |
|
- | 512 | static void MX_I2C1_Init(void) |
|
- | 513 | { |
|
- | 514 | ||
- | 515 | /* USER CODE BEGIN I2C1_Init 0 */ |
|
- | 516 | ||
- | 517 | /* USER CODE END I2C1_Init 0 */ |
|
- | 518 | ||
- | 519 | /* USER CODE BEGIN I2C1_Init 1 */ |
|
- | 520 | ||
- | 521 | /* USER CODE END I2C1_Init 1 */ |
|
- | 522 | hi2c1.Instance = I2C1; |
|
- | 523 | hi2c1.Init.ClockSpeed = 100000; |
|
- | 524 | hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; |
|
- | 525 | hi2c1.Init.OwnAddress1 = 0; |
|
- | 526 | hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
|
- | 527 | hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
|
- | 528 | hi2c1.Init.OwnAddress2 = 0; |
|
- | 529 | hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
|
- | 530 | hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
|
- | 531 | if (HAL_I2C_Init(&hi2c1) != HAL_OK) |
|
- | 532 | { |
|
- | 533 | Error_Handler(); |
|
- | 534 | } |
|
- | 535 | /* USER CODE BEGIN I2C1_Init 2 */ |
|
- | 536 | ||
- | 537 | /* USER CODE END I2C1_Init 2 */ |
|
- | 538 | } |
|
- | 539 | ||
- | 540 | /** |
|
505 | * @brief SPI1 Initialization Function |
541 | * @brief SPI1 Initialization Function |
506 | * @param None |
542 | * @param None |
507 | * @retval None |
543 | * @retval None |
508 | */ |
544 | */ |
509 | static void MX_SPI1_Init(void) |
545 | static void MX_SPI1_Init(void) |