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));
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initVbatt() {
|
2021-02-03 05:55:40 -08:00
|
|
|
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
|
2021-11-17 00:54:21 -08:00
|
|
|
AdcSubscription::SubscribeSensor(vbattSensor, engineConfiguration->vbattAdcChannel, /* filter HZ = */ 20, /* adcVoltsPerVolt = */ 1.0f);
|
2021-02-03 05:55:40 -08:00
|
|
|
|
|
|
|
vbattSensor.Register();
|
|
|
|
}
|
|
|
|
|
2021-08-24 13:41:16 -07:00
|
|
|
void deinitVbatt() {
|
2023-01-06 05:09:17 -08:00
|
|
|
AdcSubscription::UnsubscribeSensor(vbattSensor, engineConfiguration->vbattAdcChannel);
|
2021-02-03 05:55:40 -08:00
|
|
|
}
|