Created
February 17, 2016 16:59
-
-
Save don/a8fb0b9b11a4393e4b9b to your computer and use it in GitHub Desktop.
BluetoothSerial counter showing count and raw data
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 macAddress = "00:13:EF:00:08:8B"; | |
var app = { | |
initialize: function() { | |
this.bindEvents(); | |
}, | |
bindEvents: function() { | |
document.addEventListener('deviceready', this.onDeviceReady, false); | |
}, | |
onDeviceReady: function() { | |
bluetoothSerial.connect(macAddress, app.onConnect, app.onDisconnect); | |
}, | |
onConnect: function() { | |
bluetoothSerial.subscribe("\n", app.onMessage, app.subscribeFailed); | |
bluetoothSerial.subscribeRawData(app.onRawData, app.subscribeFailed); | |
statusDiv.innerHTML="Connected to " + macAddress + "."; | |
}, | |
onDisconnect: function() { | |
alert("Disconnected"); | |
statusDiv.innerHTML="Disconnected."; | |
}, | |
onMessage: function(data) { | |
counter.innerHTML = data; | |
}, | |
onRawData: function(data) { | |
rawDataDiv.innerHTML = new Uint8Array(data); | |
}, | |
subscribeFailed: function() { | |
alert("subscribe failed"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment