hopefully parsing?
This commit is contained in:
parent
5e1c369c34
commit
9c981b200c
1 changed files with 23 additions and 3 deletions
26
lights.js
26
lights.js
|
@ -9,6 +9,7 @@ const fade_ticks = cfg.fade_ticks || 20;
|
|||
var pixels = new Uint32Array(cfg.leds);
|
||||
var pixel_cache = new Uint32Array(cfg.leds);
|
||||
var next_pattern = new Uint32Array(cfg.leds);
|
||||
const targets = {}
|
||||
var pattern = {}
|
||||
|
||||
function rgb_to_int(r, g, b) {
|
||||
|
@ -32,11 +33,14 @@ ws281x.configure({
|
|||
});
|
||||
|
||||
export function set_pattern(pat) {
|
||||
pattern = pat
|
||||
log.debug("pattern set");
|
||||
pattern = pat;
|
||||
}
|
||||
|
||||
let functions = {
|
||||
rand: () => { return Math.floor(Math.random() * 256) }
|
||||
random: (index, args, prev) => { return Math.floor(Math.random() * 256) },
|
||||
constant: (index, args, prev) => { return args; },
|
||||
modulo: (index, args, prev) => { return prev % args; }
|
||||
}
|
||||
|
||||
function tick_pattern() {
|
||||
|
@ -44,7 +48,23 @@ function tick_pattern() {
|
|||
log.debug("TICKING PATTERN")
|
||||
|
||||
if (Object.keys(pattern).length > 0) {
|
||||
|
||||
for (let i = 0; i < cfg.leds; i++) {
|
||||
for (let command of pattern) {
|
||||
if (command.valid) {
|
||||
let instruction = command.instruction;
|
||||
if (functions[instruction.name.toLowerCase()]) {
|
||||
for (let target of instruction.args) {
|
||||
let channel = target.channel;
|
||||
if (!targets[channel]) {
|
||||
targets[channel] = 0;
|
||||
}
|
||||
targets[channel] =
|
||||
functions[instruction.name.toLowerCase()](i, target.arg, targets[channel]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
getRandom()
|
||||
|
|
Loading…
Reference in a new issue