diff --git a/workspace/__ardulib__/WS2812_NoBufffer/WS2812.h b/workspace/__ardulib__/WS2812_NoBufffer/WS2812.h index d1fd13e7..f2a9edac 100644 --- a/workspace/__ardulib__/WS2812_NoBufffer/WS2812.h +++ b/workspace/__ardulib__/WS2812_NoBufffer/WS2812.h @@ -33,7 +33,7 @@ public: WS2812(uint8_t pin, uint32_t length); void fill(uint8_t r, uint8_t g, uint8_t b); void fill(XColor color); - void fill(XColor color, uint32_t pixelsCount); + void fill(XColor color, uint32_t pixelCount, bool fromTail = false); void fillPattern(Pattern* pat, uint32_t shift = 0); void sendPixel(uint8_t r, uint8_t g, uint8_t b); void show(); diff --git a/workspace/__ardulib__/WS2812_NoBufffer/WS2812.inl b/workspace/__ardulib__/WS2812_NoBufffer/WS2812.inl index 774cf5b6..31a05c97 100644 --- a/workspace/__ardulib__/WS2812_NoBufffer/WS2812.inl +++ b/workspace/__ardulib__/WS2812_NoBufffer/WS2812.inl @@ -162,9 +162,16 @@ void WS2812::fill(XColor color) { show(); } -void WS2812::fill(XColor color, uint32_t pixelsCount) { +void WS2812::fill(XColor color, uint32_t pixelCount, bool fromTail = false) { cli(); - for (uint32_t i = 0; i < pixelsCount && i < _length; i++) { + // If fromTail is true + // Skip pixels by filling them with black color + uint32_t pixelsToSkip = fromTail ? _length - pixelCount : 0; + for (uint32_t i = 0; i < pixelsToSkip && i < _length; i++) { + sendPixel(0, 0, 0); + } + // Fill pixels + for (uint32_t i = pixelsToSkip; i < (pixelsToSkip + pixelCount); i++) { sendPixel(color.r, color.g, color.b); } sei(); diff --git a/workspace/__lib__/xod-dev/ws2812/example-fill-part/patch.xodp b/workspace/__lib__/xod-dev/ws2812/example-fill-part/patch.xodp index ce7cf959..22ce7e80 100644 --- a/workspace/__lib__/xod-dev/ws2812/example-fill-part/patch.xodp +++ b/workspace/__lib__/xod-dev/ws2812/example-fill-part/patch.xodp @@ -1,61 +1,133 @@ { + "comments": [ + { + "content": "This example shows how to clear the whole LED strip and then fill with the red color only last four LEDs.", + "id": "SJe1xTTeI", + "position": { + "units": "slots", + "x": 0, + "y": -1 + }, + "size": { + "height": 1, + "units": "slots", + "width": 10 + } + }, + { + "content": "<- Clear all LEDs.", + "id": "SJeBeTpl8", + "position": { + "units": "slots", + "x": 5, + "y": 1 + }, + "size": { + "height": 1, + "units": "slots", + "width": 5 + } + }, + { + "content": "<- Fill only last 4 LEDs.", + "id": "SkUHe66gL", + "position": { + "units": "slots", + "x": 5, + "y": 2 + }, + "size": { + "height": 1, + "units": "slots", + "width": 5 + } + }, + { + "content": "<- Setup the device.", + "id": "rkXNe66l8", + "position": { + "units": "slots", + "x": 5, + "y": 0 + }, + "size": { + "height": 1, + "units": "slots", + "width": 5 + } + } + ], "links": [ { - "id": "ByXhflqlU", + "id": "Hy7HJmgceI", "input": { - "nodeId": "BJznMxqlU", + "nodeId": "rJ-Hymxqx8", + "pinKey": "B1387L5RS" + }, + "output": { + "nodeId": "ByxryXe9e8", + "pinKey": "Symaj-NYCB" + } + }, + { + "id": "SyGrJQgqgL", + "input": { + "nodeId": "ByxryXe9e8", "pinKey": "By6jbVYCB" }, "output": { - "nodeId": "BJhjMxcx8", + "nodeId": "S1BkQl5e8", "pinKey": "SJxz8XtRS" } }, { - "id": "SJunfe5e8", + "id": "r1spDhTeU", "input": { - "nodeId": "ryD3fl5xL", - "pinKey": "B1387L5RS" + "nodeId": "rJ-Hymxqx8", + "pinKey": "rJWh8XIqAB" }, "output": { - "nodeId": "BJznMxqlU", - "pinKey": "Symaj-NYCB" + "nodeId": "ByxryXe9e8", + "pinKey": "Hk46jWVFAS" } } ], "nodes": [ { "boundLiterals": { - "HyI-5XSAr": "A4", - "S1C-cQBRB": "16" + "SyzTjbEKCH": "On Boot" }, - "id": "BJhjMxcx8", + "id": "ByxryXe9e8", "position": { "units": "slots", - "x": 2, - "y": 1 - }, - "type": "@/ws2812-device" - }, - { - "id": "BJznMxqlU", - "position": { - "units": "slots", - "x": 4, + "x": 0, "y": 1 }, "type": "@/clear" }, { "boundLiterals": { - "SJxhUmIcCr": "#100000", - "SkcHZece8": "4" + "HyI-5XSAr": "A4", + "S1C-cQBRB": "16" }, - "id": "ryD3fl5xL", + "id": "S1BkQl5e8", "position": { "units": "slots", - "x": 6, - "y": 1 + "x": 0, + "y": 0 + }, + "type": "@/ws2812-device" + }, + { + "boundLiterals": { + "SJxhUmIcCr": "#FF0000", + "SkcHZece8": "-4" + }, + "id": "rJ-Hymxqx8", + "position": { + "units": "slots", + "x": 0, + "y": 2 }, "type": "@/fill-solid" } diff --git a/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.cpp b/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.cpp index c6d3dc4a..00abc759 100644 --- a/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.cpp +++ b/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.cpp @@ -9,12 +9,14 @@ void evaluate(Context ctx) { if (isInputDirty(ctx)) { auto color = getValue(ctx); auto num = getValue(ctx); - if (num == -1) { + if (isinf(num)) { // Fill all the LEDs dev->fill(color); } else { // Fill only specified number of LEDs - dev->fill(color, (uint32_t)num); + bool fromTail = num < 0; + uint32_t pixelsCount = (uint32_t) abs(num); + dev->fill(color, pixelsCount, fromTail); } emitValue(ctx, 1); diff --git a/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.xodp b/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.xodp index a36bb0e8..87cc28ee 100644 --- a/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.xodp +++ b/workspace/__lib__/xod-dev/ws2812/fill-solid/patch.xodp @@ -24,7 +24,7 @@ "type": "xod/patch-nodes/output-pulse" }, { - "description": "Color value", + "description": "The color", "id": "SJxhUmIcCr", "label": "C", "position": { @@ -36,9 +36,9 @@ }, { "boundLiterals": { - "__out__": "-1" + "__out__": "Inf" }, - "description": "Number of LEDs to fill up with the solid color. Set `-1` to fill all LEDs.", + "description": "Number of LEDs to fill up with the solid color. Set `Inf` to fill all LEDs. Set to a negative value to fill from the tail.", "id": "SkcHZece8", "label": "NUM", "position": {