Subversion Repositories DashDisplay

Rev

Rev 72 | Rev 74 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 72 Rev 73
Line 67... Line 67...
67
 
67
 
68
///@brief  timeout when the ignition is switched off
68
///@brief  timeout when the ignition is switched off
69
#define IGNITION_OFF_TIMEOUT 30000UL
69
#define IGNITION_OFF_TIMEOUT 30000UL
70
 
70
 
71
/// @brief 1000mS per logger period, print average per period
71
/// @brief 1000mS per logger period, print average per period
72
#define LOGGER_INTERVAL 1000UL
72
#define LOGGER_INTERVAL 500UL
73
 
73
 
74
/// @brief  about 10 seconds after twiddle, save the dial position.
74
/// @brief  about 10 seconds after twiddle, save the dial position.
75
const int DialTimeout = 100;
75
const int DialTimeout = 100;
76
 
76
 
77
/// @brief Data storage for readings
77
/// @brief Data storage for readings
Line 120... Line 120...
120
 
120
 
121
/// \note  HC-05 only accepts : 9600,19200,38400,57600,115200,230400,460800 baud
121
/// \note  HC-05 only accepts : 9600,19200,38400,57600,115200,230400,460800 baud
122
/// \brief Setup Bluetooth module
122
/// \brief Setup Bluetooth module
123
void initModule(usart_ctl *ctl, uint32_t baudRate)
123
void initModule(usart_ctl *ctl, uint32_t baudRate)
124
{
124
{
125
  char initBuf[30];
125
  char initBuf[60];
126
  // switch to command mode
126
  // switch to command mode
-
 
127
  HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_SET);
-
 
128
  HAL_Delay(500);
-
 
129
  // clear the button press
127
  HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_RESET);
130
  HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_RESET);
128
  HAL_Delay(500);
131
  HAL_Delay(500);
129
  setBaud(ctl, 38400);
132
  setBaud(ctl, 38400);
130
  int initLen = small_sprintf(initBuf, "AT+UART=%lu,0,0\n", baudRate);
133
  int initLen = small_sprintf(initBuf, "AT\nAT+UART?\nAT+UART=%ld,0,0\n", baudRate);
131
  const char buf[] = "AT+RESET\n";
134
  const char buf[] = "AT+RESET\n";
132
  sendString(ctl, initBuf, initLen);
135
  sendString(ctl, initBuf, initLen);
133
  HAL_Delay(500);
136
  HAL_Delay(500);
134
  initLen = small_sprintf(initBuf, buf);
137
  initLen = small_sprintf(initBuf, buf);
135
  sendString(ctl, initBuf, initLen);
138
  sendString(ctl, initBuf, initLen);
136
 
139
 
137
  TxWaitEmpty(ctl);
140
  TxWaitEmpty(ctl);
138
 
141
 
139
  // clear the button press
-
 
140
  HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_SET);
-
 
141
 
-
 
142
  // switch back to normal comms at new baud rate
142
  // switch back to normal comms at new baud rate
143
  setBaud(ctl, baudRate);
143
  setBaud(ctl, baudRate);
144
  HAL_Delay(100);
144
  HAL_Delay(100);
145
}
145
}
146
 
146
 
Line 288... Line 288...
288
  cc_init();
288
  cc_init();
289
 
289
 
290
  int i;
290
  int i;
291
  for (i = 0; i < 2; i++)
291
  for (i = 0; i < 2; i++)
292
  {
292
  {
293
    contexts[i].knobPos = -1;   // set the knob position
293
    contexts[i].knobPos = -1; // set the knob position
294
  }
294
  }
295
 
295
 
296
  /* reset the display timeout, latch on power from accessories */
296
  /* reset the display timeout, latch on power from accessories */
297
  Latch_Timer = IGNITION_OFF_TIMEOUT;
297
  Latch_Timer = IGNITION_OFF_TIMEOUT;
298
  HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET);
298
  HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET);
Line 300... Line 300...
300
  setRmcCallback(&rmc_callback);
300
  setRmcCallback(&rmc_callback);
301
 
301
 
302
  // data timeout
302
  // data timeout
303
  uint32_t timeout = 0; //
303
  uint32_t timeout = 0; //
304
 
304
 
-
 
305
  // used in NMEA style logging
305
  uint32_t nextTick = 0;
306
  uint32_t nextTick = 0;    ///< time to send next
-
 
307
  uint32_t offsetTicks = 0; ///< time to print as offset in mS for each loop
-
 
308
  //
306
  uint8_t log = 0;
309
  uint8_t log = 0;
307
  // PLX decoder protocols
310
  // PLX decoder protocols
308
  char PLXPacket = 0;
311
  char PLXPacket = 0;
309
 
312
 
310
  for (i = 0; i < MAXRDG; i++)
313
  for (i = 0; i < MAXRDG; i++)
311
  {
314
  {
312
    Info[i] = nullInfo;
315
    Info[i] = nullInfo;
313
  }
316
  }
314
 
317
 
315
  int PLXPtr = 0;
318
  int PLXPtr = 0;
