From 7851830f62fb41a2e274cf2cfbb1809d67f1878f Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Tue, 25 May 2021 23:20:35 -0400 Subject: [PATCH] error catching for cfg --- index.js | 3 --- lights.js | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index eaef78d..405ec86 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,6 @@ import * as server from './server.js'; import * as lights from './lights.js'; -const cfg = require('./config.json'); - -global.cfg = cfg; server.recv( (res) => { diff --git a/lights.js b/lights.js index bf5ba0b..d5a331e 100644 --- a/lights.js +++ b/lights.js @@ -1,16 +1,18 @@ import * as ws281x from 'rpi-ws281x' -const fade_ticks = global.cfg.fade_ticks || 10; -var pixels = new Uint32Array(global.cfg.leds); -var pixel_cache = new Uint32Array(global.cfg.leds); -var next_pattern = new Uint32Array(global.cfg.leds); +const cfg = require('./config.json'); + +const fade_ticks = cfg.fade_ticks || 10; +var pixels = new Uint32Array(cfg.leds); +var pixel_cache = new Uint32Array(cfg.leds); +var next_pattern = new Uint32Array(cfg.leds); var pattern = {} ws281x.configure({ - leds: global.cfg.leds || 300, - brightness: global.cfg.brightness || 200, - gpio: global.cfg.gpio || 18, - stripType: global.cfg.type || 'grb' + leds: cfg.leds || 300, + brightness: cfg.brightness || 200, + gpio: cfg.gpio || 18, + stripType: cfg.type || 'grb' }); export function set_pattern(pat) { @@ -23,7 +25,7 @@ function tick_pattern() { var g = Math.floor(Math.random() * 100); var b = Math.floor(Math.random() * 100); - for (let i = 0; i < global.cfg.leds; i++) { + for (let i = 0; i < cfg.leds; i++) { if (i % 3 == 0) { next_pattern[i] = r; next_pattern[i + 1] = g; @@ -34,7 +36,7 @@ function tick_pattern() { export function tick() { var changed = false; - for (let i = 0; i < global.cfg.leds; i++) { + for (let i = 0; i < cfg.leds; i++) { if (next_pattern[i] != pixels[i]) { changed = true; fade(i);