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 lights from './lights.js'; | ||||
| 
 | ||||
| const cfg = require('./config.json'); | ||||
| 
 | ||||
| global.cfg = cfg; | ||||
| 
 | ||||
| server.recv( | ||||
|   (res) => { | ||||
|  |  | |||
							
								
								
									
										22
									
								
								lights.js
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								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); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue