Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mjs_fs/api_neopixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let NeoPixel = {
_i: NeoPixel._c(pin, numPixels, order),

setPixel: NeoPixel.setPixel,
setStrip: NeoPixel.setStrip,
clear: NeoPixel.clear,
show: NeoPixel.show,
});
Expand All @@ -36,6 +37,13 @@ let NeoPixel = {
NeoPixel._set(this._i, i, r, g, b);
},

// ## **`strip.setStrip(r, g, b)`**
// Set ALL pixel's RGB value.
// Note that this only affects in-memory value of the pixels.
setStrip: function(r, g, b) {
NeoPixel._setStrip(this._i, r, g, b);
},

// ## **`strip.clear()`**
// Clear in-memory values of the pixels.
clear: function() {
Expand All @@ -52,4 +60,5 @@ let NeoPixel = {
_set: ffi('void mgos_neopixel_set(void *, int, int, int, int)'),
_clear: ffi('void mgos_neopixel_clear(void *)'),
_show: ffi('void mgos_neopixel_show(void *)'),
_setStrip: ffi('void mgos_neopixel_setStrip(void *, int, int, int)')
};
7 changes: 7 additions & 0 deletions src/mgos_neopixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ void mgos_neopixel_set(struct mgos_neopixel *np, int i, int r, int g, int b) {
}
}

void mgos_neopixel_setStrip(struct mgos_neopixel *np, int r, int g, int b) {
for (int i = 0; i < np->num_pixels; i++)
{
mgos_neopixel_set(np, i, r, g, b);
}
}

void mgos_neopixel_clear(struct mgos_neopixel *np) {
memset(np->data, 0, np->num_pixels * NUM_CHANNELS);
}
Expand Down