|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
const db = require('../db')
|
|
|
|
|
const log = require('../log')('intval')
|
|
|
|
|
const storage = require('node-persist')
|
|
|
|
|
const fs = require('fs')
|
|
|
|
@ -93,6 +94,7 @@ intval._setState = function (data) {
|
|
|
|
|
paused : false,
|
|
|
|
|
exposure : 0, //length of frame exposure, in ms
|
|
|
|
|
delay : 0, //delay before start of frame, in ms
|
|
|
|
|
current : {}, //current settings
|
|
|
|
|
cb : () => {}
|
|
|
|
|
},
|
|
|
|
|
release : {
|
|
|
|
@ -178,16 +180,30 @@ intval._pause = function () {
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
intval._stop = function () {
|
|
|
|
|
intval._pin.fwd.writeSync(0)
|
|
|
|
|
intval._pin.bwd.writeSync(0)
|
|
|
|
|
const entry = {}
|
|
|
|
|
const now = +new Date()
|
|
|
|
|
const len = now - intval._state.frame.start
|
|
|
|
|
|
|
|
|
|
intval._pin.fwd.writeSync(0)
|
|
|
|
|
intval._pin.bwd.writeSync(0)
|
|
|
|
|
|
|
|
|
|
log.info(`_stop`, { frame : len })
|
|
|
|
|
|
|
|
|
|
intval._pin.micro.unwatch()
|
|
|
|
|
intval._state.frame.active = false
|
|
|
|
|
|
|
|
|
|
if (intval._state.frame.cb) intval._state.frame.cb(len)
|
|
|
|
|
|
|
|
|
|
entry.start = intval._state.frame.start
|
|
|
|
|
entry.stop = now
|
|
|
|
|
entry.len = len
|
|
|
|
|
entry.dir = intval._state.current.dir
|
|
|
|
|
entry.exposure = intval._state.frame.current.exposure
|
|
|
|
|
entry.counter = intval._state.counter
|
|
|
|
|
|
|
|
|
|
db.insert(entry)
|
|
|
|
|
|
|
|
|
|
intval._state.frame.current = {}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Callback for watching relese switch state changes.
|
|
|
|
@ -325,35 +341,35 @@ intval.setCounter = function (val = 0) {
|
|
|
|
|
/**
|
|
|
|
|
* Begin a single frame with set variables or defaults
|
|
|
|
|
*
|
|
|
|
|
* @param {?boolean} [dir="null"] (optional) Direction of the frame
|
|
|
|
|
* @param {?integer} [time="null"] (optional) Exposure time, 0 = minimum
|
|
|
|
|
* @param {?boolean} [dir="null"] (optional) Direction of the frame
|
|
|
|
|
* @param {?integer} [exposure="null"] (optional) Exposure time, 0 = minimum
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
intval.frame = function (dir = null, time = null, cb = () => {}) {
|
|
|
|
|
intval.frame = function (dir = null, expsure = null, cb = () => {}) {
|
|
|
|
|
if (dir === true || (dir === null && intval._state.frame.dir === true) ) {
|
|
|
|
|
dir = true
|
|
|
|
|
} else {
|
|
|
|
|
dir = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (time === null && intval._state.frame.exposure !== 0) {
|
|
|
|
|
time = intval._state.frame.exposure
|
|
|
|
|
} else if (time === null) {
|
|
|
|
|
time = 0 //default speed
|
|
|
|
|
if (exposure === null && intval._state.frame.exposure !== 0) {
|
|
|
|
|
exposure = intval._state.frame.exposure
|
|
|
|
|
} else if (exposure === null) {
|
|
|
|
|
exposure = 0 //default speed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intval._state.frame.start = +new Date()
|
|
|
|
|
intval._state.frame.active = true
|
|
|
|
|
intval._pin.micro.watch(intval._watchMicro)
|
|
|
|
|
|
|
|
|
|
log.info('frame', {dir : dir ? 'forward' : 'backward', exposure : time})
|
|
|
|
|
log.info('frame', {dir : dir ? 'forward' : 'backward', exposure : exposure})
|
|
|
|
|
|
|
|
|
|
if (dir) {
|
|
|
|
|
intval._startFwd()
|
|
|
|
|
} else {
|
|
|
|
|
intval._startBwd()
|
|
|
|
|
}
|
|
|
|
|
if (time !== 0) {
|
|
|
|
|
if (exposure !== 0) {
|
|
|
|
|
intval._state.frame.paused = true
|
|
|
|
|
if (dir) {
|
|
|
|
|
setTimeout(intval._pause, intval._frame.open)
|
|
|
|
@ -361,14 +377,14 @@ intval.frame = function (dir = null, time = null, cb = () => {}) {
|
|
|
|
|
setTimeout( () => {
|
|
|
|
|
intval._state.frame.paused = false
|
|
|
|
|
intval._startFwd()
|
|
|
|
|
}, time + intval._frame.closed)
|
|
|
|
|
}, exposure + intval._frame.closed)
|
|
|
|
|
} else {
|
|
|
|
|
setTimeout(intval._pause, intval._frame.openBwd)
|
|
|
|
|
setTimeout( () => {
|
|
|
|
|
//log.info('frame', 'restarting')
|
|
|
|
|
intval._state.frame.paused = false
|
|
|
|
|
intval._startBwd()
|
|
|
|
|
}, time + intval._frame.closed)
|
|
|
|
|
}, exposure + intval._frame.closed)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (dir) {
|
|
|
|
@ -384,6 +400,10 @@ intval.frame = function (dir = null, time = null, cb = () => {}) {
|
|
|
|
|
cb(len)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
intval._state.frame.current = {
|
|
|
|
|
dir: dir,
|
|
|
|
|
exposure: time
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Start a sequence of frames, using defaults or explicit instructions
|
|
|
|
|