316
  int logCount = 0;
-
 
317
 
319
 
318
  uint32_t resetCounter = 0 ; // record time at which both reset buttons were first pressed.
320
  uint32_t resetCounter = 0; // record time at which both reset buttons were first pressed.
319
 
321
 
320
  /* USER CODE END 2 */
322
  /* USER CODE END 2 */
321
 
323
 
322
  /* Infinite loop */
324
  /* Infinite loop */
323
  /* USER CODE BEGIN WHILE */
325
  /* USER CODE BEGIN WHILE */
Line 379... Line 381...
379
      // Any RMC data, send it, reset the logger timeout
381
      // Any RMC data, send it, reset the logger timeout
380
      if (rmc_length)
382
      if (rmc_length)
381
      {
383
      {
382
        sendString(&uc3, (const char *)rmc_buff, rmc_length);
384
        sendString(&uc3, (const char *)rmc_buff, rmc_length);
383
        rmc_length = 0;
385
        rmc_length = 0;
-
 
386
        offsetTicks = 0;
384
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
387
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
385
        log = 1;      // send out associated data over Bluetooth because triggered by recieving RMC
-
 
386
        logCount = 0; // first sample set this second numbered 0
388
        log = 1;
387
      }
389
      }
388
 
390
 
389
      // Timeout for data logging regularly
391
      // Timeout for data logging regularly
390
      if (HAL_GetTick() > nextTick)
392
      if (HAL_GetTick() > nextTick)
391
      {
393
      {
-
 
394
        offsetTicks += LOGGER_INTERVAL;
392
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
395
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
393
        logCount++;
-
 
394
        if (logCount > (1000 / LOGGER_INTERVAL))
-
 
395
          logCount = 0;
396
        if (offsetTicks < (1000))
396
        log = 1;
397
          log = 1;
397
      }
398
      }
398
 
399
 
399
      if (log)
400
      if (log)
400
      {
401
      {
401
        log = 0;
402
        log = 0;
402
        // Send items  to BT if it is in connected state
403
        // Send items  to BT if it is in connected state
-
 
404
 
-
 
405
        char linebuff[20];
-
 
406
        strftime(linebuff, sizeof(linebuff), "%H%M%S", &loc.tv);
403
        for (int i = 0; i < MAXRDG; ++i)
407
        for (int i = 0; i < MAXRDG; ++i)
404
        {
408
        {
405
          if (!isValid(i))
409
          if (!isValid(i))
406
            continue;
410
            continue;
407
          char outbuff[100];
411
          char outbuff[100];
408
 
412
 
409
          int cnt = small_sprintf(outbuff,
413
          int cnt = small_sprintf(outbuff,
410
                                  "$PLLOG,%d,%d,%d,%ld",
414
                                  "$PLLOG,%s.%03lu,%d,%d,%ld",
411
                                  logCount,
415
                                  linebuff,
-
 
416
                                  offsetTicks,
412
                                  Info[i].observation,
417
                                  Info[i].observation,
413
                                  Info[i].instance,
418
                                  Info[i].instance,
414
                                  Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count);
419
                                  Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count);
415
 
420
 
416
          // NMEA style checksum
421
          // NMEA style checksum
Line 558... Line 563...
558
    // handle switch rotation
563
    // handle switch rotation
559
    for (i = 0; i < MAX_DIALS; ++i)
564
    for (i = 0; i < MAX_DIALS; ++i)
560
    {
565
    {
561
      int delta = get_dial_diff(i);
566
      int delta = get_dial_diff(i);
562
      int pos = contexts[i].knobPos;
567
      int pos = contexts[i].knobPos;
563
      if(pos < 0)
568
      if (pos < 0)
564
        break; // dont process until we have read NVRAM for the first time . 
569
        break; // dont process until we have read NVRAM for the first time .
565
      int start = pos;
570
      int start = pos;
566
      // move in positive direction
571
      // move in positive direction
567
      while (delta > 0)
572
      while (delta > 0)
568
      {
573
      {
569
        // skip invalid items, dont count
574
        // skip invalid items, dont count
570
        if(pos<MAXRDG-1)
575
        if (pos < MAXRDG - 1)
571
          pos++;
576
          pos++;
572
        else
577
        else
573
          pos=0;
578
          pos = 0;
574
 
579
 
575
        if (isValid(pos))
580
        if (isValid(pos))
576
          delta--; // count a valid item 
581
          delta--; // count a valid item
577
       
582
 
578
        // wrap
583
        // wrap
579
        if (pos == start)
584
        if (pos == start)
580
          break;
585
          break;
581
      }
586
      }
582
 
587
 
583
      // move in negative direction
588
      // move in negative direction
584
      while (delta < 0)
589
      while (delta < 0)
585
     
590
 
586
      {
591
      {
587
        // skip invalid items, dont count
592
        // skip invalid items, dont count
588
        if(pos>0)
593
        if (pos > 0)
589
          pos--;
594
          pos--;
590
        else
595
        else
591
          pos=MAXRDG-1;
596
          pos = MAXRDG - 1;
592
 
597
 
593
        if (isValid(pos))
598
        if (isValid(pos))
594
          delta++; // count a valid item 
599
          delta++; // count a valid item
595
       
600
 
596
        // wrap
601
        // wrap
597
        if (pos == start)
602
        if (pos == start)
598
          break;
603
          break;
599
      }
604
      }
600
     
605
 
601
      contexts[i].knobPos = pos;
606
      contexts[i].knobPos = pos;
602
      if (pos != start)
607
      if (pos != start)
603
        contexts[i].dial_timer = DialTimeout;
608
        contexts[i].dial_timer = DialTimeout;
604
    }
609
    }
605
 
610
 
Line 608... Line 613...
608
    { // now to display the information
613
    { // now to display the information
609
      suppress = DisplayCurrent(i, suppress);
614
      suppress = DisplayCurrent(i, suppress);
610
 
615
 
611
      cc_check_nvram(i);
616
      cc_check_nvram(i);
612
    }
617
    }
-
 
618
    /* USER CODE END WHILE */
613
  }
619
  }
614
}
-
 
615
/* USER CODE END WHILE */
620
  /* USER CODE BEGIN 3 */
616
 
621
 
617
/* USER CODE BEGIN 3 */
622
  /* USER CODE END 3 */
618
 
623
}
619
/* USER CODE END 3 */
-
 
