mirror of
https://github.com/okalachev/flix.git
synced 2026-06-27 21:46:38 +00:00
71abe1bcdb
Simplify the code, print imu temperature
30 lines
727 B
Arduino
30 lines
727 B
Arduino
// Copyright (c) 2026 Oleg Kalachev <okalachev@gmail.com>
|
|
// Repository: https://github.com/okalachev/flix
|
|
|
|
// Power management
|
|
|
|
#include <soc/soc.h>
|
|
#include <soc/rtc_cntl_reg.h>
|
|
#include "lpf.h"
|
|
#include "util.h"
|
|
|
|
float voltage = NAN;
|
|
LowPassFilter<float> voltageFilter(0.2);
|
|
int voltagePin = -1;
|
|
float voltageScale = 2;
|
|
|
|
void setupPower() {
|
|
REG_CLR_BIT(RTC_CNTL_BROWN_OUT_REG, RTC_CNTL_BROWN_OUT_ENA); // disable reset on low voltage
|
|
if (digitalPinToAnalogChannel(voltagePin) == -1) voltagePin = -1; // test ADC pin
|
|
}
|
|
|
|
void readVoltage() {
|
|
if (voltagePin < 0) return;
|
|
|
|
static Rate rate(10);
|
|
if (!rate) return;
|
|
|
|
float v = analogReadMilliVolts(voltagePin) * voltageScale / 1000.0f;
|
|
voltage = voltageFilter.update(v);
|
|
}
|