Embed curve editor HTML and serve at /gpu-fan
- Include gpu_fan_html.h with embedded HTML page - Add addToWebHandlers() to register /gpu-fan endpoint - Add serveGpuFanPage() static method to serve the page - Add [Curve Editor] link in WLED Info panel - No filesystem upload required
This commit is contained in:
parent
b13dbb2897
commit
e5b02c65e8
@ -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("<button class=\"btn btn-xs\" onclick=\"requestJson({'");
|
||||
uiDomString += FPSTR(_name);
|
||||
@ -273,6 +291,7 @@ class GPUFanControllerUsermod : public Usermod {
|
||||
uiDomString += F("}});\"><i class=\"icons ");
|
||||
uiDomString += enabled ? "on" : "off";
|
||||
uiDomString += F("\"></i></button>");
|
||||
uiDomString += F(" <a href=\"/gpu-fan\" style=\"color:#e94560;font-size:0.9em;\">[Curve Editor]</a>");
|
||||
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<float>()) {
|
||||
if (!usermod["temperature"].isNull()) {
|
||||
currentTemp = usermod["temperature"].as<float>();
|
||||
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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user