/** * @return Manifold Absolute Pressure, in kPa */ float getRawMap(DECLARE_ENGINE_PARAMETER_F) { if (engineConfiguration->hasFrequencyReportingMapSensor) { return interpolate(boardConfiguration->mapFrequency0Kpa, 0, boardConfiguration->mapFrequency100Kpa, 100, mapFreq); } float voltage = getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel); return getMapByVoltage(voltage PASS_ENGINE_PARAMETER); }
percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (mockPedalPosition != MOCK_UNDEFINED) { return mockPedalPosition; } float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel); float result = interpolateMsg("pedal", engineConfiguration->throttlePedalUpVoltage, 0, engineConfiguration->throttlePedalWOTVoltage, 100, voltage); // this would put the value into the 0-100 range return maxF(0, minF(100, result)); }
float getOilPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) { // If there's no sensor, return 0 pressure. if(!hasOilPressureSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { return 0.0f; } oil_pressure_config_s* sensor = &CONFIG(oilPressure); float volts = getVoltageDivided("oilp", sensor->hwChannel); return interpolateMsg("oil", sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts); }
static void printThermistor(char *msg, Thermistor *thermistor) { int adcChannel = thermistor->channel; float voltage = getVoltageDivided(adcChannel); float r = getResistance(thermistor); float t = getTemperatureC(thermistor); scheduleMsg(&logger, "%s v=%f C=%f R=%f on channel %d", msg, voltage, t, r, adcChannel); scheduleMsg(&logger, "bias=%f A=%f B=%f C=%f", thermistor->config->bias_resistor, thermistor->config->s_h_a, thermistor->config->s_h_b, thermistor->config->s_h_c); #if EFI_PROD_CODE scheduleMsg(&logger, "@%s", getPinNameByAdcChannel(adcChannel, pinNameBuffer)); #endif }
static float getUa() { #if ! EFI_UNIT_TEST if (CONFIG(cj125ua) != EFI_ADC_NONE) { #if EFI_PROD_CODE if (engineConfiguration->cj125isUaDivided) { return getVoltageDivided("cj125ua", CONFIG(cj125ua)); } else { return getVoltage("cj125ua", CONFIG(cj125ua)); } #endif /* EFI_PROD_CODE */ } return 0.0f; #else /* EFI_UNIT_TEST */ return 0; #endif /* EFI_UNIT_TEST */ }
/** * We are executing these heavy (logarithm) methods from outside the trigger callbacks for performance reasons. * See also periodicFastCallback */ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_F) { int rpm = rpmCalculator.rpmValue; isEngineChartEnabled = CONFIG(isEngineChartEnabled) && rpm < CONFIG(engineSnifferRpmThreshold); sensorChartMode = rpm < CONFIG(sensorSnifferRpmThreshold) ? boardConfiguration->sensorChartMode : SC_OFF; engineState.updateSlowSensors(PASS_ENGINE_PARAMETER_F); if (engineConfiguration->fuelLevelSensor != EFI_ADC_NONE) { float fuelLevelVoltage = getVoltageDivided("fuel", engineConfiguration->fuelLevelSensor); engineState.fuelTankGauge = interpolate(boardConfiguration->fuelLevelEmptyTankVoltage, 0, boardConfiguration->fuelLevelFullTankVoltage, 100, fuelLevelVoltage); } float vBatt = hasVBatt(PASS_ENGINE_PARAMETER_F) ? getVBatt(PASS_ENGINE_PARAMETER_F) : 12; engineState.injectorLag = getInjectorLag(vBatt PASS_ENGINE_PARAMETER); }
/** * We are executing these heavy (logarithm) methods from outside the trigger callbacks for performance reasons. * See also periodicFastCallback */ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int rpm = rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE); isEngineChartEnabled = CONFIG(isEngineChartEnabled) && rpm < CONFIG(engineSnifferRpmThreshold); sensorChartMode = rpm < CONFIG(sensorSnifferRpmThreshold) ? boardConfiguration->sensorChartMode : SC_OFF; engineState.updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE); // todo: move this logic somewhere to sensors folder? if (engineConfiguration->fuelLevelSensor != EFI_ADC_NONE) { float fuelLevelVoltage = getVoltageDivided("fuel", engineConfiguration->fuelLevelSensor); sensors.fuelTankGauge = interpolate(boardConfiguration->fuelLevelEmptyTankVoltage, 0, boardConfiguration->fuelLevelFullTankVoltage, 100, fuelLevelVoltage); } sensors.vBatt = hasVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) ? getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) : 12; engineState.injectorLag = getInjectorLag(sensors.vBatt PASS_ENGINE_PARAMETER_SUFFIX); }
static float getUr() { #if ! EFI_UNIT_TEST if (CONFIG(cj125ur) != EFI_ADC_NONE) { #if EFI_PROD_CODE #ifdef EFI_CJ125_DIRECTLY_CONNECTED_UR // in case of directly connected Ur signal from CJ125 to the ADC pin of MCU return getVoltage("cj125ur", CONFIG(cj125ur)); #else // if a standard voltage division scheme with OpAmp is used return getVoltageDivided("cj125ur", CONFIG(cj125ur)); #endif /* EFI_CJ125_DIRECTLY_CONNECTED_UR */ #endif /* EFI_PROD_CODE */ } return 0.0f; #else /* EFI_UNIT_TEST */ return 0; #endif /* EFI_UNIT_TEST */ }
static void printThermistor(const char *msg, ThermistorConf *config, ThermistorMath *tm) { thermistor_curve_s * curve = &tm->curve; adc_channel_e adcChannel = config->adcChannel; float voltage = getVoltageDivided("term", adcChannel); float r = getResistance(config); float t = getTemperatureC(config, tm); thermistor_conf_s *tc = &config->config; scheduleMsg(&logger, "%s volts=%f Celsius=%f sensorR=%f on channel %d", msg, voltage, t, r, adcChannel); scheduleMsg(&logger, "@%s", getPinNameByAdcChannel(adcChannel, pinNameBuffer)); scheduleMsg(&logger, "C=%f/R=%f C=%f/R=%f C=%f/R=%f", tc->tempC_1, tc->resistance_1, tc->tempC_2, tc->resistance_2, tc->tempC_3, tc->resistance_3); scheduleMsg(&logger, "bias resistor=%fK A=%..100000f B=%..100000f C=%..100000f", tc->bias_resistor / 1000, curve->s_h_a, curve->s_h_b, curve->s_h_c); scheduleMsg(&logger, "=============================="); }
float getResistance(Thermistor *thermistor) { float voltage = getVoltageDivided(thermistor->channel); chDbgCheck(thermistor->config != NULL, "config is null"); float resistance = getR2InVoltageDividor(voltage, _5_VOLTS, thermistor->config->bias_resistor); return resistance; }
/* * Return voltage on TPS AND channel * */ float getTPSVoltage(void) { return getVoltageDivided(engineConfiguration->tpsAdcChannel); }
float getBaroPressure(DECLARE_ENGINE_PARAMETER_F) { float voltage = getVoltageDivided("baro", engineConfiguration->baroSensor.hwChannel); return decodePressure(voltage, &engineConfiguration->baroSensor); }
void grabPedalIsWideOpen() { #if EFI_PROD_CODE float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel); engineConfiguration->throttlePedalWOTVoltage = voltage; #endif /* EFI_PROD_CODE */ }
/* * Return voltage on TPS AND channel * */ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return getVoltageDivided("tps", engineConfiguration->tps1_1AdcChannel); }
float getVRef(DECLARE_ENGINE_PARAMETER_F) { return getVoltageDivided("vref", engineConfiguration->vRefAdcChannel); }