Created
June 9, 2018 17:25
-
-
Save vaishnavachath/bda1c2e0355e584830e8c6daf8730f93 to your computer and use it in GitHub Desktop.
script to test bonescript dual style callbacks : based on bone101 examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var b = require('bonescript'); | |
//getPlatform() | |
b.getPlatform(printData); | |
function printData(x) { | |
console.log("**********getPlatform()_previous**********"); | |
console.log('name = ' + x.name); | |
console.log('version = ' + x.version); | |
console.log('serialNumber = ' + x.serialNumber); | |
console.log('bonescript = ' + x.bonescript); | |
onGetPlatformPrevious(); | |
} | |
function onGetPlatformPrevious() { | |
b.getPlatform(printData_nodestyle); | |
function printData_nodestyle(err, data) { | |
console.log("**********getPlatform()_nodestyle**********"); | |
console.log('error = ' + err); | |
console.log('name = ' + data.name); | |
console.log('version = ' + data.version); | |
console.log('serialNumber = ' + data.serialNumber); | |
console.log('bonescript = ' + data.bonescript); | |
} | |
} | |
//pinMode() | |
b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatusp); | |
function printStatusp(x) { | |
console.log("**********pinMode()_previous**********"); | |
console.log('value = ' + x.value); | |
console.log('err = ' + x.err); | |
onPinModePrevious(); | |
} | |
function onPinModePrevious() { | |
b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus_nodestyle); | |
function printStatus_nodestyle(err, value) { | |
console.log("**********pinMode()_nodestyle**********"); | |
console.log('value = ' + value); | |
console.log('err = ' + err); | |
} | |
} | |
//getpinMode() | |
b.getPinMode("P8_13", printPinMux); | |
function printPinMux(x) { | |
console.log("**********getPinMode()_previous**********"); | |
console.log('mux = ' + x.mux); | |
console.log('pullup = ' + x.pullup); | |
console.log('slew = ' + x.slew); | |
console.log('options = ' + x.options.join(',')); | |
console.log('err = ' + x.err); | |
onGetPinModePrevious(); | |
} | |
function onGetPinModePrevious() { | |
b.getPinMode("P8_13", printPinMux_nodestyle); | |
function printPinMux_nodestyle(err, data) { | |
console.log("**********getPinMode()_nodestyle**********"); | |
console.log('mux = ' + data.mux); | |
console.log('pullup = ' + data.pullup); | |
console.log('slew = ' + data.slew); | |
console.log('options = ' + data.options.join(',')); | |
console.log('err = ' + err); | |
} | |
} | |
//digitalRead() | |
b.pinMode('P8_19', b.INPUT); | |
b.digitalRead('P8_19', printStatusd); | |
function printStatusd(x) { | |
console.log('"**********digitalRead()_previous"**********'); | |
console.log('x.value = ' + x.value); | |
console.log('x.err = ' + x.err); | |
onDigitalReadPrevious(); | |
} | |
function onDigitalReadPrevious() { | |
b.digitalRead('P8_19', printStatus_nodestyle); | |
function printStatus_nodestyle(err, value) { | |
console.log('"**********digitalRead()_nodestyle"**********'); | |
console.log('x.value = ' + value); | |
console.log('x.err = ' + err); | |
} | |
} | |
//analogRead() | |
b.analogRead('P9_36', printStatusa); | |
function printStatusa(x) { | |
console.log('**********analogRead()_previous"**********'); | |
console.log('x.value = ' + x.value); | |
console.log('x.err = ' + x.err); | |
onAnalogReadPrevious(); | |
} | |
function onAnalogReadPrevious() { | |
b.analogRead('P9_36', printStatus_nodestyle); | |
function printStatus_nodestyle(err, value) { | |
console.log('**********analogRead()_nodestyle"**********'); | |
console.log('x.value = ' + value); | |
console.log('x.err = ' + err); | |
} | |
} | |
//attachInterrupt() | |
var inputPin = 'P8_19'; | |
b.pinMode(inputPin, b.INPUT); | |
b.attachInterrupt(inputPin, true, b.CHANGE, interruptCallback); | |
function interruptCallback(x) { | |
console.log('**********attachInterrupt()_previous"**********'); | |
console.log(JSON.stringify(x)); | |
b.detachInterrupt(inputPin); | |
console.log('Interrupt detached'); | |
onAttachInterruptPrevious(); | |
} | |
function onAttachInterruptPrevious() { | |
var inputPin = 'P8_19'; | |
b.attachInterrupt(inputPin, true, b.CHANGE, interruptCallback); | |
function interruptCallback(err, value) { | |
console.log('**********attachInterrupt()_nodestyle"**********'); | |
console.log('err = ' + err); | |
console.log(JSON.stringify(value)); | |
b.detachInterrupt(inputPin); | |
console.log('Interrupt detached'); | |
} | |
} | |
//readTextFile() | |
b.readTextFile('/etc/dogtag', printStatusr); | |
function printStatusr(x) { | |
console.log('**********readTextFile()_previous"**********'); | |
console.log('x.data = ' + x.data); | |
console.log('x.err = ' + x.err); | |
onReadTextFilePrevious(); | |
} | |
function onReadTextFilePrevious() { | |
b.readTextFile('/etc/dogtag', printStatus_nodestyle); | |
function printStatus_nodestyle(err, data) { | |
console.log('**********readTextFile()_nodestyle"**********'); | |
console.log('data = ' + data); | |
console.log('err = ' + err); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment