From 709a5c1560778df92c4a53e02101a0f240780075 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Tue, 19 Jun 2018 09:49:34 -0400 Subject: [PATCH 1/8] Remove whitespace --- app/src/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/index.js b/app/src/index.js index 0244630..d130a6a 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -23,8 +23,6 @@ const mse = require('./lib/ui/mscript.js'); const Mscript = require('./lib/mscript'); - - /****** State shared by ALL interfaces *******/ From 4c98b5c82856ea67d0292c3d086dbb67dc04d2f2 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Mon, 18 Jun 2018 13:17:35 -0400 Subject: [PATCH 2/8] Update tests to use assert instead of if/and --- app/test/mscript_test.js | 62 ++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/app/test/mscript_test.js b/app/test/mscript_test.js index 749f026..b760b92 100644 --- a/app/test/mscript_test.js +++ b/app/test/mscript_test.js @@ -6,18 +6,15 @@ const mscript = new Mscript(); QUnit.test(`Basic functions`, (assert) => { const script1 = 'CF\nPF\nCB\nPB\nBF\nBB'; const script2 = `CF 3\nPF 3` - assert.expect( 2 ); + assert.expect( 5 ); mscript.interpret(script1, (obj) => { - let pass = false; - if (obj.success === true - && obj.cam === 0 - && obj.proj === 0 - && obj.arr.length === 6) { - pass = true; - } - assert.ok(pass, `Simple script1 compiles`) + assert.ok(obj.success, `Simple script1 compiles`) + assert.equal(obj.cam, 0, 'Camera gets equaled out'); + assert.equal(obj.proj, 0, 'Projector gets cancelled out'); + assert.equal(obj.arr.length, 6, 'Generate sequence of 6 steps'); }); + mscript.interpret(script2, (obj) => { let pass = false; if (obj.success === true @@ -149,3 +146,50 @@ QUnit.test('Light', (assert) => { assert.ok(pass, 'Basic light'); }); }); + +QUnit.test('Fade', (assert) => { + assert.expect(13); + const script1 = +`F 72 0,0,0 10,20,30 +CF +END +PF 10` + mscript.interpret(script1, (obj) => { + //console.dir(obj) + assert.ok(obj.success, 'Basic fade compiles'); + assert.equal(obj.cam, 72, `Camera moves forward 72 frames`); + assert.equal(obj.proj, 10, 'Projector moves forward 10 frames'); + assert.equal(obj.arr.length, 82, 'Generates 82 steps'); + assert.equal(obj.light[0], '0,0,0', 'Fade starts with starting color'); + assert.equal(obj.light[71], '10,20,30', 'Fade ends with ending color'); + assert.equal(obj.light[72], '', 'Frame after fade is default color'); + }); + + const script2 = +` +F 24 25,255,125 225,125,10 +CF +END +L 225,125,10 +CF 10` + mscript.interpret(script2, (obj) => { + //console.dir(obj) + assert.ok(obj.success, 'Mscript labeled output success'); + assert.equal(obj.cam, 34, 'There are 34 camera frames'); + assert.equal(obj.arr.length, 34, 'There are 34 steps in the script'); + assert.equal(obj.light[0], '25,255,125', 'First frame is equal to start color'); + assert.equal(obj.light[23], '225,125,10', 'Last frame in fade is equal to end color'); + assert.equal(obj.light[24], '225,125,10', 'First frame after fade is set using Light command'); + }); +}) + +QUnit.test('Variables', (assert) => { + const script1 = +`@LIGHT=200,200,200; +CF 20 +PF` + mscript.interpret(script1, obj => { + //console.dir(obj) + assert.ok(true) + }) +}) \ No newline at end of file From d306bc915c4c035745bb8a6716ee0cccc664be66 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Sun, 24 Jun 2018 12:45:14 -0400 Subject: [PATCH 3/8] When there is a loop specified in the gui, write that into the mscript that gets generated from the grid --- app/lib/ui/mscript.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/lib/ui/mscript.js b/app/lib/ui/mscript.js index 63e93b7..9283ab1 100644 --- a/app/lib/ui/mscript.js +++ b/app/lib/ui/mscript.js @@ -47,7 +47,19 @@ mse.mscript.fromSequence = function () { tmp = tmp.map(line => { return `${line.cmd} ${line.num}` }) + + if (mcopy.loop > 1) { + tmp.map(line => { + return ` ${line}`; + }) + tmp.reverse(); + tmp.push(`LOOP ${mcopy.loop}`); + tmp.reverse(); + tmp.push('END'); + } + str = tmp.join('\n'); + nav.change('script'); cont = confirm(`Are you sure you want to over-write the current sequence?`); if (cont) { From c9f5d11413c9292fb4e8a6c83855b0e2f94170e4 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Sun, 24 Jun 2018 12:45:41 -0400 Subject: [PATCH 4/8] Use startsWith, imported from lodash (don't need the whole thing) --- app/lib/mscript/index.js | 93 ++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 14 deletions(-) diff --git a/app/lib/mscript/index.js b/app/lib/mscript/index.js index ccd6004..708b7c9 100644 --- a/app/lib/mscript/index.js +++ b/app/lib/mscript/index.js @@ -23,6 +23,21 @@ const ALTS = { 'F ' : ['FADE'] }; +/** helper functions */ + +/** startswith function from lodash, do not want the entire lib for this */ +function startsWith(string, target, position) { + const { length } = string; + position = position == null ? 0 : position; + if (position < 0) { + position = 0; + } else if (position > length) { + position = length; + } + target = `${target}`; + return string.slice(position, position + target.length) == target; +} + /** class Mscript */ class Mscript { constructor () { @@ -32,6 +47,8 @@ class Mscript { * Clear the state of the script */ clear () { + this.lines = []; + this.cam = 0; this.proj = 0; this.color = ''; @@ -44,6 +61,8 @@ class Mscript { this.target = 0; //move to target using CAM # or PROJ # this.dist = 0; + this.variables = {}; + this.output = {}; } /** @@ -59,30 +78,36 @@ class Mscript { } //split string into lines, each containing a command - let lines = text.split('\n'); + this.lines = text.split('\n'); - for (let line of lines) { - line = line.replace(/\t+/g, ""); //strip tabs + this.lines = this.lines.map(line => { + line = line.replace(/\t+/g, ''); //strip tabs line = line.trim(); //remove excess whitespace before and after command line = line.toUpperCase(); + return line; + }) + + for (let line of this.lines) { this.two = line.substring(0, 2); if (CMD.indexOf(this.two) !== -1) { this.basic_cmd(line); - } else if (line.substring(0, 4) === 'LOOP') { + } else if (startsWith(line, '@') || line.indexOf('@') !== -1) { + this.variable(line); + } else if (startsWith(line, 'LOOP')) { this.new_loop(line); - } else if (line.substring(0, 2) === 'L ') { + } else if (startsWith(line, 'L ')) { this.light_state(line); - } else if (line.substring(0, 2) === 'F ') { + } else if (startsWith(line, 'F ')) { this.new_loop(line, true); - } else if (line.substring(0, 3) === 'END') { + } else if (startsWith(line, 'END')) { this.end_loop(line); - } else if (line.substring(0, 3) === 'CAM') { //directly go to that frame (black?) + } else if (startsWith(line, 'CAM')) { //directly go to that frame (black?) this.move_cam(line); - } else if (line.substring(0, 4) === 'PROJ') { //directly go to that frame + } else if (startsWith(line, 'PROJ')) { //directly go to that frame this.move_proj(line); - } else if (line.substring(0, 3) === 'SET') { //set that state + } else if (startsWith(line, 'SET')) { //set that state this.set_state(line); - } else if (line.substring(0, 1) === '#' || line.substring(0, 2) === '//') { + } else if (startsWith(line, '#') || startsWith(line, '//')) { //comments //ignore while parsing } @@ -98,6 +123,46 @@ class Mscript { //should only be invoked by running mscript.tests() callback(this.output); } + } + variable (line) { + let parts = line.split('='); + let key = parts[0]; + let value = parts[1]; + let update = false; + + if (value && value.indexOf('#') !== -1) { + value = value.split('#')[0]; + } + + if (value && value.indexOf('//') !== -1) { + value = value.split('//')[0]; + } + + if (value && value.indexOf('+') !== -1) { + if (value) + update = true; + } + + if (line.indexOf('-') !== -1) { + + update = true; + } + + if (line.indexOf(',') === -1) { //if not color string + try { + value = parseInt(value); + } catch (err) { + //supress parsing error + } + } + //console.dir(parts) + if (!this.variables[key] || update) { + this.variables[key] = value; + } + console.dir(this.variables) + } + variable_replace(line) { + } /** * Apply a basic two character command @@ -252,9 +317,9 @@ class Mscript { * Set the state of either the cam or projector */ set_state (line) { - if (line.substring(0, 7) === 'SET CAM') { + if (startsWith(line, 'SET CAM')) { this.cam = parseInt(line.split('SET CAM')[1]); - } else if (line.substring(0, 8) === 'SET PROJ') { + } else if (startsWith(line, 'SET PROJ')) { this.proj = parseInt(line.split('SET PROJ')[1]); } } @@ -466,7 +531,7 @@ END LOOP - (or END) closes loop L #RGB - sets light to rgb value -FADE +FADE 24 0,0,0 255,255,255 CF - Camera forwards PF - Projector forwards From 4e4d19aed74bc1a506286cf27bed2ab2b6358714 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Sun, 24 Jun 2018 16:09:13 -0400 Subject: [PATCH 5/8] Update tests for variables features --- app/test/mscript_test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/test/mscript_test.js b/app/test/mscript_test.js index b760b92..70c684f 100644 --- a/app/test/mscript_test.js +++ b/app/test/mscript_test.js @@ -185,9 +185,12 @@ CF 10` QUnit.test('Variables', (assert) => { const script1 = -`@LIGHT=200,200,200; +`@LIGHT=200,200,200 +@COUNT=1 CF 20 -PF` +PF +@COUNT++ +` mscript.interpret(script1, obj => { //console.dir(obj) assert.ok(true) From a051fe511fb5a946ca97303f13a437712da6a949 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Sun, 24 Jun 2018 16:09:35 -0400 Subject: [PATCH 6/8] Update todo tasks --- app/lib/mscript/TODO.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/lib/mscript/TODO.md b/app/lib/mscript/TODO.md index 84fd887..35d14cc 100644 --- a/app/lib/mscript/TODO.md +++ b/app/lib/mscript/TODO.md @@ -1,5 +1,10 @@ # TODO - mscript * Add variables and simple evaluation -* Add "Fade" feature -* Add "Light" feature \ No newline at end of file +* Add "Light" feature + +Bash-like variables? +Similar to LESS/SASS? +Makes a tokenization easier + +@ is better than $ \ No newline at end of file From ca92abea6870e988be7c1341854d3a408b72eac7 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Tue, 26 Jun 2018 09:36:18 -0400 Subject: [PATCH 7/8] Build new app.js --- app/js/app.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/js/app.js b/app/js/app.js index 5c5bf9c..9f5dadb 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -2497,8 +2497,6 @@ const mse = require('./lib/ui/mscript.js'); const Mscript = require('./lib/mscript'); - - /****** State shared by ALL interfaces *******/ From 448ad1bda496bc3c7eee95350b67b08b11b680bb Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Tue, 3 Jul 2018 14:25:36 -0400 Subject: [PATCH 8/8] Momentary switch delay was too long. --- ino/mcopy_jk_firmware/mcopy_jk_firmware.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ino/mcopy_jk_firmware/mcopy_jk_firmware.ino b/ino/mcopy_jk_firmware/mcopy_jk_firmware.ino index adc416a..958a290 100644 --- a/ino/mcopy_jk_firmware/mcopy_jk_firmware.ino +++ b/ino/mcopy_jk_firmware/mcopy_jk_firmware.ino @@ -31,7 +31,7 @@ boolean cam_dir = true; const int PROJECTOR = 8; const int PROJECTOR_FWD = 9; const int PROJECTOR_BWD = 10; -const int PROJECTOR_MOMENT = 240; +const int PROJECTOR_MOMENT = 200; const int PROJECTOR_FRAME = 950; //PROJECTOR VARIABLES boolean proj_dir = true;