Rev 53 | Rev 57 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 53 | Rev 56 | ||
|---|---|---|---|
| Line 65... | Line 65... | ||
| 65 | 65 | ||
| 66 | #define LOGGER_INTERVAL 500UL |
66 | #define LOGGER_INTERVAL 500UL |
| 67 | 67 | ||
| 68 | const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position. |
68 | const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position. |
| 69 | 69 | ||
| 70 | uint16_t dial_nvram[MAX_DISPLAYS] __attribute__((section(".NVRAM_Data"))); |
70 | nvram_info_t dial_nvram[MAX_DISPLAYS] __attribute__((section(".NVRAM_Data"))); |
| 71 | 71 | ||
| - | 72 | info_t Info[MAXRDG]; |
|
| - | 73 | ||
| - | 74 | /// \brief storage for incoming data |
|
| 72 | data_t Data; |
75 | data_t Data; |
| 73 | int Max[MAXRDG]; |
- | |
| 74 | int Min[MAXRDG]; |
- | |
| - | 76 | ||
| 75 | int PLXItems; |
77 | int PLXItems; |
| 76 | 78 | ||
| 77 | uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT; |
79 | uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT; |
| 78 | 80 | ||
| 79 | /* USER CODE END PV */ |
81 | /* USER CODE END PV */ |
| Line 102... | Line 104... | ||
| 102 | // the dial is the switch number we are using. |
104 | // the dial is the switch number we are using. |
| 103 | // suppress is the ItemIndex we wish to suppress on this display |
105 | // suppress is the ItemIndex we wish to suppress on this display |
| 104 | int |
106 | int |
| 105 | DisplayCurrent (int dial, int suppress) |
107 | DisplayCurrent (int dial, int suppress) |
| 106 | { |
108 | { |
| 107 | if (PLXItems == 0) |
- | |
| 108 | return -1; |
- | |
| 109 | - | ||
| 110 | int itemIndex = dial_pos[dial] % PLXItems; |
109 | int itemIndex = dial_pos[dial] % PLXItems; |
| - | 110 | if (itemIndex < 0) |
|
| 111 | 111 | return -1; |
|
| 112 | return cc_display (dial, itemIndex, suppress); |
112 | return cc_display (dial, itemIndex, suppress); |
| 113 | } |
113 | } |
| 114 | 114 | ||
| 115 | void |
115 | void |
| 116 | setBaud (usart_ctl *ctl, uint32_t baud) |
116 | setBaud (usart_ctl *ctl, uint32_t baud) |
| Line 128... | Line 128... | ||
| 128 | for (i = 0; i < length; i++) |
128 | for (i = 0; i < length; i++) |
| 129 | PutCharSerial (ctl, string[i]); |
129 | PutCharSerial (ctl, string[i]); |
| 130 | 130 | ||
| 131 | } |
131 | } |
| 132 | 132 | ||
| 133 | - | ||
| 134 | // this code doesnt work so it leaves speed as 9600. |
133 | /// \note this code doesnt work so it leaves speed as 9600. |
| - | 134 | /// \brief Setup Bluetooth module |
|
| 135 | void |
135 | void |
| 136 | initModule (usart_ctl *ctl, uint32_t baudRate) |
136 | initModule (usart_ctl *ctl, uint32_t baudRate) |
| 137 | { |
137 | { |
| 138 | char initBuf[30]; |
138 | char initBuf[30]; |
| 139 | // switch to command mode |
139 | // switch to command mode |
| Line 234... | Line 234... | ||
| 234 | HAL_TIM_Encoder_Start (&htim9, TIM_CHANNEL_ALL); |
234 | HAL_TIM_Encoder_Start (&htim9, TIM_CHANNEL_ALL); |
| 235 | 235 | ||
| 236 | // Switch handler called on sysTick interrupt. |
236 | // Switch handler called on sysTick interrupt. |
| 237 | InitSwitches (); |
237 | InitSwitches (); |
| 238 | 238 | ||
| 239 | initModule(&uc3,9600); |
239 | initModule (&uc3, 9600); |
| 240 | - | ||
| 241 | 240 | ||
| 242 | cc_init (); |
241 | cc_init (); |
| 243 | 242 | ||
| 244 | int i; |
243 | int i; |
| 245 | for (i = 0; i < 2; i++) |
244 | for (i = 0; i < 2; i++) |
| 246 | { |
245 | { |
| 247 | dial_pos[i] = dial_nvram[i]; |
246 | dial_pos[i] = -1; // default to items 0 and 1 |
| 248 | } |
247 | } |
| 249 | 248 | ||
| 250 | /* reset the display timeout, latch on power from accessories */ |
249 | /* reset the display timeout, latch on power from accessories */ |
| 251 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
250 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
| 252 | HAL_GPIO_WritePin (POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
251 | HAL_GPIO_WritePin (POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
| Line 279... | Line 278... | ||
| 279 | uint8_t log = 0; |
278 | uint8_t log = 0; |
| 280 | // PLX decoder protocols |
279 | // PLX decoder protocols |
| 281 | char PLXPacket = 0; |
280 | char PLXPacket = 0; |
| 282 | for (i = 0; i < MAXRDG; i++) |
281 | for (i = 0; i < MAXRDG; i++) |
| 283 | { |
282 | { |
| 284 | Max[i] = 0; |
283 | Info[i].Max = 0; |
| 285 | Min[i] = 0xFFF; // 12 bit max value |
284 | Info[i].Min = 0xFFF; // 12 bit max value |
| 286 | } |
285 | } |
| 287 | 286 | ||
| 288 | int PLXPtr = 0; |
287 | int PLXPtr = 0; |
| 289 | 288 | ||
| 290 | while (1) |
289 | while (1) |
| Line 347... | Line 346... | ||
| 347 | 346 | ||
| 348 | int DataVal; |
347 | int DataVal; |
| 349 | // process min/max |
348 | // process min/max |
| 350 | for (i = 0; i < PLXItems; i++) |
349 | for (i = 0; i < PLXItems; i++) |
| 351 | { |
350 | { |
| - | 351 | Info[i].observation = ConvPLX (Data.Sensor[i].AddrH, |
|
| - | 352 | Data.Sensor[i].AddrL); |
|
| - | 353 | Info[i].instance = Data.Sensor[i].Instance; |
|
| - | 354 | Info[i].data = ConvPLX (Data.Sensor[i].ReadingH, |
|
| - | 355 | Data.Sensor[i].ReadingL); |
|
| - | 356 | if (Info[i].data > Info[i].Max) |
|
| - | 357 | { |
|
| - | 358 | Info[i].Max = Info[i].data; |
|
| - | 359 | } |
|
| - | 360 | if (Info[i].data < Info[i].Min) |
|
| - | 361 | { |
|
| - | 362 | Info[i].Min = Info[i].data; |
|
| - | 363 | } |
|
| - | 364 | ||
| - | 365 | // Send item to BT |
|
| 352 | 366 | ||
| 353 | if (log) |
367 | if (log) |
| 354 | { |
368 | { |
| 355 | // Send item to BT |
- | |
| 356 | uint16_t addr = ConvPLX (Data.Sensor[i].AddrH, |
- | |
| 357 | Data.Sensor[i].AddrL); |
- | |
| 358 | uint8_t inst = Data.Sensor[i].Instance; |
- | |
| 359 | uint16_t reading = ConvPLX ( |
- | |
| 360 | Data.Sensor[i].ReadingH, |
- | |
| 361 | Data.Sensor[i].ReadingL); |
- | |
| - | 369 | ||
| 362 | char outbuff[100]; |
370 | char outbuff[100]; |
| 363 | 371 | ||
| 364 | int cnt = small_sprintf (outbuff, "$LOG,%d,%d,%d", |
372 | int cnt = small_sprintf (outbuff, "$LOG,%d,%d,%d", |
| - | 373 | Info[i].observation, |
|
| 365 | addr, inst, reading); |
374 | Info[i].instance, |
| - | 375 | Info[i].data); |
|
| 366 | 376 | ||
| 367 | //checksum |
377 | //checksum |
| 368 | int ck; |
378 | int ck; |
| 369 | int sum = 0; |
379 | int sum = 0; |
| 370 | for (ck = 1; ck < cnt; ck++) |
380 | for (ck = 1; ck < cnt; ck++) |
| Line 372... | Line 382... | ||
| 372 | cnt += small_sprintf (outbuff + cnt, "*%02X\n", |
382 | cnt += small_sprintf (outbuff + cnt, "*%02X\n", |
| 373 | sum & 0xFF); |
383 | sum & 0xFF); |
| 374 | sendString (&uc3, outbuff, cnt); |
384 | sendString (&uc3, outbuff, cnt); |
| 375 | 385 | ||
| 376 | } |
386 | } |
| 377 | DataVal = ConvPLX (Data.Sensor[i].ReadingH, |
- | |
| 378 | Data.Sensor[i].ReadingL); |
- | |
| 379 | if (DataVal > Max[i]) |
- | |
| 380 | { |
- | |
| 381 | Max[i] = DataVal; |
- | |
| 382 | } |
- | |
| 383 | if (DataVal < Min[i]) |
- | |
| 384 | { |
- | |
| 385 | Min[i] = DataVal; |
- | |
| 386 | } |
- | |
| 387 | } |
387 | } |
| 388 | 388 | ||
| 389 | // now to display the information |
389 | // now to display the information |
| 390 | int suppress = DisplayCurrent (0, -1); |
390 | int suppress = DisplayCurrent (0, -1); |
| 391 | DisplayCurrent (1, suppress); |
391 | DisplayCurrent (1, suppress); |
| Line 404... | Line 404... | ||
| 404 | } |
404 | } |
| 405 | 405 | ||
| 406 | } |
406 | } |
| 407 | 407 | ||
| 408 | HAL_Delay (1); |
408 | HAL_Delay (1); |
| - | 409 | ||
| - | 410 | dial_pos[0] = cc_check_nvram (0, dial_pos[0]); |
|
| - | 411 | dial_pos[1] = cc_check_nvram (1, dial_pos[1]); |
|
| - | 412 | ||
| 409 | } |
413 | } |
| 410 | 414 | ||
| 411 | /* USER CODE END WHILE */ |
415 | /* USER CODE END WHILE */ |
| 412 | 416 | ||
| 413 | /* USER CODE BEGIN 3 */ |
417 | /* USER CODE BEGIN 3 */ |