Subversion Repositories DashDisplay

Rev

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

Rev 70 Rev 71
Line 290... Line 290...
290
  cc_init();
290
  cc_init();
291
 
291
 
292
  int i;
292
  int i;
293
  for (i = 0; i < 2; i++)
293
  for (i = 0; i < 2; i++)
294
  {
294
  {
295
    dial_pos[i] = 0;            // default to items 0 and 1
-
 
296
    contexts[i].knobPos = -1;   // set the knob position
295
    contexts[i].knobPos = -1;   // set the knob position
297
    contexts[i].dial_timer = 1; // timeout immediately when decremented
-
 
298
 
-
 
299
    cc_check_nvram(i);
-
 
300
  }
296
  }
301
 
297
 
302
  /* reset the display timeout, latch on power from accessories */
298
  /* reset the display timeout, latch on power from accessories */
303
  Latch_Timer = IGNITION_OFF_TIMEOUT;
299
  Latch_Timer = IGNITION_OFF_TIMEOUT;
304
  HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET);
300
  HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET);
Line 311... Line 307...
311
  uint32_t nextTick = 0;
307
  uint32_t nextTick = 0;
312
  uint8_t log = 0;
308
  uint8_t log = 0;
313
  // PLX decoder protocols
309
  // PLX decoder protocols
314
  char PLXPacket = 0;
310
  char PLXPacket = 0;
315
 
311
 
316
 
-
 
317
  for (i = 0; i < MAXRDG; i++)
312
  for (i = 0; i < MAXRDG; i++)
318
  {
313
  {
319
    Info[i] = nullInfo;
314
    Info[i] = nullInfo;
320
  }
315
  }
321
 
316
 
322
  int PLXPtr = 0;
317
  int PLXPtr = 0;
323
  int logCount = 0;
318
  int logCount = 0;
324
 
319
 
325
  uint32_t resetCounter; // 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.
326
 
321
 
327
  /* USER CODE END 2 */
322
  /* USER CODE END 2 */
328
 
323
 
329
  /* Infinite loop */
324
  /* Infinite loop */
330
  /* USER CODE BEGIN WHILE */
325
  /* USER CODE BEGIN WHILE */
Line 364... Line 359...
364
        // Held down reset button for 10 seconds, clear NVRAM.
359
        // Held down reset button for 10 seconds, clear NVRAM.
365
        if ((HAL_GetTick() - resetCounter) > 10000)
360
        if ((HAL_GetTick() - resetCounter) > 10000)
366
        {
361
        {
367
          for (i = 0; i < 2; i++)
362
          for (i = 0; i < 2; i++)
368
          {
363
          {
369
            dial_pos[i] = 0;            // default to items 0 and 1
-
 
370
            contexts[i].knobPos = -1;   // set the knob position
364
            contexts[i].knobPos = -1;   // set the knob position
371
            contexts[i].dial_timer = 1; // timeout immediately when decremented
365
            contexts[i].dial_timer = 1; // timeout immediately when decremented
372
          }
366
          }
373
          erase_nvram();
367
          erase_nvram();
374
        }
368
        }
Line 406... Line 400...
406
 
400
 
407
      if (log)
401
      if (log)
