Make the pump-1 1 W clamp overridable up to the 8000 mA protocol max

Adds a Pump Limit Override: the pump-1 current command is clamped to a
soft 4000 mA ceiling (the 1 W diode rating) by default, liftable to the
8000 mA hard protocol max only while the new amp_pump_override switch is
ON. Fail-safe: the override defaults OFF on every boot, and switching it
OFF immediately re-clamps a running setpoint back down to 4000 mA so the
booster cannot stay parked above 1 W. The HA pump-1 number now spans
0..8000 mA; values above 4000 take effect only with the override on.

PUMP_CURRENT_MAX_MA is split into PUMP_CURRENT_SOFT_MAX_MA (4000) and
PUMP_CURRENT_HARD_MAX_MA (8000). README/BOM updated. Builds clean
(flash 59.3%); not yet flashed (ESP32 needs USB, no OTA).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
James Bateman (hp-laptop)
2026-10-02 14:21:56 +01:00
co-authored by Claude Opus 4.8
parent ffadf4b37b
commit ba1cd1ddcf
4 changed files with 50 additions and 11 deletions
+32 -3
View File
@@ -22,6 +22,13 @@ static Koheron koheron(Serial2, KOHERON_RX_PIN, KOHERON_TX_PIN, KOHERON_BA
static const uint8_t kAmpDevId[4] = {AGILTRON_DEV_ID};
static Agiltron agiltron(Serial1, AGILTRON_RX_PIN, AGILTRON_TX_PIN, AGILTRON_BAUD, kAmpDevId);
// Pump-1 limit override. false => clamp pump-1 commands to the SOFT (1 W)
// ceiling; true => allow up to the HARD (protocol) ceiling. Defaults OFF on
// every boot (fail-safe). pump1SetMa tracks the last commanded setpoint so the
// override can re-clamp a running pump down when it is switched back off.
static bool pumpOverride = false;
static int pump1SetMa = 0;
// Probe each instrument link once per boot to reveal its framing.
#define KOHERON_RAW_PROBE 1
#define AGILTRON_PROBE 1
@@ -152,7 +159,10 @@ static void publishDiscovery() {
// Amp controls
switchDiscovery("amp_pump", "Amp Pump", "amp/pump_enabled", "amp/pump", "1", "0", "mdi:flash");
numberDiscovery("amp_set_pump_current", "Amp Pump Current", "amp/pump1_set_ma", "amp/pump1_current_ma",
0, PUMP_CURRENT_MAX_MA, 10, "mA", "mdi:current-dc");
0, PUMP_CURRENT_HARD_MAX_MA, 10, "mA", "mdi:current-dc");
// Override the soft (1 W) pump-1 clamp up to the hard protocol ceiling.
switchDiscovery("amp_pump_override", "Amp Pump Limit Override", "amp/pump_override", "amp/pump_override",
"1", "0", "mdi:lock-open-variant");
}
// ── State publishing ────────────────────────────────────────────────
@@ -211,6 +221,7 @@ static void pub(const char *sub, const String &v) {
static void publishAmp() {
AmpStatus s = agiltron.getStatus();
mqtt.publish(TOPIC_BASE "/amp/link", s.valid ? AVAIL_ONLINE : AVAIL_OFFLINE, true);
pub("amp/pump_override", pumpOverride ? "1" : "0"); // reflect override state
if (!s.valid) return;
pub("amp/module_temp_c", String(s.module_temp_c, 1));
pub("amp/preamp_temp_c", String(s.preamp_temp_c, 1));
@@ -262,11 +273,29 @@ static void onMqtt(char *topic, byte *payload, unsigned int len) {
} else if (t == TOPIC_CMD "/amp/pump1_current_ma") {
int ma = (int)p.toFloat();
if (ma < 0) ma = 0;
if (ma > PUMP_CURRENT_MAX_MA) ma = PUMP_CURRENT_MAX_MA; // firmware clamp
int cap = pumpOverride ? PUMP_CURRENT_HARD_MAX_MA : PUMP_CURRENT_SOFT_MAX_MA;
if (ma > cap) ma = cap; // firmware clamp (soft unless overridden)
agiltron.setPump1Mode(Agiltron::ACC); // current-control mode (lab note: avoid APC steps)
bool ok = agiltron.setPump1Current(ma);
Serial.printf("[cmd] amp pump1 = %d mA -> %s\n", ma, ok ? "ack" : "NO-ACK");
pump1SetMa = ma;
Serial.printf("[cmd] amp pump1 = %d mA (cap %d) -> %s\n", ma, cap, ok ? "ack" : "NO-ACK");
pub("amp/pump1_set_ma", String(ma));
} else if (t == TOPIC_CMD "/amp/pump_override") {
bool on = (p == "1" || p.equalsIgnoreCase("on") || p.equalsIgnoreCase(AVAIL_ONLINE));
pumpOverride = on;
Serial.printf("[cmd] pump limit override -> %s\n",
on ? "ON (hard 8000 mA)" : "OFF (soft 4000 mA)");
// Disabling the override must not leave the booster parked above 1 W: if the
// running setpoint is above the soft cap, re-clamp it down immediately.
if (!on && pump1SetMa > PUMP_CURRENT_SOFT_MAX_MA) {
pump1SetMa = PUMP_CURRENT_SOFT_MAX_MA;
agiltron.setPump1Mode(Agiltron::ACC);
agiltron.setPump1Current(pump1SetMa);
pub("amp/pump1_set_ma", String(pump1SetMa));
Serial.printf("[cmd] override off: re-clamped pump1 to %d mA\n", pump1SetMa);
}
pub("amp/pump_override", on ? "1" : "0");
}
}