adding meassureExternalBattery

This commit is contained in:
richonguzman 2023-09-20 11:25:27 -03:00
parent 86ab157952
commit 5462521418
5 changed files with 23 additions and 1 deletions

View file

@ -56,6 +56,8 @@
"other": {
"beaconInterval": 15,
"rememberStationTime": 30,
"sendBatteryVoltage": false
"sendBatteryVoltage": false,
"externalVoltageMeasurement" : true,
"externalVoltagePin": 13
}
}

View file

@ -37,6 +37,8 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) {
beaconInterval = data["other"]["beaconInterval"].as<int>();
rememberStationTime = data["other"]["rememberStationTime"].as<int>();
sendBatteryVoltage = data["other"]["sendBatteryVoltage"].as<bool>();
externalVoltageMeasurement = data["other"]["externalVoltageMeasurement"].as<bool>();
externalVoltagePin = data["other"]["externalVoltagePin"].as<int>();
digi.comment = data["digi"]["comment"].as<String>();
digi.latitude = data["digi"]["latitude"].as<double>();

View file

@ -75,6 +75,8 @@ public:
int beaconInterval;
int rememberStationTime;
bool sendBatteryVoltage;
bool externalVoltageMeasurement;
int externalVoltagePin;
std::vector<WiFi_AP> wifiAPs;
DIGI digi;
APRS_IS aprs_is;

View file

@ -53,6 +53,21 @@ void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
String meassureExternalBattery() {
int16_t sample;
int sampleNum = 50;
float readingCorrection = 0.0018;
float batteryVoltage, sampleSum;
sampleSum = 0;
for (int i=0; i<sampleNum; i++) {
sample = analogRead(Config.externalVoltagePin);
sampleSum += sample;
delayMicroseconds(50);
}
batteryVoltage = ((sampleSum/sampleNum) - readingCorrection);
return "VBat=" + String(batteryVoltage,2) + ")";
}
void processStatus() {
String status = Config.callsign + ">APLRG1";
if (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status() == WL_CONNECTED)) {

View file

@ -5,6 +5,7 @@
namespace Utils {
String meassureExternalBattery();
void processStatus();
String getLocalIP();
void setupDisplay();