|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>JSDoc: Source: arduinoble/arduinoble.js</title> |
| 6 | + |
| 7 | + <script src="scripts/prettify/prettify.js"> </script> |
| 8 | + <script src="scripts/prettify/lang-css.js"> </script> |
| 9 | + <!--[if lt IE 9]> |
| 10 | + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 11 | + <![endif]--> |
| 12 | + <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> |
| 13 | + <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> |
| 14 | +</head> |
| 15 | + |
| 16 | +<body> |
| 17 | + |
| 18 | +<div id="main"> |
| 19 | + |
| 20 | + <h1 class="page-title">Source: arduinoble/arduinoble.js</h1> |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + <section> |
| 28 | + <article> |
| 29 | + <pre class="prettyprint source linenums"><code>// File: arduinoble.js |
| 30 | + |
| 31 | +// Load library EasyBLE. |
| 32 | +evothings.loadScript('libs/evothings/easyble/easyble.js'); |
| 33 | + |
| 34 | +/** |
| 35 | + * @namespace |
| 36 | + * @author Mikael Kindborg |
| 37 | + * @description <p>Functions for communicating with an Arduino BLE shield.</p> |
| 38 | + * <p>It is safe practise to call function {@link evothings.scriptsLoaded} |
| 39 | + * to ensure dependent libraries are loaded before calling functions |
| 40 | + * in this library.</p> |
| 41 | + * |
| 42 | + * @todo This is a very simple library that has only write capability, |
| 43 | + * read and notification functions should be added. |
| 44 | + * |
| 45 | + * @todo Add function to set the write characteristic UUID to make |
| 46 | + * the code more generic. |
| 47 | + */ |
| 48 | +evothings.arduinoble = {}; |
| 49 | + |
| 50 | +;(function() |
| 51 | +{ |
| 52 | + // Internal functions. |
| 53 | + var internal = {}; |
| 54 | + |
| 55 | + /** |
| 56 | + * Stop any ongoing scan and disconnect all devices. |
| 57 | + * @public |
| 58 | + */ |
| 59 | + evothings.arduinoble.close = function() |
| 60 | + { |
| 61 | + evothings.easyble.stopScan(); |
| 62 | + evothings.easyble.closeConnectedDevices(); |
| 63 | + }; |
| 64 | + |
| 65 | + /** |
| 66 | + * Called when you've connected to an Arduino BLE shield. |
| 67 | + * @callback evothings.arduinoble.connectsuccess |
| 68 | + * @param {evothings.arduinoble.ArduinoBLEDevice} device - |
| 69 | + * The connected BLE shield. |
| 70 | + */ |
| 71 | + |
| 72 | + /** |
| 73 | + * Connect to a BLE-shield. |
| 74 | + * @param deviceName BLE name if the shield. |
| 75 | + * @param {evothings.arduinoble.connectsuccess} success - |
| 76 | + * Success callback: success(device) |
| 77 | + * @param {function} fail - Error callback: fail(errorCode) |
| 78 | + * @example |
| 79 | + * evothings.arduinoble.connect( |
| 80 | + * 'arduinoble', // Name of BLE shield. |
| 81 | + * function(device) |
| 82 | + * { |
| 83 | + * console.log('connected!'); |
| 84 | + * device.writeDataArray(new Uint8Array([1])); |
| 85 | + * evothings.arduinoble.close(); |
| 86 | + * }, |
| 87 | + * function(errorCode) |
| 88 | + * { |
| 89 | + * console.log('Error: ' + errorCode); |
| 90 | + * }); |
| 91 | + * @public |
| 92 | + */ |
| 93 | + evothings.arduinoble.connect = function(deviceName, success, fail) |
| 94 | + { |
| 95 | + evothings.easyble.startScan( |
| 96 | + function(device) |
| 97 | + { |
| 98 | + if (device.name == deviceName) |
| 99 | + { |
| 100 | + evothings.easyble.stopScan(); |
| 101 | + internal.connectToDevice(device, success, fail); |
| 102 | + } |
| 103 | + }, |
| 104 | + function(errorCode) |
| 105 | + { |
| 106 | + fail(errorCode); |
| 107 | + }); |
| 108 | + }; |
| 109 | + |
| 110 | + /** |
| 111 | + * Connect to the BLE shield. |
| 112 | + * @private |
| 113 | + */ |
| 114 | + internal.connectToDevice = function(device, success, fail) |
| 115 | + { |
| 116 | + device.connect( |
| 117 | + function(device) |
| 118 | + { |
| 119 | + // Get services info. |
| 120 | + internal.getServices(device, success, fail); |
| 121 | + }, |
| 122 | + function(errorCode) |
| 123 | + { |
| 124 | + fail(errorCode); |
| 125 | + }); |
| 126 | + }; |
| 127 | + |
| 128 | + /** |
| 129 | + * Read all services from the device. |
| 130 | + * @private |
| 131 | + */ |
| 132 | + internal.getServices = function(device, success, fail) |
| 133 | + { |
| 134 | + device.readServices( |
| 135 | + null, // null means read info for all services |
| 136 | + function(device) |
| 137 | + { |
| 138 | + internal.addMethodsToDeviceObject(device); |
| 139 | + success(device); |
| 140 | + }, |
| 141 | + function(errorCode) |
| 142 | + { |
| 143 | + fail(errorCode); |
| 144 | + }); |
| 145 | + }; |
| 146 | + |
| 147 | + /** |
| 148 | + * Add instance methods to the device object. |
| 149 | + * @private |
| 150 | + */ |
| 151 | + internal.addMethodsToDeviceObject = function(device) |
| 152 | + { |
| 153 | + /** |
| 154 | + * Object that holds info about an Arduino BLE shield. |
| 155 | + * @namespace evothings.arduinoble.ArduinoBLEDevice |
| 156 | + */ |
| 157 | + |
| 158 | + /** |
| 159 | + * @function writeDataArray |
| 160 | + * @description Write data to an Arduino BLE shield. |
| 161 | + * @param {Uint8Array} uint8array - The data to be written. |
| 162 | + * @memberof evothings.arduinoble.ArduinoBLEDevice |
| 163 | + * @instance |
| 164 | + * @public |
| 165 | + */ |
| 166 | + device.writeDataArray = function(uint8array) |
| 167 | + { |
| 168 | + device.writeCharacteristic( |
| 169 | + // TODO: Make this possible to set. |
| 170 | + '713d0003-503e-4c75-ba94-3148f18d941e', |
| 171 | + uint8array, |
| 172 | + function() |
| 173 | + { |
| 174 | + console.log('writeCharacteristic success'); |
| 175 | + }, |
| 176 | + function(errorCode) |
| 177 | + { |
| 178 | + console.log('writeCharacteristic error: ' + errorCode); |
| 179 | + }); |
| 180 | + }; |
| 181 | + }; |
| 182 | +})(); |
| 183 | +</code></pre> |
| 184 | + </article> |
| 185 | + </section> |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | +</div> |
| 191 | + |
| 192 | +<nav> |
| 193 | + <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="evothings.html">evothings</a></li><li><a href="evothings.arduinoble.html">arduinoble</a></li><li><a href="evothings.arduinoble.ArduinoBLEDevice.html">ArduinoBLEDevice</a></li><li><a href="evothings.arduinotcp.html">arduinotcp</a></li><li><a href="evothings.easyble.html">easyble</a></li><li><a href="evothings.easyble.EasyBLEDevice.html">EasyBLEDevice</a></li><li><a href="evothings.easyble.error.html">error</a></li><li><a href="evothings.nordicble.html">nordicble</a></li><li><a href="evothings.nordicble.NordicBLEDevice.html">NordicBLEDevice</a></li><li><a href="evothings.nRF51_ble.html">nRF51_ble</a></li><li><a href="evothings.os.html">os</a></li><li><a href="evothings.rfduinoble.html">rfduinoble</a></li><li><a href="evothings.rfduinoble.RFduinoBLEDevice.html">RFduinoBLEDevice</a></li><li><a href="evothings.tisensortag.html">tisensortag</a></li><li><a href="evothings.tisensortag.ble.html">ble</a></li><li><a href="evothings.tisensortag.ble.CC2541.html">CC2541</a></li><li><a href="evothings.tisensortag.ble.CC2650.html">CC2650</a></li><li><a href="evothings.tisensortag.ble.error.html">error</a></li><li><a href="evothings.tisensortag.ble.status.html">status</a></li><li><a href="evothings.tisensortag.SensorTagInstance.html">SensorTagInstance</a></li><li><a href="evothings.tisensortag.SensorTagInstanceBLE.html">SensorTagInstanceBLE</a></li><li><a href="evothings.tisensortag.SensorTagInstanceBLE_CC2541.html">SensorTagInstanceBLE_CC2541</a></li><li><a href="evothings.tisensortag.SensorTagInstanceBLE_CC2650.html">SensorTagInstanceBLE_CC2650</a></li><li><a href="evothings.util.html">util</a></li></ul><h3>Global</h3><ul><li><a href="global.html#HIGH">HIGH</a></li><li><a href="global.html#INPUT">INPUT</a></li><li><a href="global.html#LOW">LOW</a></li><li><a href="global.html#OUTPUT">OUTPUT</a></li></ul> |
| 194 | +</nav> |
| 195 | + |
| 196 | +<br class="clear"> |
| 197 | + |
| 198 | +<footer> |
| 199 | + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Tue Oct 27 2015 14:39:06 GMT+0100 (CET) |
| 200 | +</footer> |
| 201 | + |
| 202 | +<script> prettyPrint(); </script> |
| 203 | +<script src="scripts/linenumber.js"> </script> |
| 204 | +</body> |
| 205 | +</html> |
0 commit comments