Files
James Bateman (hp-laptop)andClaude Opus 4.8 ba1cd1ddcf 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>
2026-10-02 14:21:56 +01:00

92 lines
4.8 KiB
C

// Compile-time configuration for the Butterfly EDFA Rack bridge.
#pragma once
#include "secrets.h"
// ── MQTT topics ─────────────────────────────────────────────────────
// One HA device, one topic base. Sub-units namespaced under it:
// <base>/availability online | offline (LWT)
// <base>/diag/<key> ESP/network diagnostics
// <base>/seed/<key> Koheron CTL200 (increment 3)
// <base>/amp/<key> Agiltron M511 EYDFA (increment 4)
// <base>/set/<...> command topics (increment 5)
#define TOPIC_BASE "lab/laser/" DEVICE_NAME
#define TOPIC_AVAIL TOPIC_BASE "/availability"
#define DISCOVERY_PREFIX "homeassistant"
#define AVAIL_ONLINE "online"
#define AVAIL_OFFLINE "offline"
#define TOPIC_CMD TOPIC_BASE "/set" // subscribe <base>/set/#
// ── Agiltron M511 identity & safety limits ──────────────────────────
// SN Y4022708 / PN EDFA-1C51113331111 -> device ID 0x0000006F (edfa.py).
// Startup reads SN/PN and logs them so the ID is confirmed before control.
#define AGILTRON_DEV_ID 0x00, 0x00, 0x00, 0x6F
// HA number sliders are capped here. The hardware allows 8000 mA pump, but
// the lab notes report ~2500 mA pump-1 -> ~27 dBm (~515 mW). Keep a margin.
#define SEED_CURRENT_MAX_MA 300 // CTL200 ilmax default is 1000; seed DFB is low-power
// Pump-1 current clamp. Two ceilings:
// SOFT (default) = the 1 W rated operating point (~4000 mA, measured
// 2026-06-17). Guards against accidental over-drive. NOT a safety interlock.
// HARD = the Agiltron protocol / hardware maximum (8000 mA). Reachable only
// while the "Pump limit override" switch is ON (set/amp/pump_override), for
// supervised over-rating characterisation. Driving the 1 W-rated pump diode
// toward 8000 mA trades diode lifetime (and risks damage) for extra power.
// The HA number slider spans 0..HARD; a command above SOFT is clamped to SOFT
// unless the override is ON. Turning the override OFF re-clamps a running
// setpoint back down to SOFT immediately.
#define PUMP_CURRENT_SOFT_MAX_MA 4000
#define PUMP_CURRENT_HARD_MAX_MA 8000
// Seed thermistor setpoint (CTL200 `rtset`) clamp, in ohms. The CTL200 has no
// native °C setpoint; it regulates the seed TEC to hold the thermistor at this
// resistance. The default operating point is 10 kΩ. The range below spans
// roughly 39…13 °C on the β-model (a guardrail, not a diode-safe interlock —
// narrow it if the DFB1550LP datasheet gives a tighter window).
#define SEED_RT_SETPOINT_MIN_OHM 6000
#define SEED_RT_SETPOINT_MAX_OHM 16000
// NTC β-model for the read-only resistance→°C conversion (display only; the
// CTL200 does its own regulation in ohms). Assumes a 10 kΩ @ 25 °C NTC with
// β = 3435 K. Update if the seed thermistor's R25/β are known to differ.
#define SEED_THERMISTOR_R25_OHM 10000.0f
#define SEED_THERMISTOR_BETA_K 3435.0f
#define SEED_THERMISTOR_T25_K 298.15f
// ── Serial links to the instruments (wired in later increments) ─────
// UART0 stays the USB console. The classic ESP32 has 3 hardware UARTs.
//
// Koheron CTL200 (ASCII, 115200 8N1, "\r\n", ">>" prompt) -> UART2
// ESP32 GPIO17 (TX2) -> CTL200 RX, GPIO16 (RX2) <- CTL200 TX, GND
//
// Agiltron M511 (binary 0x55AA packets, 115200 8N1) -> UART1
// ESP32 GPIO26 (TX1) -> M511 RX(pin3), GPIO25 (RX1) <- M511 TX(pin7), GND
// (UART1 default pins clash with SPI flash on WROOM, so remap to 26/25.)
#define KOHERON_UART_NUM 2
#define KOHERON_TX_PIN 17
#define KOHERON_RX_PIN 16
#define KOHERON_BAUD 115200
#define AGILTRON_UART_NUM 1
#define AGILTRON_TX_PIN 26
#define AGILTRON_RX_PIN 25
#define AGILTRON_BAUD 115200
// ── Static IP ───────────────────────────────────────────────────────
// Pinned to .150 (free as of 2026-06-17) to avoid the DHCP clash with the
// BKtel EDFA Pi on .101. Comment out USE_STATIC_IP to fall back to DHCP.
#define USE_STATIC_IP
#define STATIC_IP_OCTETS 192, 168, 0, 150
#define GATEWAY_OCTETS 192, 168, 0, 1
#define SUBNET_OCTETS 255, 255, 255, 0
#define DNS_OCTETS 192, 168, 0, 1
// ── Timing ──────────────────────────────────────────────────────────
#define PUBLISH_INTERVAL_MS 2000 // telemetry cadence
#define MQTT_RECONNECT_MS 5000
// PubSubClient's default 256-byte buffer is too small for discovery
// payloads that embed the device block; bump it.
#define MQTT_BUFFER_SIZE 1024