error catching for cfg

This commit is contained in:
jane 2021-05-25 23:20:35 -04:00
parent da801346a1
commit 7851830f62
2 changed files with 12 additions and 13 deletions

View file

@ -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) => {

View file

@ -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);