408
      {
402
      {
409
        log = 0;
403
        log = 0;
410
        // Send items  to BT if it is in connected state
404
        // Send items  to BT if it is in connected state
411
        for (int i = 0; i <  MAXRDG; ++i)
405
        for (int i = 0; i < MAXRDG; ++i)
412
        {
406
        {
413
          if(!isValid(i))
407
          if (!isValid(i))
414
            continue;
408
            continue;
415
          char outbuff[100];
409
          char outbuff[100];
416
 
410
 
417
          int cnt = small_sprintf(outbuff,
411
          int cnt = small_sprintf(outbuff,
418
                                  "$PLLOG,%d,%d,%d,%ld",
412
                                  "$PLLOG,%d,%d,%d,%ld",
419
                                  logCount,
413
                                  logCount,
Line 560... Line 554...
560
      if (PLXPacket && PLXPtr < sizeof(Data.Bytes))
554
      if (PLXPacket && PLXPtr < sizeof(Data.Bytes))
561
      {
555
      {
562
        Data.Bytes[PLXPtr++] = c;
556
        Data.Bytes[PLXPtr++] = c;
563
      }
557
      }
564
    }
558
    }
-
 
559
 
-
 
560
    // handle switch rotation
-
 
561
    for (i = 0; i < MAX_DIALS; ++i)
-
 
562
    {
-
 
563
      int delta = get_dial_diff(i);
-
 
564
      int pos = contexts[i].knobPos;
-
 
565
      if(pos < 0)
-
 
566
        break; // dont process until we have read NVRAM for the first time . 
-
 
567
      int start = pos;
-
 
568
      // move in positive direction
-
 
569
      while (delta > 0)
-
 
570
      {
-
 
571
        // skip invalid items, dont count
-
 
572
        if(pos<MAXRDG-1)
-
 
573
          pos++;
-
 
574
        else
-
 
575
          pos=0;
-
 
576
 
-
 
577
        if (isValid(pos))
-
 
578
          delta--; // count a valid item 
-
 
579
       
-
 
580
        // wrap
-
 
581
        if (pos == start)
-
 
582
          break;
-
 
583
      }
-
 
584
 
-
 
585
      // move in negative direction
-
 
586
      while (delta < 0)
-
 
587
     
-
 
588
      {
-
 
589
        // skip invalid items, dont count
-
 
590
        if(pos>0)
-
 
591
          pos--;
-
 
592
        else
-
 
593
          pos=MAXRDG-1;
-
 
594
 
-
 
595
        if (isValid(pos))
-
 
596
          delta++; // count a valid item 
-
 
597
       
-
 
598
        // wrap
-
 
599
        if (pos == start)
-
 
600
          break;
-
 
601
      }
-
 
602
     
-
 
603
      contexts[i].knobPos = pos;
-
 
604
      if (pos != start)
-
 
605
        contexts[i].dial_timer = DialTimeout;
-
 
606
    }
-
 
607
 
565
    int suppress = -1;
608
    int suppress = -1;
566
    for (i = 0; i < MAX_DISPLAYS; i++)
609
    for (i = 0; i < MAX_DISPLAYS; i++)
567
    { // now to display the information
610
    { // now to display the information
568
      suppress = DisplayCurrent(i, suppress);
611
      suppress = DisplayCurrent(i, suppress);
569
 
612
 
570
      if (dial_pos[i] < 0)
-
 
571
        dial_pos[i] = MAXRDG - 1;
-
 
572
      if (dial_pos[i] >= MAXRDG)
-
 
573
        dial_pos[i] = 0;
-
 
574
 
-
 
575
      int prevPos = contexts[i].knobPos;
-
 
576
      if (contexts[i].knobPos >= 0)
-
 
577
        contexts[i].knobPos = dial_pos[i];
-
 
578
      // if the dial position was changed then reset timer
-
 
579
      if (prevPos != contexts[i].knobPos)
-
 
580
        contexts[i].dial_timer = DialTimeout;
-
 
581
 
-
 
582
      cc_check_nvram(i);
613
      cc_check_nvram(i);
583
      if (contexts[i].knobPos >= 0)
-
 
584
        dial_pos[i] = contexts[i].knobPos;
-
 
585
    }
614
    }
586
  }
615
  }
-
 
616
}
587
  /* USER CODE END WHILE */
617
/* USER CODE END WHILE */
588
 
618
 
589
  /* USER CODE BEGIN 3 */
619
/* USER CODE BEGIN 3 */
590
 
620
 
591
  /* USER CODE END 3 */
621
/* USER CODE END 3 */
592
}
-
 
593
 
622
 
594
/**
623
/**
595
 * @brief System Clock Configuration
624
 * @brief System Clock Configuration
596
 * @retval None
625
 * @retval None
597
 */
626
 */