LED now accepts ranges
This commit is contained in:
@@ -90,7 +90,7 @@ Commands arrive as newline-terminated ASCII lines. Each `parse*` function in `pr
|
|||||||
| `HOME` | `HOME <id>` / `HOMEALL` | Run homing sequence |
|
| `HOME` | `HOME <id>` / `HOMEALL` | Run homing sequence |
|
||||||
| `SWEEP` | `SWEEP <id> <accel> <speed>` | Start sweep (0/0 stops) |
|
| `SWEEP` | `SWEEP <id> <accel> <speed>` | Start sweep (0/0 stops) |
|
||||||
| `POS?` | `POS?` | Query all gauges: `POS <id> <cur> <tgt> <homed> <homingState> <sweep>` |
|
| `POS?` | `POS?` | Query all gauges: `POS <id> <cur> <tgt> <homed> <homingState> <sweep>` |
|
||||||
| `LED` | `LED <id> <idx> <r> <g> <b>` | Set one LED (0-based index within gauge segment) to RGB colour (0–255 each) |
|
| `LED` | `LED <id> <idx> <r> <g> <b>` | Set one LED (0-based index within gauge segment) to RGB colour (0–255 each); `<idx>` may be a range `N-M` to set LEDs N through M in one command |
|
||||||
| `LED?` | `LED?` | Query all LEDs: one `LED <id> <idx> <r> <g> <b>` line per LED, then `OK` |
|
| `LED?` | `LED?` | Query all LEDs: one `LED <id> <idx> <r> <g> <b>` line per LED, then `OK` |
|
||||||
| `PING` | `PING` | Responds `PONG` |
|
| `PING` | `PING` | Responds `PONG` |
|
||||||
|
|
||||||
|
|||||||
@@ -520,13 +520,19 @@ bool parseLedQuery(const String& line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool parseLed(const String& line) {
|
bool parseLed(const String& line) {
|
||||||
int id, idx, r, g, b;
|
int id, r, g, b;
|
||||||
if (sscanf(line.c_str(), "LED %d %d %d %d %d", &id, &idx, &r, &g, &b) == 5) {
|
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 (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
||||||
if (idx < 0 || idx >= gaugePins[id].ledCount) { sendReply("ERR BAD_IDX"); return true; }
|
char* dash = strchr(idxToken, '-');
|
||||||
leds[gaugeLedOffset[id] + idx] = CRGB(constrain(r, 0, 255),
|
int idxFirst = atoi(idxToken);
|
||||||
constrain(g, 0, 255),
|
int idxLast = dash ? atoi(dash + 1) : idxFirst;
|
||||||
constrain(b, 0, 255));
|
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();
|
FastLED.show();
|
||||||
sendReply("OK");
|
sendReply("OK");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user