Add serial log levels

This commit is contained in:
2026-06-04 02:04:54 -06:00
parent 94687abbf4
commit f29acd75ee
4 changed files with 76 additions and 18 deletions
+22 -17
View File
@@ -2,6 +2,7 @@
#include <Arduino.h>
#include <NimBLEDevice.h>
#include "logger.h"
static const char* BMS_ADDRESS = "a5:c2:37:2c:05:dc";
static const char* BMS_SERVICE_UUID = "ff00";
@@ -253,14 +254,16 @@ static bool parseBasicInfo() {
bmsData.temperatureF = tempF;
bmsData.valid = true;
Serial.print("BMS: SOC ");
Serial.print(bmsData.soc);
Serial.print("%, V ");
Serial.print(bmsData.voltage);
Serial.print(", A ");
Serial.print(bmsData.current);
Serial.print(", Ah ");
Serial.println(bmsData.remainingAh);
if (currentLogLevel >= LOG_DEBUG) {
Serial.print("BMS: SOC ");
Serial.print(bmsData.soc);
Serial.print("%, V ");
Serial.print(bmsData.voltage);
Serial.print(", A ");
Serial.print(bmsData.current);
Serial.print(", Ah ");
Serial.println(bmsData.remainingAh);
}
return true;
}
@@ -312,15 +315,17 @@ static bool parseCellVoltages() {
bmsData.cellDeltaMv = (int)((maxV - minV) * 1000.0 + 0.5);
bmsData.cellsValid = true;
Serial.print("BMS: Cells ");
Serial.print(cellsReported);
Serial.print(", min ");
Serial.print(minV, 3);
Serial.print("V, max ");
Serial.print(maxV, 3);
Serial.print("V, delta ");
Serial.print(bmsData.cellDeltaMv);
Serial.println("mV");
if (currentLogLevel >= LOG_DEBUG) {
Serial.print("BMS: Cells ");
Serial.print(cellsReported);
Serial.print(", min ");
Serial.print(minV, 3);
Serial.print("V, max ");
Serial.print(maxV, 3);
Serial.print("V, delta ");
Serial.print(bmsData.cellDeltaMv);
Serial.println("mV");
}
return true;
}
@@ -0,0 +1,19 @@
#include "logger.h"
LogLevel currentLogLevel = LOG_INFO;
void setLogLevel(LogLevel level) {
currentLogLevel = level;
}
void logInfo(const String& message) {
if (currentLogLevel >= LOG_INFO) {
Serial.println(message);
}
}
void logDebug(const String& message) {
if (currentLogLevel >= LOG_DEBUG) {
Serial.println(message);
}
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include <Arduino.h>
enum LogLevel {
LOG_QUIET = 0,
LOG_INFO = 1,
LOG_DEBUG = 2
};
extern LogLevel currentLogLevel;
void setLogLevel(LogLevel level);
void logInfo(const String& message);
void logDebug(const String& message);
@@ -10,6 +10,7 @@
#include "alarms.h"
#include "system_status.h"
#include "app_config.h"
#include "logger.h"
WebServer server(80);
HardwareSerial DashboardSerial(2);
@@ -303,6 +304,24 @@ void handleDebugSerial() {
return;
}
if (command == "log quiet") {
setLogLevel(LOG_QUIET);
Serial.println("OK log level quiet");
return;
}
if (command == "log info") {
setLogLevel(LOG_INFO);
Serial.println("OK log level info");
return;
}
if (command == "log debug") {
setLogLevel(LOG_DEBUG);
Serial.println("OK log level debug");
return;
}
if (command == "factory reset") {
factoryResetConfig();
Serial.println("OK factory reset complete");
@@ -702,6 +721,6 @@ void loop() {
if (millis() - lastSensorUpdate > 5000) {
updateSensors();
lastSensorUpdate = millis();
Serial.println("Sensor Update");
logDebug("Sensor Update");
}
}