From 68c9a38aa5e45d50415b98bf07ab20620eb23827 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Mon, 22 Jan 2018 15:04:08 -0500 Subject: [PATCH] remember device if it is connected to and then distinguished --- app/main.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/main.js b/app/main.js index 14fa319..cee90b1 100644 --- a/app/main.js +++ b/app/main.js @@ -60,6 +60,7 @@ var distinguishDevice = function (device, callback) { return console.error(err) } log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true) + setTimeout(function () { arduino.distinguish(distinguishCb); }, 1000); @@ -68,6 +69,8 @@ var distinguishDevice = function (device, callback) { if (err) { return console.error(err) } + rememberDevice(device, type) + log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true) if (callback) { callback(err, type); } } @@ -154,6 +157,8 @@ var distinguishDevices = function (devices) { } }) } + console.dir(mcopy.settings) + console.dir(checklist) checklist = devices.map(device => { return next => { @@ -181,6 +186,24 @@ var distinguishDevices = function (devices) { }) }; +var rememberDevice = function (device, type) { + let deviceEntry + let match = mcopy.settings.devices.filter(dev => { + if (dev.arduino && dev.arduino === device) { + return dev + } + }) + if (match.length === 0) { + deviceEntry = { + arduino : device, + type : type + } + mcopy.settings.devices.push(deviceEntry) + settings.update('devices', mcopy.settings.devices) + settings.save() + } +} + var devicesReady = function (projector, camera, light) { mainWindow.webContents.send('ready', {camera: camera, projector: projector, light: light }) settings.update('camera', { arduino : camera })