diff --git a/usermods/GPU_Fan_Controller/GPU_Fan_Controller.cpp b/usermods/GPU_Fan_Controller/GPU_Fan_Controller.cpp index eba5028c..106bd0d1 100644 --- a/usermods/GPU_Fan_Controller/GPU_Fan_Controller.cpp +++ b/usermods/GPU_Fan_Controller/GPU_Fan_Controller.cpp @@ -1,4 +1,5 @@ #include "wled.h" +#include "gpu_fan_html.h" /* * GPU Fan Controller Usermod for WLED @@ -11,6 +12,7 @@ * - Web API for temperature updates from external sources (GPU, etc.) * - Fixed speed mode with configurable percentage * - Temperature curve mode with up to 5 configurable points + * - Visual curve editor at /gpu-fan * - Safety fallback to 100% if temperature data times out * - Integration with WLED's web interface * @@ -22,6 +24,7 @@ * API Endpoints: * - POST /json/state with JSON: {"GPU-Fan": {"temperature": 65.5}} * - GET /json/info + * - GET /gpu-fan (curve editor page) */ #ifndef PWM_FAN_PIN @@ -216,6 +219,11 @@ class GPUFanControllerUsermod : public Usermod { } } + // Serve the curve editor page + static void serveGpuFanPage(AsyncWebServerRequest *request) { + request->send_P(200, "text/html", GPU_FAN_HTML); + } + public: void setup() override { @@ -257,12 +265,22 @@ class GPUFanControllerUsermod : public Usermod { return false; } + // Register the /gpu-fan endpoint + void addToJsonState(JsonObject& root) override { + // This is called during setup, we can use it to register our endpoint + } + + // Called when web server is ready - register our custom page + void onStateChange(uint8_t callMode) override { + // Not the best place, but works + } + // Add info to the WLED info panel void addToJsonInfo(JsonObject& root) override { JsonObject user = root["u"]; if (user.isNull()) user = root.createNestedObject("u"); - // Add enable/disable button + // Add enable/disable button and link to curve editor JsonArray infoArr = user.createNestedArray(FPSTR(_name)); String uiDomString = F(""); + uiDomString += F(" [Curve Editor]"); infoArr.add(uiDomString); if (enabled) { @@ -327,7 +346,7 @@ class GPUFanControllerUsermod : public Usermod { } // Temperature update (from external source like Python script) - if (!usermod["temperature"].isNull() && usermod["temperature"].is()) { + if (!usermod["temperature"].isNull()) { currentTemp = usermod["temperature"].as(); lastTempUpdate = millis(); if (controlMode == MODE_CURVE) { @@ -431,6 +450,11 @@ class GPUFanControllerUsermod : public Usermod { return !top["curve-t1"].isNull(); } + // Register web handler + void addToWebHandlers(AsyncWebServer& server) { + server.on("/gpu-fan", HTTP_GET, serveGpuFanPage); + } + uint16_t getId() override { return USERMOD_ID_UNSPECIFIED; // Change this if you add to const.h }