From 2f05a3d21e85cfbc994600a859a5a948090f83d8 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Thu, 15 Mar 2018 11:55:10 -0400 Subject: [PATCH] Testing issue with light.js and the new async/await functions in main.js. Fundamental breakdown in light functionality that isn't occuring in proj.js. Ok I am just figuring out the issue as I type this, damnit. --- app/lib/ui/light.js | 2 ++ app/main.js | 54 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/lib/ui/light.js b/app/lib/ui/light.js index 95c6852..04149b9 100644 --- a/app/lib/ui/light.js +++ b/app/lib/ui/light.js @@ -124,6 +124,8 @@ light.set = function (rgb, callback) { //rgb = [0,0,0] rgb : rgb, id : uuid.v4() }; + console.log(rgb) + console.log(obj) ipcRenderer.sendSync('light', obj); if (typeof callback !== 'undefined') { diff --git a/app/main.js b/app/main.js index 713aab0..5fc1799 100644 --- a/app/main.js +++ b/app/main.js @@ -354,7 +354,8 @@ var createWindow = function () { width: 800, height: 600, minWidth : 800, - minHeight : 600 + minHeight : 600, + icon: path.join(__dirname, 'assets/icons/icon.png') }) mainWindow.loadURL('file://' + __dirname + '/index.html') if (process.argv.indexOf('-d') !== -1 || process.argv.indexOf('--dev') !== -1) { @@ -369,9 +370,17 @@ light.init = function () { light.listen() } light.listen = function () { - ipcMain.on('light', (event, arg) => { - light.set(arg.rgb, arg.id) - event.returnValue = true + ipcMain.on('light', async (event, arg) => { + //return new Promise(async(resolve, reject) => { + try { + await light.set(arg.rgb, arg.id) + }catch (err) { + console.error(err) + return reject(err) + } + event.returnValue = true + // return resolve(true) + //}) }) } light.set = async function (rgb, id) { @@ -382,7 +391,13 @@ light.set = async function (rgb, id) { } catch (err) { console.error(err) } - await arduino.string('light', str) + console.log(ms) + await delay(10) + try { + arduino.string('light', str) + } catch (err) { + console.error(err) + } return await light.end(rgb, id, ms) } light.end = async function (rgb, id, ms) { @@ -423,11 +438,19 @@ proj.move = async function (frame, id) { return await proj.end(mcopy.cfg.arduino.cmd.projector, id, ms) } proj.listen = function () { - ipcMain.on('proj', (event, arg) => { + ipcMain.on('proj', async (event, arg) => { if (typeof arg.dir !== 'undefined') { - proj.set(arg.dir, arg.id) + try { + await proj.set(arg.dir, arg.id) + } catch (err) { + console.error(err) + } } else if (typeof arg.frame !== 'undefined') { - proj.move(arg.frame, arg.id) + try { + await proj.move(arg.frame, arg.id) + } catch (err) { + console.error(err) + } } event.returnValue = true }) @@ -488,6 +511,7 @@ cam.move = async function (frame, id) { const cmd = mcopy.cfg.arduino.cmd.camera let ms if (cam.intval) { + ms = await cam.intval.move() } else { ms = await arduino.send('camera', cmd) @@ -527,11 +551,19 @@ cam.connectIntval = function (event, arg) { } cam.listen = function () { - ipcMain.on('cam', (event, arg) => { + ipcMain.on('cam', async (event, arg) => { if (typeof arg.dir !== 'undefined') { - cam.set(arg.dir, arg.id) + try { + await cam.set(arg.dir, arg.id) + } catch (err) { + console.error(err) + } } else if (typeof arg.frame !== 'undefined') { - cam.move(arg.frame, arg.id) + try { + await cam.move(arg.frame, arg.id) + } catch (err) { + console.error(err) + } } event.returnValue = true })