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 () {