From 507aabcb07ccca84e06bf3f2a440ac96f3e4da8d Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 18 Jun 2016 20:08:01 -0400 Subject: [PATCH] Cam moved to cam-ui.js module --- app/lib/cam-ui.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++ app/src/index.js | 73 +--------------------------------------------- 2 files changed, 75 insertions(+), 72 deletions(-) create mode 100644 app/lib/cam-ui.js diff --git a/app/lib/cam-ui.js b/app/lib/cam-ui.js new file mode 100644 index 0000000..a376387 --- /dev/null +++ b/app/lib/cam-ui.js @@ -0,0 +1,74 @@ +var cam = {}; + +cam.queue = {}; +cam.lock = false; +cam.init = function () { + 'use strict'; + cam.listen(); +}; +cam.set = function (dir, callback) { + 'use strict'; + var obj; + if (cam.lock) { + return false; + } + obj = { + dir : dir, + id : uuid.v4() + }; + ipcRenderer.sendSync('cam', obj); + + if (typeof callback !== 'undefined') { + obj.callback = callback; + } + cam.queue[obj.id] = obj; + cam.lock = true; +}; +cam.move = function (callback) { + 'use strict'; + var obj; + if (cam.lock) { + return false; + } + obj = { + frame : true, + id : uuid.v4() + }; + ipcRenderer.sendSync('cam', obj); + + if (typeof callback !== 'undefined') { + obj.callback = callback; + } + cam.queue[obj.id] = obj; + cam.lock = true; +}; +cam.end = function (c, id, ms) { + 'use strict'; + if (c === mcopy.cfg.arduino.cmd.cam_forward) { + mcopy.state.camera.direction = true; + } else if (c === mcopy.cfg.arduino.cmd.cam_backward) { + mcopy.state.camera.direction = false; + } else if (c === mcopy.cfg.arduino.cmd.camera) { + if (mcopy.state.camera.direction) { + mcopy.state.camera.pos += 1; + } else { + mcopy.state.camera.pos -= 1; + } + } + if (typeof cam.queue[id] !== 'undefined') { + if (typeof cam.queue[id].callback !== 'undefined') { + cam.queue[id].callback(ms); + } + delete cam.queue[id]; + cam.lock = false; + } +}; +cam.listen = function () { + 'use strict'; + ipcRenderer.on('cam', function (event, arg) { + cam.end(arg.cmd, arg.id, arg.ms); + return event.returnValue = true; + }); +}; + +module.exports = cam; \ No newline at end of file diff --git a/app/src/index.js b/app/src/index.js index 1875b39..9c12c7b 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -9,7 +9,7 @@ var remote = require('remote'), mcopy = {}, light = require('./lib/light-ui.js'), proj = require('./lib/proj-ui.js'), - cam = {}, + cam = require('./lib/cam-ui.js'), nav = {}, seq = require('./lib/seq-ui.js'), cmd = require('./lib/cmd-ui.js'), @@ -59,77 +59,6 @@ mcopy.state = { //mcopy.gui.updateState(); -cam.queue = {}; -cam.lock = false; -cam.init = function () { - 'use strict'; - cam.listen(); -}; -cam.set = function (dir, callback) { - 'use strict'; - var obj; - if (cam.lock) { - return false; - } - obj = { - dir : dir, - id : uuid.v4() - }; - ipcRenderer.sendSync('cam', obj); - - if (typeof callback !== 'undefined') { - obj.callback = callback; - } - cam.queue[obj.id] = obj; - cam.lock = true; -}; -cam.move = function (callback) { - 'use strict'; - var obj; - if (cam.lock) { - return false; - } - obj = { - frame : true, - id : uuid.v4() - }; - ipcRenderer.sendSync('cam', obj); - - if (typeof callback !== 'undefined') { - obj.callback = callback; - } - cam.queue[obj.id] = obj; - cam.lock = true; -}; -cam.end = function (c, id, ms) { - 'use strict'; - if (c === mcopy.cfg.arduino.cmd.cam_forward) { - mcopy.state.camera.direction = true; - } else if (c === mcopy.cfg.arduino.cmd.cam_backward) { - mcopy.state.camera.direction = false; - } else if (c === mcopy.cfg.arduino.cmd.camera) { - if (mcopy.state.camera.direction) { - mcopy.state.camera.pos += 1; - } else { - mcopy.state.camera.pos -= 1; - } - } - if (typeof cam.queue[id] !== 'undefined') { - if (typeof cam.queue[id].callback !== 'undefined') { - cam.queue[id].callback(ms); - } - delete cam.queue[id]; - cam.lock = false; - } -}; -cam.listen = function () { - 'use strict'; - ipcRenderer.on('cam', function (event, arg) { - cam.end(arg.cmd, arg.id, arg.ms); - return event.returnValue = true; - }); -}; - //GUI gui.fmtZero = function (val, len) { var raw = val,