error catching for cfg
This commit is contained in:
parent
da801346a1
commit
7851830f62
2 changed files with 12 additions and 13 deletions
3
index.js
3
index.js
|
@ -1,9 +1,6 @@
|
||||||
import * as server from './server.js';
|
import * as server from './server.js';
|
||||||
import * as lights from './lights.js';
|
import * as lights from './lights.js';
|
||||||
|
|
||||||
const cfg = require('./config.json');
|
|
||||||
|
|
||||||
global.cfg = cfg;
|
|
||||||
|
|
||||||
server.recv(
|
server.recv(
|
||||||
(res) => {
|
(res) => {
|
||||||
|
|
22
lights.js
22
lights.js
|
@ -1,16 +1,18 @@
|
||||||
import * as ws281x from 'rpi-ws281x'
|
import * as ws281x from 'rpi-ws281x'
|
||||||
|
|
||||||
const fade_ticks = global.cfg.fade_ticks || 10;
|
const cfg = require('./config.json');
|
||||||
var pixels = new Uint32Array(global.cfg.leds);
|
|
||||||
var pixel_cache = new Uint32Array(global.cfg.leds);
|
const fade_ticks = cfg.fade_ticks || 10;
|
||||||
var next_pattern = new Uint32Array(global.cfg.leds);
|
var pixels = new Uint32Array(cfg.leds);
|
||||||
|
var pixel_cache = new Uint32Array(cfg.leds);
|
||||||
|
var next_pattern = new Uint32Array(cfg.leds);
|
||||||
var pattern = {}
|
var pattern = {}
|
||||||
|
|
||||||
ws281x.configure({
|
ws281x.configure({
|
||||||
leds: global.cfg.leds || 300,
|
leds: cfg.leds || 300,
|
||||||
brightness: global.cfg.brightness || 200,
|
brightness: cfg.brightness || 200,
|
||||||
gpio: global.cfg.gpio || 18,
|
gpio: cfg.gpio || 18,
|
||||||
stripType: global.cfg.type || 'grb'
|
stripType: cfg.type || 'grb'
|
||||||
});
|
});
|
||||||
|
|
||||||
export function set_pattern(pat) {
|
export function set_pattern(pat) {
|
||||||
|
@ -23,7 +25,7 @@ function tick_pattern() {
|
||||||
var g = Math.floor(Math.random() * 100);
|
var g = Math.floor(Math.random() * 100);
|
||||||
var b = 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) {
|
if (i % 3 == 0) {
|
||||||
next_pattern[i] = r;
|
next_pattern[i] = r;
|
||||||
next_pattern[i + 1] = g;
|
next_pattern[i + 1] = g;
|
||||||
|
@ -34,7 +36,7 @@ function tick_pattern() {
|
||||||
|
|
||||||
export function tick() {
|
export function tick() {
|
||||||
var changed = false;
|
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]) {
|
if (next_pattern[i] != pixels[i]) {
|
||||||
changed = true;
|
changed = true;
|
||||||
fade(i);
|
fade(i);
|
||||||
|
|
Loading…
Reference in a new issue