hellen on a bike: both TS and SD card logs report -32v on secondary TPS and secondary PPS #6376
only:saving sensorVolts
This commit is contained in:
parent
d7bae2cd2f
commit
f981d04c44
|
@ -2,11 +2,10 @@
|
|||
|
||||
#include "adc_subscription.h"
|
||||
|
||||
#include "biquad.h"
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
|
||||
/*static*/ void AdcSubscription::SubscribeSensor(FunctionalSensor&, adc_channel_e, float, float) {
|
||||
/*static*/ AdcSubscriptionEntry * AdcSubscription::SubscribeSensor(FunctionalSensor&, adc_channel_e, float, float) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*static*/ void AdcSubscription::UnsubscribeSensor(FunctionalSensor&) {
|
||||
|
@ -17,14 +16,6 @@
|
|||
|
||||
#else
|
||||
|
||||
struct AdcSubscriptionEntry {
|
||||
FunctionalSensor *Sensor;
|
||||
float VoltsPerAdcVolt;
|
||||
Biquad Filter;
|
||||
adc_channel_e Channel;
|
||||
bool HasUpdated = false;
|
||||
};
|
||||
|
||||
static AdcSubscriptionEntry s_entries[16];
|
||||
|
||||
static AdcSubscriptionEntry* findEntry(FunctionalSensor* sensor) {
|
||||
|
@ -42,22 +33,22 @@ static AdcSubscriptionEntry* findEntry() {
|
|||
return findEntry(nullptr);
|
||||
}
|
||||
|
||||
/*static*/ void AdcSubscription::SubscribeSensor(FunctionalSensor &sensor,
|
||||
/*static*/ AdcSubscriptionEntry* AdcSubscription::SubscribeSensor(FunctionalSensor &sensor,
|
||||
adc_channel_e channel,
|
||||
float lowpassCutoff,
|
||||
float voltsPerAdcVolt /*= 0.0f*/) {
|
||||
// Don't subscribe null channels
|
||||
if (!isAdcChannelValid(channel)) {
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// If you passed the same sensor again, resubscribe it with the new parameters
|
||||
auto entry = findEntry(&sensor);
|
||||
AdcSubscriptionEntry* entry = findEntry(&sensor);
|
||||
|
||||
if (entry) {
|
||||
// If the channel didn't change, we're already set
|
||||
if (entry->Channel == channel) {
|
||||
return;
|
||||
return entry;
|
||||
}
|
||||
|
||||
// avoid updates to this while we're mucking with the configuration
|
||||
|
@ -72,7 +63,7 @@ static AdcSubscriptionEntry* findEntry() {
|
|||
// Ensure that a free entry was found
|
||||
if (!entry) {
|
||||
firmwareError(ObdCode::CUSTOM_INVALID_ADC, "too many ADC subscriptions subscribing %s", name);
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if EFI_PROD_CODE && HAL_USE_ADC
|
||||
|
@ -99,6 +90,7 @@ TODO: this code is similar to initIfValid, what is the plan? shall we extract he
|
|||
|
||||
// Set the sensor last - it's the field we use to determine whether this entry is in use
|
||||
entry->Sensor = &sensor;
|
||||
return entry;
|
||||
}
|
||||
|
||||
/*static*/ void AdcSubscription::UnsubscribeSensor(FunctionalSensor& sensor) {
|
||||
|
@ -145,17 +137,17 @@ void AdcSubscription::UpdateSubscribers(efitick_t nowNt) {
|
|||
}
|
||||
|
||||
float mcuVolts = getVoltage("sensor", entry.Channel);
|
||||
float sensorVolts = mcuVolts * entry.VoltsPerAdcVolt;
|
||||
entry.sensorVolts = mcuVolts * entry.VoltsPerAdcVolt;
|
||||
|
||||
// On the very first update, preload the filter as if we've been
|
||||
// seeing this value for a long time. This prevents a slow ramp-up
|
||||
// towards the correct value just after startup
|
||||
if (!entry.HasUpdated) {
|
||||
entry.Filter.cookSteadyState(sensorVolts);
|
||||
entry.Filter.cookSteadyState(entry.sensorVolts);
|
||||
entry.HasUpdated = true;
|
||||
}
|
||||
|
||||
float filtered = entry.Filter.filter(sensorVolts);
|
||||
float filtered = entry.Filter.filter(entry.sensorVolts);
|
||||
|
||||
entry.Sensor->postRawValue(filtered, nowNt);
|
||||
}
|
||||
|
|
|
@ -6,10 +6,20 @@
|
|||
|
||||
#include "functional_sensor.h"
|
||||
#include "global.h"
|
||||
#include "biquad.h"
|
||||
|
||||
struct AdcSubscriptionEntry {
|
||||
FunctionalSensor *Sensor;
|
||||
float VoltsPerAdcVolt;
|
||||
float sensorVolts;
|
||||
Biquad Filter;
|
||||
adc_channel_e Channel;
|
||||
bool HasUpdated = false;
|
||||
};
|
||||
|
||||
class AdcSubscription {
|
||||
public:
|
||||
static void SubscribeSensor(FunctionalSensor &sensor, adc_channel_e channel, float lowpassCutoffHZ, float voltsPerAdcVolt = 0.0f);
|
||||
static AdcSubscriptionEntry *SubscribeSensor(FunctionalSensor &sensor, adc_channel_e channel, float lowpassCutoffHZ, float voltsPerAdcVolt = 0.0f);
|
||||
static void UnsubscribeSensor(FunctionalSensor& sensor);
|
||||
static void UnsubscribeSensor(FunctionalSensor& sensor, adc_channel_e newChannel);
|
||||
static void UpdateSubscribers(efitick_t nowNt);
|
||||
|
|
Loading…
Reference in New Issue