2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2020-09-01 13:22:31 -07:00
|
|
|
#include "init.h"
|
|
|
|
#include "adc_subscription.h"
|
|
|
|
#include "function_pointer_sensor.h"
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
struct GetAfrWrapper {
|
2020-09-01 13:22:31 -07:00
|
|
|
float getLambda() {
|
2021-11-16 01:15:29 -08:00
|
|
|
return getAfr() / 14.7f;
|
2020-09-01 13:22:31 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static GetAfrWrapper afrWrapper;
|
|
|
|
|
2020-12-09 17:26:23 -08:00
|
|
|
static FunctionPointerSensor lambdaSensor(SensorType::Lambda1,
|
2020-09-01 13:22:31 -07:00
|
|
|
[]() {
|
|
|
|
return afrWrapper.getLambda();
|
|
|
|
});
|
|
|
|
|
2020-09-21 03:01:54 -07:00
|
|
|
#if EFI_CAN_SUPPORT
|
|
|
|
#include "AemXSeriesLambda.h"
|
2020-12-09 17:26:23 -08:00
|
|
|
static AemXSeriesWideband aem1(0, SensorType::Lambda1);
|
|
|
|
static AemXSeriesWideband aem2(1, SensorType::Lambda2);
|
2020-09-21 03:01:54 -07:00
|
|
|
#endif
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initLambda() {
|
2020-09-01 13:22:31 -07:00
|
|
|
|
2020-09-21 03:01:54 -07:00
|
|
|
#if EFI_CAN_SUPPORT
|
2021-11-17 00:54:21 -08:00
|
|
|
if (engineConfiguration->enableAemXSeries) {
|
|
|
|
if (!engineConfiguration->canWriteEnabled || !engineConfiguration->canReadEnabled) {
|
2021-07-13 04:32:41 -07:00
|
|
|
firmwareError(OBD_PCM_Processor_Fault, "CAN read and write are required to use CAN wideband.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-09 17:26:23 -08:00
|
|
|
registerCanSensor(aem1);
|
|
|
|
registerCanSensor(aem2);
|
2020-09-21 03:01:54 -07:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-06 12:00:30 -08:00
|
|
|
lambdaSensor.Register();
|
2020-09-01 13:22:31 -07:00
|
|
|
}
|