Skip to content

Commit

Permalink
set valid bit only when nernst voltage is well controlled
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Nov 23, 2023
1 parent 55c25a5 commit ea46db5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions firmware/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ void SendRusefiFormat(uint8_t ch)
const auto& sampler = GetSampler(ch);
const auto& heater = GetHeaterController(ch);

float nernstDc = sampler.GetNernstDc();

{
CanTxTyped<wbo::StandardData> frame(baseAddress + 0);

Expand All @@ -153,7 +155,9 @@ void SendRusefiFormat(uint8_t ch)
uint16_t lambda = GetLambda(ch) * 10000;
frame.get().Lambda = lambda;
frame.get().TemperatureC = sampler.GetSensorTemperature();
frame.get().Valid = heater.IsRunningClosedLoop() ? 0x01 : 0x00;
bool heaterClosedLoop = heater.IsRunningClosedLoop();
bool nernstValid = nernstDc > (NERNST_TARGET - 0.1f) && nernstDc < (NERNST_TARGET + 0.1f);
frame.get().Valid = (heaterClosedLoop && nernstValid) ? 0x01 : 0x00;
}

{
Expand All @@ -162,7 +166,7 @@ void SendRusefiFormat(uint8_t ch)
CanTxTyped<wbo::DiagData> frame(baseAddress + 1);

frame.get().Esr = esr;
frame.get().NernstDc = sampler.GetNernstDc() * 1000;
frame.get().NernstDc = nernstDc * 1000;
frame.get().PumpDuty = GetPumpOutputDuty(ch) * 255;
frame.get().Status = GetCurrentFault(ch);
frame.get().HeaterDuty = GetHeaterDuty(ch) * 255;
Expand Down

0 comments on commit ea46db5

Please sign in to comment.