Use callback model for bluetooth write events.

This commit is contained in:
mmcwilliams 2017-12-12 13:09:13 -05:00
parent f74465cbbc
commit 4aadc5a9df
2 changed files with 22 additions and 12 deletions

View File

@ -41,10 +41,14 @@ function createServer () {
}) })
} }
function bleBindings () { function createBLE () {
ble = new BLE(() => {
return intval.status()
})
ble.on('frame', bFrame)
} }
//Restify functions
function rDir (req, res, next) { function rDir (req, res, next) {
let dir = true let dir = true
let set = false let set = false
@ -279,6 +283,13 @@ function rSequence (req, res, next) {
} }
} }
//Ble functions
function bFrame (cb) {
console.log(str)
cb({ dir: true, len : 630 })
}
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) {
@ -290,14 +301,9 @@ function index (req, res, next) {
} }
function init () { function init () {
createServer()
intval.init() intval.init()
ble = new BLE(() => { createServer()
return intval.status() createBLE()
})
ble.on('data', (str) => {
console.log(str)
})
} }
init() init()

View File

@ -171,12 +171,16 @@ class BLE {
return callback(result) return callback(result)
} }
utf8 = data.toString('utf8') utf8 = data.toString('utf8')
console.log(utf8)
obj = JSON.parse(utf8) obj = JSON.parse(utf8)
console.dir(obj)
result = bleno.Characteristic.RESULT_SUCCESS result = bleno.Characteristic.RESULT_SUCCESS
if (obj.type && this[`_on${capitalize(obj.type)}`]) {
this[`_on${capitalize(obj.type)}`]( data => {
return callback(result, data.slice(offset, data.length))
})
} else {
return callback(result) return callback(result)
} }
}
_onRead (offset, callback) { _onRead (offset, callback) {
const result = bleno.Characteristic.RESULT_SUCCESS const result = bleno.Characteristic.RESULT_SUCCESS
const state = getState() const state = getState()