Reference os module in main.js app and add intval module, for controling an intval intervalometer with the mcopy GUI.
This commit is contained in:
parent
fd438d6426
commit
d54c62053c
|
@ -0,0 +1,52 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const req = require('request')
|
||||||
|
const devices = {}
|
||||||
|
|
||||||
|
class Intval {
|
||||||
|
constructor (device, url) {
|
||||||
|
devices[device] = `http://${url}`
|
||||||
|
}
|
||||||
|
move (device, cb) {
|
||||||
|
const timeStart = +new Date()
|
||||||
|
const baseUrl = devices[device]
|
||||||
|
const url = `${baseUrl}/frame`
|
||||||
|
console.log(url)
|
||||||
|
req(url, (err, res, body) => {
|
||||||
|
let ms = (+new Date()) - timeStart
|
||||||
|
if (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
cb(ms)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setDir (device, dir, cb) {
|
||||||
|
const timeStart = +new Date()
|
||||||
|
const baseUrl = devices[device]
|
||||||
|
const url = `${baseUrl}/dir?dir=${dir}`
|
||||||
|
console.log(url)
|
||||||
|
req(url, (err, res, body) => {
|
||||||
|
let ms = (+new Date()) - timeStart
|
||||||
|
if (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
cb(ms)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
setExposure (device, exposure, cb) {
|
||||||
|
const timeStart = +new Date()
|
||||||
|
const baseUrl = devices[device]
|
||||||
|
const url = `${baseUrl}/exposure?exposure=${exposure}`
|
||||||
|
console.log(url)
|
||||||
|
req(url, (err, res, body) => {
|
||||||
|
let ms = (+new Date()) - timeStart
|
||||||
|
if (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
cb(ms)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Intval
|
35
app/main.js
35
app/main.js
|
@ -3,6 +3,7 @@
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const { Menu, MenuItem, ipcMain, BrowserWindow, app } = electron
|
const { Menu, MenuItem, ipcMain, BrowserWindow, app } = electron
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const os = require('os')
|
||||||
const winston = require('winston')
|
const winston = require('winston')
|
||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
const uuid = require('uuid')
|
const uuid = require('uuid')
|
||||||
|
@ -11,14 +12,17 @@ const async = require('async')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const ee = new events.EventEmitter()
|
const ee = new events.EventEmitter()
|
||||||
const capture = require('./lib/capture')(ee)
|
const capture = require('./lib/capture')(ee)
|
||||||
const Server = require('./lib/server')
|
|
||||||
const settings = require('./lib/settings')
|
const settings = require('./lib/settings')
|
||||||
|
|
||||||
|
const Server = require('./lib/server')
|
||||||
|
const Intval = require('./lib/intval')
|
||||||
|
|
||||||
const mcopy = {}
|
const mcopy = {}
|
||||||
|
|
||||||
let mainWindow
|
let mainWindow
|
||||||
let mscript
|
let mscript
|
||||||
let arduino
|
let arduino
|
||||||
|
let intval
|
||||||
let projector
|
let projector
|
||||||
let camera
|
let camera
|
||||||
let server
|
let server
|
||||||
|
@ -287,9 +291,10 @@ cam.state = {
|
||||||
}
|
}
|
||||||
cam.init = function () {
|
cam.init = function () {
|
||||||
cam.listen()
|
cam.listen()
|
||||||
|
cam.intval = new Intval('camera', '192.168.1.224')
|
||||||
}
|
}
|
||||||
cam.set = function (dir, id) {
|
cam.set = function (dir, id) {
|
||||||
var cmd
|
let cmd
|
||||||
if (dir) {
|
if (dir) {
|
||||||
cmd = mcopy.cfg.arduino.cmd.cam_forward
|
cmd = mcopy.cfg.arduino.cmd.cam_forward
|
||||||
} else {
|
} else {
|
||||||
|
@ -300,19 +305,17 @@ cam.set = function (dir, id) {
|
||||||
cam.end(cmd, id, ms)
|
cam.end(cmd, id, ms)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
cam.setWeb = function (dir, id) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
cam.move = function (frame, id) {
|
cam.move = function (frame, id) {
|
||||||
arduino.send('camera', mcopy.cfg.arduino.cmd.camera, (ms) => {
|
let cmd = mcopy.cfg.arduino.cmd.camera
|
||||||
cam.end(mcopy.cfg.arduino.cmd.camera, id, ms)
|
/*arduino.send('camera', cmd, (ms) => {
|
||||||
|
cam.end(cmd, id, ms)
|
||||||
|
})*/
|
||||||
|
cam.intval.move('camera', (ms) => {
|
||||||
|
cam.end(cmd, id, ms)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
cam.moveWeb = function (frame, id) {
|
|
||||||
|
|
||||||
}
|
|
||||||
cam.listen = function () {
|
cam.listen = function () {
|
||||||
ipcMain.on('cam', (event, arg) => {
|
ipcMain.on('cam', (event, arg) => {
|
||||||
if (typeof arg.dir !== 'undefined') {
|
if (typeof arg.dir !== 'undefined') {
|
||||||
|
@ -343,20 +346,22 @@ cam.end = function (cmd, id, ms) {
|
||||||
};
|
};
|
||||||
|
|
||||||
log.file = function () {
|
log.file = function () {
|
||||||
let logPath = `/var/log/mcopy/`
|
let logPath = path.join(os.homedir(), `/.config/mcopy/`)
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
logPath = path.join(os.homedir(), `/Library/Logs/mcopy/`)
|
||||||
} else if (process.platform === 'win32') {
|
} else if (process.platform === 'win32') {
|
||||||
|
logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy/`)
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(logPath)) {
|
||||||
|
fs.mkdirSync(logPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(logPath, 'mcopy.log')
|
return path.join(logPath, 'mcopy.log')
|
||||||
}
|
}
|
||||||
log.time = 'MM/DD/YY-HH:mm:ss'
|
log.time = 'MM/DD/YY-HH:mm:ss'
|
||||||
log.transport = new (winston.Logger)({
|
log.transport = new (winston.Logger)({
|
||||||
transports: [
|
transports: [
|
||||||
new (winston.transports.Console)(),
|
new (winston.transports.Console)(),
|
||||||
new (winston.transports.File)({ filename: './logs/mcopy.log' })
|
new (winston.transports.File)({ filename: log.file() })
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
log.init = function () {
|
log.init = function () {
|
||||||
|
|
Loading…
Reference in New Issue