From f2c2d6ce43920f6fb56196c885f94e2191a9ba6f Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Wed, 20 Mar 2019 18:37:00 -0400 Subject: [PATCH] WIP wednesday --- app/lib/arduino/index.js | 10 +++--- app/lib/ui/cmd.js | 41 ++++++++++++++++++----- app/lib/ui/proj.js | 72 +++++++++++++++++++++++++++++++++++++++- app/main.js | 36 +++++++++++++++++--- app/src/index.js | 14 ++++---- scad/jk_extras.scad | 8 ++++- 6 files changed, 155 insertions(+), 26 deletions(-) diff --git a/app/lib/arduino/index.js b/app/lib/arduino/index.js index 0798b29..8f59a00 100644 --- a/app/lib/arduino/index.js +++ b/app/lib/arduino/index.js @@ -283,17 +283,17 @@ class Arduino { type = 'projector_second'; } else if (data === cfg.ardino.cmd.proj_dual_identifier) { - type = 'projectors'; + type = 'projector,projector_second'; } else if (data === cfg.ardino.cmd.cam_second_identifier) { type = 'camera_second'; } else if (data === cfg.ardino.cmd.cam_dual_identifier) { - type = 'cameras'; + type = 'camera,camera_second'; } - //camera,projectors - //cameras,projector - //cameras,projectors + //camera,projector,projector_second + //camera,camera_second,projector + //camera,camera_second,projector,projector_second return resolve(type); }; await delay(cfg.arduino.serialDelay); diff --git a/app/lib/ui/cmd.js b/app/lib/ui/cmd.js index b57bb8b..0f06b77 100644 --- a/app/lib/ui/cmd.js +++ b/app/lib/ui/cmd.js @@ -202,16 +202,39 @@ cmd.black_backward = function (callback) { cam_forward_cam2_backward : 'CFCB', cam_backward_cam2_forward : 'CBCF', - - proj2_forward : 'P2F', - proj2_backward : 'P2B', - - projs_forward : 'PPF', - projs_backward : 'PPB', - - proj_forward_proj2_backward : 'PFPB', - proj_backward_proj2_forward : 'PBPF' */ +/** + * Move the secondary projector forward one frame + * + * @param {function} callback Function to call after action + **/ +cmd.proj2_forward = function (callback) { + 'use strict'; + var res = function (ms) { + $('#cmd_proj2_forward').removeClass('active'); + gui.updateState(); + if (callback) { callback(ms); } + }; + $('#cmd_proj2_forward').addClass('active'); + if (!mcopy.state.projector2.direction) { + proj.set2(true, function (ms) { + setTimeout(function () { + proj.move2(res); + }, mcopy.cfg.arduino.serialDelay); + }); + } else { + setTimeout(function () { + proj.move2(res); + }, mcopy.cfg.arduino.serialDelay); + } +}; +cmd.proj2_backward = function (callback) {}; + +cmd.projs_forward = function (callback) {}; +cmd.projs_backward = function (callback) {}; + +cmd.proj_forward_proj2_backward = function (callback) {}; +cmd.proj_backward_proj2_forward = function (callback) {}; /** * Move the camera to a specific frame. Accepts the input with the "move_cam_to" diff --git a/app/lib/ui/proj.js b/app/lib/ui/proj.js index 519a50a..fe4a6e2 100644 --- a/app/lib/ui/proj.js +++ b/app/lib/ui/proj.js @@ -2,6 +2,7 @@ var proj = {}; proj.queue = {}; proj.lock = false; +proj.lock2 = false; proj.init = function () { 'use strict'; proj.listen(); @@ -42,6 +43,64 @@ proj.move = function (callback) { proj.queue[obj.id] = obj; proj.lock = true; }; +proj.set2 = function (dir, callback) { + 'use strict'; + var obj; + if (proj.lock2) { + return false; + } + obj = { + dir : dir, + second : true, + id : uuid.v4() + }; + ipcRenderer.sendSync('proj', obj); + + if (typeof callback !== 'undefined') { + obj.callback = callback; + } + proj.queue[obj.id] = obj; + proj.lock2 = true; +}; +proj.move2 = function (callback) { + 'use strict'; + var obj; + if (proj2.lock) { + return false; + } + obj = { + frame : true, + second : true, + id : uuid.v4() + }; + ipcRenderer.sendSync('proj', obj); + + if (typeof callback !== 'undefined') { + obj.callback = callback; + } + proj.queue[obj.id] = obj; + proj.lock2 = true; +}; +proj.both = function (callback) { + 'use strict'; + var obj; + if (proj.lock || proj2.lock) { + return false; + } + obj = { + frame : true, + both : true, + id : uuid.v4() + }; + ipcRenderer.sendSync('proj', obj); + + if (typeof callback !== 'undefined') { + obj.callback = callback; + } + proj.queue[obj.id] = obj; + proj.lock = true; + proj.lock2 = true; +} proj.end = function (c, id, ms) { 'use strict'; if (c === mcopy.cfg.arduino.cmd.proj_forward) { @@ -55,6 +114,7 @@ proj.end = function (c, id, ms) { mcopy.state.projector.pos -= 1; } } + // if (typeof proj.queue[id] !== 'undefined') { if (typeof proj.queue[id].callback !== 'undefined') { proj.queue[id].callback(ms); @@ -78,6 +138,16 @@ proj.setValue = function (val) { id : uuid.v4() }; ipcRenderer.sendSync('proj', obj); -} +}; + +proj.setValue2 = function (val) { + 'use strict'; + var obj = { + val: val, + second : true, + id : uuid.v4() + }; + ipcRenderer.sendSync('proj', obj); +}; module.exports = proj; \ No newline at end of file diff --git a/app/main.js b/app/main.js index c39064d..a05d20f 100644 --- a/app/main.js +++ b/app/main.js @@ -461,6 +461,26 @@ proj.set = async function (dir, id) { } return await proj.end(cmd, id, ms) } +proj.set2 = async function (dir, id) { + let cmd + let ms + if (dir) { + cmd = mcopy.cfg.arduino.cmd.proj2_forward + } else { + cmd = mcopy.cfg.arduino.cmd.proj2_backward + } + proj.state.dir = dir + if (proj.state.digital) { + dig.set(dir) + } else { + try { + ms = await arduino.send('projector', cmd) + } catch (err) { + console.error(err) + } + } + return await proj.end(cmd, id, ms) +} proj.move = async function (frame, id) { const cmd = mcopy.cfg.arduino.cmd.projector let ms @@ -482,10 +502,18 @@ proj.move = async function (frame, id) { proj.listen = function () { ipcMain.on('proj', async (event, arg) => { if (typeof arg.dir !== 'undefined') { - try { - await proj.set(arg.dir, arg.id) - } catch (err) { - console.error(err) + if (typeof arg.second !== 'undefined') { + try { + await proj.set2(arg.dir, arg.id) + } catch (err) { + console.error(err) + } + } else { + try { + await proj.set(arg.dir, arg.id) + } catch (err) { + console.error(err) + } } } else if (typeof arg.frame !== 'undefined') { try { diff --git a/app/src/index.js b/app/src/index.js index d130a6a..e9a1413 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -36,16 +36,18 @@ mcopy.state = { pos : 0, direction: true }, + camera_second : { + pos : 0, + direction : true + }, + projector_second : { + pos : 0, + direction : true + } sequence : { size : 24, arr : ['CF', 'PF'], light : ['255,255,255', ''], - cmd : { - camera: mcopy.cfg.arduino.cmd.camera, - projector: mcopy.cfg.arduino.cmd.projector, - cam_direction: mcopy.cfg.arduino.cmd.cam_direction, - cam_direction: mcopy.cfg.arduino.cmd.proj_direction - }, pads: { cam_forward: 'CF', proj_forward : 'PF', diff --git a/scad/jk_extras.scad b/scad/jk_extras.scad index ff36374..bffb8ac 100644 --- a/scad/jk_extras.scad +++ b/scad/jk_extras.scad @@ -14,4 +14,10 @@ module measurement_bar (X = 20 * IN, Y = 16.4, Z = 3, BOLT = 4, BOLT_OFFSET = (3 } } -projection() measurement_bar(); \ No newline at end of file +projection() { + difference () { + measurement_bar(); + translate([-11 * IN, 0, 0]) cube([20 * IN, 16.5, 4], center = true); + translate([11 * IN, 0, 0]) cube([20 * IN, 16.5, 4], center = true); + } +} \ No newline at end of file