mirror of
https://github.com/xodio/xod.git
synced 2026-03-11 19:26:53 +01:00
feat(stdlib): make possible to fill a specified amount of LEDs from the tail
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ void evaluate(Context ctx) {
|
||||
if (isInputDirty<input_DO>(ctx)) {
|
||||
auto color = getValue<input_C>(ctx);
|
||||
auto num = getValue<input_NUM>(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<output_DONE>(ctx, 1);
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user