max31855/egt: migrate to SensorType framework

This commit is contained in:
Andrey Gusakov 2024-03-09 14:33:15 +03:00 committed by Andrey
parent b7d0dbd327
commit 9fc1806ed6
3 changed files with 52 additions and 9 deletions

View File

@ -438,6 +438,17 @@ static void updateFuelSensors() {
engine->outputChannels.fuelTankLevel = Sensor::getOrZero(SensorType::FuelLevel);
}
static void updateEgtSensors() {
engine->outputChannels.egt[0] = Sensor::getOrZero(SensorType::EGT1);
engine->outputChannels.egt[1] = Sensor::getOrZero(SensorType::EGT2);
engine->outputChannels.egt[2] = Sensor::getOrZero(SensorType::EGT3);
engine->outputChannels.egt[3] = Sensor::getOrZero(SensorType::EGT4);
engine->outputChannels.egt[4] = Sensor::getOrZero(SensorType::EGT5);
engine->outputChannels.egt[5] = Sensor::getOrZero(SensorType::EGT6);
engine->outputChannels.egt[6] = Sensor::getOrZero(SensorType::EGT7);
engine->outputChannels.egt[7] = Sensor::getOrZero(SensorType::EGT8);
}
static void updateVvtSensors() {
#if EFI_SHAFT_POSITION_INPUT
// 248
@ -520,6 +531,7 @@ static void updateSensors() {
updateRawSensors();
updateLambda();
updateFuelSensors();
updateEgtSensors();
updateVvtSensors();
updateVehicleSpeed();
updatePressures();

View File

@ -89,9 +89,14 @@ enum class SensorType : unsigned char {
InputShaftSpeed,
// todo: migrate to SensorType framework!
// EGT1,
// EGT2,
EGT1,
EGT2,
EGT3,
EGT4,
EGT5,
EGT6,
EGT7,
EGT8,
Maf2, // Second bank MAF sensor

View File

@ -24,6 +24,11 @@
#if EFI_MAX_31855
#include "thread_controller.h"
#include "stored_value_sensor.h"
#ifndef MAX31855_REFRESH_TIME
#define MAX31855_REFRESH_TIME 500
#endif
/* TODO: move all stuff to Max31855Read class */
class Max31855Read final : public ThreadController<UTILITY_THREAD_STACK_SIZE> {
@ -48,12 +53,21 @@ public:
/* WARN: this will clear all other bits in cr1 */
spiConfig.cr1 = getSpiPrescaler(_5MHz, device);
for (size_t i = 0; i < EGT_CHANNEL_COUNT; i++) {
/* and mark used! */
auto& sensor = egtSensors[i];
m_cs[i] = Gpio::Invalid;
// If there's already another (CAN?) EGT sensor configured,
// don't configure this one.
if (Sensor::hasSensor(sensor.type()))
continue;
// get CS pin and mark used!
if (isBrainPinValid(cs[i])) {
initSpiCs(&spiConfig, cs[i]);
m_cs[i] = cs[i];
} else {
m_cs[i] = Gpio::Invalid;
sensor.Register();
}
}
ThreadController::start();
@ -69,14 +83,15 @@ public:
max_31855_code ret = getMax31855EgtValue(i, &value, NULL);
if (ret == MC_OK) {
// todo: migrate to SensorType framework!
engine->currentEgtValue[i] = value;
auto& sensor = egtSensors[i];
sensor.setValidValue(value, getTimeNowNt());
} else {
/* TODO: report error code? */
}
}
chThdSleepMilliseconds(500);
chThdSleepMilliseconds(MAX31855_REFRESH_TIME);
}
}
@ -228,6 +243,17 @@ private:
}
return code;
}
StoredValueSensor egtSensors[EGT_CHANNEL_COUNT] = {
{ SensorType::EGT1, MS2NT(MAX31855_REFRESH_TIME * 3) },
{ SensorType::EGT2, MS2NT(MAX31855_REFRESH_TIME * 3) },
{ SensorType::EGT3, MS2NT(MAX31855_REFRESH_TIME * 3) },
{ SensorType::EGT4, MS2NT(MAX31855_REFRESH_TIME * 3) },
{ SensorType::EGT5, MS2NT(MAX31855_REFRESH_TIME * 3) },
{ SensorType::EGT6, MS2NT(MAX31855_REFRESH_TIME * 3) },
{ SensorType::EGT7, MS2NT(MAX31855_REFRESH_TIME * 3) },
{ SensorType::EGT8, MS2NT(MAX31855_REFRESH_TIME * 3) }
};
};
static Max31855Read instance;