added ping command for device identification

This commit is contained in:
2026-01-17 02:59:14 +01:00
parent 73c7dfb8e5
commit d432db9985

View File

@@ -1,6 +1,15 @@
#include <Arduino.h> #include <Arduino.h>
#include <RP2040_PWM.h> #include <RP2040_PWM.h>
// -------------------------------
// Firmware version
// -------------------------------
const char* FIRMWARE_VERSION = "V1.0";
// -------------------------------
// PWM setup
// -------------------------------
const uint8_t NUM_CHANNELS = 8; const uint8_t NUM_CHANNELS = 8;
uint8_t pwmPins[NUM_CHANNELS] = {14, 15, 26, 27, 8, 7, 6, 5}; uint8_t pwmPins[NUM_CHANNELS] = {14, 15, 26, 27, 8, 7, 6, 5};
@@ -28,7 +37,6 @@ float calibratedPoints[NUM_CHANNELS][5] = {
// ------------------------------- // -------------------------------
float currentDuty[NUM_CHANNELS] = {0.0f}; float currentDuty[NUM_CHANNELS] = {0.0f};
RP2040_PWM* pwm[NUM_CHANNELS]; RP2040_PWM* pwm[NUM_CHANNELS];
// ------------------------------- // -------------------------------
@@ -37,7 +45,6 @@ RP2040_PWM* pwm[NUM_CHANNELS];
unsigned long lastSerialTime = 0; unsigned long lastSerialTime = 0;
const unsigned long watchdogTimeout = 5000; // 5 seconds const unsigned long watchdogTimeout = 5000; // 5 seconds
const float fadeStep = 0.001f; // 0.001% per ms
unsigned long lastFadeTime = 0; unsigned long lastFadeTime = 0;
// ------------------------------- // -------------------------------
@@ -87,6 +94,15 @@ void loop() {
while (Serial.available()) { while (Serial.available()) {
String s = Serial.readStringUntil('\n'); String s = Serial.readStringUntil('\n');
s.trim(); s.trim();
// --- Device identification command ---
if (s.equalsIgnoreCase("PING")) {
Serial.print("Analog_System_Monitor_");
Serial.println(FIRMWARE_VERSION);
lastSerialTime = millis();
continue;
}
int eq = s.indexOf('='); int eq = s.indexOf('=');
if (eq > 0) { if (eq > 0) {
int ch = s.substring(0, eq).toInt(); int ch = s.substring(0, eq).toInt();
@@ -106,8 +122,7 @@ void loop() {
// -------- Watchdog fade-to-zero (time-based exponential) -------- // -------- Watchdog fade-to-zero (time-based exponential) --------
if (millis() - lastSerialTime > watchdogTimeout) { if (millis() - lastSerialTime > watchdogTimeout) {
// Apply fade only every X ms const unsigned long fadeInterval = 1;
const unsigned long fadeInterval = 1; // adjust for slower/faster decay
if (millis() - lastFadeTime >= fadeInterval) { if (millis() - lastFadeTime >= fadeInterval) {
lastFadeTime = millis(); lastFadeTime = millis();
@@ -116,7 +131,7 @@ void loop() {
if (currentDuty[ch] > 0.0f) { if (currentDuty[ch] > 0.0f) {
const float fadeFactor = 0.999f; // exponential decay per interval const float fadeFactor = 0.999f;
currentDuty[ch] *= fadeFactor; currentDuty[ch] *= fadeFactor;
if (currentDuty[ch] < 0.01f) if (currentDuty[ch] < 0.01f)