From 25c01716f5ba548ad8c8339fd6965f0b6e7ba6bb Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Tue, 14 Apr 2026 13:41:23 +0200 Subject: [PATCH] LED now accepts ranges --- Gaugecontroller/Gaugecontroller.ino | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Gaugecontroller/Gaugecontroller.ino b/Gaugecontroller/Gaugecontroller.ino index 55b6407..139c3aa 100644 --- a/Gaugecontroller/Gaugecontroller.ino +++ b/Gaugecontroller/Gaugecontroller.ino @@ -520,13 +520,19 @@ bool parseLedQuery(const String& line) { } bool parseLed(const String& line) { - int id, idx, r, g, b; - if (sscanf(line.c_str(), "LED %d %d %d %d %d", &id, &idx, &r, &g, &b) == 5) { + int id, r, g, b; + char idxToken[16]; + if (sscanf(line.c_str(), "LED %d %15s %d %d %d", &id, idxToken, &r, &g, &b) == 5) { if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; } - if (idx < 0 || idx >= gaugePins[id].ledCount) { sendReply("ERR BAD_IDX"); return true; } - leds[gaugeLedOffset[id] + idx] = CRGB(constrain(r, 0, 255), - constrain(g, 0, 255), - constrain(b, 0, 255)); + char* dash = strchr(idxToken, '-'); + int idxFirst = atoi(idxToken); + int idxLast = dash ? atoi(dash + 1) : idxFirst; + if (idxFirst < 0 || idxLast >= gaugePins[id].ledCount || idxFirst > idxLast) { + sendReply("ERR BAD_IDX"); return true; + } + CRGB color(constrain(r, 0, 255), constrain(g, 0, 255), constrain(b, 0, 255)); + for (int i = idxFirst; i <= idxLast; i++) + leds[gaugeLedOffset[id] + i] = color; FastLED.show(); sendReply("OK"); return true;