diff --git a/app/lib/mscript/Readme.md b/app/lib/mscript/Readme.md
new file mode 100644
index 0000000..93bfafb
--- /dev/null
+++ b/app/lib/mscript/Readme.md
@@ -0,0 +1,136 @@
+
+
+## lib/mscript
+
+* [lib/mscript](#module_lib/mscript)
+ * [~mscript](#module_lib/mscript..mscript)
+ * [.arg(shrt, lng)](#module_lib/mscript..mscript.arg) ⇒ boolean
+ * [.arg_pos(shrt, lng)](#module_lib/mscript..mscript.arg_pos) ⇒ boolean
+ * [.state_clear()](#module_lib/mscript..mscript.state_clear)
+ * [.alts_unique()](#module_lib/mscript..mscript.alts_unique)
+ * [.interpret()](#module_lib/mscript..mscript.interpret)
+ * [.last_loop()](#module_lib/mscript..mscript.last_loop)
+ * [.parent_loop()](#module_lib/mscript..mscript.parent_loop)
+ * [.state_update()](#module_lib/mscript..mscript.state_update)
+ * [.str_to_arr()](#module_lib/mscript..mscript.str_to_arr)
+ * [.light_state()](#module_lib/mscript..mscript.light_state)
+ * [.light_to_arr()](#module_lib/mscript..mscript.light_to_arr)
+ * [.loop_count()](#module_lib/mscript..mscript.loop_count)
+ * [.fail()](#module_lib/mscript..mscript.fail)
+ * [.output()](#module_lib/mscript..mscript.output)
+ * [.init()](#module_lib/mscript..mscript.init)
+ * [.tests()](#module_lib/mscript..mscript.tests)
+
+
+
+### lib/mscript~mscript
+object mscript
+
+**Kind**: inner constant of [lib/mscript
](#module_lib/mscript)
+
+* [~mscript](#module_lib/mscript..mscript)
+ * [.arg(shrt, lng)](#module_lib/mscript..mscript.arg) ⇒ boolean
+ * [.arg_pos(shrt, lng)](#module_lib/mscript..mscript.arg_pos) ⇒ boolean
+ * [.state_clear()](#module_lib/mscript..mscript.state_clear)
+ * [.alts_unique()](#module_lib/mscript..mscript.alts_unique)
+ * [.interpret()](#module_lib/mscript..mscript.interpret)
+ * [.last_loop()](#module_lib/mscript..mscript.last_loop)
+ * [.parent_loop()](#module_lib/mscript..mscript.parent_loop)
+ * [.state_update()](#module_lib/mscript..mscript.state_update)
+ * [.str_to_arr()](#module_lib/mscript..mscript.str_to_arr)
+ * [.light_state()](#module_lib/mscript..mscript.light_state)
+ * [.light_to_arr()](#module_lib/mscript..mscript.light_to_arr)
+ * [.loop_count()](#module_lib/mscript..mscript.loop_count)
+ * [.fail()](#module_lib/mscript..mscript.fail)
+ * [.output()](#module_lib/mscript..mscript.output)
+ * [.init()](#module_lib/mscript..mscript.init)
+ * [.tests()](#module_lib/mscript..mscript.tests)
+
+
+
+#### mscript.arg(shrt, lng) ⇒ boolean
+Check for the presence of specific arguments in process
+argv
+
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+**Returns**: boolean
- Is flag present
+
+| Param | Type | Description |
+| --- | --- | --- |
+| shrt | string
| Short version of argument or flag |
+| lng | string
| Long version of argument or flag |
+
+
+
+#### mscript.arg_pos(shrt, lng) ⇒ boolean
+Check for the position of specific arguments in process
+argv
+
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+**Returns**: boolean
- Position of arg or flag, for locating input
+
+| Param | Type | Description |
+| --- | --- | --- |
+| shrt | string
| Short version of argument or flag |
+| lng | string
| Long version of argument or flag |
+
+
+
+#### mscript.state_clear()
+Clear the state object
+
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.alts_unique()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.interpret()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.last_loop()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.parent_loop()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.state_update()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.str_to_arr()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.light_state()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.light_to_arr()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.loop_count()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.fail()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.output()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.init()
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
+
+
+#### mscript.tests()
+Legacy tests. To be deprecated in future releases.
+
+**Kind**: static method of [mscript
](#module_lib/mscript..mscript)
diff --git a/app/lib/mscript/index.js b/app/lib/mscript/index.js
index 4a2ef53..8ab7a06 100644
--- a/app/lib/mscript/index.js
+++ b/app/lib/mscript/index.js
@@ -1,10 +1,22 @@
'use strict';
+/** @module lib/mscript */
+
let fs;
let input;
+/** object mscript */
const mscript = {};
+/**
+ * Check for the presence of specific arguments in process
+ * argv
+ *
+ * @param {string} shrt Short version of argument or flag
+ * @param {string} lng Long version of argument or flag
+ *
+ * @return {boolean} Is flag present
+ */
mscript.arg = function arg (shrt, lng) {
if (process.argv.indexOf(shrt) !== -1 ||
process.argv.indexOf(lng) !== -1) {
@@ -13,6 +25,15 @@ mscript.arg = function arg (shrt, lng) {
return false;
};
+/**
+ * Check for the position of specific arguments in process
+ * argv
+ *
+ * @param {string} shrt Short version of argument or flag
+ * @param {string} lng Long version of argument or flag
+ *
+ * @return {boolean} Position of arg or flag, for locating input
+ */
mscript.arg_pos = function arg_pos (shrt, lng) {
var pos = -1;
pos = process.argv.indexOf(shrt);
@@ -21,6 +42,7 @@ mscript.arg_pos = function arg_pos (shrt, lng) {
}
return pos;
};
+
mscript.black = '0,0,0';
mscript.cmd = [
'CF',
@@ -33,13 +55,19 @@ mscript.cmd = [
mscript.alts = {
'CF' : ['CAMERA FORWARD', 'CAM FORWARD'],
'PF' : ['PROJECTOR FORWARD', 'PROJ FORWARD'],
- 'BF': ['BLACK FORWARD'],
+ 'BF': ['BLACK FORWARD', 'BLACK', 'BLANK FORWARD', 'BLANK'],
'CB' : ['CAMERA BACKWARD', 'CAM BACKWARD', 'CAMERA BACK', 'CAM BACK'],
'PB' : ['PROJECTOR FORWARD', 'PROJ FORWARD', 'PROJECTOR BACK', 'PROJ BACK'],
- 'BB' : ['BLACK BACKWARD', 'BLACK BACK'],
- 'L ' : ['LIGHT', 'COLOR', 'LAMP']
+ 'BB' : ['BLACK BACKWARD', 'BLACK BACK', 'BLANK BACK'],
+ 'L ' : ['LIGHT', 'COLOR', 'LAMP'],
+ 'F ' : ['FADE']
};
+
mscript.state = {};
+
+/**
+ * Clear the state object
+ */
mscript.state_clear = function state_clear () {
mscript.state = {
cam : 0,
@@ -49,6 +77,9 @@ mscript.state_clear = function state_clear () {
rec : -1
};
};
+/**
+ *
+ */
mscript.alts_unique = function alts_unique () {
var ids = Object.keys(mscript.alts),
all = [];
@@ -60,6 +91,9 @@ mscript.alts_unique = function alts_unique () {
}
}
};
+/**
+ *
+ */
mscript.interpret = function interpret (text, callback) {
mscript.state_clear();
if (typeof text === 'undefined') {
@@ -214,12 +248,21 @@ mscript.interpret = function interpret (text, callback) {
return mscript.output(output);
}
};
+/**
+ *
+ */
mscript.last_loop = function last_loop () {
return mscript.state.loops[mscript.state.loops.length - 1];
};
+/**
+ *
+ */
mscript.parent_loop = function parent_loop () {
return mscript.state.loops[mscript.state.loops.length - 2];
};
+/**
+ *
+ */
mscript.state_update = function state_update (cmd, val) {
if (cmd === 'END') {
for (var i = 0; i < val; i++) {
@@ -271,6 +314,9 @@ mscript.state_update = function state_update (cmd, val) {
}
};
+/**
+ *
+ */
mscript.str_to_arr = function str_to_arr (str, cmd) {
var cnt = str.split(cmd),
c = parseInt(cnt[1]),
@@ -286,11 +332,17 @@ mscript.str_to_arr = function str_to_arr (str, cmd) {
}
return arr;
};
+/**
+ *
+ */
mscript.light_state = function light_state (str) {
//add parsers for other color spaces
var color = str.replace('L ', '').trim();
mscript.state.color = color;
};
+/**
+ *
+ */
mscript.light_to_arr = function light_to_arr (str, cmd) {
var cnt = str.split(cmd),
c = parseInt(cnt[1]),
@@ -313,13 +365,25 @@ mscript.light_to_arr = function light_to_arr (str, cmd) {
}
return arr;
};
+/**
+ *
+ */
mscript.loop_count = function loop_count (str) {
- return parseInt(str.split('LOOP ')[1]);
+ return parseInt(str.split(' ')[1]);
};
+mscript.fade_count = function fade_count (str) {
+ return parseInt(str.split(' ')[1]);
+}
+/**
+ *
+ */
mscript.fail = function fail (reason) {
console.error(JSON.stringify({success: false, error: true, msg : reason}));
if (process) process.exit();
};
+/**
+ *
+ */
mscript.output = function output (data) {
var json = true; //default
if (mscript.arg('-j', '--json')) {
@@ -339,6 +403,9 @@ mscript.output = function output (data) {
}
}
};
+/**
+ *
+ */
mscript.init = function init () {
if (mscript.arg('-t', '--tests')) {
return mscript.tests();
@@ -367,7 +434,9 @@ mscript.init = function init () {
console.timeEnd('mscript');
}
};
-
+/**
+ * Legacy tests. To be deprecated in future releases.
+ */
mscript.tests = function tests () {
console.log('Running mscript tests');
console.time('Tests took');