620
 
624
 
621
/**
625
/**
622
 * @brief System Clock Configuration
626
 * @brief System Clock Configuration
623
 * @retval None
627
 * @retval None
624
 */
628
 */
Line 1011... Line 1015...
1011
  __HAL_RCC_GPIOA_CLK_ENABLE();
1015
  __HAL_RCC_GPIOA_CLK_ENABLE();
1012
  __HAL_RCC_GPIOC_CLK_ENABLE();
1016
  __HAL_RCC_GPIOC_CLK_ENABLE();
1013
  __HAL_RCC_GPIOB_CLK_ENABLE();
1017
  __HAL_RCC_GPIOB_CLK_ENABLE();
1014
 
1018
 
1015
  /*Configure GPIO pin Output Level */
1019
  /*Configure GPIO pin Output Level */
1016
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | BT_RESET_Pin, GPIO_PIN_SET);
1020
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | BT_BUTTON_Pin | BT_RESET_Pin, GPIO_PIN_SET);
1017
 
1021
 
1018
  /*Configure GPIO pin Output Level */
1022
  /*Configure GPIO pin Output Level */
1019
  HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin | BT_BUTTON_Pin, GPIO_PIN_RESET);
1023
  HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
1020
 
1024
 
1021
  /*Configure GPIO pin Output Level */
1025
  /*Configure GPIO pin Output Level */
1022
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin | POWER_LATCH_Pin | USB_PWR_Pin, GPIO_PIN_RESET);
1026
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin | POWER_LATCH_Pin | USB_PWR_Pin, GPIO_PIN_RESET);
1023
 
1027
 
1024
  /*Configure GPIO pin Output Level */
1028
  /*Configure GPIO pin Output Level */
Line 1048... Line 1052...
1048
  GPIO_InitStruct.Pin = IGNITION_Pin;
1052
  GPIO_InitStruct.Pin = IGNITION_Pin;
1049
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
1053
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
1050
  GPIO_InitStruct.Pull = GPIO_NOPULL;
1054
  GPIO_InitStruct.Pull = GPIO_NOPULL;
1051
  HAL_GPIO_Init(IGNITION_GPIO_Port, &GPIO_InitStruct);
1055
  HAL_GPIO_Init(IGNITION_GPIO_Port, &GPIO_InitStruct);
1052
 
1056
 
1053
  /*Configure GPIO pins : BT_BUTTON_Pin BT_RESET_Pin */
1057
  /*Configure GPIO pin : BT_BUTTON_Pin */
1054
  GPIO_InitStruct.Pin = BT_BUTTON_Pin | BT_RESET_Pin;
1058
  GPIO_InitStruct.Pin = BT_BUTTON_Pin;
1055
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
1059
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
1056
  GPIO_InitStruct.Pull = GPIO_NOPULL;
1060
  GPIO_InitStruct.Pull = GPIO_PULLUP;
1057
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1061
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
-
 
1062
  HAL_GPIO_Init(BT_BUTTON_GPIO_Port, &GPIO_InitStruct);
-
 
1063
 
-
 
1064
  /*Configure GPIO pin : BT_RESET_Pin */
-
 
1065
  GPIO_InitStruct.Pin = BT_RESET_Pin;
-
 
1066
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-
 
1067
  GPIO_InitStruct.Pull = GPIO_NOPULL;
-
 
1068
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
1058
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
1069
  HAL_GPIO_Init(BT_RESET_GPIO_Port, &GPIO_InitStruct);
1059
}
1070
}
1060
 
1071
 
1061
/* USER CODE BEGIN 4 */
1072
/* USER CODE BEGIN 4 */
1062
 
1073
 
1063
/* USER CODE END 4 */
1074
/* USER CODE END 4 */