From 11cdb9b51427550dd261b01afd0682b81a930d92 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Thu, 9 Jun 2016 17:21:49 -0400 Subject: [PATCH] Make mscript command line function Can issue commands using GUI --- app/js/app.js | 128 ++++++++-------------------------------------- app/lib/cmd-ui.js | 108 ++++++++++++++++++++++++++++++++++++++ app/src/index.js | 128 ++++++++-------------------------------------- 3 files changed, 150 insertions(+), 214 deletions(-) create mode 100644 app/lib/cmd-ui.js diff --git a/app/js/app.js b/app/js/app.js index 75f7739..dcbe73c 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -3051,9 +3051,10 @@ var remote = require('remote'), cam = {}, nav = {}, seq = require('./lib/seq-ui.js'), - cmd = {}, + cmd = require('./lib/cmd-ui.js'), gui = {}, - log = require('./lib/log-ui.js'); + log = require('./lib/log-ui.js'), + mscript = require('./lib/mscript.js'); //console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) ); mcopy.cfg = JSON.parse(fs.readFileSync('./data/cfg.json'), 'utf8'); @@ -3097,111 +3098,6 @@ mcopy.state = { //mcopy.gui.updateState(); -cmd.proj_forward = function (callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - if (callback) { callback(ms); } - }; - if (!mcopy.state.projector.direction) { - proj.set(true, function (ms) { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - } -}; -cmd.proj_backward = function (callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - if (callback) { callback(ms); } - }; - if (mcopy.state.projector.direction) { - proj.set(false, function (ms) { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - } -}; -cmd.cam_forward = function (rgb, callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - setTimeout(function () { - light.display([0,0,0]); - light.set([0, 0, 0], function () { - if (callback) { callback(ms); } - }); - }, mcopy.cfg.arduino.serialDelay); - }; - if (!mcopy.state.camera.direction) { - cam.set(true, function () { - setTimeout( function () { - light.display(rgb); - light.set(rgb, function () { - setTimeout( function () { - cam.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - light.display(rgb); - light.set(rgb, function () { - setTimeout(function () { - cam.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - } -}; -cmd.black_forward = function (callback) { - 'use strict'; - var off = [0, 0, 0]; - cmd.cam_forward(off, callback); -}; -cmd.cam_backward = function (rgb, callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - light.display([0,0,0]); - light.set([0, 0, 0], function () { - if (callback) { callback(ms); } - }); - }; - if (mcopy.state.camera.direction) { - cam.set(false, function () { - setTimeout(function () { - light.display(rgb); - light.set(rgb, function () { - cam.move(res); - }); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - setTimeout(function () { - light.display(rgb); - light.set(rgb, function () { - cam.move(res); - }); - }, mcopy.cfg.arduino.serialDelay); - } -}; -cmd.black_backward = function (callback) { - 'use strict'; - var off = [0, 0, 0]; - cmd.cam_backward(off, callback); -}; - proj.queue = {}; proj.lock = false; proj.init = function () { @@ -3579,8 +3475,26 @@ gui.console.init = function () { } }); }; +gui.console.lines = []; +gui.console.parse = function () { + 'use strict'; + var lines = gui.console.elem.val().split('\n'), + line = lines[lines.length - 2].replace('>', '').trim(); + gui.console.lines.push(line); +}; gui.console.exec = function () { 'use strict'; + var command; + gui.console.parse(); + command = gui.console.lines[gui.console.lines.length - 1].replace('>', '').trim(); + console.log(command); + if (mscript.cmd.indexOf(command) !== -1) { + if (command === 'CF') { + cmd.cam_forward(light.color); + } else if (cmd === 'CB') { + cmd.cam_backward(light.color); + } + } gui.console.newLine(); }; gui.console.newLine = function () { diff --git a/app/lib/cmd-ui.js b/app/lib/cmd-ui.js new file mode 100644 index 0000000..a8b9a80 --- /dev/null +++ b/app/lib/cmd-ui.js @@ -0,0 +1,108 @@ +var cmd = {}; + +cmd.proj_forward = function (callback) { + 'use strict'; + var res = function (ms) { + gui.updateState(); + if (callback) { callback(ms); } + }; + if (!mcopy.state.projector.direction) { + proj.set(true, function (ms) { + setTimeout(function () { + proj.move(res); + }, mcopy.cfg.arduino.serialDelay); + }); + } else { + setTimeout(function () { + proj.move(res); + }, mcopy.cfg.arduino.serialDelay); + } +}; +cmd.proj_backward = function (callback) { + 'use strict'; + var res = function (ms) { + gui.updateState(); + if (callback) { callback(ms); } + }; + if (mcopy.state.projector.direction) { + proj.set(false, function (ms) { + setTimeout(function () { + proj.move(res); + }, mcopy.cfg.arduino.serialDelay); + }); + } else { + setTimeout(function () { + proj.move(res); + }, mcopy.cfg.arduino.serialDelay); + } +}; +cmd.cam_forward = function (rgb, callback) { + 'use strict'; + var res = function (ms) { + gui.updateState(); + setTimeout(function () { + light.display([0,0,0]); + light.set([0, 0, 0], function () { + if (callback) { callback(ms); } + }); + }, mcopy.cfg.arduino.serialDelay); + }; + if (!mcopy.state.camera.direction) { + cam.set(true, function () { + setTimeout( function () { + light.display(rgb); + light.set(rgb, function () { + setTimeout( function () { + cam.move(res); + }, mcopy.cfg.arduino.serialDelay); + }); + }, mcopy.cfg.arduino.serialDelay); + }); + } else { + light.display(rgb); + light.set(rgb, function () { + setTimeout(function () { + cam.move(res); + }, mcopy.cfg.arduino.serialDelay); + }); + } +}; +cmd.black_forward = function (callback) { + 'use strict'; + var off = [0, 0, 0]; + cmd.cam_forward(off, callback); +}; +cmd.cam_backward = function (rgb, callback) { + 'use strict'; + var res = function (ms) { + gui.updateState(); + light.display([0,0,0]); + light.set([0, 0, 0], function () { + if (callback) { callback(ms); } + }); + }; + if (mcopy.state.camera.direction) { + cam.set(false, function () { + setTimeout(function () { + light.display(rgb); + light.set(rgb, function () { + cam.move(res); + }); + }, mcopy.cfg.arduino.serialDelay); + }); + } else { + setTimeout(function () { + light.display(rgb); + light.set(rgb, function () { + cam.move(res); + }); + }, mcopy.cfg.arduino.serialDelay); + } +}; +cmd.black_backward = function (callback) { + 'use strict'; + var off = [0, 0, 0]; + cmd.cam_backward(off, callback); +}; + +module.exports = cmd; \ No newline at end of file diff --git a/app/src/index.js b/app/src/index.js index 0c97079..8862486 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -12,9 +12,10 @@ var remote = require('remote'), cam = {}, nav = {}, seq = require('./lib/seq-ui.js'), - cmd = {}, + cmd = require('./lib/cmd-ui.js'), gui = {}, - log = require('./lib/log-ui.js'); + log = require('./lib/log-ui.js'), + mscript = require('./lib/mscript.js'); //console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) ); mcopy.cfg = JSON.parse(fs.readFileSync('./data/cfg.json'), 'utf8'); @@ -58,111 +59,6 @@ mcopy.state = { //mcopy.gui.updateState(); -cmd.proj_forward = function (callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - if (callback) { callback(ms); } - }; - if (!mcopy.state.projector.direction) { - proj.set(true, function (ms) { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - } -}; -cmd.proj_backward = function (callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - if (callback) { callback(ms); } - }; - if (mcopy.state.projector.direction) { - proj.set(false, function (ms) { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - setTimeout(function () { - proj.move(res); - }, mcopy.cfg.arduino.serialDelay); - } -}; -cmd.cam_forward = function (rgb, callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - setTimeout(function () { - light.display([0,0,0]); - light.set([0, 0, 0], function () { - if (callback) { callback(ms); } - }); - }, mcopy.cfg.arduino.serialDelay); - }; - if (!mcopy.state.camera.direction) { - cam.set(true, function () { - setTimeout( function () { - light.display(rgb); - light.set(rgb, function () { - setTimeout( function () { - cam.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - light.display(rgb); - light.set(rgb, function () { - setTimeout(function () { - cam.move(res); - }, mcopy.cfg.arduino.serialDelay); - }); - } -}; -cmd.black_forward = function (callback) { - 'use strict'; - var off = [0, 0, 0]; - cmd.cam_forward(off, callback); -}; -cmd.cam_backward = function (rgb, callback) { - 'use strict'; - var res = function (ms) { - gui.updateState(); - light.display([0,0,0]); - light.set([0, 0, 0], function () { - if (callback) { callback(ms); } - }); - }; - if (mcopy.state.camera.direction) { - cam.set(false, function () { - setTimeout(function () { - light.display(rgb); - light.set(rgb, function () { - cam.move(res); - }); - }, mcopy.cfg.arduino.serialDelay); - }); - } else { - setTimeout(function () { - light.display(rgb); - light.set(rgb, function () { - cam.move(res); - }); - }, mcopy.cfg.arduino.serialDelay); - } -}; -cmd.black_backward = function (callback) { - 'use strict'; - var off = [0, 0, 0]; - cmd.cam_backward(off, callback); -}; - proj.queue = {}; proj.lock = false; proj.init = function () { @@ -540,8 +436,26 @@ gui.console.init = function () { } }); }; +gui.console.lines = []; +gui.console.parse = function () { + 'use strict'; + var lines = gui.console.elem.val().split('\n'), + line = lines[lines.length - 2].replace('>', '').trim(); + gui.console.lines.push(line); +}; gui.console.exec = function () { 'use strict'; + var command; + gui.console.parse(); + command = gui.console.lines[gui.console.lines.length - 1].replace('>', '').trim(); + console.log(command); + if (mscript.cmd.indexOf(command) !== -1) { + if (command === 'CF') { + cmd.cam_forward(light.color); + } else if (cmd === 'CB') { + cmd.cam_backward(light.color); + } + } gui.console.newLine(); }; gui.console.newLine = function () {