2019-02-24 13:13:47 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const program = require('commander')
|
|
|
|
const uuid = require('uuid')
|
|
|
|
const moment = require('moment')
|
2019-02-24 13:45:13 +00:00
|
|
|
const events = require('events')
|
|
|
|
const ee = new events.EventEmitter()
|
|
|
|
|
|
|
|
const cfg = require('../app/data/cfg.json')
|
|
|
|
const pkg = require('./package.json')
|
2019-02-24 13:13:47 +00:00
|
|
|
|
|
|
|
const delay = require('delay')
|
2019-02-26 01:24:30 +00:00
|
|
|
const exit = require('exit')
|
2019-02-24 13:32:16 +00:00
|
|
|
const intval = require('intval')
|
2019-02-24 13:45:13 +00:00
|
|
|
const arduino = require('arduino')(cfg, ee)
|
2019-02-24 13:22:59 +00:00
|
|
|
const Mscript = require('mscript')
|
|
|
|
const mscript = new Mscript()
|
2019-02-24 13:13:47 +00:00
|
|
|
|
2019-02-27 02:54:04 +00:00
|
|
|
const dev = require('device')(arduino)
|
2019-02-24 13:13:47 +00:00
|
|
|
let log
|
|
|
|
let readline
|
|
|
|
|
2019-02-26 01:24:30 +00:00
|
|
|
let devices
|
2019-02-24 13:13:47 +00:00
|
|
|
|
|
|
|
async function command () {
|
|
|
|
return new Promise ((resolve, reject) => {
|
|
|
|
return readline.question(`Input:`, (str) => {
|
|
|
|
log.info(str)
|
2019-02-24 13:22:59 +00:00
|
|
|
console.dir(mscript.interpret(str))
|
|
|
|
|
2019-02-24 13:13:47 +00:00
|
|
|
//interpret string
|
2019-02-24 13:22:59 +00:00
|
|
|
//readline.close()
|
2019-02-24 13:13:47 +00:00
|
|
|
return resolve(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function live () {
|
|
|
|
readline = require('readline').createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
|
|
|
})
|
|
|
|
log.info('Starting live control mode')
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
await command()
|
|
|
|
} catch (err) {
|
2019-02-24 13:45:13 +00:00
|
|
|
log.error('Error executing command', err)
|
2019-02-24 13:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 13:45:13 +00:00
|
|
|
function parsePattern () {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-24 13:13:47 +00:00
|
|
|
async function main (arg) {
|
2019-03-09 03:33:23 +00:00
|
|
|
log = await require('log')(arg)
|
2019-02-24 13:45:13 +00:00
|
|
|
|
2019-02-24 13:13:47 +00:00
|
|
|
log.info('mcopy-cli')
|
2019-02-24 13:45:13 +00:00
|
|
|
|
|
|
|
try {
|
2019-02-26 01:24:30 +00:00
|
|
|
devices = await arduino.enumerate()
|
2019-02-24 13:45:13 +00:00
|
|
|
} catch (err) {
|
|
|
|
log.error('Error enumerating devices')
|
|
|
|
log.error(err)
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:24:30 +00:00
|
|
|
if (!devices ||devices.length > 1) {
|
2019-02-27 02:54:04 +00:00
|
|
|
//return exit('No devices found', 1)
|
|
|
|
devices = []
|
2019-02-26 01:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await dev.all(devices)
|
|
|
|
|
2019-02-24 13:45:13 +00:00
|
|
|
if (arg.pattern) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg.live) {
|
|
|
|
try {
|
|
|
|
await live()
|
|
|
|
} catch (err) {
|
|
|
|
log.error('Error running in live control mode', err)
|
|
|
|
}
|
|
|
|
}
|
2019-02-24 13:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
program
|
|
|
|
.version(pkg.version)
|
|
|
|
.option('-l, --live', 'Live control mode')
|
|
|
|
.option('-f, --frames', 'Number of frames to capture with camera')
|
|
|
|
.option('-p, --pattern', 'Pattern of sequence to be repeated')
|
2019-02-26 01:24:30 +00:00
|
|
|
.option('-i, --intval', 'URL of intval3')
|
2019-02-24 13:13:47 +00:00
|
|
|
.option('-m, --mscript', 'Execute an mscript file')
|
|
|
|
.option('-q, --quiet', 'Suppresses all log messages')
|
|
|
|
.parse(process.argv)
|
|
|
|
|
|
|
|
main(program)
|