mirror of https://github.com/rusefi/rusefi-1.git
put vbatt in sensor model (#2261)
* vbatt in sensor model * sensor name * vbatt * s * oy vei * a little bit of cleanup * memory apparently * cj125 test Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
c9b0334eb5
commit
5ceeac93e9
|
@ -268,7 +268,8 @@ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
CONFIG(fuelLevelFullTankVoltage), 100,
|
||||
fuelLevelVoltage);
|
||||
}
|
||||
sensors.vBatt = hasVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) ? getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) : 12;
|
||||
|
||||
sensors.vBatt = Sensor::get(SensorType::BatteryVoltage).value_or(12);
|
||||
|
||||
#if (BOARD_TLE8888_COUNT > 0)
|
||||
// nasty value injection into C driver which would not be able to access Engine class
|
||||
|
|
|
@ -711,7 +711,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
|
|||
* UNUSED_SIZE constants.
|
||||
*/
|
||||
#ifndef RAM_UNUSED_SIZE
|
||||
#define RAM_UNUSED_SIZE 3200
|
||||
#define RAM_UNUSED_SIZE 3150
|
||||
#endif
|
||||
#ifndef CCM_UNUSED_SIZE
|
||||
#define CCM_UNUSED_SIZE 2800
|
||||
|
|
|
@ -41,6 +41,8 @@ static const char* s_sensorNames[] = {
|
|||
"Idle Valve Position",
|
||||
|
||||
"Flex Fuel",
|
||||
|
||||
"Battery Voltage",
|
||||
};
|
||||
|
||||
// This struct represents one sensor in the registry.
|
||||
|
|
|
@ -60,6 +60,8 @@ enum class SensorType : unsigned char {
|
|||
|
||||
FuelEthanolPercent,
|
||||
|
||||
BatteryVoltage,
|
||||
|
||||
// Leave me at the end!
|
||||
PlaceholderLast
|
||||
};
|
||||
|
|
|
@ -14,10 +14,6 @@
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
bool hasVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
return isAdcChannelValid(engineConfiguration->vbattAdcChannel);
|
||||
}
|
||||
|
||||
float getVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
#ifdef USE_ADC3_VBATT_HACK
|
||||
extern adcsample_t vbattSampleProteus;
|
||||
|
|
|
@ -16,6 +16,5 @@
|
|||
#include "engine_configuration.h"
|
||||
|
||||
float getVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
bool hasVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -19,6 +19,7 @@ void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|||
|
||||
// Internal init functions for individual systems
|
||||
// Sensor init/config
|
||||
void initVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void initMap(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void initTps(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void initOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
@ -28,6 +29,7 @@ void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|||
void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
||||
// Sensor reconfiguration
|
||||
void reconfigureVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void reconfigureTps(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void reconfigureThermistors(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void reconfigureOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
|
|
@ -7,3 +7,4 @@ INIT_SRC_CPP = $(PROJECT_DIR)/init/sensor/init_sensors.cpp \
|
|||
$(PROJECT_DIR)/init/sensor/init_lambda.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_map.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_flex.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_vbatt.cpp \
|
||||
|
|
|
@ -13,6 +13,7 @@ void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
initCanSensors();
|
||||
#endif
|
||||
|
||||
initVbatt(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
initTps(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initOilPressure(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
@ -25,6 +26,7 @@ void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
}
|
||||
|
||||
void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
reconfigureVbatt(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
reconfigureTps(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
reconfigureOilPressure(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
reconfigureThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#include "init.h"
|
||||
#include "adc_inputs.h"
|
||||
#include "adc_subscription.h"
|
||||
#include "engine.h"
|
||||
#include "functional_sensor.h"
|
||||
#include "linear_func.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static LinearFunc vbattFunc;
|
||||
static FunctionalSensor vbattSensor(SensorType::BatteryVoltage, /* timeout = */ MS2NT(100));
|
||||
|
||||
void initVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
vbattFunc.configure(0, 0, 1, engineConfiguration->vbattDividerCoeff, 0, 50);
|
||||
vbattSensor.setFunction(vbattFunc);
|
||||
|
||||
if (!isAdcChannelValid(engineConfiguration->vbattAdcChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// adcVoltsPerVolt is set to 1.0 because vbatt doesn't go thru the analog input divider
|
||||
AdcSubscription::SubscribeSensor(vbattSensor, CONFIG(vbattAdcChannel), /* filter HZ = */ 20, /* adcVoltsPerVolt = */ 1.0f);
|
||||
|
||||
vbattSensor.Register();
|
||||
}
|
||||
|
||||
void reconfigureVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
vbattFunc.configure(0, 0, 1, engineConfiguration->vbattDividerCoeff, 0, 50);
|
||||
}
|
|
@ -26,7 +26,6 @@ TEST(testCJ125, testInitialState) {
|
|||
ASSERT_EQ(cj.heaterDuty, 0);
|
||||
|
||||
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
||||
ASSERT_EQ(engine->sensors.vBatt, 0);
|
||||
|
||||
cj.StartHeaterControl((pwm_gen_callback*)&applyHeaterPinState PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
ASSERT_EQ(cj.heaterDuty, CJ125_HEATER_IDLE_RATE);
|
||||
|
|
Loading…
Reference in New Issue