diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6941d49 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +*.bak +*.tmp diff --git a/fs/animateLights.js b/fs/animateLights.js new file mode 100755 index 0000000..4687cca --- /dev/null +++ b/fs/animateLights.js @@ -0,0 +1,155 @@ +load('api_rpc.js'); +load("api_neopixel.js"); +load("api_file.js"); + + +let colors = { + black: {r:0, g:0, b:0}, + red: {r:255, g:0, b:0}, + green: {r:0, g:255, b:0}, + blue: {r:0, g:0, b:255}, + yellow: {r:255, g:255, b:0}, + orange: {r:255, g:127, b:0}, + purple: {r:255, g:0, b:255}, + white: {r:255, g:255, b:255}, + dimmedWhite: {r:50, g:50, b:50} +}; + + +let LightAnimation = { + numberOfBulbs: 3, + ledPin: 4, + running: false, + mode: "demo", + colorSequence: [ + colors.dimmedWhite, + colors.red, + colors.green, + colors.blue, + colors.yellow, + colors.orange, + colors.purple, + colors.red, + colors.red, + colors.green, + colors.green, + colors.white, + colors.white + ] +}; + +// Add RPC handlers + +RPC.addHandler('HouseLightning.Start', function(args) { + LightAnimation.running = true; + return {result: 'ok'}; +}, null); + +RPC.addHandler('HouseLightning.Stop', function(args) { + LightAnimation.running = false; + return {result: 'ok'}; +}, null); + +RPC.addHandler('HouseLightning.DemoMode', function(args) { + LightAnimation.mode = "demo"; + LightAnimation.running = true; + return {result: 'ok'}; +}, null); + +RPC.addHandler('HouseLightning.CycleMode', function(args) { + LightAnimation.mode = "cycle"; + LightAnimation.running = true; + return {result: 'ok'}; +}, null); + +RPC.addHandler('HouseLightning.GetAnimationConfig', function(args) { + return LightAnimation.animationConfig; +}, null); + +RPC.addHandler('HouseLightning.SetAnimationConfig', function(args) { + if (args !== undefined && args.config !== undefined) { + LightAnimation.animationConfig = JSON.parse(args.config); + if (LightAnimation.animationConfig.comment === undefined) { + return {error: 'config is incomplete or invalid / comment not found'}; + } + if (LightAnimation.animationConfig.lights === undefined) { + return {error: 'config is incomplete or invalid / lights definition not found'}; + } + if (LightAnimation.animationConfig.lights[0] === undefined) { + return {error: 'config is incomplete or invalid / lights not an array?'}; + } + let i; + for (i=0; i