rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
init_thermistors.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "adc_subscription.h"
4#include "functional_sensor.h"
5#include "linear_func.h"
6#include "thermistor_func.h"
7
8// Each one could be either linear or thermistor
9struct FuncPair {
10 LinearFunc linear;
11 thermistor_t thermistor;
12};
13
18
23
24static FuncPair fclt, fiat, faux1, faux2, foil, ffuel, fambient, fcdt;
25
26static void validateThermistorConfig(const char *msg, thermistor_conf_s& cfg) {
27 if (cfg.tempC_1 >= cfg.tempC_2 ||
28 cfg.tempC_2 >= cfg.tempC_3) {
29 firmwareError(ObdCode::OBD_ThermistorConfig, "Invalid thermistor %s configuration: please check that temperatures are in the ascending order %f %f %f",
30 msg,
31 (float)cfg.tempC_1,
32 (float)cfg.tempC_2,
33 (float)cfg.tempC_3);
34 }
35}
36
38 thermistor_conf_s& cfg, FuncPair& p, bool isLinear, bool isPulldown) {
39 if (isLinear) {
40 p.linear.configure(cfg.resistance_1, cfg.tempC_1, cfg.resistance_2, cfg.tempC_2, -50, 250);
41
42 return p.linear;
43 } else /* sensor is thermistor */ {
45
46 p.thermistor.get<resist>().configure(5.0f, cfg.bias_resistor, isPulldown);
47 p.thermistor.get<therm>().configure(cfg);
48
49 return p.thermistor;
50 }
51}
52
53static void configTherm(const char *msg,
55 FuncPair &p,
56 ThermistorConf &p_config,
57 bool isLinear,
58 bool isPulldown) {
59 // nothing to do if no channel
60 if (!isAdcChannelValid(p_config.adcChannel)) {
61 return;
62 }
63
64 // Configure the conversion function for this sensor
65 sensor.setFunction(configureTempSensorFunction(msg, p_config.config, p, isLinear, isPulldown));
66}
67
68static void configureTempSensor(const char *msg,
70 FuncPair &p,
71 ThermistorConf &p_config,
72 bool isLinear,
73 bool isPulldown = false) {
74 auto channel = p_config.adcChannel;
75
76 // Only register if we have a sensor
78 return;
79 }
80
81 configTherm(msg, sensor, p, p_config, isLinear, isPulldown);
82
83 // Register & subscribe
86}
87
141
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:23
uint16_t channel
Definition adc_inputs.h:104
static AdcSubscriptionEntry * SubscribeSensor(FunctionalSensorBase &sensor, adc_channel_e channel, float lowpassCutoffHZ, float voltsPerAdcVolt=0.0f)
static void UnsubscribeSensor(FunctionalSensorBase &sensor)
Class for sensors that convert from some raw floating point value (ex: voltage, frequency,...
bool Register()
Definition sensor.cpp:131
static constexpr engine_configuration_s * engineConfiguration
void firmwareError(ObdCode code, const char *fmt,...)
static Lps25Sensor sensor(device)
static CCM_OPTIONAL FunctionalSensor fuelTempSensor(SensorType::FuelTemperature, MS2NT(10))
static FuncPair fiat
static CCM_OPTIONAL FunctionalSensor aux2(SensorType::AuxTemp2, MS2NT(10))
void initThermistors()
static void configureTempSensor(const char *msg, FunctionalSensor &sensor, FuncPair &p, ThermistorConf &p_config, bool isLinear, bool isPulldown=false)
static FuncPair ffuel
static FuncPair fcdt
static void configTherm(const char *msg, FunctionalSensor &sensor, FuncPair &p, ThermistorConf &p_config, bool isLinear, bool isPulldown)
static SensorConverter & configureTempSensorFunction(const char *msg, thermistor_conf_s &cfg, FuncPair &p, bool isLinear, bool isPulldown)
static FuncPair fambient
static FuncPair foil
static CCM_OPTIONAL FunctionalSensor compressorDischargeTemp(SensorType::CompressorDischargeTemperature, MS2NT(10))
static FuncPair faux1
static FuncPair fclt
static FuncPair faux2
static CCM_OPTIONAL FunctionalSensor iat(SensorType::Iat, MS2NT(10))
static CCM_OPTIONAL FunctionalSensor aux1(SensorType::AuxTemp1, MS2NT(10))
static CCM_OPTIONAL FunctionalSensor ambientTempSensor(SensorType::AmbientTemperature, MS2NT(10))
static CCM_OPTIONAL FunctionalSensor clt(SensorType::Clt, MS2NT(10))
static CCM_OPTIONAL FunctionalSensor oilTempSensor(SensorType::OilTemperature, MS2NT(10))
static void validateThermistorConfig(const char *msg, thermistor_conf_s &cfg)
void deinitThermistors()
@ OBD_ThermistorConfig
@ AmbientTemperature
@ CompressorDischargeTemperature
static chibios_rt::Mailbox< CompositeBuffer *, BUFFER_COUNT > freeBuffers CCM_OPTIONAL