From 8b483ce2ef9660b2c57e9fd324fe6aea3da0a511 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 18 Jun 2016 20:06:57 -0400 Subject: [PATCH] Migrate proj object int lib/proj-ui.js Modulize that sucker --- app/lib/proj-ui.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++ app/src/index.js | 73 +-------------------------------------------- 2 files changed, 75 insertions(+), 72 deletions(-) create mode 100644 app/lib/proj-ui.js diff --git a/app/lib/proj-ui.js b/app/lib/proj-ui.js new file mode 100644 index 0000000..90d7491 --- /dev/null +++ b/app/lib/proj-ui.js @@ -0,0 +1,74 @@ +var proj = {}; + +proj.queue = {}; +proj.lock = false; +proj.init = function () { + 'use strict'; + proj.listen(); +}; +proj.set = function (dir, callback) { + 'use strict'; + var obj; + if (proj.lock) { + return false; + } + obj = { + dir : dir, + id : uuid.v4() + }; + ipcRenderer.sendSync('proj', obj); + + if (typeof callback !== 'undefined') { + obj.callback = callback; + } + proj.queue[obj.id] = obj; + proj.lock = true; +}; +proj.move = function (callback) { + 'use strict'; + var obj; + if (proj.lock) { + return false; + } + obj = { + frame : true, + id : uuid.v4() + }; + ipcRenderer.sendSync('proj', obj); + + if (typeof callback !== 'undefined') { + obj.callback = callback; + } + proj.queue[obj.id] = obj; + proj.lock = true; +}; +proj.end = function (c, id, ms) { + 'use strict'; + if (c === mcopy.cfg.arduino.cmd.proj_forward) { + mcopy.state.projector.direction = true; + } else if (c === mcopy.cfg.arduino.cmd.proj_backward) { + mcopy.state.projector.direction = false; + } else if (c === mcopy.cfg.arduino.cmd.projector) { + if (mcopy.state.projector.direction) { + mcopy.state.projector.pos += 1; + } else { + mcopy.state.projector.pos -= 1; + } + } + if (typeof proj.queue[id] !== 'undefined') { + if (typeof proj.queue[id].callback !== 'undefined') { + proj.queue[id].callback(ms); + } + delete proj.queue[id]; + proj.lock = false; + } +}; +proj.listen = function () { + 'use strict'; + ipcRenderer.on('proj', function (event, arg) { + proj.end(arg.cmd, arg.id, arg.ms); + return event.returnValue = true; + }); +}; + +module.exports = proj; \ No newline at end of file diff --git a/app/src/index.js b/app/src/index.js index 8862486..1875b39 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -8,7 +8,7 @@ var remote = require('remote'), ipcRenderer = require('electron').ipcRenderer, mcopy = {}, light = require('./lib/light-ui.js'), - proj = {}, + proj = require('./lib/proj-ui.js'), cam = {}, nav = {}, seq = require('./lib/seq-ui.js'), @@ -59,77 +59,6 @@ mcopy.state = { //mcopy.gui.updateState(); -proj.queue = {}; -proj.lock = false; -proj.init = function () { - 'use strict'; - proj.listen(); -}; -proj.set = function (dir, callback) { - 'use strict'; - var obj; - if (proj.lock) { - return false; - } - obj = { - dir : dir, - id : uuid.v4() - }; - ipcRenderer.sendSync('proj', obj); - - if (typeof callback !== 'undefined') { - obj.callback = callback; - } - proj.queue[obj.id] = obj; - proj.lock = true; -}; -proj.move = function (callback) { - 'use strict'; - var obj; - if (proj.lock) { - return false; - } - obj = { - frame : true, - id : uuid.v4() - }; - ipcRenderer.sendSync('proj', obj); - - if (typeof callback !== 'undefined') { - obj.callback = callback; - } - proj.queue[obj.id] = obj; - proj.lock = true; -}; -proj.end = function (c, id, ms) { - 'use strict'; - if (c === mcopy.cfg.arduino.cmd.proj_forward) { - mcopy.state.projector.direction = true; - } else if (c === mcopy.cfg.arduino.cmd.proj_backward) { - mcopy.state.projector.direction = false; - } else if (c === mcopy.cfg.arduino.cmd.projector) { - if (mcopy.state.projector.direction) { - mcopy.state.projector.pos += 1; - } else { - mcopy.state.projector.pos -= 1; - } - } - if (typeof proj.queue[id] !== 'undefined') { - if (typeof proj.queue[id].callback !== 'undefined') { - proj.queue[id].callback(ms); - } - delete proj.queue[id]; - proj.lock = false; - } -}; -proj.listen = function () { - 'use strict'; - ipcRenderer.on('proj', function (event, arg) { - proj.end(arg.cmd, arg.id, arg.ms); - return event.returnValue = true; - }); -}; - cam.queue = {}; cam.lock = false; cam.init = function () {