made the serial debug output a bit nicer
This commit is contained in:
@@ -34,6 +34,31 @@ uint8_t pwmPins[NUM_CHANNELS] = {
|
|||||||
const uint32_t pwmFrequency = 25000; // 25 kHz
|
const uint32_t pwmFrequency = 25000; // 25 kHz
|
||||||
const uint8_t pwmResolution = 10; // 10-bit resolution (0–1023)
|
const uint8_t pwmResolution = 10; // 10-bit resolution (0–1023)
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// Channel labels for debugging
|
||||||
|
// -------------------------------
|
||||||
|
const char* channelLabels[NUM_CHANNELS] = {
|
||||||
|
"CPU Load",
|
||||||
|
"CPU Temp",
|
||||||
|
"RAM Usage",
|
||||||
|
"GPU Load",
|
||||||
|
"GPU Temp",
|
||||||
|
"VRAM Usage",
|
||||||
|
"Reserved 6",
|
||||||
|
"Reserved 7"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* channelUnits[NUM_CHANNELS] = {
|
||||||
|
"%", // CPU Load
|
||||||
|
"°C", // CPU Temp
|
||||||
|
"%", // RAM Usage
|
||||||
|
"%", // GPU Load
|
||||||
|
"°C", // GPU Temp
|
||||||
|
"%", // VRAM Usage
|
||||||
|
"", // Reserved
|
||||||
|
"" // Reserved
|
||||||
|
};
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// Calibration tables
|
// Calibration tables
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
@@ -50,7 +75,6 @@ float calibratedPoints[NUM_CHANNELS][5] = {
|
|||||||
{0.0f, 26.0f, 50.0f, 76.0f, 99.0f}
|
{0.0f, 26.0f, 50.0f, 76.0f, 99.0f}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// Duty tracking + Slew system
|
// Duty tracking + Slew system
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
@@ -99,26 +123,22 @@ void setup() {
|
|||||||
Serial.print("Firmware: ");
|
Serial.print("Firmware: ");
|
||||||
Serial.println(FIRMWARE_VERSION);
|
Serial.println(FIRMWARE_VERSION);
|
||||||
|
|
||||||
// LEDC PWM init (ESP32 Core 3.x API)
|
// LEDC PWM init
|
||||||
for (int ch = 0; ch < NUM_CHANNELS; ch++) {
|
for (int ch = 0; ch < NUM_CHANNELS; ch++) {
|
||||||
bool ok = ledcAttach(pwmPins[ch], pwmFrequency, pwmResolution);
|
bool ok = ledcAttach(pwmPins[ch], pwmFrequency, pwmResolution);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
Serial.print("LEDC attach failed on pin ");
|
Serial.print("LEDC attach failed on pin ");
|
||||||
Serial.println(pwmPins[ch]);
|
Serial.println(pwmPins[ch]);
|
||||||
}
|
}
|
||||||
ledcWrite(pwmPins[ch], 0); // duty = 0%
|
ledcWrite(pwmPins[ch], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------
|
// WiFi Manager
|
||||||
// WiFi Manager (Captive Portal)
|
|
||||||
// -------------------------------
|
|
||||||
WiFiManager wm;
|
WiFiManager wm;
|
||||||
|
|
||||||
wm.setHostname("AnalogMonitor");
|
wm.setHostname("AnalogMonitor");
|
||||||
wm.setTimeout(180); // 3 minutes before giving up
|
wm.setTimeout(180);
|
||||||
|
|
||||||
Serial.println("Starting WiFiManager...");
|
Serial.println("Starting WiFiManager...");
|
||||||
|
|
||||||
bool res = wm.autoConnect("AnalogMonitor-Setup");
|
bool res = wm.autoConnect("AnalogMonitor-Setup");
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
@@ -131,7 +151,6 @@ void setup() {
|
|||||||
Serial.print("IP: ");
|
Serial.print("IP: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
// UDP init
|
|
||||||
udp.begin(listenPort);
|
udp.begin(listenPort);
|
||||||
Serial.print("Listening on UDP port ");
|
Serial.print("Listening on UDP port ");
|
||||||
Serial.println(listenPort);
|
Serial.println(listenPort);
|
||||||
@@ -169,22 +188,28 @@ void loop() {
|
|||||||
slewStartDuty[ch] = currentDuty[ch];
|
slewStartDuty[ch] = currentDuty[ch];
|
||||||
}
|
}
|
||||||
slewStartTime = millis();
|
slewStartTime = millis();
|
||||||
|
|
||||||
lastPacketTime = millis();
|
lastPacketTime = millis();
|
||||||
|
|
||||||
// Debug output
|
// -------- Improved Debug Output --------
|
||||||
Serial.println("Received UDP packet:");
|
Serial.println("Received UDP packet:");
|
||||||
for (int i = 0; i < NUM_CHANNELS; i++) {
|
for (int i = 0; i < NUM_CHANNELS; i++) {
|
||||||
Serial.print(" CH");
|
Serial.print(" CH");
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(": ");
|
Serial.print(" (");
|
||||||
Serial.println(values[i]);
|
Serial.print(channelLabels[i]);
|
||||||
|
Serial.print("): ");
|
||||||
|
Serial.print(values[i], 2);
|
||||||
|
if (channelUnits[i][0] != '\0') {
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.print(channelUnits[i]);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- Slew-rate limiting (only when NOT in watchdog mode) --------
|
// -------- Slew-rate limiting --------
|
||||||
if (millis() - lastPacketTime <= watchdogTimeout) {
|
if (millis() - lastPacketTime <= watchdogTimeout) {
|
||||||
|
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
@@ -202,7 +227,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- Watchdog fade-to-zero (UDP-based) --------
|
// -------- Watchdog fade-to-zero --------
|
||||||
if (millis() - lastPacketTime > watchdogTimeout) {
|
if (millis() - lastPacketTime > watchdogTimeout) {
|
||||||
|
|
||||||
const unsigned long fadeInterval = 1;
|
const unsigned long fadeInterval = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user