Created
October 25, 2013 22:52
-
-
Save akey7/51906412b8bfb5abc24b to your computer and use it in GitHub Desktop.
BLE event handlers in JS
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
// There are some contrived things in here, but if you are talking about putting handlers in aan array, this may help you. | |
var allBleDevices = []; | |
function genericBleEventHanlder(ble_device, event) { | |
// Do something with the event | |
} | |
function makeSpecificBleHandler(bleDevice) { | |
return (function(bleDevice, event) { | |
// Do something with the bleDevice and event here | |
}); | |
} | |
// Calls the callback on successful connection | |
function waitForBleToConnect(function(bleDevice) { | |
var deviceAndHandler = { | |
handler: makeSpecificBleHandler(bleDevice), | |
device: bleDevice; | |
}; | |
allBleDevices.push(deviceAndHandler); | |
}); | |
// Calls call back upon events | |
function awaitEvents(function(bleDeviceIndex, event) { | |
if (typeof allBleDevices[bleDeviceIndex] !== "undefined") { | |
allBleDevices[bleDeviceIndex].handler(event); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment