void hipAdcCallback(adcsample_t value) { if (state == WAITING_FOR_ADC_TO_SKIP) { state = WAITING_FOR_RESULT_ADC; } else if (state == WAITING_FOR_RESULT_ADC) { engine->knockVolts = adcToVoltsDivided(value); hipValueMax = maxF(engine->knockVolts, hipValueMax); engine->knockLogic(engine->knockVolts); float angleWindowWidth = engineConfiguration->knockDetectionWindowEnd - engineConfiguration->knockDetectionWindowStart; if (angleWindowWidth != currentAngleWindowWidth) { currentAngleWindowWidth = angleWindowWidth; prepareHip9011RpmLookup(currentAngleWindowWidth); } int integratorIndex = getIntegrationIndexByRpm(engine->rpmCalculator.rpmValue); int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain); int bandIndex = getBandIndex(); int prescalerIndex = engineConfiguration->hip9011PrescalerAndSDO; if (currentGainIndex != gainIndex) { currentGainIndex = gainIndex; tx_buff[0] = SET_GAIN_CMD + gainIndex; state = IS_SENDING_SPI_COMMAND; spiSelectI(driver); spiStartExchangeI(driver, 1, tx_buff, rx_buff); } else if (currentIntergratorIndex != integratorIndex) { currentIntergratorIndex = integratorIndex; tx_buff[0] = SET_INTEGRATOR_CMD + integratorIndex; state = IS_SENDING_SPI_COMMAND; spiSelectI(driver); spiStartExchangeI(driver, 1, tx_buff, rx_buff); } else if (currentBandIndex != bandIndex) { currentBandIndex = bandIndex; tx_buff[0] = SET_BAND_PASS_CMD + bandIndex; state = IS_SENDING_SPI_COMMAND; spiSelectI(driver); spiStartExchangeI(driver, 1, tx_buff, rx_buff); } else if (currentPrescaler != prescalerIndex) { currentPrescaler = prescalerIndex; tx_buff[0] = SET_PRESCALER_CMD + prescalerIndex; state = IS_SENDING_SPI_COMMAND; spiSelectI(driver); spiStartExchangeI(driver, 1, tx_buff, rx_buff); } else { state = READY_TO_INTEGRATE; } } }
static void printAdcValue(adc_channel_e channel) { int value = getAdcValue("print", channel); float volts = adcToVoltsDivided(value); scheduleMsg(&logger, "adc voltage : %.2f", volts); }
static void printAdcValue(int channel) { int value = getAdcValue(channel); float volts = adcToVoltsDivided(value); scheduleMsg(&logger, "adc voltage : %f", volts); }