Advertisement
Guest User

TPIC mods

a guest
May 30th, 2015
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. void hipAdcCallback(adcsample_t value) {
  2.     if (state == WAITING_FOR_ADC_TO_SKIP) {
  3.         state = WAITING_FOR_RESULT_ADC;
  4.     } else if (state == WAITING_FOR_RESULT_ADC) {
  5.         if (adcToVoltsDivided(value) > engineConfiguration->hipThreshold) {
  6.             totalKnockEventsCount++;
  7.             timeOfLastKnockEvent = getTimeNowUs();
  8.         }
  9.  
  10.         int integratorIndex = getIntegrationIndexByRpm(engine->rpmCalculator.rpmValue);
  11.         int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain);
  12.         int bandIndex = getBandIndex();
  13.         int prescalerIndex = engineConfiguration->hip9011PrescalerAndSDO;
  14.  
  15.         if (currentGainIndex != gainIndex) {
  16.             currentGainIndex = gainIndex;
  17.  
  18.             //added CMD bits
  19.             tx_buff[0] = SET_GAIN_CMD + gainIndex;
  20.  
  21.             state = IS_SENDING_SPI_COMMAND;
  22.             spiSelectI(driver);
  23.             spiStartExchangeI(driver, 1, tx_buff, rx_buff);
  24.         } else if (currentIntergratorIndex != integratorIndex) {
  25.             currentIntergratorIndex = integratorIndex;
  26.  
  27.             //added CMD bits
  28.             tx_buff[0] = SET_INTEGRATOR_CMD + integratorIndex;
  29.  
  30.             state = IS_SENDING_SPI_COMMAND;
  31.             spiSelectI(driver);
  32.             spiStartExchangeI(driver, 1, tx_buff, rx_buff);
  33.         } else if (currentBandIndex != bandIndex) {
  34.             currentBandIndex = bandIndex;
  35.  
  36.             //added CMD bits
  37.             tx_buff[0] = SET_BAND_PASS_CMD + bandIndex;
  38.  
  39.             state = IS_SENDING_SPI_COMMAND;
  40.             spiSelectI(driver);
  41.             spiStartExchangeI(driver, 1, tx_buff, rx_buff);
  42.         } else if (currentPrescaler != prescalerIndex) {
  43.             currentPrescaler = prescalerIndex;
  44.             tx_buff[0] = SET_PRESCALER_CMD + prescalerIndex;
  45.  
  46.             state = IS_SENDING_SPI_COMMAND;
  47.             spiSelectI(driver);
  48.             spiStartExchangeI(driver, 1, tx_buff, rx_buff);
  49.         } else {
  50.             state = READY_TO_INTEGRATE;
  51.         }
  52.     }
  53. }
  54.  
  55. static void setPrescalerAndSDO(int value) {
  56.     engineConfiguration->hip9011PrescalerAndSDO = value;
  57.     //this can be changed real time
  58.     //scheduleMsg(logger, "Reboot to apply %d", value);
  59.     showHipInfo();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement