ETB target is using integer values #945

refactoring - ADC mocking is a mess
This commit is contained in:
rusefi 2019-09-22 16:41:10 -04:00
parent c6bca8e77a
commit e1b537935d
3 changed files with 12 additions and 3 deletions

View File

@ -53,6 +53,11 @@ float getVoltageDivided(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_
return getVoltage(msg, hwChannel PASS_ENGINE_PARAMETER_SUFFIX) * engineConfiguration->analogInputDividerCoefficient; return getVoltage(msg, hwChannel PASS_ENGINE_PARAMETER_SUFFIX) * engineConfiguration->analogInputDividerCoefficient;
} }
// voltage in MCU universe, from zero to VDD
float getVoltage(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) {
return adcToVolts(getAdcValue(msg, hwChannel));
}
AdcDevice::AdcDevice(ADCConversionGroup* hwConfig) { AdcDevice::AdcDevice(ADCConversionGroup* hwConfig) {
this->hwConfig = hwConfig; this->hwConfig = hwConfig;
channelCount = 0; channelCount = 0;

View File

@ -11,15 +11,14 @@
#ifndef ADC_MATH_H_ #ifndef ADC_MATH_H_
#define ADC_MATH_H_ #define ADC_MATH_H_
#include "global.h" #include "engine_configuration.h"
#define ADC_MAX_VALUE 4095 #define ADC_MAX_VALUE 4095
#define adcToVolts(adc) ((engineConfiguration->adcVcc) / ADC_MAX_VALUE * (adc)) #define adcToVolts(adc) ((engineConfiguration->adcVcc) / ADC_MAX_VALUE * (adc))
#define voltsToAdc(volts) ((volts) * (ADC_MAX_VALUE / (engineConfiguration->adcVcc))) #define voltsToAdc(volts) ((volts) * (ADC_MAX_VALUE / (engineConfiguration->adcVcc)))
// voltage in MCU universe, from zero to VDD float getVoltage(const char *msg, adc_channel_e channel DECLARE_ENGINE_PARAMETER_SUFFIX);
#define getVoltage(msg, hwChannel) (adcToVolts(getAdcValue(msg, hwChannel)))
// DECLARE_ENGINE_PARAMETER_SUFFIX // DECLARE_ENGINE_PARAMETER_SUFFIX
float getVoltageDivided(const char *msg, adc_channel_e channel); float getVoltageDivided(const char *msg, adc_channel_e channel);

View File

@ -19,6 +19,11 @@ int getAdcValue(const char *msg, int hwChannel) {
return engine->engineState.mockAdcState.getMockAdcValue(hwChannel); return engine->engineState.mockAdcState.getMockAdcValue(hwChannel);
} }
// voltage in MCU universe, from zero to VDD
float getVoltage(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) {
return adcToVolts(getAdcValue(msg, hwChannel));
}
// Board voltage, with divider coefficient accounted for // Board voltage, with divider coefficient accounted for
float getVoltageDivided(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) { float getVoltageDivided(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) {
return getVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient; return getVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient;