Declare intval object variables before init function
This commit is contained in:
parent
a039e8f616
commit
b605f875bc
|
@ -38,32 +38,6 @@ const PINS = {
|
|||
/** Object representing the intval3 features */
|
||||
const intval = {}
|
||||
|
||||
intval.init = function () {
|
||||
if (!fs.existsSync('./state')) fs.mkdirSync('./state')
|
||||
storage.init({
|
||||
dir: './state',
|
||||
stringify: JSON.stringify,
|
||||
parse: JSON.parse,
|
||||
encoding: 'utf8',
|
||||
logging: false, // can also be custom logging function
|
||||
continuous: true, // continously persist to disk
|
||||
interval: false, // milliseconds, persist to disk on an interval
|
||||
ttl: false, // ttl* [NEW], can be true for 24h default or a number in MILLISECONDS
|
||||
expiredInterval: 2 * 60 * 1000, // [NEW] every 2 minutes the process will clean-up the expired cache
|
||||
forgiveParseErrors: false // [NEW]
|
||||
}).then((res) => {
|
||||
//console.dir(res)
|
||||
storage.getItem('_state', 'test').then(intval._setState).catch((err) => {
|
||||
intval._setState(undefined)
|
||||
log.error('init', err)
|
||||
})
|
||||
}).catch((err) => {
|
||||
log.error('init', err)
|
||||
fs.rmdirSync('./state')
|
||||
log.warn('Restarting')
|
||||
process.exit()
|
||||
})
|
||||
|
||||
intval._frame = {
|
||||
open : 250, //delay before pausing frame in open state
|
||||
openBwd : 400,
|
||||
|
@ -77,11 +51,39 @@ intval.init = function () {
|
|||
intval._microDelay = 10 // delay after stop signal before stopping motors
|
||||
intval._pin = {}
|
||||
|
||||
intval._declarePins()
|
||||
intval.init = function () {
|
||||
if (!fs.existsSync('./state')) fs.mkdirSync('./state')
|
||||
storage.init({
|
||||
dir: './state',
|
||||
stringify: JSON.stringify,
|
||||
parse: JSON.parse,
|
||||
encoding: 'utf8',
|
||||
logging: false, // can also be custom logging function
|
||||
continuous: true, // continously persist to disk
|
||||
interval: false, // milliseconds, persist to disk on an interval
|
||||
ttl: false, // ttl* [NEW], can be true for 24h default or a number in MILLISECONDS
|
||||
expiredInterval: 2 * 60 * 1000, // [NEW] every 2 minutes the process will clean-up the expired cache
|
||||
forgiveParseErrors: false // [NEW]
|
||||
}).then(intval._restoreState).catch((err) => {
|
||||
log.error('init', err)
|
||||
fs.rmdirSync('./state')
|
||||
log.warn('Restarting')
|
||||
return process.exit(1)
|
||||
})
|
||||
|
||||
process.on('SIGINT', intval._undeclarePins)
|
||||
process.on('uncaughtException', intval._undeclarePins)
|
||||
}
|
||||
|
||||
intval._restoreState = function (res) {
|
||||
//console.dir(res)
|
||||
storage.getItem('_state', 'test').then(intval._setState).catch((err) => {
|
||||
intval._setState(undefined)
|
||||
log.error('init', err)
|
||||
})
|
||||
intval._declarePins()
|
||||
}
|
||||
|
||||
intval._setState = function (data) {
|
||||
if (typeof data !== 'undefined') {
|
||||
intval._state = data
|
||||
|
|
Loading…
Reference in New Issue