2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2021-02-03 05:55:40 -08:00
|
|
|
#include "init.h"
|
|
|
|
#include "adc_subscription.h"
|
|
|
|
#include "functional_sensor.h"
|
|
|
|
#include "linear_func.h"
|
|
|
|
|
|
|
|
static LinearFunc vbattFunc;
|
|
|
|
static FunctionalSensor vbattSensor(SensorType::BatteryVoltage, /* timeout = */ MS2NT(100));
|
|
|
|
|
|
|
|
void initVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|
|
|
vbattFunc.configure(0, 0, 1, engineConfiguration->vbattDividerCoeff, 0, 50);
|
|
|
|
vbattSensor.setFunction(vbattFunc);
|
|
|
|
|
|
|
|
if (!isAdcChannelValid(engineConfiguration->vbattAdcChannel)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adcVoltsPerVolt is set to 1.0 because vbatt doesn't go thru the analog input divider
|
|
|
|
AdcSubscription::SubscribeSensor(vbattSensor, CONFIG(vbattAdcChannel), /* filter HZ = */ 20, /* adcVoltsPerVolt = */ 1.0f);
|
|
|
|
|
|
|
|
vbattSensor.Register();
|
|
|
|
}
|
|
|
|
|
2021-08-24 13:41:16 -07:00
|
|
|
void deinitVbatt() {
|
|
|
|
AdcSubscription::UnsubscribeSensor(vbattSensor);
|
2021-02-03 05:55:40 -08:00
|
|
|
}
|