Restart, update and reset all have ble and restify endpoints

This commit is contained in:
mmcwilliams 2018-02-08 15:31:48 -05:00
parent b56afa3ba7
commit 5f71e48c38
2 changed files with 52 additions and 8 deletions

View File

@ -618,8 +618,24 @@ mobile.resetSuccess = function () {
}; };
mobile.update = function () { mobile.update = function () {
const reset = confirm(`Check for updates? You will be disconnected from the INTVAL3 during this process.`);
if (!reset) return false;
let opts = {
type : 'reset'
}; };
ble.write(mobile.ble.device.id,
mobile.ble.SERVICE_ID,
mobile.ble.CHAR_ID,
stringToBytes(JSON.stringify(opts)),
mobile.updateSuccess,
mobile.ble.onError);
};
mobile.updateSuccess = function () {
alert()
};
mobile.restart = function () {}
/** /**
* Mobile helper functions * Mobile helper functions

View File

@ -38,8 +38,12 @@ function createServer () {
app.get( '/sequence', rSequence) app.get( '/sequence', rSequence)
app.post('/sequence', rSequence) app.post('/sequence', rSequence)
app.post('/reset', rReset)
app.get( '/status', rStatus) app.get( '/status', rStatus)
app.post('/reset', rReset)
app.get('/update', rUpdate)
app.get('/restart', rRestart)
app.listen(PORT, () => { app.listen(PORT, () => {
log.info('server', { name : APPNAME, port : PORT }) log.info('server', { name : APPNAME, port : PORT })
}) })
@ -55,7 +59,10 @@ function createBLE () {
ble.on('delay', bDelay) ble.on('delay', bDelay)
ble.on('counter', bCounter) ble.on('counter', bCounter)
ble.on('sequence', bSequence) ble.on('sequence', bSequence)
ble.on('reset', bReset) ble.on('reset', bReset)
ble.on('update', bUpdate)
ble.on('restart', bRestart)
} }
//Restify functions //Restify functions
@ -337,6 +344,18 @@ function rSequence (req, res, next) {
} }
} }
function rUpdate (req, res, next) {
exec('sh ./scripts/update.sh', (err, stdio, stderr) => {
res.send({ success : true })
process.exit(0)
})
}
function rRestart (req, res, next) {
res.send({ success : true })
process.exit(0)
}
//Ble functions //Ble functions
function bFrame (obj, cb) { function bFrame (obj, cb) {
@ -509,6 +528,21 @@ function bReset (obj, cb) {
setTimeout(cb, 10) setTimeout(cb, 10)
} }
function bUpdate (obj, cb) {
cb()
setTimeout(() => {
exec('sh ./scripts/update.sh', (err, stdio, stderr) => {
process.exit(0)
})
}, 20)
}
function bRestart (obj, cb) {
cb()
setTimeout(() => {
process.exit(0)
}, 20)
}
function seq () { function seq () {
let dir = intval._state.frame.dir let dir = intval._state.frame.dir
let exposure = intval._state.frame.exposure let exposure = intval._state.frame.exposure
@ -539,12 +573,6 @@ function seq () {
} }
} }
function update (req, res, next) {
exec('sh ./scripts/update.sh', (err, stdio, stderr) => {
process.exit()
})
}
function index (req, res, next) { function index (req, res, next) {
fs.readFile(INDEXPATH, 'utf8', (err, data) => { fs.readFile(INDEXPATH, 'utf8', (err, data) => {
if (err) { if (err) {