diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 07861b8a6b4..dc2c7a63d84 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -690,11 +690,10 @@ void updateTunerStudioState() { tsOutputChannels->checkEngine = hasErrorCodes(); -#if EFI_MAX_31855 - for (int i = 0; i < EGT_CHANNEL_COUNT; i++) + for (int i = 0; i < EGT_CHANNEL_COUNT; i++) { // todo: migrate to SensorType framework! - tsOutputChannels->egt[i] = getMax31855EgtValue(i); -#endif /* EFI_MAX_31855 */ + tsOutputChannels->egt[i] = engine->currentEgtValue[i]; + } updateWarningCodes(); diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 494dd84da34..6f79bbf0f88 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -32,6 +32,7 @@ #include "fan_control.h" #include "ac_control.h" #include "vr_pwm.h" +#include "max31855.h" #if EFI_MC33816 #include "mc33816.h" #endif // EFI_MC33816 @@ -160,6 +161,9 @@ void Engine::periodicSlowCallback() { updateVrThresholdPwm(); updateGppwm(); +#if EFI_MAX_31855 + grabEgtValues(); +#endif /* EFI_MAX_31855 */ engine->engineModules.apply_all([](auto & m) { m.onSlowCallback(); }); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 0fdb5ac8151..9afd5a95fcb 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -298,6 +298,8 @@ class Engine final : public TriggerStateListener { void updateTriggerWaveform(); bool isRunningPwmTest = false; + // todo: encapsulate + uint16_t currentEgtValue[EGT_CHANNEL_COUNT]; /** * are we running any kind of functional test? this affect diff --git a/firmware/hw_layer/sensors/max31855.cpp b/firmware/hw_layer/sensors/max31855.cpp index 1b3ac925669..a51f1421422 100644 --- a/firmware/hw_layer/sensors/max31855.cpp +++ b/firmware/hw_layer/sensors/max31855.cpp @@ -101,7 +101,7 @@ static uint32_t readEgtPacket(int egtChannel) { #define GET_TEMPERATURE_C(x) (((x) >> 18) / 4) -uint16_t getMax31855EgtValue(int egtChannel) { +static uint16_t getMax31855EgtValue(int egtChannel) { uint32_t packet = readEgtPacket(egtChannel); max_32855_code code = getResultCode(packet); if (code != MC_OK) { @@ -158,4 +158,11 @@ void initMax31855(spi_device_e device, egt_cs_array_t max31855_cs) { } } +void grabEgtValues() { + for (int i = 0; i < EGT_CHANNEL_COUNT; i++) { + // todo: migrate to SensorType framework! + engine->currentEgtValue[i] = getMax31855EgtValue(i); + } +} + #endif /* EFI_MAX_31855 */ diff --git a/firmware/hw_layer/sensors/max31855.h b/firmware/hw_layer/sensors/max31855.h index 645a8b1b5ac..4138d726b23 100644 --- a/firmware/hw_layer/sensors/max31855.h +++ b/firmware/hw_layer/sensors/max31855.h @@ -14,5 +14,4 @@ void initMax31855(spi_device_e device, egt_cs_array_t max31855_cs); #endif /* HAL_USE_SPI */ -uint16_t getMax31855EgtValue(int egtChannel); - +void grabEgtValues();