diff --git a/app/lib/devices/index.js b/app/lib/devices/index.js new file mode 100644 index 0000000..24475df --- /dev/null +++ b/app/lib/devices/index.js @@ -0,0 +1,408 @@ +'use strict'; +Object.defineProperty(exports, "__esModule", { value: true }); +const delay = require("delay"); +const Log = require("log"); +/** + * class representing the device discovery features + * + * + **/ +class Devices { + /** + * + **/ + constructor(arduino, settings, mainWindow, cam) { + this.connected = {}; + this.arduino = arduino; + this.settings = settings; + this.mainWindow = mainWindow; + this.ui = this.mainWindow.webContents; + this.cam = cam; + this.init(); + } + /** + * + **/ + async init() { + this.log = await Log({ label: 'devices' }); + this.ipc = require('electron').ipcMain; + this.listen(); + } + /** + * + **/ + listen() { + this.ipc.on('profile', this.listener.bind(this)); + } + /** + * + **/ + listener(event, arg) { + this.log.info(`Saving profile ${arg.profile}`, 'SETTINGS', false, false); + this.settings.update('profile', arg.profile); + this.settings.save(); + } + /** + * + **/ + async enumerate() { + let devices; + try { + devices = await this.arduino.enumerate(); + } + catch (err) { + this.log.warn(err, 'SERIAL', false, true); + await delay(1000); + return this.all([]); + } + this.log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true); + devices = this.favor(devices); + return await this.all(devices); + } + /** + * + **/ + favor(devices) { + const past = this.settings.state.devices.filter((device) => { + if (device.arduino) { + return device; + } + }).map((device) => { + return device.arduino; + }); + if (past.length === 0) { + return devices; + } + devices.sort((a, b) => { + if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) { + return 1; + } + else if (past.indexOf(a) === -1 && past.indexOf(b) !== -1) { + return -1; + } + return 0; + }); + return devices; + } + /** + * + **/ + async distinguish(device) { + let connectSuccess; + let verifySuccess; + let type; + try { + connectSuccess = await this.arduino.connect('connect', device, true); + } + catch (err) { + this.log.error('Error connecting', err); + return null; + } + await delay(2000); + try { + verifySuccess = await this.arduino.verify(); + } + catch (err) { + this.log.error('Error verifying device', err); + return null; + } + this.log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true); + await delay(1000); + try { + type = await this.arduino.distinguish(); + } + catch (err) { + this.log.error('Error distinguishing device', err); + return null; + } + this.remember('arduino', device, type); + this.log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true); + return type; + } + /** + * + **/ + async fakeProjector() { + this.connected.projector = '/dev/fake'; + try { + await this.arduino.fakeConnect('projector'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake PRONECTOR device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake PROJECTOR device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async fakeCamera() { + this.connected.camera = '/dev/fake'; + try { + await this.arduino.fakeConnect('camera'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake CAMERA device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake CAMERA device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async fakeLight() { + this.connected.light = '/dev/fake'; + try { + await this.arduino.fakeConnect('light'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake LIGHT device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake LIGHT device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async connectDevice(device, type) { + let closeSuccess; + let connectSuccess; + try { + closeSuccess = await this.arduino.close(); + } + catch (err) { + this.log.error('Error closing arduino connection', err); + return false; + } + if (type === 'projector') { + this.connected.projector = device; + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true); + } + else if (type === 'camera') { + this.connected.camera = device; + try { + connectSuccess = await this.arduino.connect('camera', device, false); + } + catch (err) { + this.log.error('Error connecting to camera', err); + return false; + } + this.log.info(`Connected to ${device} as CAMERA`, 'SERIAL', true, true); + } + else if (type === 'light') { + this.connected.light = device; + try { + connectSuccess = await this.arduino.connect('light', device, false); + } + catch (err) { + this.log.error('Error connecting to light', err); + return false; + } + this.log.info(`Connected to ${device} as LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,light') { + this.connected.projector = device; + this.connected.light = device; + this.arduino.aliasSerial('light', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector and light', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,camera,light') { + this.connected.projector = device; + this.connected.camera = device; + this.connected.light = device; + this.arduino.aliasSerial('camera', device); + this.arduino.aliasSerial('light', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector, camera and light', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA + LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,camera') { + this.connected.projector = device; + this.connected.camera = device; + this.arduino.aliasSerial('camera', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector and camera', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA`, 'SERIAL', true, true); + } + else if (type === 'projector_second') { + this.connected.projector_second = device; + this.arduino.aliasSerial('projector_second', device); + try { + connectSuccess = await this.arduino.connect('projector_second', device, false); + } + catch (err) { + this.log.error('Error connecting to secondary projector', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR_SECOND`, 'SERIAL', true, true); + } + else if (type === 'projector,projector_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + else if (type === 'camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + else if (type === 'camera,camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + return connectSuccess; + } + /** + * + **/ + //Cases for 1 or 2 arduinos connected + async all(devices) { + let c = {}; + let p = {}; + let l = {}; + let type; + let d; + let s = {}; + let checklist = []; + this.connected = { + projector: false, + camera: false, + light: false, + projector_second: false + }; + for (let device of devices) { + try { + type = await this.distinguish(device); + } + catch (err) { + this.log.error('Error distinguishing device', err); + throw err; + } + try { + await this.connectDevice(device, type); + } + catch (err) { + this.log.error('Error connecting to device', err); + throw err; + } + } + //done checking devices + if (!this.connected.projector) { + await this.fakeProjector(); + } + p.arduino = this.connected.projector; + if (!this.connected.camera) { + await this.fakeCamera(); + } + c.arduino = this.connected.camera; + if (this.settings.state.camera && this.settings.state.camera.intval) { + c.intval = this.settings.camera.intval; + await delay(1000); + await this.cam.connectIntval(null, { connect: true, url: c.intval }); + } + if (!this.connected.light) { + await this.fakeLight(); + } + l.arduino = this.connected.light; + if (this.connected.projector_second) { + s = this.connected.projector_second; + } + return this.ready(p, c, l, s); + } + /** + * + **/ + remember(which, device, type) { + let deviceEntry; + const match = this.settings.state.devices.filter((dev) => { + if (dev[which] && dev[which] === device) { + return dev; + } + }); + if (match.length === 0) { + deviceEntry = { + type: type + }; + deviceEntry[which] = device; + this.settings.state.devices.push(deviceEntry); + this.settings.update('devices', this.settings.state.devices); + this.settings.save(); + } + } + ; + /** + * + **/ + ready(projector, camera, light, projector_second) { + let args = { + camera, + projector, + light, + profile: this.settings.profile + }; + if (projector_second && projector_second.arduino) { + args.projector_second = projector_second; + } + this.ui.send('ready', args); + this.settings.update('camera', camera); + this.settings.update('projector', projector); + this.settings.update('light', light); + if (projector_second && projector_second.arduino) { + this.settings.update('projector_second', projector_second); + this.mainWindow.setSize(800, 800); + } + this.settings.save(); + return true; + } + ; +} +module.exports = function (arduino, settings, mainWindow, cam) { + return new Devices(arduino, settings, mainWindow, cam); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/app/lib/devices/index.js.map b/app/lib/devices/index.js.map new file mode 100644 index 0000000..534979a --- /dev/null +++ b/app/lib/devices/index.js.map @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ACZ,CAAC;IAAA,CAAC;CAMF;AAED,MAAM,CAAC,OAAO,GAAG,UAAU,OAAiB,EAAE,QAAc,EAAE,UAAgB,EAAE,GAAS;IACxF,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;AACvD,CAAC,CAAA"} \ No newline at end of file diff --git a/app/lib/devices/package.json b/app/lib/devices/package.json new file mode 100644 index 0000000..53b9f3e --- /dev/null +++ b/app/lib/devices/package.json @@ -0,0 +1,11 @@ +{ + "name": "devices", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/app/lib/settings/index.js.map b/app/lib/settings/index.js.map new file mode 100644 index 0000000..a5099b7 --- /dev/null +++ b/app/lib/settings/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/settings/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,yBAA0B;AAC1B,6BAA8B;AAC9B,+BAAgC;AAEhC,MAAM,QAAQ;IAab;;QAEI;IACJ;QAfQ,SAAI,GAAW,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,uBAAuB,CAAC,CAAC;QACjE,UAAK,GAAS;YACpB,MAAM,EAAG;gBACR,IAAI,EAAG,IAAI;gBACX,OAAO,EAAG,IAAI;aACd;YACD,OAAO,EAAG,EAAE;YACZ,OAAO,EAAG,OAAO;YACjB,MAAM,EAAG,EAAE;YACX,SAAS,EAAG,EAAE;YACd,KAAK,EAAG,EAAE;SACV,CAAA;IAMD,CAAC;IACD;;QAEI;IACI,KAAK,CAAC,QAAQ;QACrB,MAAM,GAAG,GAAY,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;QACxD,MAAM,MAAM,GAAa,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,C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IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC3C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAC7B;aAAM;YACN,IAAI,CAAC,IAAI,EAAE,CAAC;SACZ;IACF,CAAC;IACD;;QAEI;IACG,KAAK,CAAC,KAAK;QACjB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE;YACX,IAAI;gBACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC3B;YAAC,OAAO,GAAG,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACnB;SACD;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;IAChB,CAAC;IAAA,CAAC;CACF;AAED,MAAM,CAAC,OAAO,GAAG,IAAI,QAAQ,EAAE,CAAA"} \ No newline at end of file diff --git a/cli/lib/devices/index.js b/cli/lib/devices/index.js new file mode 100644 index 0000000..24475df --- /dev/null +++ b/cli/lib/devices/index.js @@ -0,0 +1,408 @@ +'use strict'; +Object.defineProperty(exports, "__esModule", { value: true }); +const delay = require("delay"); +const Log = require("log"); +/** + * class representing the device discovery features + * + * + **/ +class Devices { + /** + * + **/ + constructor(arduino, settings, mainWindow, cam) { + this.connected = {}; + this.arduino = arduino; + this.settings = settings; + this.mainWindow = mainWindow; + this.ui = this.mainWindow.webContents; + this.cam = cam; + this.init(); + } + /** + * + **/ + async init() { + this.log = await Log({ label: 'devices' }); + this.ipc = require('electron').ipcMain; + this.listen(); + } + /** + * + **/ + listen() { + this.ipc.on('profile', this.listener.bind(this)); + } + /** + * + **/ + listener(event, arg) { + this.log.info(`Saving profile ${arg.profile}`, 'SETTINGS', false, false); + this.settings.update('profile', arg.profile); + this.settings.save(); + } + /** + * + **/ + async enumerate() { + let devices; + try { + devices = await this.arduino.enumerate(); + } + catch (err) { + this.log.warn(err, 'SERIAL', false, true); + await delay(1000); + return this.all([]); + } + this.log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true); + devices = this.favor(devices); + return await this.all(devices); + } + /** + * + **/ + favor(devices) { + const past = this.settings.state.devices.filter((device) => { + if (device.arduino) { + return device; + } + }).map((device) => { + return device.arduino; + }); + if (past.length === 0) { + return devices; + } + devices.sort((a, b) => { + if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) { + return 1; + } + else if (past.indexOf(a) === -1 && past.indexOf(b) !== -1) { + return -1; + } + return 0; + }); + return devices; + } + /** + * + **/ + async distinguish(device) { + let connectSuccess; + let verifySuccess; + let type; + try { + connectSuccess = await this.arduino.connect('connect', device, true); + } + catch (err) { + this.log.error('Error connecting', err); + return null; + } + await delay(2000); + try { + verifySuccess = await this.arduino.verify(); + } + catch (err) { + this.log.error('Error verifying device', err); + return null; + } + this.log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true); + await delay(1000); + try { + type = await this.arduino.distinguish(); + } + catch (err) { + this.log.error('Error distinguishing device', err); + return null; + } + this.remember('arduino', device, type); + this.log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true); + return type; + } + /** + * + **/ + async fakeProjector() { + this.connected.projector = '/dev/fake'; + try { + await this.arduino.fakeConnect('projector'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake PRONECTOR device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake PROJECTOR device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async fakeCamera() { + this.connected.camera = '/dev/fake'; + try { + await this.arduino.fakeConnect('camera'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake CAMERA device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake CAMERA device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async fakeLight() { + this.connected.light = '/dev/fake'; + try { + await this.arduino.fakeConnect('light'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake LIGHT device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake LIGHT device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async connectDevice(device, type) { + let closeSuccess; + let connectSuccess; + try { + closeSuccess = await this.arduino.close(); + } + catch (err) { + this.log.error('Error closing arduino connection', err); + return false; + } + if (type === 'projector') { + this.connected.projector = device; + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true); + } + else if (type === 'camera') { + this.connected.camera = device; + try { + connectSuccess = await this.arduino.connect('camera', device, false); + } + catch (err) { + this.log.error('Error connecting to camera', err); + return false; + } + this.log.info(`Connected to ${device} as CAMERA`, 'SERIAL', true, true); + } + else if (type === 'light') { + this.connected.light = device; + try { + connectSuccess = await this.arduino.connect('light', device, false); + } + catch (err) { + this.log.error('Error connecting to light', err); + return false; + } + this.log.info(`Connected to ${device} as LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,light') { + this.connected.projector = device; + this.connected.light = device; + this.arduino.aliasSerial('light', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector and light', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,camera,light') { + this.connected.projector = device; + this.connected.camera = device; + this.connected.light = device; + this.arduino.aliasSerial('camera', device); + this.arduino.aliasSerial('light', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector, camera and light', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA + LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,camera') { + this.connected.projector = device; + this.connected.camera = device; + this.arduino.aliasSerial('camera', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector and camera', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA`, 'SERIAL', true, true); + } + else if (type === 'projector_second') { + this.connected.projector_second = device; + this.arduino.aliasSerial('projector_second', device); + try { + connectSuccess = await this.arduino.connect('projector_second', device, false); + } + catch (err) { + this.log.error('Error connecting to secondary projector', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR_SECOND`, 'SERIAL', true, true); + } + else if (type === 'projector,projector_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + else if (type === 'camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + else if (type === 'camera,camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + return connectSuccess; + } + /** + * + **/ + //Cases for 1 or 2 arduinos connected + async all(devices) { + let c = {}; + let p = {}; + let l = {}; + let type; + let d; + let s = {}; + let checklist = []; + this.connected = { + projector: false, + camera: false, + light: false, + projector_second: false + }; + for (let device of devices) { + try { + type = await this.distinguish(device); + } + catch (err) { + this.log.error('Error distinguishing device', err); + throw err; + } + try { + await this.connectDevice(device, type); + } + catch (err) { + this.log.error('Error connecting to device', err); + throw err; + } + } + //done checking devices + if (!this.connected.projector) { + await this.fakeProjector(); + } + p.arduino = this.connected.projector; + if (!this.connected.camera) { + await this.fakeCamera(); + } + c.arduino = this.connected.camera; + if (this.settings.state.camera && this.settings.state.camera.intval) { + c.intval = this.settings.camera.intval; + await delay(1000); + await this.cam.connectIntval(null, { connect: true, url: c.intval }); + } + if (!this.connected.light) { + await this.fakeLight(); + } + l.arduino = this.connected.light; + if (this.connected.projector_second) { + s = this.connected.projector_second; + } + return this.ready(p, c, l, s); + } + /** + * + **/ + remember(which, device, type) { + let deviceEntry; + const match = this.settings.state.devices.filter((dev) => { + if (dev[which] && dev[which] === device) { + return dev; + } + }); + if (match.length === 0) { + deviceEntry = { + type: type + }; + deviceEntry[which] = device; + this.settings.state.devices.push(deviceEntry); + this.settings.update('devices', this.settings.state.devices); + this.settings.save(); + } + } + ; + /** + * + **/ + ready(projector, camera, light, projector_second) { + let args = { + camera, + projector, + light, + profile: this.settings.profile + }; + if (projector_second && projector_second.arduino) { + args.projector_second = projector_second; + } + this.ui.send('ready', args); + this.settings.update('camera', camera); + this.settings.update('projector', projector); + this.settings.update('light', light); + if (projector_second && projector_second.arduino) { + this.settings.update('projector_second', projector_second); + this.mainWindow.setSize(800, 800); + } + this.settings.save(); + return true; + } + ; +} +module.exports = function (arduino, settings, mainWindow, cam) { + return new Devices(arduino, settings, mainWindow, cam); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/cli/lib/devices/index.js.map b/cli/lib/devices/index.js.map new file mode 100644 index 0000000..534979a --- /dev/null +++ b/cli/lib/devices/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,+BAAgC;AAChC,2BAA4B;AAE5B;;;;IAII;AAEJ,MAAM,OAAO;IAYZ;;QAEI;IACJ,YAAa,OAAiB,EAAE,QAAc,EAAE,UAAgB,EAAE,GAAS;QAZpE,cAAS,GAAS,EAAE,CAAA;QAa1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAA;QACrC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;IACD;;QAEI;IACI,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,G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jD,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;SACxC;QACD,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QACtC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;QAC5C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACpC,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,OAAO,EAAE;YACjD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;YAC1D,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SACjC;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;QACpB,OAAO,IAAI,CAAA;IACZ,CAAC;IAAA,CAAC;CAMF;AAED,MAAM,CAAC,OAAO,GAAG,UAAU,OAAiB,EAAE,QAAc,EAAE,UAAgB,EAAE,GAAS;IACxF,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;AACvD,CAAC,CAAA"} \ No newline at end of file diff --git a/cli/lib/devices/package.json b/cli/lib/devices/package.json new file mode 100644 index 0000000..53b9f3e --- /dev/null +++ b/cli/lib/devices/package.json @@ -0,0 +1,11 @@ +{ + "name": "devices", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/cli/lib/settings/index.js b/cli/lib/settings/index.js new file mode 100644 index 0000000..aeefcea --- /dev/null +++ b/cli/lib/settings/index.js @@ -0,0 +1,107 @@ +'use strict'; +Object.defineProperty(exports, "__esModule", { value: true }); +const os = require("os"); +const path = require("path"); +const fs = require("fs-extra"); +class Settings { + /** + * + **/ + constructor() { + this.file = path.join(os.homedir(), `/.mcopy/settings.json`); + this.state = { + server: { + port: 1111, + enabled: true + }, + devices: [], + profile: 'mcopy', + camera: {}, + projector: {}, + light: {} + }; + } + /** + * + **/ + async checkDir() { + const dir = path.join(os.homedir(), '.mcopy/'); + const exists = await fs.exists(dir); + if (!exists) { + try { + await fs.mkdir(dir); + } + catch (err) { + if (err.code === 'EEXIST') + return true; + console.error(err); + } + } + return true; + } + /** + * + **/ + async save() { + const str = JSON.stringify(this.state, null, '\t'); + this.checkDir(); + try { + await fs.writeFile(this.file, str, 'utf8'); + } + catch (err) { + console.error(err); + } + } + /** + * + **/ + update(key, val) { + this.state[key] = val; + } + /** + * + **/ + get(key) { + return this.state[key]; + } + /** + * + **/ + all() { + return this.state; + } + /** + * + **/ + async restore() { + let exists; + let str; + this.checkDir(); + exists = await fs.exists(this.file); + if (exists) { + str = await fs.readFile(this.file, 'utf8'); + this.state = JSON.parse(str); + } + else { + this.save(); + } + } + /** + * + **/ + async reset() { + const exists = await fs.exists(this.file); + if (exists) { + try { + await fs.unlink(this.file); + } + catch (err) { + console.error(err); + } + } + this.restore(); + } + ; +} +module.exports = new Settings(); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/cli/lib/settings/index.js.map b/cli/lib/settings/index.js.map new file mode 100644 index 0000000..a5099b7 --- /dev/null +++ b/cli/lib/settings/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/settings/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,yBAA0B;AAC1B,6BAA8B;AAC9B,+BAAgC;AAEhC,MAAM,QAAQ;IAab;;QAEI;IACJ;QAfQ,SAAI,GAAW,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,uBAAuB,CAAC,CAAC;QACjE,UAAK,GAAS;YACpB,MAAM,EAAG;gBACR,IAAI,EAAG,IA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G,CAAC,CAAC;IACxB,CAAC;IACD;;QAEI;IACG,GAAG;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IACD;;QAEI;IACG,KAAK,CAAC,OAAO;QACnB,IAAI,MAAM,CAAC;QACX,IAAI,GAAG,CAAC;QAER,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpC,IAAI,MAAM,EAAE;YACX,GAAG,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC3C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAC7B;aAAM;YACN,IAAI,CAAC,IAAI,EAAE,CAAC;SACZ;IACF,CAAC;IACD;;QAEI;IACG,KAAK,CAAC,KAAK;QACjB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE;YACX,IAAI;gBACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC3B;YAAC,OAAO,GAAG,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACnB;SACD;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;IAChB,CAAC;IAAA,CAAC;CACF;AAED,MAAM,CAAC,OAAO,GAAG,IAAI,QAAQ,EAAE,CAAA"} \ No newline at end of file diff --git a/cli/lib/settings/package.json b/cli/lib/settings/package.json new file mode 100644 index 0000000..87cc2fb --- /dev/null +++ b/cli/lib/settings/package.json @@ -0,0 +1,11 @@ +{ + "name": "settings", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/lib/devices/index.js b/lib/devices/index.js new file mode 100644 index 0000000..24475df --- /dev/null +++ b/lib/devices/index.js @@ -0,0 +1,408 @@ +'use strict'; +Object.defineProperty(exports, "__esModule", { value: true }); +const delay = require("delay"); +const Log = require("log"); +/** + * class representing the device discovery features + * + * + **/ +class Devices { + /** + * + **/ + constructor(arduino, settings, mainWindow, cam) { + this.connected = {}; + this.arduino = arduino; + this.settings = settings; + this.mainWindow = mainWindow; + this.ui = this.mainWindow.webContents; + this.cam = cam; + this.init(); + } + /** + * + **/ + async init() { + this.log = await Log({ label: 'devices' }); + this.ipc = require('electron').ipcMain; + this.listen(); + } + /** + * + **/ + listen() { + this.ipc.on('profile', this.listener.bind(this)); + } + /** + * + **/ + listener(event, arg) { + this.log.info(`Saving profile ${arg.profile}`, 'SETTINGS', false, false); + this.settings.update('profile', arg.profile); + this.settings.save(); + } + /** + * + **/ + async enumerate() { + let devices; + try { + devices = await this.arduino.enumerate(); + } + catch (err) { + this.log.warn(err, 'SERIAL', false, true); + await delay(1000); + return this.all([]); + } + this.log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true); + devices = this.favor(devices); + return await this.all(devices); + } + /** + * + **/ + favor(devices) { + const past = this.settings.state.devices.filter((device) => { + if (device.arduino) { + return device; + } + }).map((device) => { + return device.arduino; + }); + if (past.length === 0) { + return devices; + } + devices.sort((a, b) => { + if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) { + return 1; + } + else if (past.indexOf(a) === -1 && past.indexOf(b) !== -1) { + return -1; + } + return 0; + }); + return devices; + } + /** + * + **/ + async distinguish(device) { + let connectSuccess; + let verifySuccess; + let type; + try { + connectSuccess = await this.arduino.connect('connect', device, true); + } + catch (err) { + this.log.error('Error connecting', err); + return null; + } + await delay(2000); + try { + verifySuccess = await this.arduino.verify(); + } + catch (err) { + this.log.error('Error verifying device', err); + return null; + } + this.log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true); + await delay(1000); + try { + type = await this.arduino.distinguish(); + } + catch (err) { + this.log.error('Error distinguishing device', err); + return null; + } + this.remember('arduino', device, type); + this.log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true); + return type; + } + /** + * + **/ + async fakeProjector() { + this.connected.projector = '/dev/fake'; + try { + await this.arduino.fakeConnect('projector'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake PRONECTOR device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake PROJECTOR device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async fakeCamera() { + this.connected.camera = '/dev/fake'; + try { + await this.arduino.fakeConnect('camera'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake CAMERA device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake CAMERA device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async fakeLight() { + this.connected.light = '/dev/fake'; + try { + await this.arduino.fakeConnect('light'); + } + catch (err) { + console.error(err); + this.log.error(`Error connecting to fake LIGHT device`, 'SERIAL', true, true); + return false; + } + this.log.info('Connected to fake LIGHT device', 'SERIAL', true, true); + return true; + } + /** + * + **/ + async connectDevice(device, type) { + let closeSuccess; + let connectSuccess; + try { + closeSuccess = await this.arduino.close(); + } + catch (err) { + this.log.error('Error closing arduino connection', err); + return false; + } + if (type === 'projector') { + this.connected.projector = device; + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true); + } + else if (type === 'camera') { + this.connected.camera = device; + try { + connectSuccess = await this.arduino.connect('camera', device, false); + } + catch (err) { + this.log.error('Error connecting to camera', err); + return false; + } + this.log.info(`Connected to ${device} as CAMERA`, 'SERIAL', true, true); + } + else if (type === 'light') { + this.connected.light = device; + try { + connectSuccess = await this.arduino.connect('light', device, false); + } + catch (err) { + this.log.error('Error connecting to light', err); + return false; + } + this.log.info(`Connected to ${device} as LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,light') { + this.connected.projector = device; + this.connected.light = device; + this.arduino.aliasSerial('light', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector and light', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,camera,light') { + this.connected.projector = device; + this.connected.camera = device; + this.connected.light = device; + this.arduino.aliasSerial('camera', device); + this.arduino.aliasSerial('light', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector, camera and light', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA + LIGHT`, 'SERIAL', true, true); + } + else if (type === 'projector,camera') { + this.connected.projector = device; + this.connected.camera = device; + this.arduino.aliasSerial('camera', device); + try { + connectSuccess = await this.arduino.connect('projector', device, false); + } + catch (err) { + this.log.error('Error connecting to projector and camera', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA`, 'SERIAL', true, true); + } + else if (type === 'projector_second') { + this.connected.projector_second = device; + this.arduino.aliasSerial('projector_second', device); + try { + connectSuccess = await this.arduino.connect('projector_second', device, false); + } + catch (err) { + this.log.error('Error connecting to secondary projector', err); + return false; + } + this.log.info(`Connected to ${device} as PROJECTOR_SECOND`, 'SERIAL', true, true); + } + else if (type === 'projector,projector_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + else if (type === 'camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + else if (type === 'camera,camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + return connectSuccess; + } + /** + * + **/ + //Cases for 1 or 2 arduinos connected + async all(devices) { + let c = {}; + let p = {}; + let l = {}; + let type; + let d; + let s = {}; + let checklist = []; + this.connected = { + projector: false, + camera: false, + light: false, + projector_second: false + }; + for (let device of devices) { + try { + type = await this.distinguish(device); + } + catch (err) { + this.log.error('Error distinguishing device', err); + throw err; + } + try { + await this.connectDevice(device, type); + } + catch (err) { + this.log.error('Error connecting to device', err); + throw err; + } + } + //done checking devices + if (!this.connected.projector) { + await this.fakeProjector(); + } + p.arduino = this.connected.projector; + if (!this.connected.camera) { + await this.fakeCamera(); + } + c.arduino = this.connected.camera; + if (this.settings.state.camera && this.settings.state.camera.intval) { + c.intval = this.settings.camera.intval; + await delay(1000); + await this.cam.connectIntval(null, { connect: true, url: c.intval }); + } + if (!this.connected.light) { + await this.fakeLight(); + } + l.arduino = this.connected.light; + if (this.connected.projector_second) { + s = this.connected.projector_second; + } + return this.ready(p, c, l, s); + } + /** + * + **/ + remember(which, device, type) { + let deviceEntry; + const match = this.settings.state.devices.filter((dev) => { + if (dev[which] && dev[which] === device) { + return dev; + } + }); + if (match.length === 0) { + deviceEntry = { + type: type + }; + deviceEntry[which] = device; + this.settings.state.devices.push(deviceEntry); + this.settings.update('devices', this.settings.state.devices); + this.settings.save(); + } + } + ; + /** + * + **/ + ready(projector, camera, light, projector_second) { + let args = { + camera, + projector, + light, + profile: this.settings.profile + }; + if (projector_second && projector_second.arduino) { + args.projector_second = projector_second; + } + this.ui.send('ready', args); + this.settings.update('camera', camera); + this.settings.update('projector', projector); + this.settings.update('light', light); + if (projector_second && projector_second.arduino) { + this.settings.update('projector_second', projector_second); + this.mainWindow.setSize(800, 800); + } + this.settings.save(); + return true; + } + ; +} +module.exports = function (arduino, settings, mainWindow, cam) { + return new Devices(arduino, settings, mainWindow, cam); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/devices/index.js.map b/lib/devices/index.js.map new file mode 100644 index 0000000..534979a --- /dev/null +++ b/lib/devices/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":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AC,OAAO,GAAG,UAAU,OAAiB,EAAE,QAAc,EAAE,UAAgB,EAAE,GAAS;IACxF,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;AACvD,CAAC,CAAA"} \ No newline at end of file diff --git a/lib/devices/package.json b/lib/devices/package.json new file mode 100644 index 0000000..53b9f3e --- /dev/null +++ b/lib/devices/package.json @@ -0,0 +1,11 @@ +{ + "name": "devices", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/lib/settings/index.js b/lib/settings/index.js new file mode 100644 index 0000000..aeefcea --- /dev/null +++ b/lib/settings/index.js @@ -0,0 +1,107 @@ +'use strict'; +Object.defineProperty(exports, "__esModule", { value: true }); +const os = require("os"); +const path = require("path"); +const fs = require("fs-extra"); +class Settings { + /** + * + **/ + constructor() { + this.file = path.join(os.homedir(), `/.mcopy/settings.json`); + this.state = { + server: { + port: 1111, + enabled: true + }, + devices: [], + profile: 'mcopy', + camera: {}, + projector: {}, + light: {} + }; + } + /** + * + **/ + async checkDir() { + const dir = path.join(os.homedir(), '.mcopy/'); + const exists = await fs.exists(dir); + if (!exists) { + try { + await fs.mkdir(dir); + } + catch (err) { + if (err.code === 'EEXIST') + return true; + console.error(err); + } + } + return true; + } + /** + * + **/ + async save() { + const str = JSON.stringify(this.state, null, '\t'); + this.checkDir(); + try { + await fs.writeFile(this.file, str, 'utf8'); + } + catch (err) { + console.error(err); + } + } + /** + * + **/ + update(key, val) { + this.state[key] = val; + } + /** + * + **/ + get(key) { + return this.state[key]; + } + /** + * + **/ + all() { + return this.state; + } + /** + * + **/ + async restore() { + let exists; + let str; + this.checkDir(); + exists = await fs.exists(this.file); + if (exists) { + str = await fs.readFile(this.file, 'utf8'); + this.state = JSON.parse(str); + } + else { + this.save(); + } + } + /** + * + **/ + async reset() { + const exists = await fs.exists(this.file); + if (exists) { + try { + await fs.unlink(this.file); + } + catch (err) { + console.error(err); + } + } + this.restore(); + } + ; +} +module.exports = new Settings(); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/settings/index.js.map b/lib/settings/index.js.map new file mode 100644 index 0000000..a5099b7 --- /dev/null +++ b/lib/settings/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/settings/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,yBAA0B;AAC1B,6BAA8B;AAC9B,+BAAgC;AAEhC,MAAM,QAAQ;IAab;;QAEI;IACJ;QAfQ,SAAI,GAAW,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,uBAAuB,CAAC,CAAC;QACjE,UAAK,GAAS;YACpB,MAAM,EAAG;gBACR,IAAI,EAAG,IAAI;gBACX,OAAO,EAAG,IAAI;aACd;YACD,OAAO,EAAG,EAAE;YACZ,OAAO,EAAG,OAAO;YACjB,MAAM,EAAG,EAAE;YACX,SAAS,EAAG,EAAE;YACd,KAAK,EAAG,EAAE;SACV,CAAA;IAMD,CAAC;IACD;;QAEI;IACI,KAAK,CAAC,QAAQ;QACrB,MAAM,GAAG,GAAY,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;QACxD,MAAM,MAAM,GAAa,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC7C,IAAI,CAAC,MAAM,EAAE;YACZ,IAAI;gBACH,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACpB;YAAC,OAAO,GAAG,EAAE;gBACb,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;oBAAE,OAAO,IAAI,CAAA;gBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACnB;SACD;QACD,OAAO,IAAI,CAAA;IACZ,CAAC;IACD;;QAEI;IACG,KAAK,CAAC,IAAI;Q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ACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC3B;YAAC,OAAO,GAAG,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACnB;SACD;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;IAChB,CAAC;IAAA,CAAC;CACF;AAED,MAAM,CAAC,OAAO,GAAG,IAAI,QAAQ,EAAE,CAAA"} \ No newline at end of file diff --git a/lib/settings/package.json b/lib/settings/package.json new file mode 100644 index 0000000..87cc2fb --- /dev/null +++ b/lib/settings/package.json @@ -0,0 +1,11 @@ +{ + "name": "settings", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/src/devices/index.ts b/src/devices/index.ts new file mode 100644 index 0000000..60333de --- /dev/null +++ b/src/devices/index.ts @@ -0,0 +1,416 @@ +'use strict'; + +import delay = require('delay'); +import Log = require('log'); + +/** + * class representing the device discovery features + * + * + **/ + +class Devices { + + public settings : any; + public connected : any = {} + + private arduino : Arduino; + private log : any; + private ui : any; + private ipc : any; + private mainWindow : any; + private cam : any; + + /** + * + **/ + constructor (arduino : Arduino, settings : any, mainWindow : any, cam : any) { + this.arduino = arduino; + this.settings = settings; + this.mainWindow = mainWindow; + this.ui = this.mainWindow.webContents + this.cam = cam; + this.init(); + } + /** + * + **/ + private async init () { + this.log = await Log({ label : 'devices' }) + this.ipc = require('electron').ipcMain; + this.listen() + } + /** + * + **/ + private listen () { + this.ipc.on('profile', this.listener.bind(this)); + } + /** + * + **/ + private listener (event : any, arg : any){ + this.log.info(`Saving profile ${arg.profile}`, 'SETTINGS', false, false); + this.settings.update('profile', arg.profile); + this.settings.save(); + } + /** + * + **/ + public async enumerate () { + let devices : Device[]; + try{ + devices = await this.arduino.enumerate(); + } catch (err) { + this.log.warn(err, 'SERIAL', false, true); + await delay(1000); + return this.all([]); + } + this.log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true); + devices = this.favor(devices); + return await this.all(devices); + } + /** + * + **/ + private favor (devices : Device[]) { + const past = this.settings.state.devices.filter((device : Device) => { + if (device.arduino) { + return device; + } + }).map((device : Device) => { + return device.arduino; + }) + if (past.length === 0) { + return devices; + } + devices.sort((a : any, b : any) => { + if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) { + return 1; + } else if (past.indexOf(a) === -1 && past.indexOf(b) !== -1) { + return -1; + } + return 0; + }) + return devices; + } + /** + * + **/ + private async distinguish (device : Device) { + let connectSuccess : any; + let verifySuccess : any; + let type : any; + + try { + connectSuccess = await this.arduino.connect('connect', device, true) + } catch (err) { + this.log.error('Error connecting', err) + return null + } + + await delay(2000) + + try { + verifySuccess = await this.arduino.verify() + } catch (err) { + this.log.error('Error verifying device', err) + return null + } + + this.log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true) + + await delay(1000) + + try { + type = await this.arduino.distinguish() + } catch (err) { + this.log.error('Error distinguishing device', err) + return null + } + + this.remember('arduino', device, type) + this.log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true) + + return type + } + /** + * + **/ + private async fakeProjector () { + this.connected.projector = '/dev/fake' + try { + await this.arduino.fakeConnect('projector') + } catch (err) { + console.error(err) + this.log.error(`Error connecting to fake PRONECTOR device`, 'SERIAL', true, true) + return false + } + this.log.info('Connected to fake PROJECTOR device', 'SERIAL', true, true) + return true + } + /** + * + **/ + private async fakeCamera () { + this.connected.camera = '/dev/fake' + try { + await this.arduino.fakeConnect('camera') + } catch (err) { + console.error(err) + this.log.error(`Error connecting to fake CAMERA device`, 'SERIAL', true, true) + return false + } + this.log.info('Connected to fake CAMERA device', 'SERIAL', true, true) + return true + } + /** + * + **/ + private async fakeLight () { + this.connected.light = '/dev/fake' + try { + await this.arduino.fakeConnect('light') + } catch (err) { + console.error(err) + this.log.error(`Error connecting to fake LIGHT device`, 'SERIAL', true, true) + return false + } + this.log.info('Connected to fake LIGHT device', 'SERIAL', true, true) + return true + } + /** + * + **/ + private async connectDevice (device : Device, type : any) { + let closeSuccess : any; + let connectSuccess : any; + try { + closeSuccess = await this.arduino.close() + } catch (err) { + this.log.error('Error closing arduino connection', err) + return false + } + if (type === 'projector') { + this.connected.projector = device + try { + connectSuccess = await this.arduino.connect('projector', device, false) + } catch (err) { + this.log.error('Error connecting to projector', err) + return false + } + this.log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true) + } else if (type === 'camera') { + this.connected.camera = device + try { + connectSuccess = await this.arduino.connect('camera', device, false) + } catch (err) { + this.log.error('Error connecting to camera', err) + return false + } + this.log.info(`Connected to ${device} as CAMERA`, 'SERIAL', true, true) + } else if (type === 'light') { + this.connected.light = device + try { + connectSuccess = await this.arduino.connect('light', device, false) + } catch (err) { + this.log.error('Error connecting to light', err) + return false + } + this.log.info(`Connected to ${device} as LIGHT`, 'SERIAL', true, true) + } else if (type === 'projector,light') { + this.connected.projector = device + this.connected.light = device + this.arduino.aliasSerial('light', device) + try{ + connectSuccess = await this.arduino.connect('projector', device, false) + } catch (err) { + this.log.error('Error connecting to projector and light', err) + return false + } + this.log.info(`Connected to ${device} as PROJECTOR + LIGHT`, 'SERIAL', true, true) + + } else if (type === 'projector,camera,light') { + this.connected.projector = device + this.connected.camera = device + this.connected.light = device + this.arduino.aliasSerial('camera', device) + this.arduino.aliasSerial('light', device) + try { + connectSuccess = await this.arduino.connect('projector', device, false) + } catch (err) { + this.log.error('Error connecting to projector, camera and light', err) + return false + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA + LIGHT`, 'SERIAL', true, true) + + } else if (type === 'projector,camera') { + this.connected.projector = device + this.connected.camera = device + this.arduino.aliasSerial('camera', device) + try { + connectSuccess = await this.arduino.connect('projector', device, false) + } catch (err) { + this.log.error('Error connecting to projector and camera', err) + return false + } + this.log.info(`Connected to ${device} as PROJECTOR + CAMERA`, 'SERIAL', true, true) + } else if (type === 'projector_second') { + this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + this.log.error('Error connecting to secondary projector', err) + return false + } + this.log.info(`Connected to ${device} as PROJECTOR_SECOND`, 'SERIAL', true, true) + } else if (type === 'projector,projector_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } else if (type === 'camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } else if (type === 'camera,camera_second') { + /*this.connected.projector_second = device + this.arduino.aliasSerial('projector_second', device) + try { + connectSuccess = await this.arduino.connect('projector_second', device, false) + } catch (err) { + console.error(err) + return false + }*/ + } + return connectSuccess + } + /** + * + **/ + //Cases for 1 or 2 arduinos connected + private async all (devices : Device[]) { + let c : any = {} + let p : any = {} + let l : any = {} + let type : string; + let d : any + let s : any = {} + let checklist : any[] = [] + + this.connected = { + projector : false, + camera : false, + light : false, + projector_second : false + } + + for (let device of devices) { + try { + type = await this.distinguish(device) + } catch (err) { + this.log.error('Error distinguishing device', err) + throw err + } + + try { + await this.connectDevice(device, type) + } catch (err) { + this.log.error('Error connecting to device', err) + throw err + } + } + + //done checking devices + + if (!this.connected.projector) { + await this.fakeProjector() + } + p.arduino = this.connected.projector + if (!this.connected.camera) { + await this.fakeCamera() + } + c.arduino = this.connected.camera + + if (this.settings.state.camera && this.settings.state.camera.intval) { + c.intval = this.settings.camera.intval + await delay(1000) + await this.cam.connectIntval(null, { connect : true, url : c.intval }) + } + + if (!this.connected.light) { + await this.fakeLight() + } + + l.arduino = this.connected.light + + if (this.connected.projector_second) { + s = this.connected.projector_second + } + + return this.ready(p, c, l, s) + } + /** + * + **/ + private remember (which : string, device : any, type : string) { + let deviceEntry : any; + const match = this.settings.state.devices.filter((dev : any) => { + if (dev[which] && dev[which] === device) { + return dev + } + }) + if (match.length === 0) { + deviceEntry = { + type : type + } + deviceEntry[which] = device + this.settings.state.devices.push(deviceEntry) + this.settings.update('devices', this.settings.state.devices) + this.settings.save() + } + }; + /** + * + **/ + private ready (projector : any, camera : any, light : any, projector_second : any) { + let args : any = { + camera, + projector, + light, + profile: this.settings.profile + } + if (projector_second && projector_second.arduino) { + args.projector_second = projector_second + } + this.ui.send('ready', args) + this.settings.update('camera', camera) + this.settings.update('projector', projector) + this.settings.update('light', light) + if (projector_second && projector_second.arduino) { + this.settings.update('projector_second', projector_second) + this.mainWindow.setSize(800, 800) + } + this.settings.save() + return true + }; + + /** + * + **/ + +} + +module.exports = function (arduino : Arduino, settings : any, mainWindow : any, cam : any) { + return new Devices(arduino, settings, mainWindow, cam) +} \ No newline at end of file diff --git a/src/globals.d.ts b/src/globals.d.ts index 37cf208..f09c6e6 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -2,8 +2,20 @@ declare module 'delay'; declare module 'log'; declare module 'intval'; declare module 'electron'; +declare module 'fs-extra'; + +interface Device { + arduino : string; +} interface Arduino { send (id : string, cmd : string) : number; string (id : string, str : string) : any; + enumerate () : any; + connect (id : string, device : Device, state : boolean) : any; + verify () : any; + distinguish () : any; + fakeConnect ( id : string) : any; + close () : any; + aliasSerial ( id : string, device : Device) : any; } diff --git a/src/settings/index.ts b/src/settings/index.ts new file mode 100644 index 0000000..621d577 --- /dev/null +++ b/src/settings/index.ts @@ -0,0 +1,105 @@ +'use strict' + +import os = require('os'); +import path = require('path'); +import fs = require('fs-extra'); + +class Settings { + private file : string= path.join(os.homedir(), `/.mcopy/settings.json`); + public state : any = { + server : { + port : 1111, + enabled : true + }, + devices : [], + profile : 'mcopy', + camera : {}, + projector : {}, + light : {} + } + /** + * + **/ + constructor () { + + } + /** + * + **/ + private async checkDir () { + const dir : string = path.join(os.homedir(), '.mcopy/'); + const exists : boolean = await fs.exists(dir) + if (!exists) { + try { + await fs.mkdir(dir); + } catch (err) { + if (err.code === 'EEXIST') return true + console.error(err); + } + } + return true + } + /** + * + **/ + public async save () { + const str = JSON.stringify(this.state, null, '\t'); + this.checkDir(); + try { + await fs.writeFile(this.file, str, 'utf8'); + } catch (err) { + console.error(err); + } + } + /** + * + **/ + public update (key : string, val : any) { + this.state[key] = val; + } + /** + * + **/ + public get (key : string) { + return this.state[key]; + } + /** + * + **/ + public all () { + return this.state; + } + /** + * + **/ + public async restore () { + let exists; + let str; + + this.checkDir(); + exists = await fs.exists(this.file); + + if (exists) { + str = await fs.readFile(this.file, 'utf8'); + this.state = JSON.parse(str); + } else { + this.save(); + } + } + /** + * + **/ + public async reset () { + const exists = await fs.exists(this.file); + if (exists) { + try { + await fs.unlink(this.file); + } catch (err) { + console.error(err); + } + } + this.restore(); + }; +} + +module.exports = new Settings() \ No newline at end of file