├── libs ├── framework7 │ ├── css │ │ └── my-app.css │ ├── app-icon.png │ ├── img │ │ ├── i-f7-ios.png │ │ ├── i-f7-material.png │ │ ├── i-form-comment-material.svg │ │ ├── i-form-email-material.svg │ │ ├── i-form-calendar-material.svg │ │ ├── i-form-tel-material.svg │ │ ├── i-form-name-material.svg │ │ ├── i-form-password-material.svg │ │ ├── i-form-toggle-material.svg │ │ ├── i-form-settings-material.svg │ │ ├── i-form-toggle-ios.svg │ │ ├── i-form-gender-material.svg │ │ ├── i-form-email-ios.svg │ │ ├── i-form-gender-ios.svg │ │ ├── i-form-url-material.svg │ │ ├── i-form-calendar-ios.svg │ │ ├── i-form-password-ios.svg │ │ ├── i-form-comment-ios.svg │ │ ├── i-form-settings-ios.svg │ │ ├── i-form-name-ios.svg │ │ ├── i-form-tel-ios.svg │ │ └── i-form-url-ios.svg │ ├── evothings.json │ ├── uninstall.js │ ├── install.js │ └── js │ │ └── my-app.js ├── jquery │ ├── VERSION │ ├── app-icon.png │ └── evothings.json ├── onsenui │ ├── .npmignore │ ├── app-icon.png │ ├── css │ │ ├── ionicons │ │ │ └── fonts │ │ │ │ ├── ionicons.eot │ │ │ │ ├── ionicons.ttf │ │ │ │ └── ionicons.woff │ │ ├── font_awesome │ │ │ └── fonts │ │ │ │ ├── FontAwesome.otf │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ └── fontawesome-webfont.woff2 │ │ └── material-design-iconic-font │ │ │ └── fonts │ │ │ ├── Material-Design-Iconic-Font.eot │ │ │ ├── Material-Design-Iconic-Font.ttf │ │ │ ├── Material-Design-Iconic-Font.woff │ │ │ └── Material-Design-Iconic-Font.woff2 │ ├── evothings.json │ ├── LICENSE │ ├── uninstall.js │ └── install.js ├── evothings │ ├── VERSION │ ├── evothings-dist-base.js │ ├── ui │ │ └── ui.js │ ├── dialog-iotsensor │ │ ├── iotsensor-raw.js │ │ ├── iotsensor-sfl.js │ │ └── README.md │ ├── arduinoble │ │ └── arduinoble.js │ ├── util │ │ └── util.js │ ├── evothings.js │ ├── arduinotcp │ │ └── arduinotcp.js │ └── tisensortag │ │ ├── tisensortag.js │ │ ├── tisensortag-ble-cc2541.js │ │ └── tisensortag-ble-cc2650.js ├── mdl │ ├── app-icon.png │ ├── icons │ │ ├── MaterialIcons-Regular.eot │ │ ├── MaterialIcons-Regular.ttf │ │ ├── MaterialIcons-Regular.woff │ │ ├── MaterialIcons-Regular.woff2 │ │ ├── README.md │ │ ├── material-icons.css │ │ └── LICENSE │ ├── evothings.json │ ├── bower.json │ ├── uninstall.js │ ├── install.js │ ├── package.json │ └── LICENSE ├── mqttws │ ├── app-icon.png │ └── evothings.json ├── smoothie │ ├── app-icon.png │ └── evothings.json ├── bleat │ ├── VERSION │ ├── LICENSE │ ├── bluetooth.helpers.js │ └── api.classic.js └── lorawan │ └── evothings.json ├── .gitignore ├── README.md ├── arduino ├── arduinoethernet │ └── arduinoethernet.ino └── arduinowifi │ ├── arduinowifi_cc3000.ino │ └── arduinowifi.ino └── LICENSE /libs/framework7/css/my-app.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /libs/jquery/VERSION: -------------------------------------------------------------------------------- 1 | jquery-2.1.1.min.js 2 | -------------------------------------------------------------------------------- /libs/onsenui/.npmignore: -------------------------------------------------------------------------------- 1 | onsenui.zip 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | out/ 3 | generated 4 | -------------------------------------------------------------------------------- /libs/evothings/VERSION: -------------------------------------------------------------------------------- 1 | Evothings Libraries version 2.1.0 2 | -------------------------------------------------------------------------------- /libs/mdl/app-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/mdl/app-icon.png -------------------------------------------------------------------------------- /libs/jquery/app-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/jquery/app-icon.png -------------------------------------------------------------------------------- /libs/mqttws/app-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/mqttws/app-icon.png -------------------------------------------------------------------------------- /libs/onsenui/app-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/app-icon.png -------------------------------------------------------------------------------- /libs/smoothie/app-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/smoothie/app-icon.png -------------------------------------------------------------------------------- /libs/framework7/app-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/framework7/app-icon.png -------------------------------------------------------------------------------- /libs/bleat/VERSION: -------------------------------------------------------------------------------- 1 | Bleat version 2016-05-15 commit 7d0fff9b04eb78f3eeff023219322c36621ea3f6 2 | https://github.com/thegecko/bleat 3 | -------------------------------------------------------------------------------- /libs/framework7/img/i-f7-ios.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/framework7/img/i-f7-ios.png -------------------------------------------------------------------------------- /libs/framework7/img/i-f7-material.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/framework7/img/i-f7-material.png -------------------------------------------------------------------------------- /libs/mdl/icons/MaterialIcons-Regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/mdl/icons/MaterialIcons-Regular.eot -------------------------------------------------------------------------------- /libs/mdl/icons/MaterialIcons-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/mdl/icons/MaterialIcons-Regular.ttf -------------------------------------------------------------------------------- /libs/mdl/icons/MaterialIcons-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/mdl/icons/MaterialIcons-Regular.woff -------------------------------------------------------------------------------- /libs/mdl/icons/MaterialIcons-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/mdl/icons/MaterialIcons-Regular.woff2 -------------------------------------------------------------------------------- /libs/onsenui/css/ionicons/fonts/ionicons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/ionicons/fonts/ionicons.eot -------------------------------------------------------------------------------- /libs/onsenui/css/ionicons/fonts/ionicons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/ionicons/fonts/ionicons.ttf -------------------------------------------------------------------------------- /libs/onsenui/css/ionicons/fonts/ionicons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/ionicons/fonts/ionicons.woff -------------------------------------------------------------------------------- /libs/onsenui/css/font_awesome/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/font_awesome/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/font_awesome/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.eot -------------------------------------------------------------------------------- /libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.ttf -------------------------------------------------------------------------------- /libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.woff -------------------------------------------------------------------------------- /libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evothings/evothings-libraries/HEAD/libs/onsenui/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.woff2 -------------------------------------------------------------------------------- /libs/onsenui/evothings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "onsenui", 3 | "versions": ["2.0.0"], 4 | "title": "Onsen UI", 5 | "description": "HTML5 Mobile Framework & UI Components", 6 | "icon": "app-icon.png", 7 | "doc-url": "https://onsen.io" 8 | } 9 | -------------------------------------------------------------------------------- /libs/framework7/evothings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "framework7", 3 | "versions": ["1.4.2"], 4 | "title": "Framework7", 5 | "description": "Full Featured Mobile HTML Framework For Building iOS & Android Apps.", 6 | "icon": "app-icon.png", 7 | "doc-url": "https://framework7.io" 8 | } 9 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-comment-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /libs/mqttws/evothings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mqttws", 3 | "versions": ["3.1"], 4 | "title": "Paho MQTTWS", 5 | "description": "Paho MQTTWS is an MQTT client library that uses WebSockets to connect to an MQTT Broker.", 6 | "icon" :"app-icon.png", 7 | "doc-url" :"https://eclipse.org/paho/clients/js/" 8 | } 9 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-email-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /libs/smoothie/evothings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "smoothie", 3 | "versions": ["1.28"], 4 | "title": "Smoothie Charts", 5 | "description": "Smoothie Charts is a simple library for displaying smooth live time lines. It's very easy to use, small and looks good.", 6 | "icon" :"app-icon.png", 7 | "doc-url" :"http://smoothiecharts.org" 8 | } 9 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-calendar-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /libs/mdl/icons/README.md: -------------------------------------------------------------------------------- 1 | The recommended way to use the Material Icons font is by linking to the web font hosted on Google Fonts: 2 | 3 | ```html 4 | 6 | ``` 7 | 8 | Read more in our full usage guide: 9 | http://google.github.io/material-design-icons/#icon-font-for-the-web 10 | -------------------------------------------------------------------------------- /libs/lorawan/evothings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lorawan", 3 | "versions": ["0.1"], 4 | "title": "LoRaWAN", 5 | "description": "LoRaWAN is an abstraction library modelled after NodeJS client SDK for TheThingsNetwork. It has been adapted to use MQTT over WebSockets for communicating with LoRaWAN networks like TheThingsNetwork.", 6 | "icon" :"app-icon.png", 7 | "doc-url" :"" 8 | } 9 | -------------------------------------------------------------------------------- /libs/jquery/evothings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "versions": ["2.1.1"], 4 | "title": "jQuery", 5 | "description": "jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.", 6 | "icon" :"app-icon.png", 7 | "doc-url" :"https://jquery.com" 8 | } 9 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-tel-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-name-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-password-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /libs/evothings/evothings-dist-base.js: -------------------------------------------------------------------------------- 1 | // File: evothings-dist-base.js 2 | // 3 | // Set up definitions needed by Evothings JavaScript libraries 4 | // distribution files. 5 | // 6 | 7 | // Global holding everything. 8 | window.evothings = window.evothings || {}; 9 | 10 | // Define an empty No Operation function. This function is called 11 | // in place of async script loading, since we build a single merged file. 12 | evothings.__NOOP_FUN__ = function() {}; 13 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-toggle-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-settings-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /libs/mdl/evothings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mdl", 3 | "versions": ["1.2.1"], 4 | "title": "Material Design Lite", 5 | "description": "Material Design Lite lets you add a Material Design look and feel to your websites. It doesn’t rely on any JavaScript frameworks and aims to optimize for cross-device use, gracefully degrade in older browsers, and offer an experience that is immediately accessible. Material Design Icons are included from https://github.com/jossef/material-design-icons-iconfont", 6 | "icon" :"app-icon.png", 7 | "doc-url" :"https://getmdl.io" 8 | } 9 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-toggle-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /libs/onsenui/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013-2016 ASIAL CORPORATION 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /libs/mdl/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "material-design-lite", 3 | "version": "1.2.1", 4 | "homepage": "https://github.com/google/material-design-lite", 5 | "authors": [ 6 | "Material Design Lite team" 7 | ], 8 | "description": "Material Design Components in CSS, JS and HTML", 9 | "main": [ 10 | "material.min.css", 11 | "material.min.js" 12 | ], 13 | "keywords": [ 14 | "material", 15 | "design", 16 | "styleguide", 17 | "style", 18 | "guide" 19 | ], 20 | "license": "Apache-2", 21 | "ignore": [ 22 | "**/.*", 23 | "node_modules", 24 | "bower_components", 25 | "./lib/.bower_components", 26 | "test", 27 | "tests" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-gender-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-email-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-gender-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-url-material.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /libs/mdl/icons/material-icons.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Material Icons'; 3 | font-style: normal; 4 | font-weight: 400; 5 | src: url(MaterialIcons-Regular.eot); /* For IE6-8 */ 6 | src: local('Material Icons'), 7 | local('MaterialIcons-Regular'), 8 | url(MaterialIcons-Regular.woff2) format('woff2'), 9 | url(MaterialIcons-Regular.woff) format('woff'), 10 | url(MaterialIcons-Regular.ttf) format('truetype'); 11 | } 12 | 13 | .material-icons { 14 | font-family: 'Material Icons'; 15 | font-weight: normal; 16 | font-style: normal; 17 | font-size: 24px; /* Preferred icon size */ 18 | display: inline-block; 19 | line-height: 1; 20 | text-transform: none; 21 | letter-spacing: normal; 22 | word-wrap: normal; 23 | white-space: nowrap; 24 | direction: ltr; 25 | 26 | /* Support for all WebKit browsers. */ 27 | -webkit-font-smoothing: antialiased; 28 | /* Support for Safari and Chrome. */ 29 | text-rendering: optimizeLegibility; 30 | 31 | /* Support for Firefox. */ 32 | -moz-osx-font-smoothing: grayscale; 33 | 34 | /* Support for IE. */ 35 | font-feature-settings: 'liga'; 36 | } 37 | -------------------------------------------------------------------------------- /libs/bleat/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Rob Moran 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /libs/framework7/img/i-form-calendar-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /libs/evothings/ui/ui.js: -------------------------------------------------------------------------------- 1 | /* 2 | Evothings UI functionality. 3 | 4 | FastClick is used to make UI responsive. 5 | */ 6 | 7 | ;(function() 8 | { 9 | // Special layout hack for iOS 7. 10 | function applyiOS7LayoutHack() 11 | { 12 | // Set an absolute base font size in iOS 7 due to that viewport-relative 13 | // font sizes doesn't work properly caused by the WebKit bug described at 14 | // https://bugs.webkit.org/show_bug.cgi?id=131863. 15 | if (evothings.os.isIOS7()) 16 | { 17 | document.body.style.fontSize = '20pt'; 18 | } 19 | } 20 | 21 | function applyUIUpdatesWhenPageHasLoaded() 22 | { 23 | var applyUIUpdates = function() { 24 | applyiOS7LayoutHack(); 25 | FastClick.attach(document.body); 26 | } 27 | 28 | /* If the DOMContentLoaded event was already fired, apply the UI updates 29 | * now, otherwise wait for the event. 30 | */ 31 | if (evothings.gotDOMContentLoaded) 32 | { 33 | applyUIUpdates() 34 | } 35 | else 36 | { 37 | window.addEventListener('DOMContentLoaded', applyUIUpdates) 38 | } 39 | } 40 | 41 | // Load FastClick, when loaded apply UI modifications. 42 | evothings.loadScript( 43 | 'libs/evothings/ui/fastclick.js', 44 | applyUIUpdatesWhenPageHasLoaded); 45 | })(); 46 | -------------------------------------------------------------------------------- /libs/framework7/uninstall.js: -------------------------------------------------------------------------------- 1 | // Uninstall library in application. 2 | // see main-window-func.js, removeLibraryFromApp 3 | 4 | // 1. Remove all references in index.html 5 | var indexPath = APP_SETTINGS.getIndexFileFullPath(path) 6 | var html = FILEUTIL.readFileSync(indexPath) 7 | var scriptPath = `libs/${lib}/js/${lib}.js` 8 | var cssPath = `libs/${lib}/css/${lib}.ios.css` 9 | var cssColorsPath = `libs/${lib}/css/${lib}.ios.colors.css` 10 | 11 | cher = CHEERIO.load(html, { xmlMode: false }) 12 | var element = cher('script').filter(function(i, el) { 13 | return cher(this).attr('src') === scriptPath 14 | }) 15 | if (element.length > 0) { 16 | element.remove() 17 | } 18 | var element = cher('link').filter(function(i, el) { 19 | return cher(this).attr('href') === cssPath 20 | }) 21 | if (element.length > 0) { 22 | element.remove() 23 | } 24 | var element = cher('link').filter(function(i, el) { 25 | return cher(this).attr('href') === cssColorsPath 26 | }) 27 | if (element.length > 0) { 28 | element.remove() 29 | } 30 | 31 | FILEUTIL.writeFileSync(indexPath, cher.html()) 32 | LOGGER.log("Removed " + lib + " from " + path) 33 | 34 | // 2. Remove directory libs/libname 35 | var libPath = PATH.join(APP_SETTINGS.getLibDirFullPath(path), lib) 36 | FSEXTRA.removeSync(libPath) 37 | -------------------------------------------------------------------------------- /libs/onsenui/uninstall.js: -------------------------------------------------------------------------------- 1 | // Uninstall library in application. 2 | // see main-window-func.js, removeLibraryFromApp 3 | 4 | // 1. Remove all references in index.html 5 | var indexPath = APP_SETTINGS.getIndexFileFullPath(path) 6 | var html = FILEUTIL.readFileSync(indexPath) 7 | var scriptPath = `libs/${lib}/js/${lib}.js` 8 | var cssPath = `libs/${lib}/css/${lib}.css` 9 | var cssComponentsPath = `libs/${lib}/css/onsen-css-components.css` 10 | 11 | // 1. Remove any existing reference in index.html 12 | cher = CHEERIO.load(html, { xmlMode: false }) 13 | var element = cher('script').filter(function(i, el) { 14 | return cher(this).attr('src') === scriptPath 15 | }) 16 | if (element.length > 0) { 17 | element.remove() 18 | } 19 | var element = cher('link').filter(function(i, el) { 20 | return cher(this).attr('href') === cssPath 21 | }) 22 | if (element.length > 0) { 23 | element.remove() 24 | } 25 | var element = cher('link').filter(function(i, el) { 26 | return cher(this).attr('href') === cssComponentsPath 27 | }) 28 | if (element.length > 0) { 29 | element.remove() 30 | } 31 | 32 | FILEUTIL.writeFileSync(indexPath, cher.html()) 33 | LOGGER.log("Removed " + lib + " from " + path) 34 | 35 | // 2. Remove directory libs/libname 36 | var libPath = PATH.join(APP_SETTINGS.getLibDirFullPath(path), lib) 37 | FSEXTRA.removeSync(libPath) 38 | -------------------------------------------------------------------------------- /libs/mdl/uninstall.js: -------------------------------------------------------------------------------- 1 | // Uninstall library in application. 2 | // see main-window-func.js, removeLibraryFromApp 3 | 4 | // 1. Remove all references in index.html looking like: 5 | // 6 | // 7 | var indexPath = APP_SETTINGS.getIndexFileFullPath(path) 8 | var html = FILEUTIL.readFileSync(indexPath) 9 | var scriptPath = `libs/${lib}/material.js` 10 | var cssPath = `libs/${lib}/material.css` 11 | var googleFonts = `libs/${lib}/icons/material-icons.css` 12 | 13 | var cher = CHEERIO.load(html, { xmlMode: false }) 14 | var element = cher('script').filter(function(i, el) { 15 | return cher(this).attr('src') === scriptPath 16 | }) 17 | if (element.length > 0) { 18 | element.remove() 19 | } 20 | var element = cher('link').filter(function(i, el) { 21 | return cher(this).attr('href') === cssPath 22 | }) 23 | if (element.length > 0) { 24 | element.remove() 25 | } 26 | var element = cher('link').filter(function(i, el) { 27 | return cher(this).attr('href') === googleFonts 28 | }) 29 | if (element.length > 0) { 30 | element.remove() 31 | } 32 | 33 | FILEUTIL.writeFileSync(indexPath, cher.html()) 34 | LOGGER.log("Removed " + lib + " from " + path) 35 | 36 | // 2. Remove directory libs/libname 37 | var libPath = PATH.join(APP_SETTINGS.getLibDirFullPath(path), lib) 38 | FSEXTRA.removeSync(libPath) 39 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-password-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-comment-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /libs/mdl/install.js: -------------------------------------------------------------------------------- 1 | // Install library in application. 2 | // see main-window-func.js, addLibraryToApp 3 | 4 | // 0. Read the index file to manipulate it 5 | var indexPath = APP_SETTINGS.getIndexFileFullPath(path) 6 | var html = FILEUTIL.readFileSync(indexPath) 7 | var scriptPath = `libs/${lib}/material.js` 8 | var cssPath = `libs/${lib}/material.css` 9 | var googleFonts = `libs/${lib}/icons/material-icons.css` 10 | 11 | // 1. Remove any existing reference in index.html 12 | cher = CHEERIO.load(html, { xmlMode: false }) 13 | var element = cher('script').filter(function(i, el) { 14 | return cher(this).attr('src') === scriptPath 15 | }) 16 | if (element.length > 0) { 17 | element.remove() 18 | } 19 | var element = cher('link').filter(function(i, el) { 20 | return cher(this).attr('href') === cssPath 21 | }) 22 | if (element.length > 0) { 23 | element.remove() 24 | } 25 | var element = cher('link').filter(function(i, el) { 26 | return cher(this).attr('href') === googleFonts 27 | }) 28 | if (element.length > 0) { 29 | element.remove() 30 | } 31 | 32 | // 2. Add a reference in index.html right before 33 | // Note that we can't use 40 | `) 41 | 42 | // 3. Write index.html file back to disk 43 | FILEUTIL.writeFileSync(indexPath, cher.html()) 44 | LOGGER.log("Added " + lib + " to " + path) 45 | -------------------------------------------------------------------------------- /libs/framework7/install.js: -------------------------------------------------------------------------------- 1 | // Install library in application. 2 | // see main-window-func.js, addLibraryToApp 3 | 4 | // 0. Read the index file to manipulate it 5 | var indexPath = APP_SETTINGS.getIndexFileFullPath(path) 6 | var html = FILEUTIL.readFileSync(indexPath) 7 | var scriptPath = `libs/${lib}/js/${lib}.js` 8 | var cssPath = `libs/${lib}/css/${lib}.ios.css` 9 | var cssColorsPath = `libs/${lib}/css/${lib}.ios.colors.css` 10 | 11 | // 1. Remove any existing reference in index.html 12 | cher = CHEERIO.load(html, { xmlMode: false }) 13 | var element = cher('script').filter(function(i, el) { 14 | return cher(this).attr('src') === scriptPath 15 | }) 16 | if (element.length > 0) { 17 | element.remove() 18 | } 19 | var element = cher('link').filter(function(i, el) { 20 | return cher(this).attr('href') === cssPath 21 | }) 22 | if (element.length > 0) { 23 | element.remove() 24 | } 25 | var element = cher('link').filter(function(i, el) { 26 | return cher(this).attr('href') === cssColorsPath 27 | }) 28 | if (element.length > 0) { 29 | element.remove() 30 | } 31 | 32 | // 2. Add a reference in index.html right before 33 | // Note that we can't use 40 | `) 41 | 42 | // 3. Write index.html file back to disk 43 | FILEUTIL.writeFileSync(indexPath, cher.html()) 44 | LOGGER.log("Added " + lib + " to " + path) 45 | -------------------------------------------------------------------------------- /libs/onsenui/install.js: -------------------------------------------------------------------------------- 1 | // Install library in application. 2 | // see main-window-func.js, addLibraryToApp 3 | 4 | // 0. Read the index file to manipulate it 5 | var indexPath = APP_SETTINGS.getIndexFileFullPath(path) 6 | var html = FILEUTIL.readFileSync(indexPath) 7 | var scriptPath = `libs/${lib}/js/${lib}.js` 8 | var cssPath = `libs/${lib}/css/${lib}.css` 9 | var cssComponentsPath = `libs/${lib}/css/onsen-css-components.css` 10 | 11 | // 1. Remove any existing reference in index.html 12 | cher = CHEERIO.load(html, { xmlMode: false }) 13 | var element = cher('script').filter(function(i, el) { 14 | return cher(this).attr('src') === scriptPath 15 | }) 16 | if (element.length > 0) { 17 | element.remove() 18 | } 19 | var element = cher('link').filter(function(i, el) { 20 | return cher(this).attr('href') === cssPath 21 | }) 22 | if (element.length > 0) { 23 | element.remove() 24 | } 25 | var element = cher('link').filter(function(i, el) { 26 | return cher(this).attr('href') === cssComponentsPath 27 | }) 28 | if (element.length > 0) { 29 | element.remove() 30 | } 31 | 32 | // 2. Add a reference in index.html right before 33 | // Note that we can't use 40 | `) 41 | 42 | // 3. Write index.html file back to disk 43 | FILEUTIL.writeFileSync(indexPath, cher.html()) 44 | LOGGER.log("Added " + lib + " to " + path) 45 | -------------------------------------------------------------------------------- /libs/evothings/dialog-iotsensor/iotsensor-raw.js: -------------------------------------------------------------------------------- 1 | // Specific object for RAW 2 | // TODO: Add more info about RAW here 3 | 4 | ;(function() 5 | { 6 | "use strict"; 7 | 8 | evothings.iotsensor.ble.RAW = {}; 9 | 10 | /** 11 | * @namespace 12 | * @description Internal implementation of JavaScript library for the IoT Sensor RAW project. 13 | * @alias evothings.iotsensor.ble.RAW 14 | */ 15 | var iotsensor = {}; 16 | 17 | evothings.iotsensor.ble.RAW = iotsensor; 18 | 19 | /** 20 | * Create an IoT Sensor RAW instance 21 | * @returns {@link evothings.iotsensor.instance_ble_raw} 22 | * @private 23 | */ 24 | iotsensor.addInstanceMethods = function(anInstance) 25 | { 26 | 27 | /** 28 | * @namespace 29 | * @alias evothings.iotsensor.instance_ble_raw 30 | * @description IoT Sensor RAW instance object. 31 | * @private 32 | */ 33 | var instance = evothings.iotsensor.settings.addInstanceMethods(anInstance); 34 | 35 | // Add generic BLE instance methods. 36 | evothings.iotsensor.ble.addInstanceMethods(instance); 37 | 38 | /** 39 | * Device model 40 | * @instance 41 | * @public 42 | */ 43 | instance.deviceModel = 'RAW'; 44 | 45 | /** 46 | * @description Determine if a BLE device is an IoT Sensor RAW.
47 | * Checks for the IoT Sensor using the name. 48 | * @instance 49 | * @public 50 | */ 51 | instance.isIoTSensor = function(device) 52 | { 53 | return (device != null) && 54 | (device.name != null) && 55 | (device.name == evothings.iotsensor.RAW); 56 | } 57 | 58 | // Finally return the IoT Sensor instance object 59 | return instance; 60 | } 61 | 62 | 63 | })(); -------------------------------------------------------------------------------- /libs/framework7/img/i-form-settings-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Evothings Studio Libraries 2 | 3 | This repository contains libraries for mobile apps for the Internet of Things (IoT). Supported functionality include Bluetooth Low Energy (BLE) and Eddystone. The libraries are bundled with [Evothings Studio](https://evothings.com/download/). 4 | 5 | ## Structure 6 | 7 | Folder structure: 8 | 9 | arduino 10 | Programs for communicating with Arduino boards over TCP and BLE 11 | libs 12 | JavaScript libraries 13 | 14 | ## Documentation 15 | 16 | [Documentation for Evothings JavaScript libraries](https://evothings.com/doc/lib-doc/index.html) is available on the [Evothings documentation web site](https://evothings.com/doc/). 17 | 18 | To generate HTML documentation for Evothings JavaScript libraries yourself, 19 | you can install [JSDoc](https://github.com/jsdoc3/jsdoc) and run the the following command in the root folder of this repository: 20 | 21 | jsdoc -r ./libs/ 22 | 23 | ## Evothings example apps 24 | 25 | Example apps that use the libraries in this repository are available in the [evothings-examples](https://github.com/evothings/evothings-examples) repository, in folder [generated/examples](https://github.com/evothings/evothings-examples/tree/master/generated/examples). 26 | 27 | These example apps are included with [Evothings Studio](https://evothings.com/download/). 28 | 29 | [Documentation for example apps](https://evothings.com/doc/examples/examples.html) is available at the [Evothings documentation web site](https://evothings.com/doc/). 30 | 31 | ## Get started quickly with Evothings Studio 32 | 33 | [Download Evothings Studio](https://evothings.com/download/) and get up and running in minutes! 34 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-name-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /libs/framework7/js/my-app.js: -------------------------------------------------------------------------------- 1 | // Initialize your app 2 | var myApp = new Framework7(); 3 | 4 | // Export selectors engine 5 | var $$ = Dom7; 6 | 7 | // Add view 8 | var mainView = myApp.addView('.view-main', { 9 | // Because we use fixed-through navbar we can enable dynamic navbar 10 | dynamicNavbar: true 11 | }); 12 | 13 | // Callbacks to run specific code for specific pages, for example for About page: 14 | myApp.onPageInit('about', function (page) { 15 | // run createContentPage func after link was clicked 16 | $$('.create-page').on('click', function () { 17 | createContentPage(); 18 | }); 19 | }); 20 | 21 | // Generate dynamic page 22 | var dynamicPageIndex = 0; 23 | function createContentPage() { 24 | mainView.router.loadContent( 25 | '' + 26 | '' + 32 | '
' + 33 | ' ' + 34 | '
' + 35 | ' ' + 36 | '
' + 37 | '
' + 38 | '
' + 39 | '

Here is a dynamic page created on ' + new Date() + ' !

' + 40 | '

Go back or go to Services.

' + 41 | '
' + 42 | '
' + 43 | '
' + 44 | '
' + 45 | '
' 46 | ); 47 | return; 48 | } -------------------------------------------------------------------------------- /libs/framework7/img/i-form-tel-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /libs/mdl/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "material-design-lite", 3 | "version": "1.2.1", 4 | "description": "Material Design Components in CSS, JS and HTML", 5 | "license": "Apache-2.0", 6 | "author": "Google", 7 | "repository": "google/material-design-lite", 8 | "main": "dist/material.min.js", 9 | "devDependencies": { 10 | "acorn": "^3.3.0", 11 | "babel-core": "^5.8.25", 12 | "browser-sync": "^2.2.3", 13 | "chai": "^3.3.0", 14 | "chai-jquery": "^2.0.0", 15 | "del": "^2.0.2", 16 | "drool": "^0.3.1", 17 | "escodegen": "^1.6.1", 18 | "google-closure-compiler": "", 19 | "gulp": "^3.9.0", 20 | "gulp-autoprefixer": "^3.0.2", 21 | "gulp-cache": "^0.3.0", 22 | "gulp-closure-compiler": "^0.3.1", 23 | "gulp-concat": "^2.4.1", 24 | "gulp-connect": "^5.0.0", 25 | "gulp-css-inline-images": "^0.1.1", 26 | "gulp-csso": "1.0.0", 27 | "gulp-file": "^0.2.0", 28 | "gulp-flatten": "^0.3.1", 29 | "gulp-front-matter": "^1.2.2", 30 | "gulp-header": "^1.2.2", 31 | "gulp-if": "^2.0.0", 32 | "gulp-iife": "^0.1.0", 33 | "gulp-imagemin": "^2.2.1", 34 | "gulp-jscs": "^3.0.1", 35 | "gulp-jshint": "^1.6.3", 36 | "gulp-load-plugins": "^0.10.0", 37 | "gulp-marked": "^1.0.0", 38 | "gulp-mocha-phantomjs": "^0.10.1", 39 | "gulp-open": "^1.0.0", 40 | "gulp-rename": "^1.2.0", 41 | "gulp-replace": "^0.5.3", 42 | "gulp-sass": "2.0.*", 43 | "gulp-shell": "^0.4.2", 44 | "gulp-size": "^2.0.0", 45 | "gulp-sourcemaps": "^1.3.0", 46 | "gulp-subtree": "^0.1.0", 47 | "gulp-tap": "^0.1.3", 48 | "gulp-uglify": "^2.0.0", 49 | "gulp-util": "^3.0.4", 50 | "gulp-zip": "^3.0.2", 51 | "humanize": "0.0.9", 52 | "jquery": "^2.1.3", 53 | "jshint-stylish": "^2.0.1", 54 | "merge-stream": "^1.0.0", 55 | "mocha": "^3.0.2", 56 | "prismjs": "0.0.1", 57 | "run-sequence": "^1.0.2", 58 | "swig": "^1.4.2", 59 | "through2": "^2.0.0", 60 | "vinyl-paths": "^2.0.0" 61 | }, 62 | "engines": { 63 | "node": ">=0.12.0" 64 | }, 65 | "scripts": { 66 | "test": "gulp && git status | grep 'working directory clean' >/dev/null || (echo 'Please commit all changes generated by building'; exit 1)" 67 | }, 68 | "babel": { 69 | "only": "gulpfile.babel.js" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /libs/evothings/dialog-iotsensor/iotsensor-sfl.js: -------------------------------------------------------------------------------- 1 | // Specific object for SFL 2 | // TODO: Add more info about SFL here 3 | 4 | ;(function() 5 | { 6 | "use strict"; 7 | 8 | evothings.iotsensor.ble.SFL = {}; 9 | 10 | /** 11 | * @namespace 12 | * @description Internal implementation of JavaScript library for the IoT Sensor SFL project. 13 | * @alias evothings.iotsensor.ble.SLF 14 | */ 15 | var iotsensor = {}; 16 | 17 | evothings.iotsensor.ble.SFL = iotsensor; 18 | 19 | /** 20 | * Create an IoT Sensor SFL instance 21 | * @returns {@link evothings.iotsensor.instance_ble_sfl} 22 | * @private 23 | */ 24 | iotsensor.addInstanceMethods = function(anInstance) 25 | { 26 | 27 | /** 28 | * @namespace 29 | * @alias evothings.iotsensor.instance_ble_sfl 30 | * @description IoT Sensor SFL instance object. 31 | * @private 32 | */ 33 | var instance = evothings.iotsensor.settings.addInstanceMethods(anInstance); 34 | 35 | // Add generic BLE instance methods. 36 | evothings.iotsensor.ble.addInstanceMethods(instance); 37 | 38 | /** 39 | * Device model 40 | * @instance 41 | * @public 42 | */ 43 | instance.deviceModel = 'SFL'; 44 | 45 | /** 46 | * @description Determine if a BLE device is an IoT Sensor SFL.
47 | * Checks for the IoT Sensor using the name. 48 | * @instance 49 | * @public 50 | */ 51 | instance.isIoTSensor = function(device) 52 | { 53 | return (device != null) && 54 | (device.name != null) && 55 | (device.name == evothings.iotsensor.SFL); 56 | } 57 | 58 | /** 59 | * @description SFL only. Implementation of {@link evothings.iotsensor.instance#sflCallback} 60 | * @instance 61 | * @private 62 | */ 63 | instance.sflCallback = function(callbackFun) 64 | { 65 | instance.sflFun = callbackFun; 66 | instance.SFL.dataFun = getSflValues; 67 | return instance; 68 | } 69 | 70 | /** 71 | * @description SFL only. Implementation of {@link evothings.iotsensor.instance#sflOn} 72 | * @instance 73 | * @private 74 | */ 75 | instance.sflOn = function() 76 | { 77 | instance.sensorOn( 78 | instance.SFL, 79 | instance.sflFun 80 | ); 81 | return instance; 82 | } 83 | 84 | /** 85 | * @description SFL only. Implementation of {@link evothings.iotsensor.instance#sflOn} 86 | * @instance 87 | * @private 88 | */ 89 | instance.sflOff = function() 90 | { 91 | instance.sensorOff(instance.SFL); 92 | return instance; 93 | } 94 | 95 | /** 96 | * @description SFL only. 97 | * Private. Calculate sensor fusion values from raw data 98 | * @param data - Uint8Array. 99 | * @return Object with fields: w, x, y, z. 100 | * @instance 101 | * @private 102 | */ 103 | function getSflValues(data) 104 | { 105 | // Calculate accelerometer values. 106 | var wx = evothings.util.littleEndianToInt16(data, 3); 107 | var ax = evothings.util.littleEndianToInt16(data, 5); 108 | var ay = evothings.util.littleEndianToInt16(data, 7); 109 | var az = evothings.util.littleEndianToInt16(data, 9); 110 | 111 | return { w: wx, x: ax, y: ay, z: az } 112 | } 113 | 114 | // Finally return the IoT Sensor instance object 115 | return instance; 116 | } 117 | 118 | 119 | })(); -------------------------------------------------------------------------------- /libs/evothings/arduinoble/arduinoble.js: -------------------------------------------------------------------------------- 1 | // File: arduinoble.js 2 | 3 | // Load library EasyBLE. 4 | evothings.loadScript('libs/evothings/easyble/easyble.js'); 5 | 6 | /** 7 | * @namespace 8 | * @author Mikael Kindborg 9 | * @description

Functions for communicating with an Arduino BLE shield.

10 | *

It is safe practise to call function {@link evothings.scriptsLoaded} 11 | * to ensure dependent libraries are loaded before calling functions 12 | * in this library.

13 | * 14 | * @todo This is a very simple library that has only write capability, 15 | * read and notification functions should be added. 16 | * 17 | * @todo Add function to set the write characteristic UUID to make 18 | * the code more generic. 19 | */ 20 | evothings.arduinoble = {}; 21 | 22 | ;(function() 23 | { 24 | // Internal functions. 25 | var internal = {}; 26 | 27 | /** 28 | * Stop any ongoing scan and disconnect all devices. 29 | * @public 30 | */ 31 | evothings.arduinoble.close = function() 32 | { 33 | evothings.easyble.stopScan(); 34 | evothings.easyble.closeConnectedDevices(); 35 | }; 36 | 37 | /** 38 | * Called when you've connected to an Arduino BLE shield. 39 | * @callback evothings.arduinoble.connectsuccess 40 | * @param {evothings.arduinoble.ArduinoBLEDevice} device - 41 | * The connected BLE shield. 42 | */ 43 | 44 | /** 45 | * Connect to a BLE-shield. 46 | * @param deviceName BLE name if the shield. 47 | * @param {evothings.arduinoble.connectsuccess} success - 48 | * Success callback: success(device) 49 | * @param {function} fail - Error callback: fail(errorCode) 50 | * @example 51 | * evothings.arduinoble.connect( 52 | * 'arduinoble', // Name of BLE shield. 53 | * function(device) 54 | * { 55 | * console.log('connected!'); 56 | * device.writeDataArray(new Uint8Array([1])); 57 | * evothings.arduinoble.close(); 58 | * }, 59 | * function(errorCode) 60 | * { 61 | * console.log('Error: ' + errorCode); 62 | * }); 63 | * @public 64 | */ 65 | evothings.arduinoble.connect = function(deviceName, success, fail) 66 | { 67 | evothings.easyble.startScan( 68 | function(device) 69 | { 70 | if (device.name == deviceName) 71 | { 72 | evothings.easyble.stopScan(); 73 | internal.connectToDevice(device, success, fail); 74 | } 75 | }, 76 | function(errorCode) 77 | { 78 | fail(errorCode); 79 | }); 80 | }; 81 | 82 | /** 83 | * Connect to the BLE shield. 84 | * @private 85 | */ 86 | internal.connectToDevice = function(device, success, fail) 87 | { 88 | device.connect( 89 | function(device) 90 | { 91 | // Get services info. 92 | internal.getServices(device, success, fail); 93 | }, 94 | function(errorCode) 95 | { 96 | fail(errorCode); 97 | }); 98 | }; 99 | 100 | /** 101 | * Read all services from the device. 102 | * @private 103 | */ 104 | internal.getServices = function(device, success, fail) 105 | { 106 | device.readServices( 107 | null, // null means read info for all services 108 | function(device) 109 | { 110 | internal.addMethodsToDeviceObject(device); 111 | success(device); 112 | }, 113 | function(errorCode) 114 | { 115 | fail(errorCode); 116 | }); 117 | }; 118 | 119 | /** 120 | * Add instance methods to the device object. 121 | * @private 122 | */ 123 | internal.addMethodsToDeviceObject = function(device) 124 | { 125 | /** 126 | * Object that holds info about an Arduino BLE shield. 127 | * @namespace evothings.arduinoble.ArduinoBLEDevice 128 | */ 129 | 130 | /** 131 | * @function writeDataArray 132 | * @description Write data to an Arduino BLE shield. 133 | * @param {Uint8Array} uint8array - The data to be written. 134 | * @memberof evothings.arduinoble.ArduinoBLEDevice 135 | * @instance 136 | * @public 137 | */ 138 | device.writeDataArray = function(uint8array, uuid) 139 | { 140 | uuid = uuid || '713d0003-503e-4c75-ba94-3148f18d941e'; 141 | device.writeCharacteristic( 142 | uuid, 143 | uint8array, 144 | function() 145 | { 146 | console.log('writeCharacteristic success'); 147 | }, 148 | function(errorCode) 149 | { 150 | console.log('writeCharacteristic error: ' + errorCode); 151 | }); 152 | }; 153 | }; 154 | })(); 155 | -------------------------------------------------------------------------------- /libs/framework7/img/i-form-url-ios.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /arduino/arduinoethernet/arduinoethernet.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino Ethernet Script Server 3 | 4 | Created Mars 4, 2014 5 | Mikael Kindborg, Evothings AB 6 | 7 | TCP socket server that accept commands for basic scripting 8 | of the Arduino board. 9 | 10 | This example is written for use with an Ethernet shield. 11 | 12 | The API consists of the requests listed below. 13 | 14 | Requests and responses end with a new line. 15 | 16 | The input parameter n is a pin number ranging from 2 to 9. 17 | 18 | The response is always a 4-character string with a 19 | hex encoded number ranging from 0 to FFFF. 20 | 21 | Possible response string values: 22 | 23 | H (result from digital read) 24 | L (result from digital read) 25 | 0 to 1023 - Analog value (result from analog read) 26 | 27 | Set pin mode to OUTPUT for pin n: On 28 | Response: None 29 | Example: O5 30 | Note: O is upper case letter o, not digit zero (0). 31 | 32 | Set pin mode to INPUT for pin n: In 33 | Response: None 34 | Example: I5 35 | 36 | Write LOW to pin n: Ln 37 | Response: None 38 | Example: L5 39 | 40 | Write HIGH to pin n: Hn 41 | Response: None 42 | Example: H5 43 | 44 | READ pin n: Rn 45 | Response: "H" (HIGH) or "L" (LOW) 46 | Example: R5 -> H 47 | 48 | ANALOG read pin n: An 49 | Response: int value as string (range "0" to "1023") 50 | Example: A5 -> 42 51 | */ 52 | 53 | // Include files. 54 | #include 55 | #include 56 | 57 | // Enter a MAC address for your controller below, usually found on a sticker 58 | // on the back of your Ethernet shield. 59 | byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xD0, 0x93 }; 60 | 61 | // The IP address will be dependent on your local network. 62 | // If you have IP network info, uncomment the lines starting 63 | // with IPAddress and enter relevant data for your network. 64 | // If you don't know, you probably have dynamically allocated IP adresses, then 65 | // you don't need to do anything, move along. 66 | // IPAddress ip(192,168,1, 177); 67 | // IPAddress gateway(192,168,1, 1); 68 | // IPAddress subnet(255, 255, 255, 0); 69 | 70 | // Create a server listening on the given port. 71 | EthernetServer server(3300); 72 | 73 | void setup() 74 | { 75 | // Start serial communication with the given baud rate. 76 | // NOTE: Remember to set the baud rate in the Serial 77 | // monitor to the same value. 78 | Serial.begin(9600); 79 | 80 | // Wait for serial port to connect. Needed for Leonardo only. 81 | while (!Serial) { ; } 82 | 83 | // Initialize the Ethernet shield. 84 | // If you entered fixed ipaddress info, gateway, subnet mask, 85 | // then uncommment the next line. 86 | // Ethernet.begin(mac, ip, gateway, subnet); 87 | 88 | // If it works to get a dynamic IP from a DHCP server, use this 89 | // code to test if you're getting a dynamic adress. If this 90 | // does not work, use the above method of specifying an IP-address. 91 | // dhcp test starts here 92 | if (Ethernet.begin(mac) == 0) 93 | { 94 | Serial.println("Failed to configure Ethernet using DHCP"); 95 | // No point in carrying on, stop here forever. 96 | while(true) ; 97 | } 98 | // dhcp test end 99 | 100 | // Start the server. 101 | server.begin(); 102 | 103 | // Print status. 104 | printServerStatus(); 105 | } 106 | 107 | void loop() 108 | { 109 | // Listen for incoming client requests. 110 | EthernetClient client = server.available(); 111 | if (!client) 112 | { 113 | return; 114 | } 115 | 116 | Serial.println("Client connected"); 117 | 118 | String request = readRequest(&client); 119 | executeRequest(&client, &request); 120 | 121 | // Close the connection. 122 | //client.stop(); 123 | 124 | Serial.println("Client disonnected"); 125 | } 126 | 127 | // Read the request line, 128 | String readRequest(EthernetClient* client) 129 | { 130 | String request = ""; 131 | 132 | // Loop while the client is connected. 133 | while (client->connected()) 134 | { 135 | // Read available bytes. 136 | while (client->available()) 137 | { 138 | // Read a byte. 139 | char c = client->read(); 140 | 141 | // Print the value (for debugging). 142 | Serial.write(c); 143 | 144 | // Exit loop if end of line. 145 | if ('\n' == c) 146 | { 147 | return request; 148 | } 149 | 150 | // Add byte to request line. 151 | request += c; 152 | } 153 | } 154 | return request; 155 | } 156 | 157 | void executeRequest(EthernetClient* client, String* request) 158 | { 159 | char command = readCommand(request); 160 | int n = readParam(request); 161 | if ('O' == command) 162 | { 163 | pinMode(n, OUTPUT); 164 | } 165 | else if ('I' == command) 166 | { 167 | pinMode(n, INPUT); 168 | } 169 | else if ('L' == command) 170 | { 171 | digitalWrite(n, LOW); 172 | } 173 | else if ('H' == command) 174 | { 175 | digitalWrite(n, HIGH); 176 | } 177 | else if ('R' == command) 178 | { 179 | sendResponse(client, String(digitalRead(n))); 180 | } 181 | else if ('A' == command) 182 | { 183 | sendResponse(client, String(analogRead(n))); 184 | } 185 | } 186 | 187 | // Read the command from the request string. 188 | char readCommand(String* request) 189 | { 190 | String commandString = request->substring(0, 1); 191 | return commandString.charAt(0); 192 | } 193 | 194 | // Read the parameter from the request string. 195 | int readParam(String* request) 196 | { 197 | // This handles a hex digit 0 to F (0 to 15). 198 | char buffer[2]; 199 | buffer[0] = request->charAt(1); 200 | buffer[1] = 0; 201 | return (int) strtol(buffer, NULL, 16); 202 | } 203 | 204 | void sendResponse(EthernetClient* client, String response) 205 | { 206 | // Send response to client. 207 | client->println(response); 208 | 209 | // Debug print. 210 | Serial.println("sendResponse:"); 211 | Serial.println(response); 212 | } 213 | 214 | void printServerStatus() 215 | { 216 | Serial.print("Server address:"); 217 | Serial.println(Ethernet.localIP()); 218 | } 219 | -------------------------------------------------------------------------------- /arduino/arduinowifi/arduinowifi_cc3000.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino CC3000 Wifi Module 3 | Created January 15, 2016 4 | Klaus Camilleri 5 | 6 | This example is a mix of both an example written by Adafruit team & Wifi example written by Mikael Kindborg, Evothings AB 7 | 8 | TCP socket server that accept commands for basic scripting 9 | of the Arduino board. 10 | This example is written for a network using WPA encryption. 11 | For WEP or WPA, change the Wifi.begin() call accordingly. 12 | The API consists of the requests listed below. 13 | Requests and responses end with a new line. 14 | The input parameter n is a pin number ranging from 2 to 9. 15 | The response is always a 4-character string with a 16 | hex encoded number ranging from 0 to FFFF. 17 | Possible response string values: 18 | H (result from digital read) 19 | L (result from digital read) 20 | 0 to 1023 - Analog value (result from analog read) 21 | Set pin mode to OUTPUT for pin n: On 22 | Response: None 23 | Example: O5 24 | Note: O is upper case letter o, not digit zero (0). 25 | Set pin mode to INPUT for pin n: In 26 | Response: None 27 | Example: I5 28 | Write LOW to pin n: Ln 29 | Response: None 30 | Example: L5 31 | Write HIGH to pin n: Hn 32 | Response: None 33 | Example: H5 34 | READ pin n: Rn 35 | Response: "H" (HIGH) or "L" (LOW) 36 | Example: R5 -> H 37 | ANALOG read pin n: An 38 | Response: int value as string (range "0" to "1023") 39 | Example: A5 -> 42 40 | */ 41 | 42 | #include 43 | #include 44 | 45 | // These are the interrupt and control pins 46 | #define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! 47 | // These can be any two pins 48 | #define ADAFRUIT_CC3000_VBAT 5 49 | #define ADAFRUIT_CC3000_CS 10 50 | // Use hardware SPI for the remaining pins 51 | // On an UNO, SCK = 13, MISO = 12, and MOSI = 11 52 | 53 | Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, 54 | SPI_CLOCK_DIVIDER); // you can change this clock speed 55 | 56 | #define WLAN_SSID "wifi" // cannot be longer than 32 characters! 57 | #define WLAN_PASS "password" 58 | // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 59 | #define WLAN_SECURITY WLAN_SEC_WPA2 60 | 61 | #define LISTEN_PORT 3300 // What TCP port to listen on for connections. 62 | 63 | #define BUFFER_SIZE 120 64 | 65 | #define TIMEOUT_MS 500 // Amount of time in milliseconds to wait for 66 | // an incoming request to finish. Don't set this 67 | // too high or your server could be slow to respond. 68 | 69 | Adafruit_CC3000_Server httpServer(LISTEN_PORT); 70 | uint8_t buffer[BUFFER_SIZE+1]; 71 | int bufindex = 0; 72 | 73 | void setup(void) 74 | { 75 | Serial.begin(115200); 76 | 77 | // Initialise the module 78 | Serial.println(F("\nInitializing...")); 79 | if (!cc3000.begin()) 80 | { 81 | Serial.println(F("Couldn't begin()! Check your wiring?")); 82 | while(1); 83 | } 84 | 85 | Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID); 86 | if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { 87 | Serial.println(F("Failed!")); 88 | while(1); 89 | } 90 | 91 | Serial.println(F("Connected!")); 92 | 93 | Serial.println(F("Request DHCP")); 94 | while (!cc3000.checkDHCP()) 95 | { 96 | delay(100); 97 | } 98 | 99 | // Start listening for connections 100 | httpServer.begin(); 101 | 102 | Serial.println(F("Listening for connections...")); 103 | } 104 | 105 | void loop(void) 106 | { 107 | // Try to get a client which is connected. 108 | Adafruit_CC3000_ClientRef client = httpServer.available(); 109 | if (client) { 110 | Serial.println(F("Client connected.")); 111 | 112 | Serial.println("Client connected"); 113 | 114 | String request = readRequest(&client); 115 | executeRequest(&client, &request); 116 | 117 | // Close the connection. 118 | //client.stop(); 119 | 120 | Serial.println("Client disonnected"); 121 | } 122 | } 123 | 124 | 125 | 126 | String readRequest(Adafruit_CC3000_ClientRef* client) 127 | { 128 | String request = ""; 129 | 130 | // Loop while the client is connected. 131 | while (client->connected()) 132 | { 133 | // Read available bytes. 134 | while (client->available()) 135 | { 136 | // Read a byte. 137 | char c = client->read(); 138 | 139 | // Print the value (for debugging). 140 | Serial.write(c); 141 | 142 | // Exit loop if end of line. 143 | if ('\n' == c) 144 | { 145 | return request; 146 | } 147 | 148 | // Add byte to request line. 149 | request += c; 150 | } 151 | } 152 | return request; 153 | } 154 | 155 | 156 | void executeRequest(Adafruit_CC3000_ClientRef* client, String* request) 157 | { 158 | char command = readCommand(request); 159 | int n = readParam(request); 160 | if ('O' == command) 161 | { 162 | pinMode(n, OUTPUT); 163 | } 164 | else if ('I' == command) 165 | { 166 | pinMode(n, INPUT); 167 | } 168 | else if ('L' == command) 169 | { 170 | digitalWrite(n, LOW); 171 | } 172 | else if ('H' == command) 173 | { 174 | digitalWrite(n, HIGH); 175 | } 176 | else if ('R' == command) 177 | { 178 | sendResponse(client, String(digitalRead(n))); 179 | } 180 | else if ('A' == command) 181 | { 182 | sendResponse(client, String(analogRead(n))); 183 | } 184 | } 185 | 186 | // Read the command from the request string. 187 | char readCommand(String* request) 188 | { 189 | String commandString = request->substring(0, 1); 190 | return commandString.charAt(0); 191 | } 192 | 193 | 194 | // Read the parameter from the request string. 195 | int readParam(String* request) 196 | { 197 | // This handles a hex digit 0 to F (0 to 15). 198 | char buffer[2]; 199 | buffer[0] = request->charAt(1); 200 | buffer[1] = 0; 201 | return (int) strtol(buffer, NULL, 16); 202 | } 203 | 204 | void sendResponse(Adafruit_CC3000_ClientRef* client, String response) 205 | { 206 | // Send response to client. 207 | client->println(response); 208 | 209 | // Debug print. 210 | Serial.println("sendResponse:"); 211 | Serial.println(response); 212 | } 213 | -------------------------------------------------------------------------------- /arduino/arduinowifi/arduinowifi.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino WiFi Script Server 3 | 4 | Created October 20, 2013 5 | Mikael Kindborg, Evothings AB 6 | 7 | TCP socket server that accept commands for basic scripting 8 | of the Arduino board. 9 | 10 | This example is written for a network using WPA encryption. 11 | For WEP or WPA, change the Wifi.begin() call accordingly. 12 | 13 | The API consists of the requests listed below. 14 | 15 | Requests and responses end with a new line. 16 | 17 | The input parameter n is a pin number ranging from 2 to 9. 18 | 19 | The response is always a 4-character string with a 20 | hex encoded number ranging from 0 to FFFF. 21 | 22 | Possible response string values: 23 | 24 | H (result from digital read) 25 | L (result from digital read) 26 | 0 to 1023 - Analog value (result from analog read) 27 | 28 | Set pin mode to OUTPUT for pin n: On 29 | Response: None 30 | Example: O5 31 | Note: O is upper case letter o, not digit zero (0). 32 | 33 | Set pin mode to INPUT for pin n: In 34 | Response: None 35 | Example: I5 36 | 37 | Write LOW to pin n: Ln 38 | Response: None 39 | Example: L5 40 | 41 | Write HIGH to pin n: Hn 42 | Response: None 43 | Example: H5 44 | 45 | READ pin n: Rn 46 | Response: "H" (HIGH) or "L" (LOW) 47 | Example: R5 -> H 48 | 49 | ANALOG read pin n: An 50 | Response: int value as string (range "0" to "1023") 51 | Example: A5 -> 42 52 | */ 53 | 54 | // Include files. 55 | #include 56 | #include 57 | 58 | // Remove this line once you've entered WiFi SSID and password below. 59 | #error "WiFi SSID and password required!" 60 | 61 | // Your network SSID (network name). 62 | // TODO: Enter the name of your wifi network here. 63 | char ssid[] = "wifi name"; 64 | 65 | // Your network password. 66 | // TODO: Enter the password of your wifi network here. 67 | char pass[] = "wifi password"; 68 | 69 | // Your network key Index number (needed only for WEP). 70 | int keyIndex = 0; 71 | 72 | // Server status flag. 73 | int status = WL_IDLE_STATUS; 74 | 75 | // Create WiFi server listening on the given port. 76 | WiFiServer server(3300); 77 | 78 | void setup() 79 | { 80 | // Start serial communication with the given baud rate. 81 | // NOTE: Remember to set the baud rate in the Serial 82 | // monitor to the same value. 83 | Serial.begin(9600); 84 | 85 | // Wait for serial port to connect. Needed for Leonardo only 86 | while (!Serial) { ; } 87 | 88 | // Check for the presence of the WiFi shield. 89 | if (WiFi.status() == WL_NO_SHIELD) 90 | { 91 | // If no shield, print message and exit setup. 92 | Serial.println("WiFi shield not present"); 93 | status = WL_NO_SHIELD; 94 | return; 95 | } 96 | 97 | String version = WiFi.firmwareVersion(); 98 | if (version != "1.1.0") 99 | { 100 | Serial.println("Please upgrade the firmware"); 101 | } 102 | 103 | // Connect to Wifi network. 104 | while (status != WL_CONNECTED) 105 | { 106 | Serial.print("Connecting to Network named: "); 107 | Serial.println(ssid); 108 | 109 | // Connect to WPA/WPA2 network. Update this line if 110 | // using open or WEP network. 111 | status = WiFi.begin(ssid, pass); 112 | 113 | // Wait for connection. 114 | delay(1000); 115 | } 116 | 117 | // Start the server. 118 | server.begin(); 119 | 120 | // Print WiFi status. 121 | printWifiStatus(); 122 | } 123 | 124 | void loop() 125 | { 126 | // Check that we are connected. 127 | if (status != WL_CONNECTED) 128 | { 129 | return; 130 | } 131 | 132 | // Listen for incoming client requests. 133 | WiFiClient client = server.available(); 134 | if (!client) 135 | { 136 | return; 137 | } 138 | 139 | Serial.println("Client connected"); 140 | 141 | String request = readRequest(&client); 142 | executeRequest(&client, &request); 143 | 144 | // Close the connection. 145 | //client.stop(); 146 | 147 | Serial.println("Client disonnected"); 148 | } 149 | 150 | // Read the request line. The string from the JavaScript client ends with a newline. 151 | String readRequest(WiFiClient* client) 152 | { 153 | String request = ""; 154 | 155 | // Loop while the client is connected. 156 | while (client->connected()) 157 | { 158 | // Read available bytes. 159 | while (client->available()) 160 | { 161 | // Read a byte. 162 | char c = client->read(); 163 | 164 | // Print the value (for debugging). 165 | Serial.write(c); 166 | 167 | // Exit loop if end of line. 168 | if ('\n' == c) 169 | { 170 | return request; 171 | } 172 | 173 | // Add byte to request line. 174 | request += c; 175 | } 176 | } 177 | return request; 178 | } 179 | 180 | void executeRequest(WiFiClient* client, String* request) 181 | { 182 | char command = readCommand(request); 183 | int n = readParam(request); 184 | if ('O' == command) 185 | { 186 | pinMode(n, OUTPUT); 187 | } 188 | else if ('I' == command) 189 | { 190 | pinMode(n, INPUT); 191 | } 192 | else if ('L' == command) 193 | { 194 | digitalWrite(n, LOW); 195 | } 196 | else if ('H' == command) 197 | { 198 | digitalWrite(n, HIGH); 199 | } 200 | else if ('R' == command) 201 | { 202 | sendResponse(client, String(digitalRead(n))); 203 | } 204 | else if ('A' == command) 205 | { 206 | sendResponse(client, String(analogRead(n))); 207 | } 208 | } 209 | 210 | // Read the command from the request string. 211 | char readCommand(String* request) 212 | { 213 | String commandString = request->substring(0, 1); 214 | return commandString.charAt(0); 215 | } 216 | 217 | // Read the parameter from the request string. 218 | int readParam(String* request) 219 | { 220 | // This handles a hex digit 0 to F (0 to 15). 221 | char buffer[2]; 222 | buffer[0] = request->charAt(1); 223 | buffer[1] = 0; 224 | return (int) strtol(buffer, NULL, 16); 225 | } 226 | 227 | void sendResponse(WiFiClient* client, String response) 228 | { 229 | // Send response to client. 230 | client->println(response); 231 | 232 | // Debug print. 233 | Serial.println("sendResponse:"); 234 | Serial.println(response); 235 | } 236 | 237 | void printWifiStatus() 238 | { 239 | Serial.println("WiFi status"); 240 | 241 | // Print network name. 242 | Serial.print(" SSID: "); 243 | Serial.println(WiFi.SSID()); 244 | 245 | // Print WiFi shield IP address. 246 | IPAddress ip = WiFi.localIP(); 247 | Serial.print(" IP Address: "); 248 | Serial.println(ip); 249 | 250 | // Print the signal strength. 251 | long rssi = WiFi.RSSI(); 252 | Serial.print(" Signal strength (RSSI):"); 253 | Serial.print(rssi); 254 | Serial.println(" dBm"); 255 | } 256 | -------------------------------------------------------------------------------- /libs/evothings/util/util.js: -------------------------------------------------------------------------------- 1 | // File: util.js 2 | 3 | evothings = window.evothings || {}; 4 | 5 | /** 6 | * @namespace 7 | * @author Aaron Ardiri 8 | * @author Fredrik Eldh 9 | * @description Utilities for byte arrays. 10 | */ 11 | evothings.util = {}; 12 | 13 | ;(function() 14 | { 15 | /** 16 | * Interpret byte buffer as little endian 8 bit integer. 17 | * Returns converted number. 18 | * @param {ArrayBuffer} data - Input buffer. 19 | * @param {number} offset - Start of data. 20 | * @return Converted number. 21 | * @public 22 | */ 23 | evothings.util.littleEndianToInt8 = function(data, offset) 24 | { 25 | var x = evothings.util.littleEndianToUint8(data, offset) 26 | if (x & 0x80) x = x - 256 27 | return x 28 | } 29 | 30 | /** 31 | * Interpret byte buffer as unsigned little endian 8 bit integer. 32 | * Returns converted number. 33 | * @param {ArrayBuffer} data - Input buffer. 34 | * @param {number} offset - Start of data. 35 | * @return Converted number. 36 | * @public 37 | */ 38 | evothings.util.littleEndianToUint8 = function(data, offset) 39 | { 40 | return data[offset] 41 | } 42 | 43 | /** 44 | * Interpret byte buffer as little endian 16 bit integer. 45 | * Returns converted number. 46 | * @param {ArrayBuffer} data - Input buffer. 47 | * @param {number} offset - Start of data. 48 | * @return Converted number. 49 | * @public 50 | */ 51 | evothings.util.littleEndianToInt16 = function(data, offset) 52 | { 53 | return (evothings.util.littleEndianToInt8(data, offset + 1) << 8) + 54 | evothings.util.littleEndianToUint8(data, offset) 55 | } 56 | 57 | /** 58 | * Interpret byte buffer as unsigned little endian 16 bit integer. 59 | * Returns converted number. 60 | * @param {ArrayBuffer} data - Input buffer. 61 | * @param {number} offset - Start of data. 62 | * @return Converted number. 63 | * @public 64 | */ 65 | evothings.util.littleEndianToUint16 = function(data, offset) 66 | { 67 | return (evothings.util.littleEndianToUint8(data, offset + 1) << 8) + 68 | evothings.util.littleEndianToUint8(data, offset) 69 | } 70 | 71 | /** 72 | * Interpret byte buffer as unsigned little endian 32 bit integer. 73 | * Returns converted number. 74 | * @param {ArrayBuffer} data - Input buffer. 75 | * @param {number} offset - Start of data. 76 | * @return Converted number. 77 | * @public 78 | */ 79 | evothings.util.littleEndianToUint32 = function(data, offset) 80 | { 81 | return (evothings.util.littleEndianToUint8(data, offset + 3) << 24) + 82 | (evothings.util.littleEndianToUint8(data, offset + 2) << 16) + 83 | (evothings.util.littleEndianToUint8(data, offset + 1) << 8) + 84 | evothings.util.littleEndianToUint8(data, offset) 85 | } 86 | 87 | 88 | /** 89 | * Interpret byte buffer as signed big endian 16 bit integer. 90 | * Returns converted number. 91 | * @param {ArrayBuffer} data - Input buffer. 92 | * @param {number} offset - Start of data. 93 | * @return Converted number. 94 | * @public 95 | */ 96 | evothings.util.bigEndianToInt16 = function(data, offset) 97 | { 98 | return (evothings.util.littleEndianToInt8(data, offset) << 8) + 99 | evothings.util.littleEndianToUint8(data, offset + 1) 100 | } 101 | 102 | /** 103 | * Interpret byte buffer as unsigned big endian 16 bit integer. 104 | * Returns converted number. 105 | * @param {ArrayBuffer} data - Input buffer. 106 | * @param {number} offset - Start of data. 107 | * @return Converted number. 108 | * @public 109 | */ 110 | evothings.util.bigEndianToUint16 = function(data, offset) 111 | { 112 | return (evothings.util.littleEndianToUint8(data, offset) << 8) + 113 | evothings.util.littleEndianToUint8(data, offset + 1) 114 | } 115 | 116 | /** 117 | * Interpret byte buffer as unsigned big endian 32 bit integer. 118 | * Returns converted number. 119 | * @param {ArrayBuffer} data - Input buffer. 120 | * @param {number} offset - Start of data. 121 | * @return Converted number. 122 | * @public 123 | */ 124 | evothings.util.bigEndianToUint32 = function(data, offset) 125 | { 126 | return (evothings.util.littleEndianToUint8(data, offset) << 24) + 127 | (evothings.util.littleEndianToUint8(data, offset + 1) << 16) + 128 | (evothings.util.littleEndianToUint8(data, offset + 2) << 8) + 129 | evothings.util.littleEndianToUint8(data, offset + 3) 130 | } 131 | 132 | /** 133 | * Converts a single Base64 character to a 6-bit integer. 134 | * @private 135 | */ 136 | function b64ToUint6(nChr) { 137 | return nChr > 64 && nChr < 91 ? 138 | nChr - 65 139 | : nChr > 96 && nChr < 123 ? 140 | nChr - 71 141 | : nChr > 47 && nChr < 58 ? 142 | nChr + 4 143 | : nChr === 43 ? 144 | 62 145 | : nChr === 47 ? 146 | 63 147 | : 148 | 0; 149 | } 150 | 151 | /** 152 | * Decodes a Base64 string. Returns a Uint8Array. 153 | * nBlocksSize is optional. 154 | * @param {String} sBase64 155 | * @param {int} nBlocksSize 156 | * @return {Uint8Array} 157 | * @public 158 | */ 159 | evothings.util.base64DecToArr = function(sBase64, nBlocksSize) { 160 | var sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""); 161 | var nInLen = sB64Enc.length; 162 | var nOutLen = nBlocksSize ? 163 | Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize 164 | : nInLen * 3 + 1 >> 2; 165 | var taBytes = new Uint8Array(nOutLen); 166 | 167 | for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) { 168 | nMod4 = nInIdx & 3; 169 | nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4; 170 | if (nMod4 === 3 || nInLen - nInIdx === 1) { 171 | for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) { 172 | taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255; 173 | } 174 | nUint24 = 0; 175 | } 176 | } 177 | 178 | return taBytes; 179 | } 180 | 181 | /** 182 | * Returns the integer i in hexadecimal string form, 183 | * with leading zeroes, such that 184 | * the resulting string is at least byteCount*2 characters long. 185 | * @param {int} i 186 | * @param {int} byteCount 187 | * @public 188 | */ 189 | evothings.util.toHexString = function(i, byteCount) { 190 | var string = (new Number(i)).toString(16); 191 | while(string.length < byteCount*2) { 192 | string = '0'+string; 193 | } 194 | return string; 195 | } 196 | 197 | /** 198 | * Takes a ArrayBuffer or TypedArray and returns its hexadecimal representation. 199 | * No spaces or linebreaks. 200 | * @param data 201 | * @public 202 | */ 203 | evothings.util.typedArrayToHexString = function(data) { 204 | // view data as a Uint8Array, unless it already is one. 205 | if(data.buffer) { 206 | if(!(data instanceof Uint8Array)) 207 | data = new Uint8Array(data.buffer); 208 | } else if(data instanceof ArrayBuffer) { 209 | data = new Uint8Array(data); 210 | } else { 211 | throw "not an ArrayBuffer or TypedArray."; 212 | } 213 | var str = ''; 214 | for(var i=0; iFunctions for loading scripts asynchronously, 12 | * detecting platform, and other common application functionality.

13 | * @alias evothings 14 | * @public 15 | */ 16 | var evothings = window.evothings; 17 | 18 | /* ------------------ Script loading ------------------ */ 19 | 20 | var mScriptLoadingCounter = 0; 21 | var mLoadedScripts = {}; 22 | var mScriptsLoadedCallbacks = []; 23 | 24 | /** 25 | * Make sure to catch any DOMContentLoaded events occurring before 26 | * asynchronous loading of scripts. Those scripts, like ui.js, should check 27 | * this variable before listening for the event. 28 | */ 29 | evothings.gotDOMContentLoaded = false; 30 | 31 | window.addEventListener('DOMContentLoaded', function(e) 32 | { 33 | evothings.gotDOMContentLoaded = true; 34 | }) 35 | 36 | /** 37 | * Load a script. 38 | * @param {string} url - URL or path to the script. Relative paths are 39 | * relative to the HTML file that initiated script loading. 40 | * @param {function} successCallback - Optional parameterless function that 41 | * will be called when the script has loaded. 42 | * @param {function} errorCallback - Optional function that will be called 43 | * if loading the script fails, takes an error object as parameter. 44 | * @public 45 | */ 46 | evothings.loadScript = function(url, successCallback, errorCallback) 47 | { 48 | // If script is already loaded call callback directly and return. 49 | if (mLoadedScripts[url] == 'loadingcomplete') 50 | { 51 | successCallback && successCallback(); 52 | return; 53 | } 54 | 55 | // Add script to dictionary of loaded scripts. 56 | mLoadedScripts[url] = 'loadingstarted'; 57 | ++mScriptLoadingCounter; 58 | 59 | // Create script tag. 60 | var script = document.createElement('script'); 61 | script.type = 'text/javascript'; 62 | script.src = url; 63 | 64 | // Bind the onload event. 65 | script.onload = function() 66 | { 67 | // Mark as loaded. 68 | mLoadedScripts[url] = 'loadingcomplete'; 69 | --mScriptLoadingCounter; 70 | 71 | // Call success callback if given. 72 | successCallback && successCallback(); 73 | 74 | // Call scripts loaded callbacks if this was the last script loaded. 75 | if (0 == mScriptLoadingCounter) 76 | { 77 | for (var i = 0; i < mScriptsLoadedCallbacks.length; ++i) 78 | { 79 | var loadedCallback = mScriptsLoadedCallbacks[i]; 80 | loadedCallback && loadedCallback(); 81 | } 82 | 83 | // Clear callbacks - should we do this??? 84 | mScriptsLoadedCallbacks = []; 85 | } 86 | }; 87 | 88 | // onerror fires for things like malformed URLs and 404's. 89 | // If this function is called, the matching onload will not be called and 90 | // scriptsLoaded will not fire. 91 | script.onerror = function(error) 92 | { 93 | errorCallback && errorCallback(error); 94 | }; 95 | 96 | // Attaching the script tag to the document starts loading the script. 97 | document.head.appendChild(script); 98 | }; 99 | 100 | /** 101 | * Load array of scripts. 102 | * @param {array} array - Array of URL or path name stringa. 103 | * Relative paths are relative to the HTML file that initiated 104 | * script loading. 105 | * @param {function} loadedCallback - Optional parameterless 106 | * function called when all scripts in the array has loaded. 107 | * @public 108 | */ 109 | evothings.loadScripts = function(array, loadedCallback) 110 | { 111 | var lib = array.shift(); 112 | if (!lib) 113 | { 114 | // Array is empty and all scripts are loaded. 115 | loadedCallback && loadedCallback(); 116 | } 117 | else 118 | { 119 | // Load next script. 120 | evothings.loadScript(lib, function() { 121 | evothings.loadScripts(array, loadedCallback); 122 | }); 123 | } 124 | }; 125 | 126 | /** 127 | * Experimental. 128 | * Mark a script as loaded. This is useful if a script is designed 129 | * to be included both in HTML and in JavaScript. 130 | * @param {string} pathOrURL - URL or path to the script. Relative paths are 131 | * relative to the HTML file that initiated script loading. 132 | * @public 133 | */ 134 | evothings.markScriptAsLoaded = function(pathOrURL) 135 | { 136 | mLoadedScripts[url] = 'loadingcomplete'; 137 | }; 138 | 139 | /** 140 | *

Add a callback that will be called when all scripts are loaded.

141 | *

It is good practise to always use this function when 142 | * loading script asynchronously or using a library that does so.

143 | * @param {function} callback - Parameterless function that will 144 | * be called when all scripts have finished loading. 145 | * @public 146 | */ 147 | evothings.scriptsLoaded = function(callback) 148 | { 149 | // If scripts are already loaded call the callback directly, 150 | // else add the callback to the callbacks array. 151 | if (0 != Object.keys(mLoadedScripts).length && 152 | 0 == mScriptLoadingCounter) 153 | { 154 | callback && callback(); 155 | } 156 | else 157 | { 158 | mScriptsLoadedCallbacks.push(callback); 159 | } 160 | }; 161 | 162 | /* ------------------ Debugging ------------------ */ 163 | 164 | /** 165 | * Print a JavaScript object (dictionary). For debugging. 166 | * 167 | * @param {Object} obj - Object to print. 168 | * @param {function} printFun - print function (optional - defaults to 169 | * console.log if not given). 170 | * 171 | * @example 172 | * var obj = { company: 'Evothings', field: 'IoT' }; 173 | * evothings.printObject(obj); 174 | * evothings.printObject(obj, console.log); 175 | * 176 | * @public 177 | */ 178 | evothings.printObject = function(obj, printFun) 179 | { 180 | printFun = printFun || console.log; 181 | function print(obj, level) 182 | { 183 | var indent = new Array(level + 1).join(' '); 184 | for (var prop in obj) 185 | { 186 | if (obj.hasOwnProperty(prop)) 187 | { 188 | var value = obj[prop]; 189 | if (typeof value == 'object') 190 | { 191 | printFun(indent + prop + ':'); 192 | print(value, level + 1); 193 | } 194 | else 195 | { 196 | printFun(indent + prop + ': ' + value); 197 | } 198 | } 199 | } 200 | } 201 | print(obj, 0); 202 | }; 203 | 204 | /* ------------------ Platform check ------------------ */ 205 | 206 | /** 207 | * @namespace 208 | * @description Namespace for platform check functions. 209 | */ 210 | evothings.os = {}; 211 | 212 | /** 213 | * Returns true if current platform is iOS, false if not. 214 | * @return {boolean} true if platform is iOS, false if not. 215 | * @public 216 | */ 217 | evothings.os.isIOS = function() 218 | { 219 | return /iP(hone|ad|od)/.test(navigator.userAgent); 220 | }; 221 | 222 | /** 223 | * Returns true if current platform is iOS 7, false if not. 224 | * @return {boolean} true if platform is iOS 7, false if not. 225 | * @public 226 | */ 227 | evothings.os.isIOS7 = function() 228 | { 229 | return /iP(hone|ad|od).*OS 7/.test(navigator.userAgent); 230 | }; 231 | 232 | /** 233 | * Returns true if current platform is Android, false if not. 234 | * @return {boolean} true if platform is Android, false if not. 235 | * @public 236 | */ 237 | evothings.os.isAndroid = function() 238 | { 239 | return /Android|android/.test(navigator.userAgent); 240 | }; 241 | 242 | /** 243 | * Returns true if current platform is Windows Phone, false if not. 244 | * @return {boolean} true if platform is Windows Phone, false if not. 245 | * @public 246 | */ 247 | evothings.os.isWP = function() 248 | { 249 | return /Windows Phone/.test(navigator.userAgent); 250 | }; 251 | })(); 252 | -------------------------------------------------------------------------------- /libs/evothings/dialog-iotsensor/README.md: -------------------------------------------------------------------------------- 1 | # IoT Sensor Library 2 | 3 | This JavaScript library is used to communicate with the [IoT Sensor Development Kit](http://www.dialog-semiconductor.com/iotsensor). 4 | 5 | In order to use this library, build a Cordova app that contains the [BLE plugin](https://github.com/evothings/cordova-ble) or create a new application using the [Evothings Workbench](https://evothings.com/doc/studio/workbench.html). 6 | 7 | To use this library, place the `libs/evothings/dialog-iotsensor` folder in the root of your Evothings application or `www` folder (Cordova). 8 | 9 | Make sure to also copy the easyble library to `libs/evothings/easyble`. You can find the latest version on the [evothings-libraries repository](https://github.com/evothings/evothings-libraries). 10 | 11 | ## Initialization & Connecting 12 | 13 | Include the `iotsensor.js` file 14 | 15 | ```html 16 | 17 | ``` 18 | 19 | Create a new iotsensor object by specifying the project type (RAW or SFL) you are using. 20 | 21 | ```javascript 22 | // Device type we are connecting to, can either be RAW or SFL 23 | var type = evothings.iotsensor.SFL; 24 | 25 | // Create a new IoT Sensor SFL instance 26 | var iotsensor = evothings.iotsensor.createInstance(type); 27 | ``` 28 | 29 | Now that we have created a new IoT Sensor instance, we can try to connect to the sensor using BLE. 30 | The library provides the option to automatically connect to the closest IoT Sensor available using the `connectToClosestSensor(scanTime, callbackFun, disconnectFun)` function. 31 | 32 | ```javascript 33 | // Scan for 3000ms 34 | iotsensor.connectToClosestSensor( 35 | 3000, 36 | function() 37 | { 38 | console.log('We are connected!'); 39 | }, 40 | function(error) 41 | { 42 | console.log('Disconnect error: ' + error); 43 | } 44 | ); 45 | ``` 46 | You can also connect to a device manually, see the [documentation](http://nbezembinder1.github.io/dialog/docs/evothings.iotsensor.instance_ble.html#connectToDevice__anchor) for more information. 47 | ```javascript 48 | iotsensor.startScanningForDevices( 49 | function(device) 50 | { 51 | console.log('Device found: ' + device.name + ' RSSI: ' + device.rssi); 52 | if(iotsensor.isIoTSensor(device)) 53 | { 54 | // We have an IoT Sensor, let's connect! 55 | iotsensor.connectToDevice( 56 | device, 57 | function() 58 | { 59 | // Connected and device is ready 60 | }, 61 | function(error) 62 | { 63 | console.log('Disconnect error ' + error); 64 | } 65 | ); 66 | } 67 | } 68 | ); 69 | ``` 70 | 71 | ## Device info & Sensor data 72 | 73 | The IoT Sensor provides a features report to see which sensors are available and the firmware version of the device connected. 74 | It is good practice to use these options to determine the capabilities of the device. 75 | ```javascript 76 | console.log('IoT Sensor device info:' 77 | + '\n Device model: ' + iotsensor.getDeviceModel() 78 | + '\n Firmware: ' + iotsensor.getFirmwareString() 79 | + '\n Accelerometer: ' + iotsensor.isAccelerometerAvailable() 80 | + '\n Gyroscope: ' + iotsensor.isGyroscopeAvailable() 81 | + '\n Magnetometer: ' + iotsensor.isMagnetometerAvailable() 82 | + '\n Barometer: ' + iotsensor.isBarometerAvailable() 83 | + '\n Temperature: ' + iotsensor.isTemperatureAvailable() 84 | + '\n Humidity: ' + iotsensor.isHumidityAvailable() 85 | + '\n Sensor Fusion: ' + iotsensor.isSflAvailable()); 86 | ``` 87 | 88 | In order to receive data from one of the sensors, a callback function must be set. This function is called everytime new data is available from the sensor. 89 | Once the callback is set, the sensor can be enabled. Note that Sensor Fusion is not available in RAW projects. 90 | ```javascript 91 | // Set the accelerometer callback and turn on the accelerometer 92 | iotsensor.accelerometerCallback(handleReply) 93 | .accelerometerOn(); 94 | 95 | function handleReply(data) 96 | { 97 | console.log('Accelerometer: ' + 98 | '\n x: ' + data.x + 99 | '\n y: ' + data.y + 100 | '\n z: ' + data.z); 101 | } 102 | ``` 103 | Note: All data (except for Sensor Fusion) is automatically converted to the correct unit of measurement. Please refer to the [documentation](http://nbezembinder1.github.io/dialog/docs/evothings.iotsensor.instance.html#accelerometerCallback__anchor) for more information 104 | 105 | ## Settings 106 | Using this JavaScript library the IoT Sensor can be configured to your liking. 107 | The settings of the device can be divided into three categories: 108 | 109 | Basic configuration 110 | Used to configure the sensors 111 | Sensor fusion 112 | Set the SFL coefficients to control the relative weight of accelerometer and magnetometer data 113 | Calibration 114 | Set calibration coefficients 115 | Set calibration control flags 116 | 117 | For a complete overview of all available settings, refer to the [documentation](http://nbezembinder1.github.io/dialog/docs/evothings.iotsensor.instance_settings.html). 118 | 119 | ### Basic configuration 120 | 121 | It is good practice to read the basic configuration settings from the device on startup, 122 | in case the settings in flash memory do not match the default settings specified in configuration.BASIC 123 | 124 | The `configuration.BASIC` object is an array and contains eleven different settings to control the sensors. 125 | In order to set correct values in the device, refer to the [enums](http://nbezembinder1.github.io/dialog/docs/evothings.iotsensor.instance_settings.html) object. These objects contain all possible values that can be written to the device. Currently there is no check build in to make sure you are not writing wrong values to the device. 126 | ```javascript 127 | // Change accelerometer range to 16g 128 | iotsensor.configuration.BASIC.ACCELEROMETER_RANGE = iotsensor.enums.ACCELEROMETER_RANGE._16g; 129 | 130 | // After changing a settings, set the basic configuration in device 131 | iotsensor.setBasicConfiguration(); 132 | 133 | // Optional - Store basic configuration in flash 134 | iotsensor.storeBasicConfigurationInFlash(); 135 | 136 | // Optional - Retrieve new settings from device 137 | iotsensor.readBasicConfiguration( 138 | function(data) 139 | { 140 | console.log('Settings: ' + data); 141 | } 142 | ); 143 | ``` 144 | 145 | ## Sensor Fusion 146 | Changing the Sensor Fusion coefficients works the same as changing the basic configuration: 147 | ```javascript 148 | // Change Beta A to 2000 149 | iotsensor.configuration.SFL_COEF.BETA_A = 2000; 150 | 151 | // Set basic configuration in device 152 | iotsensor.setSflCoefficients(); 153 | 154 | // Retrieve sensor fusion coefficients from device 155 | iotsensor.readSflCoefficients( 156 | function(data) 157 | { 158 | console.log('Sfl coefficients: ' + data); 159 | } 160 | ); 161 | ``` 162 | 163 | ## Calibration 164 | In order to change the calibration coefficients and calibration control flag settings, refer to the `configuration.CAL_COEF` and `configuration.CAL_CONTROL` object. 165 | ```javascript 166 | // Set Q_FORMAT 167 | iotsensor.configuration.CAL_COEF.Q_FORMAT = 12; 168 | 169 | // Set offset vector 170 | iotsensor.configuration.OFFSET_VECTOR = new Int16Array([100, 100, 100]); 171 | 172 | // Set matrix 173 | iotsensor.configuration.MATRIX = [new Int16Array([100, 0, 0]), new Int16Array([0, 100, 0]), new Int16Array([0, 0, 100])]; 174 | 175 | // Set Calibration coefficients in device 176 | iotsensor.setCalibrationCoefficients(); 177 | 178 | // Retrieve calibration coefficients from device 179 | iotsensor.readCalibrationCoefficients( 180 | function(data) 181 | { 182 | console.log('Calibration coefficients: ' + data); 183 | } 184 | ); 185 | ``` 186 | 187 | ```javascript 188 | // Set calibration control flag byte 2 (CONTROL_FLAG[0]) 189 | iotsensor.configuration.CAL_CONTROL.CONTROL_FLAGS[0] = 28 // 0011100 190 | 191 | // Set calibration control flags in device 192 | iotsensor.setCalibrationControl(); 193 | 194 | // Retrieve calibration control flags from device 195 | iotsensor.readCalibrationControl( 196 | function(data) 197 | { 198 | console.log('Calibration control ' + data); 199 | } 200 | ); 201 | ``` 202 | 203 | To learn more about the different control flags, refer to the user manual on the [Dialog customer support](http://support.dialog-semiconductor.com/) site. 204 | 205 | The function `storeCalibrationAndControl()` stores all settings regarding Sensor Fusion and Calibration in flash memory. 206 | ```javascript 207 | iotsensor.storeCalibrationAndControl(); 208 | ``` 209 | 210 | ## Other 211 | When an error occurs or when there is a new update, the default error and status handler is called. 212 | The default handler outputs the error and status to the console as follows: 213 | ```javascript 214 | // Error 215 | console.log(evothings.iotsensor.currentTime() + ' IoT Sensor error: ' + error); 216 | 217 | // Status 218 | console.log(evothings.iotsensor.currentTime() + ' IoT Sensor status: ' + status); 219 | ``` 220 | Both the error and status handler can be set to your liking: 221 | ```javascript 222 | iotsensor.errorCallback(errorFun) 223 | .statusCallback(statusFun); 224 | 225 | function errorFun(error) 226 | { 227 | console.log('ERROR: ' + error); 228 | } 229 | 230 | function statusFun(status) 231 | { 232 | console.log('STATUS: ' + status); 233 | } 234 | ``` 235 | In order to determine if a sensor is correctly turned ON the sensor status callback can be used. 236 | This function is called everytime a sensor receives a START command and sends a reply back to the device. 237 | 238 | Note: If this callback function is not set, an error `Callback function not set for COMMAND_ID 1` is returned every time a sensor is turned ON. 239 | ```javascript 240 | iotsensor.sensorStatusCallback(handleReply); 241 | 242 | function handleReply(data) 243 | { 244 | console.log('Sensor status: ' + data); // 1: On 245 | } 246 | -------------------------------------------------------------------------------- /libs/evothings/arduinotcp/arduinotcp.js: -------------------------------------------------------------------------------- 1 | // File: arduinotcp.js 2 | // Author: Mikael Kindborg 3 | // Functions for scripting the Arduino board from JavaScript. 4 | 5 | /* 6 | * Readable names for parameter values. (Having these as 7 | * globals is a bit ugly but makes for shorter names in 8 | * the application code.) 9 | */ 10 | 11 | /** 12 | * Value for setting a pin to output. 13 | * @todo Move into namespace 14 | */ 15 | var OUTPUT = 1 16 | 17 | /** 18 | * Value for setting a pin to input. 19 | * @todo Move into namespace 20 | */ 21 | var INPUT = 2 22 | 23 | /** 24 | * Value for setting a pin to on. 25 | * @todo Move into namespace 26 | */ 27 | var HIGH = true 28 | 29 | /** 30 | * Value for setting a pin to off. 31 | * @todo Move into namespace 32 | */ 33 | var LOW = false 34 | 35 | /** 36 | * @namespace 37 | * @description

Functions for communicating with an Arduino 38 | * WiFi shield or Ethernet shield.

39 | */ 40 | evothings.arduinotcp = {} 41 | 42 | ;(function() 43 | { 44 | /** 45 | * Holder of internal library functions. 46 | * @private 47 | */ 48 | var internal = {} 49 | 50 | /** 51 | * Internal string that holds data read from server. 52 | * @private 53 | */ 54 | internal.receiveBuffer = '' 55 | 56 | /** 57 | * Internal flag that keeps track of the receive listener. 58 | * @private 59 | */ 60 | internal.receiveListnerAdded = false 61 | 62 | /** 63 | * Internal arrays for timeouts. 64 | * @private 65 | */ 66 | internal.timerTimeouts = [] 67 | 68 | /** 69 | * Internal arrays for timer intervals. 70 | * @private 71 | */ 72 | internal.timerIntervals = [] 73 | 74 | /** 75 | * Start timeout timer. This function makes it easier to 76 | * use timeouts in Arduino scripts. 77 | * @param fun Timer function, takes no parameters. 78 | * @param ms Timer delay in milliseconds. 79 | * @public 80 | */ 81 | evothings.arduinotcp.setTimeout = function(fun, ms) 82 | { 83 | internal.timerTimeouts.push( 84 | setTimeout(fun, ms)) 85 | } 86 | 87 | /** 88 | * Start interval timer. This function makes it easier to 89 | * use timer intervals in Arduino scripts. 90 | * @param fun Timer function, takes no parameters. 91 | * @param ms Timer interval in milliseconds. 92 | * @public 93 | */ 94 | evothings.arduinotcp.setInterval = function(fun, ms) 95 | { 96 | internal.timerIntervals.push( 97 | setInterval(fun, ms)) 98 | } 99 | 100 | /** 101 | * Clear all timers. 102 | */ 103 | evothings.arduinotcp.clearAllTimers = function() 104 | { 105 | for (var i = 0; i < internal.timerTimeouts.length; ++i) 106 | { 107 | clearTimeout(internal.timerTimeouts[i]) 108 | } 109 | for (var i = 0; i < internal.timerIntervals.length; ++i) 110 | { 111 | clearInterval(internal.timerIntervals[i]) 112 | } 113 | internal.timerTimeouts = [] 114 | internal.timerIntervals = [] 115 | } 116 | 117 | /** 118 | * The IP address of the Arduino board. 119 | * @public 120 | */ 121 | evothings.arduinotcp.ipAddress = '' 122 | 123 | /** 124 | * The port number used by the Arduino server. 125 | * @public 126 | */ 127 | evothings.arduinotcp.port = 0 128 | 129 | /** 130 | * Returns the current IP address value. 131 | * @return {string} IP address. 132 | * @public 133 | */ 134 | evothings.arduinotcp.getIpAddress = function() 135 | { 136 | return evothings.arduinotcp.ipAddress 137 | } 138 | 139 | /** 140 | * Write a digital output value. 141 | * @param {number} pinNumber - pin number to read 142 | * @param {number} value - HIGH or LOW 143 | * @public 144 | */ 145 | evothings.arduinotcp.digitalWrite = function(pinNumber, value) 146 | { 147 | if (value == HIGH) 148 | { 149 | internal.sendRequest('H' + pinNumber, internal.callbackFun) 150 | } 151 | else if (value == LOW) 152 | { 153 | internal.sendRequest('L' + pinNumber, internal.callbackFun) 154 | } 155 | } 156 | 157 | /** 158 | * Set pin to output or input. 159 | * @param {number} pinNumber - pin number to read 160 | * @param {number} mode - OUTPUT or INPUT 161 | * @public 162 | */ 163 | evothings.arduinotcp.pinMode = function(pinNumber, mode) 164 | { 165 | if (mode == OUTPUT) 166 | { 167 | internal.sendRequest('O' + pinNumber, internal.callbackFun) 168 | } 169 | else if (mode == INPUT) 170 | { 171 | internal.sendRequest('I' + pinNumber, internal.callbackFun) 172 | } 173 | } 174 | 175 | /** 176 | * Read a digital input value, callback is called with the value 177 | * 'H' or 'L' corresponding to the result of the Arduino function 178 | * digitalRead(). 179 | * @param {number} pinNumber - pin number to read 180 | * @param {function} callback - Function called with value of pin. 181 | * Format: callback(value) where value is 'H' or 'L', 182 | * or null on error. 183 | * @public 184 | */ 185 | evothings.arduinotcp.digitalRead = function(pinNumber, callback) 186 | { 187 | internal.sendRequest( 188 | 'R' + pinNumber, 189 | function(result) 190 | { 191 | if (result) 192 | { 193 | internal.readServerResult(function(data) 194 | { 195 | callback(data) 196 | }) 197 | } 198 | else 199 | { 200 | callback(null) 201 | } 202 | } 203 | ) 204 | } 205 | 206 | /** 207 | * Read an analog input value. The callback function is called 208 | * with the value of the Arduino function analogRead(). 209 | * @param {number} pinNumber - pin number to read. 210 | * @param {function} callback - Function called with analog value of pin. 211 | * Format: callback(value) where is a number, or null on error. 212 | * @public 213 | */ 214 | evothings.arduinotcp.analogRead = function(pinNumber, callback) 215 | { 216 | internal.sendRequest( 217 | 'A' + pinNumber, 218 | function(result) 219 | { 220 | if (result) 221 | { 222 | internal.readServerResult(function(data) 223 | { 224 | callback(data) 225 | }) 226 | } 227 | else 228 | { 229 | callback(null) 230 | } 231 | } 232 | ) 233 | } 234 | 235 | /** 236 | * Connect to a server running on the Arduino. 237 | * @param {string} hostname 238 | * @param {number} port 239 | * @param {number} callback Function called when connect 240 | * operation has completed. Format: callback(successFlag) 241 | * where successFlag is true on success and false on error. 242 | * @public 243 | */ 244 | evothings.arduinotcp.connect = function(hostname, port, callback) 245 | { 246 | evothings.arduinotcp.disconnect() 247 | 248 | chrome.sockets.tcp.create(function(createInfo) 249 | { 250 | // Save socket id. 251 | internal.socketId = createInfo.socketId 252 | 253 | // Connect. 254 | chrome.sockets.tcp.connect( 255 | createInfo.socketId, 256 | hostname, 257 | port, 258 | function(resultCode) 259 | { 260 | if (resultCode === 0) 261 | { 262 | // Connect success. 263 | 264 | // Set up receive listener (lazy initialisation). 265 | if (!internal.receiveListnerAdded) 266 | { 267 | internal.receiveListnerAdded = true 268 | 269 | chrome.sockets.tcp.onReceive.addListener(function(info) 270 | { 271 | // Accumulate result. 272 | internal.receiveBuffer += internal.bufferToString(info.data) 273 | 274 | // Process data. 275 | internal.readNext() 276 | }) 277 | } 278 | 279 | internal.connected = true 280 | } 281 | else 282 | { 283 | // Error. 284 | internal.connected = false 285 | } 286 | 287 | callback(internal.connected) 288 | } 289 | ) 290 | }) 291 | } 292 | 293 | /** 294 | * Disconnect from the Arduino. 295 | * @public 296 | */ 297 | evothings.arduinotcp.disconnect = function() 298 | { 299 | if (internal.connected) 300 | { 301 | chrome.sockets.tcp.close(internal.socketId) 302 | internal.connected = false 303 | } 304 | } 305 | 306 | /** 307 | * Internal connected flag. 308 | * @private 309 | */ 310 | internal.connected = false 311 | 312 | /** 313 | * Send a request to the Arduino. 314 | * @param command - the command string 315 | * @callback - function on the format: callback(successFlag) 316 | * @private 317 | */ 318 | internal.sendRequest = function(command, callback) 319 | { 320 | if (internal.connected) 321 | { 322 | internal.write( 323 | internal.socketId, 324 | command + '\n', // Here a newline is added to the end of the request. 325 | function(bytesWritten) 326 | { 327 | // Command length is +1 due to the added newline. 328 | callback(bytesWritten === command.length + 1) 329 | } 330 | ) 331 | } 332 | } 333 | 334 | /** 335 | * Write data. 336 | * Format: callback(bytesWritten) 337 | * @private 338 | */ 339 | internal.write = function(socketId, string, callback) 340 | { 341 | chrome.sockets.tcp.send( 342 | socketId, 343 | internal.stringToBuffer(string), 344 | function(sendInfo) 345 | { 346 | callback(sendInfo.bytesSent) 347 | } 348 | ) 349 | } 350 | 351 | /** 352 | * Array for the callback queue. 353 | * @private 354 | */ 355 | internal.resultCallbackQueue = [] 356 | 357 | /** 358 | * Read result from server, calling the callback function 359 | * with the result. 360 | * Format: callback(data) where data is a string 361 | * @private 362 | */ 363 | internal.readServerResult = function(callback) 364 | { 365 | // Add callback to queue. 366 | internal.resultCallbackQueue.push(callback) 367 | 368 | // If this is the only callback there is no read operation 369 | // in progress, so start reading. 370 | internal.readNext() 371 | } 372 | 373 | /** 374 | * Parse data received from server, when a result is found (reading up to 375 | * next newline char) the first function in the callback queue is called. 376 | * This function may return if data has not yet arrived from the server. 377 | * In that case it will be called again. 378 | * @private 379 | */ 380 | internal.readNext = function() 381 | { 382 | if (internal.resultCallbackQueue.length === 0) 383 | { 384 | // No callback in queue. 385 | return 386 | } 387 | 388 | console.log('internal.readNext: ' + internal.receiveBuffer) 389 | 390 | var data = internal.receiveBuffer 391 | 392 | // Does in buffer contain a newline? 393 | var pos = data.indexOf('\n') 394 | 395 | if (pos > -1) 396 | { 397 | // Extract data up to newline. 398 | var result = data.substr(0, pos) 399 | 400 | // Remove data from input buffer. 401 | internal.receiveBuffer = internal.receiveBuffer.substring(pos + 1) 402 | 403 | // Call next callback in queue with the result. 404 | var callback = internal.resultCallbackQueue.shift() 405 | callback(result) 406 | 407 | // If there are callbacks waiting, continue reading 408 | // the next result. 409 | if (internal.resultCallbackQueue.length > 0) 410 | { 411 | internal.readNext() 412 | } 413 | } 414 | } 415 | 416 | /** 417 | * @private 418 | */ 419 | internal.callbackFun = function(result) 420 | { 421 | if (result == false) 422 | { 423 | alert('Failed to send the command to the Arduino.') 424 | } 425 | } 426 | 427 | /** 428 | * @private 429 | */ 430 | internal.bufferToString = function(buffer) 431 | { 432 | return String.fromCharCode.apply(null, new Uint8Array(buffer)) 433 | } 434 | 435 | /** 436 | * @private 437 | */ 438 | internal.stringToBuffer = function(string) 439 | { 440 | var buffer = new ArrayBuffer(string.length) 441 | var bufferView = new Uint8Array(buffer); 442 | for (var i = 0; i < string.length; ++i) 443 | { 444 | bufferView[i] = string.charCodeAt(i) //string[i] 445 | } 446 | return buffer 447 | } 448 | })() 449 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /libs/mdl/icons/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /libs/bleat/bluetooth.helpers.js: -------------------------------------------------------------------------------- 1 | /* @license 2 | * 3 | * BLE Abstraction Tool: bluetooth helpers 4 | * 5 | * The MIT License (MIT) 6 | * 7 | * Copyright (c) 2016 Rob Moran 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in all 17 | * copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | * SOFTWARE. 26 | */ 27 | 28 | // https://github.com/umdjs/umd 29 | (function (root, factory) { 30 | if (typeof define === 'function' && define.amd) { 31 | // AMD. Register as an anonymous module. 32 | define(factory); 33 | } else if (typeof exports === 'object') { 34 | // Node. Does not work with strict CommonJS 35 | module.exports = factory(); 36 | } else { 37 | // Browser globals with support for web workers (root is window) 38 | root.bleatHelpers = factory(); 39 | } 40 | }(this, function() { 41 | "use strict"; 42 | 43 | var bluetoothServices = { 44 | "alert_notification": 0x1811, 45 | "automation_io": 0x1815, 46 | "battery_service": 0x180F, 47 | "blood_pressure": 0x1810, 48 | "body_composition": 0x181B, 49 | "bond_management": 0x181E, 50 | "continuous_glucose_monitoring": 0x181F, 51 | "current_time": 0x1805, 52 | "cycling_power": 0x1818, 53 | "cycling_speed_and_cadence": 0x1816, 54 | "device_information": 0x180A, 55 | "environmental_sensing": 0x181A, 56 | "generic_access": 0x1800, 57 | "generic_attribute": 0x1801, 58 | "glucose": 0x1808, 59 | "health_thermometer": 0x1809, 60 | "heart_rate": 0x180D, 61 | "human_interface_device": 0x1812, 62 | "immediate_alert": 0x1802, 63 | "indoor_positioning": 0x1821, 64 | "internet_protocol_support": 0x1820, 65 | "link_loss": 0x1803, 66 | "location_and_navigation": 0x1819, 67 | "next_dst_change": 0x1807, 68 | "phone_alert_status": 0x180E, 69 | "pulse_oximeter": 0x1822, 70 | "reference_time_update": 0x1806, 71 | "running_speed_and_cadence": 0x1814, 72 | "scan_parameters": 0x1813, 73 | "tx_power": 0x1804, 74 | "user_data": 0x181C, 75 | "weight_scale": 0x181D 76 | }; 77 | 78 | var bluetoothCharacteristics = { 79 | "aerobic_heart_rate_lower_limit": 0x2A7E, 80 | "aerobic_heart_rate_upper_limit": 0x2A84, 81 | "aerobic_threshold": 0x2A7F, 82 | "age": 0x2A80, 83 | "aggregate": 0x2A5A, 84 | "alert_category_id": 0x2A43, 85 | "alert_category_id_bit_mask": 0x2A42, 86 | "alert_level": 0x2A06, 87 | "alert_notification_control_point": 0x2A44, 88 | "alert_status": 0x2A3F, 89 | "altitude": 0x2AB3, 90 | "anaerobic_heart_rate_lower_limit": 0x2A81, 91 | "anaerobic_heart_rate_upper_limit": 0x2A82, 92 | "anaerobic_threshold": 0x2A83, 93 | "analog": 0x2A58, 94 | "apparent_wind_direction": 0x2A73, 95 | "apparent_wind_speed": 0x2A72, 96 | "gap.appearance": 0x2A01, 97 | "barometric_pressure_trend": 0x2AA3, 98 | "battery_level": 0x2A19, 99 | "blood_pressure_feature": 0x2A49, 100 | "blood_pressure_measurement": 0x2A35, 101 | "body_composition_feature": 0x2A9B, 102 | "body_composition_measurement": 0x2A9C, 103 | "body_sensor_location": 0x2A38, 104 | "bond_management_control_point": 0x2AA4, 105 | "bond_management_feature": 0x2AA5, 106 | "boot_keyboard_input_report": 0x2A22, 107 | "boot_keyboard_output_report": 0x2A32, 108 | "boot_mouse_input_report": 0x2A33, 109 | "gap.central_address_resolution_support": 0x2AA6, 110 | "cgm_feature": 0x2AA8, 111 | "cgm_measurement": 0x2AA7, 112 | "cgm_session_run_time": 0x2AAB, 113 | "cgm_session_start_time": 0x2AAA, 114 | "cgm_specific_ops_control_point": 0x2AAC, 115 | "cgm_status": 0x2AA9, 116 | "csc_feature": 0x2A5C, 117 | "csc_measurement": 0x2A5B, 118 | "current_time": 0x2A2B, 119 | "cycling_power_control_point": 0x2A66, 120 | "cycling_power_feature": 0x2A65, 121 | "cycling_power_measurement": 0x2A63, 122 | "cycling_power_vector": 0x2A64, 123 | "database_change_increment": 0x2A99, 124 | "date_of_birth": 0x2A85, 125 | "date_of_threshold_assessment": 0x2A86, 126 | "date_time": 0x2A08, 127 | "day_date_time": 0x2A0A, 128 | "day_of_week": 0x2A09, 129 | "descriptor_value_changed": 0x2A7D, 130 | "gap.device_name": 0x2A00, 131 | "dew_point": 0x2A7B, 132 | "digital": 0x2A56, 133 | "dst_offset": 0x2A0D, 134 | "elevation": 0x2A6C, 135 | "email_address": 0x2A87, 136 | "exact_time_256": 0x2A0C, 137 | "fat_burn_heart_rate_lower_limit": 0x2A88, 138 | "fat_burn_heart_rate_upper_limit": 0x2A89, 139 | "firmware_revision_string": 0x2A26, 140 | "first_name": 0x2A8A, 141 | "five_zone_heart_rate_limits": 0x2A8B, 142 | "floor_number": 0x2AB2, 143 | "gender": 0x2A8C, 144 | "glucose_feature": 0x2A51, 145 | "glucose_measurement": 0x2A18, 146 | "glucose_measurement_context": 0x2A34, 147 | "gust_factor": 0x2A74, 148 | "hardware_revision_string": 0x2A27, 149 | "heart_rate_control_point": 0x2A39, 150 | "heart_rate_max": 0x2A8D, 151 | "heart_rate_measurement": 0x2A37, 152 | "heat_index": 0x2A7A, 153 | "height": 0x2A8E, 154 | "hid_control_point": 0x2A4C, 155 | "hid_information": 0x2A4A, 156 | "hip_circumference": 0x2A8F, 157 | "humidity": 0x2A6F, 158 | "ieee_11073-20601_regulatory_certification_data_list": 0x2A2A, 159 | "indoor_positioning_configuration": 0x2AAD, 160 | "intermediate_blood_pressure": 0x2A36, 161 | "intermediate_temperature": 0x2A1E, 162 | "irradiance": 0x2A77, 163 | "language": 0x2AA2, 164 | "last_name": 0x2A90, 165 | "latitude": 0x2AAE, 166 | "ln_control_point": 0x2A6B, 167 | "ln_feature": 0x2A6A, 168 | "local_east_coordinate.xml": 0x2AB1, 169 | "local_north_coordinate": 0x2AB0, 170 | "local_time_information": 0x2A0F, 171 | "location_and_speed": 0x2A67, 172 | "location_name": 0x2AB5, 173 | "longitude": 0x2AAF, 174 | "magnetic_declination": 0x2A2C, 175 | "magnetic_flux_density_2D": 0x2AA0, 176 | "magnetic_flux_density_3D": 0x2AA1, 177 | "manufacturer_name_string": 0x2A29, 178 | "maximum_recommended_heart_rate": 0x2A91, 179 | "measurement_interval": 0x2A21, 180 | "model_number_string": 0x2A24, 181 | "navigation": 0x2A68, 182 | "new_alert": 0x2A46, 183 | "gap.peripheral_preferred_connection_parameters": 0x2A04, 184 | "gap.peripheral_privacy_flag": 0x2A02, 185 | "plx_continuous_measurement": 0x2A5F, 186 | "plx_features": 0x2A60, 187 | "plx_spot_check_measurement": 0x2A5E, 188 | "pnp_id": 0x2A50, 189 | "pollen_concentration": 0x2A75, 190 | "position_quality": 0x2A69, 191 | "pressure": 0x2A6D, 192 | "protocol_mode": 0x2A4E, 193 | "rainfall": 0x2A78, 194 | "gap.reconnection_address": 0x2A03, 195 | "record_access_control_point": 0x2A52, 196 | "reference_time_information": 0x2A14, 197 | "report": 0x2A4D, 198 | "report_map": 0x2A4B, 199 | "resting_heart_rate": 0x2A92, 200 | "ringer_control_point": 0x2A40, 201 | "ringer_setting": 0x2A41, 202 | "rsc_feature": 0x2A54, 203 | "rsc_measurement": 0x2A53, 204 | "sc_control_point": 0x2A55, 205 | "scan_interval_window": 0x2A4F, 206 | "scan_refresh": 0x2A31, 207 | "sensor_location": 0x2A5D, 208 | "serial_number_string": 0x2A25, 209 | "gatt.service_changed": 0x2A05, 210 | "software_revision_string": 0x2A28, 211 | "sport_type_for_aerobic_and_anaerobic_thresholds": 0x2A93, 212 | "supported_new_alert_category": 0x2A47, 213 | "supported_unread_alert_category": 0x2A48, 214 | "system_id": 0x2A23, 215 | "temperature": 0x2A6E, 216 | "temperature_measurement": 0x2A1C, 217 | "temperature_type": 0x2A1D, 218 | "three_zone_heart_rate_limits": 0x2A94, 219 | "time_accuracy": 0x2A12, 220 | "time_source": 0x2A13, 221 | "time_update_control_point": 0x2A16, 222 | "time_update_state": 0x2A17, 223 | "time_with_dst": 0x2A11, 224 | "time_zone": 0x2A0E, 225 | "true_wind_direction": 0x2A71, 226 | "true_wind_speed": 0x2A70, 227 | "two_zone_heart_rate_limit": 0x2A95, 228 | "tx_power_level": 0x2A07, 229 | "uncertainty": 0x2AB4, 230 | "unread_alert_status": 0x2A45, 231 | "user_control_point": 0x2A9F, 232 | "user_index": 0x2A9A, 233 | "uv_index": 0x2A76, 234 | "vo2_max": 0x2A96, 235 | "waist_circumference": 0x2A97, 236 | "weight": 0x2A98, 237 | "weight_measurement": 0x2A9D, 238 | "weight_scale_feature": 0x2A9E, 239 | "wind_chill": 0x2A79 240 | }; 241 | 242 | var bluetoothDescriptors = { 243 | "gatt.characteristic_extended_properties": 0x2900, 244 | "gatt.characteristic_user_description": 0x2901, 245 | "gatt.client_characteristic_configuration": 0x2902, 246 | "gatt.server_characteristic_configuration": 0x2903, 247 | "gatt.characteristic_presentation_format": 0x2904, 248 | "gatt.characteristic_aggregate_format": 0x2905, 249 | "valid_range": 0x2906, 250 | "external_report_reference": 0x2907, 251 | "report_reference": 0x2908, 252 | "number_of_digitals": 0x2909, 253 | "value_trigger_setting": 0x290A, 254 | "es_configuration": 0x290B, 255 | "es_measurement": 0x290C, 256 | "es_trigger_setting": 0x290D, 257 | "time_trigger_setting": 0x290E 258 | }; 259 | 260 | function getCanonicalUUID(uuid) { 261 | if (typeof uuid === "number") uuid = uuid.toString(16); 262 | uuid = uuid.toLowerCase(); 263 | if (uuid.length <= 8) uuid = ("00000000" + uuid).slice(-8) + "-0000-1000-8000-00805f9b34fb"; 264 | if (uuid.length === 32) uuid = uuid.match(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/).splice(1).join("-"); 265 | return uuid; 266 | } 267 | 268 | function getServiceUUID(uuid) { 269 | if (bluetoothServices[uuid]) uuid = bluetoothServices[uuid]; 270 | return getCanonicalUUID(uuid); 271 | } 272 | 273 | function getCharacteristicUUID(uuid) { 274 | if (bluetoothCharacteristics[uuid]) uuid = bluetoothCharacteristics[uuid]; 275 | return getCanonicalUUID(uuid); 276 | } 277 | 278 | function getDescriptorUUID(uuid) { 279 | if (bluetoothDescriptors[uuid]) uuid = bluetoothDescriptors[uuid]; 280 | return getCanonicalUUID(uuid); 281 | } 282 | 283 | return { 284 | Services: bluetoothServices, 285 | Characteristics: bluetoothCharacteristics, 286 | Descriptors: bluetoothDescriptors, 287 | getCanonicalUUID: getCanonicalUUID, 288 | getServiceUUID: getServiceUUID, 289 | getCharacteristicUUID: getCharacteristicUUID, 290 | getDescriptorUUID: getDescriptorUUID 291 | }; 292 | })); -------------------------------------------------------------------------------- /libs/bleat/api.classic.js: -------------------------------------------------------------------------------- 1 | /* @license 2 | * 3 | * BLE Abstraction Tool: core functionality - classic specification 4 | * 5 | * The MIT License (MIT) 6 | * 7 | * Copyright (c) 2016 Rob Moran 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in all 17 | * copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | * SOFTWARE. 26 | */ 27 | 28 | // https://github.com/umdjs/umd 29 | (function (root, factory) { 30 | if (typeof define === 'function' && define.amd) { 31 | // AMD. Register as an anonymous module. 32 | define(['bluetooth.helpers'], factory); 33 | } else if (typeof exports === 'object') { 34 | // Node. Does not work with strict CommonJS 35 | module.exports = factory(require('./bluetooth.helpers')); 36 | } else { 37 | // Browser globals with support for web workers (root is window) 38 | root.bleat = factory(root.bleatHelpers); 39 | } 40 | }(this, function(helpers) { 41 | "use strict"; 42 | 43 | var adapter = null; 44 | var adapters = {}; 45 | 46 | // Helpers 47 | function raiseError(errorFn, msg) { 48 | return function(error) { 49 | if (errorFn) errorFn(msg + ": " + error); 50 | }; 51 | } 52 | 53 | function executeFn(fn) { 54 | return function() { 55 | if (typeof fn === "function") { 56 | var args = [].slice.call(arguments); 57 | fn.apply(this, args); 58 | } 59 | }; 60 | } 61 | 62 | function AsyncWait(finishFn, errorFn) { 63 | var count = 0; 64 | var callbackAdded = false; 65 | this.addCallback = function(fn) { 66 | count++; 67 | callbackAdded = true; 68 | return function() { 69 | if (fn) fn.apply(null, arguments); 70 | if (--count === 0 && finishFn) finishFn(); 71 | }; 72 | }; 73 | this.error = function() { 74 | if (errorFn) errorFn.apply(null, arguments); 75 | if (--count === 0 && finishFn) finishFn(); 76 | }; 77 | this.finish = function() { 78 | if (!callbackAdded && finishFn) finishFn(); 79 | }; 80 | } 81 | 82 | // Device Object 83 | var Device = function(deviceInfo) { 84 | this._handle = deviceInfo._handle; 85 | 86 | this.address = deviceInfo._handle; 87 | this.name = deviceInfo.name; 88 | this.serviceUUIDs = deviceInfo.uuids; 89 | this.adData = deviceInfo.adData; 90 | 91 | this.connected = false; 92 | this.services = {}; 93 | }; 94 | Device.prototype.hasService = function(serviceUUID) { 95 | return this.serviceUUIDs.some(function(uuid) { 96 | return (uuid === serviceUUID); 97 | }); 98 | }; 99 | Device.prototype.connect = function(connectFn, disconnectFn, errorFn, suppressDiscovery) { 100 | adapter.connect(this._handle, function() { 101 | this.connected = true; 102 | if (typeof errorFn === "boolean") { 103 | suppressDiscovery = errorFn; 104 | errorFn = null; 105 | } 106 | if (suppressDiscovery) return executeFn(connectFn)(); 107 | this.discoverAll(connectFn, errorFn); 108 | }.bind(this), function() { 109 | this.connected = false; 110 | this.services = {}; 111 | executeFn(disconnectFn)(); 112 | }.bind(this), raiseError(errorFn, "connect error")); 113 | }; 114 | Device.prototype.disconnect = function(errorFn) { 115 | adapter.disconnect(this._handle, raiseError(errorFn, "disconnect error")); 116 | }; 117 | Device.prototype.discoverServices = function(serviceUUIDs, completeFn, errorFn) { 118 | if (this.connected === false) return raiseError(errorFn, "discovery error")("device not connected"); 119 | if (typeof serviceUUIDs === "function") { 120 | completeFn = serviceUUIDs; 121 | serviceUUIDs = []; 122 | } else if (typeof serviceUUIDs === "string") { 123 | serviceUUIDs = [serviceUUIDs]; 124 | } 125 | adapter.discoverServices(this._handle, serviceUUIDs, function(services) { 126 | services.forEach(function(serviceInfo) { 127 | this.services[serviceInfo.uuid] = new Service(serviceInfo); 128 | }, this); 129 | 130 | if (completeFn) completeFn(); 131 | }.bind(this), raiseError(errorFn, "service discovery error")); 132 | }; 133 | Device.prototype.discoverAll = function(completeFn, errorFn) { 134 | if (this.connected === false) return raiseError(errorFn, "discovery error")("device not connected"); 135 | var wait = new AsyncWait(completeFn, errorFn); 136 | 137 | this.discoverServices(wait.addCallback(function() { 138 | Object.keys(this.services).forEach(function(serviceUUID) { 139 | var service = this.services[serviceUUID]; 140 | 141 | service.discoverIncludedServices(wait.addCallback(), wait.error); 142 | 143 | service.discoverCharacteristics(wait.addCallback(function() { 144 | Object.keys(service.characteristics).forEach(function(characteristicUUID) { 145 | var characteristic = service.characteristics[characteristicUUID]; 146 | characteristic.discoverDescriptors(wait.addCallback(), wait.error); 147 | }, this); 148 | }.bind(this)), wait.error); 149 | 150 | }, this); 151 | }.bind(this)), wait.error); 152 | 153 | wait.finish(); 154 | }; 155 | 156 | // Service Object 157 | var Service = function(serviceInfo) { 158 | this._handle = serviceInfo._handle; 159 | 160 | this.uuid = serviceInfo.uuid; 161 | this.primary = serviceInfo.primary; 162 | 163 | this.includedServices = {}; 164 | this.characteristics = {}; 165 | }; 166 | Service.prototype.discoverIncludedServices = function(serviceUUIDs, completeFn, errorFn) { 167 | if (typeof serviceUUIDs === "function") { 168 | completeFn = serviceUUIDs; 169 | serviceUUIDs = []; 170 | } else if (typeof serviceUUIDs === "string") { 171 | serviceUUIDs = [serviceUUIDs]; 172 | } 173 | adapter.discoverIncludedServices(this._handle, serviceUUIDs, function(services) { 174 | services.forEach(function(serviceInfo) { 175 | this.includedServices[serviceInfo.uuid] = new Service(serviceInfo); 176 | }, this); 177 | 178 | if (completeFn) completeFn(); 179 | }.bind(this), raiseError(errorFn, "included service discovery error")); 180 | }; 181 | Service.prototype.discoverCharacteristics = function(characteristicUUIDs, completeFn, errorFn) { 182 | if (typeof characteristicUUIDs === "function") { 183 | completeFn = characteristicUUIDs; 184 | characteristicUUIDs = []; 185 | } else if (typeof characteristicUUIDs === "string") { 186 | characteristicUUIDs = [characteristicUUIDs]; 187 | } 188 | adapter.discoverCharacteristics(this._handle, characteristicUUIDs, function(characteristics) { 189 | characteristics.forEach(function(characteristicInfo) { 190 | this.characteristics[characteristicInfo.uuid] = new Characteristic(characteristicInfo); 191 | }, this); 192 | 193 | if (completeFn) completeFn(); 194 | }.bind(this), raiseError(errorFn, "characteristic discovery error")); 195 | }; 196 | 197 | // Characteristic Object 198 | var Characteristic = function(characteristicInfo) { 199 | this._handle = characteristicInfo._handle; 200 | 201 | this.uuid = characteristicInfo.uuid; 202 | this.properties = characteristicInfo.properties; 203 | 204 | this.descriptors = {}; 205 | }; 206 | Characteristic.prototype.discoverDescriptors = function(descriptorUUIDs, completeFn, errorFn) { 207 | if (typeof descriptorUUIDs === "function") { 208 | completeFn = descriptorUUIDs; 209 | descriptorUUIDs = []; 210 | } else if (typeof descriptorUUIDs === "string") { 211 | descriptorUUIDs = [descriptorUUIDs]; 212 | } 213 | adapter.discoverDescriptors(this._handle, descriptorUUIDs, function(descriptors) { 214 | descriptors.forEach(function(descriptorInfo) { 215 | this.descriptors[descriptorInfo.uuid] = new Descriptor(descriptorInfo); 216 | }, this); 217 | 218 | if (completeFn) completeFn(); 219 | }.bind(this), raiseError(errorFn, "descriptor discovery error")); 220 | }; 221 | Characteristic.prototype.read = function(completeFn, errorFn) { 222 | adapter.readCharacteristic(this._handle, executeFn(completeFn), raiseError(errorFn, "read characteristic error")); 223 | }; 224 | Characteristic.prototype.write = function(dataView, completeFn, errorFn) { 225 | adapter.writeCharacteristic(this._handle, dataView, executeFn(completeFn), raiseError(errorFn, "write characteristic error")); 226 | }; 227 | Characteristic.prototype.enableNotify = function(notifyFn, completeFn, errorFn) { 228 | adapter.enableNotify(this._handle, executeFn(notifyFn), executeFn(completeFn), raiseError(errorFn, "enable notify error")); 229 | }; 230 | Characteristic.prototype.disableNotify = function(completeFn, errorFn) { 231 | adapter.disableNotify(this._handle, executeFn(completeFn), raiseError(errorFn, "disable notify error")); 232 | }; 233 | 234 | // Descriptor Object 235 | var Descriptor = function(descriptorInfo) { 236 | this._handle = descriptorInfo._handle; 237 | 238 | this.uuid = descriptorInfo.uuid; 239 | }; 240 | Descriptor.prototype.read = function(completeFn, errorFn) { 241 | adapter.readDescriptor(this._handle, executeFn(completeFn), raiseError(errorFn, "read descriptor error")); 242 | }; 243 | Descriptor.prototype.write = function(dataView, completeFn, errorFn) { 244 | adapter.writeDescriptor(this._handle, dataView, executeFn(completeFn), raiseError(errorFn, "write descriptor error")); 245 | }; 246 | 247 | // Main Module 248 | return { 249 | _addAdapter: function(adapterName, definition) { 250 | adapters[adapterName] = definition; 251 | adapter = definition; 252 | }, 253 | startScan: function(serviceUUIDs, foundFn, completeFn, errorFn, allowDuplicates) { 254 | if (typeof serviceUUIDs === "function") { 255 | // Service UUIDs not present, shift args. 256 | allowDuplicates = errorFn; 257 | errorFn = completeFn; 258 | completeFn = foundFn; 259 | foundFn = serviceUUIDs; 260 | serviceUUIDs = []; 261 | } else if (typeof serviceUUIDs === "string") { 262 | serviceUUIDs = [serviceUUIDs]; 263 | } 264 | adapter.stopScan(raiseError(errorFn, "stop scan error")); 265 | var devices = {}; 266 | adapter.startScan(serviceUUIDs, function(deviceInfo) { 267 | var device = new Device(deviceInfo); 268 | if (devices[device.address] && !allowDuplicates) return; 269 | devices[device.address] = device; 270 | if (foundFn) foundFn(device); 271 | }.bind(this), completeFn, raiseError(errorFn, "scan error")); 272 | }, 273 | stopScan: function(errorFn) { 274 | adapter.stopScan(raiseError(errorFn, "stop scan error")); 275 | } 276 | }; 277 | })); -------------------------------------------------------------------------------- /libs/mdl/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2015 Google Inc 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | All code in any directories or sub-directories that end with *.html or 205 | *.css is licensed under the Creative Commons Attribution International 206 | 4.0 License, which full text can be found here: 207 | https://creativecommons.org/licenses/by/4.0/legalcode. 208 | 209 | As an exception to this license, all html or css that is generated by 210 | the software at the direction of the user is copyright the user. The 211 | user has full ownership and control over such content, including 212 | whether and how they wish to license it. 213 | -------------------------------------------------------------------------------- /libs/evothings/tisensortag/tisensortag.js: -------------------------------------------------------------------------------- 1 | // File: tisensortag.js 2 | 3 | /** 4 | * @namespace 5 | * @description Top-level object that holds generic functions and sub-modules. 6 | * @public 7 | */ 8 | evothings.tisensortag = {} 9 | 10 | /** 11 | * Constant identifying the CC2650 Bluetooth Smart SensorTag. 12 | * @public 13 | */ 14 | evothings.tisensortag.CC2650_BLUETOOTH_SMART = 'CC2650 Bluetooth Smart' 15 | 16 | /** 17 | * Constant identifying the CC2541 Bluetooth Smart SensorTag. 18 | * @public 19 | */ 20 | evothings.tisensortag.CC2541_BLUETOOTH_SMART = 'CC2541 Bluetooth Smart' 21 | 22 | /** 23 | * Public. Create a SensorTag instance. 24 | * @param {string} type String with type of tag. Use constants 25 | * evothings.tisensortag.CC2650_BLUETOOTH_SMART and 26 | * evothings.tisensortag.CC2541_BLUETOOTH_SMART. 27 | * @returns {@link evothings.tisensortag.SensorTagInstance} or null 28 | * if an object of the requested type cannot be created. 29 | * @public 30 | */ 31 | evothings.tisensortag.createInstance = function(type) 32 | { 33 | // TODO: Update this function as new models are added. 34 | 35 | // Get a factory object that will add in specific methods. 36 | if (evothings.tisensortag.CC2541_BLUETOOTH_SMART == type) 37 | { 38 | var factory = evothings.tisensortag.ble.CC2541 39 | } 40 | else if (evothings.tisensortag.CC2650_BLUETOOTH_SMART == type) 41 | { 42 | var factory = evothings.tisensortag.ble.CC2650 43 | } 44 | else 45 | { 46 | return null 47 | } 48 | 49 | // Create abstract instance. 50 | var instance = evothings.tisensortag.createGenericInstance() 51 | 52 | // Add specific implementation. 53 | return factory.addInstanceMethods(instance) 54 | } 55 | 56 | /** 57 | * Create an object with functions common to all SensorTag models. 58 | * This object specifies the public interface for SensorTag instances. 59 | * @public 60 | */ 61 | evothings.tisensortag.createGenericInstance = function() 62 | { 63 | /** 64 | * @namespace 65 | * @alias evothings.tisensortag.SensorTagInstance 66 | * @description Abstract SensorTag instance object that defines a common interface. 67 | * @public 68 | */ 69 | var instance = {} 70 | 71 | /** 72 | * Internal. Default error handler function. 73 | * @instance 74 | * @private 75 | */ 76 | instance.errorFun = function(error) 77 | { 78 | console.log('SensorTag error: ' + error) 79 | } 80 | 81 | /** 82 | * Internal. Default status handler function. 83 | * @instance 84 | * @private 85 | */ 86 | instance.statusFun = function(status) 87 | { 88 | console.log('SensorTag status: ' + status) 89 | } 90 | 91 | /** 92 | * Public. Set the IR temperature notification callback. 93 | * @param fun - success callback called repeatedly: fun(data) 94 | * @param interval - update rate in milliseconds (min 300ms) 95 | * @instance 96 | * @public 97 | */ 98 | instance.temperatureCallback = function(fun, interval) 99 | { 100 | return instance 101 | } 102 | 103 | /** 104 | * Public. Set the accelerometer notification callback. 105 | * @param fun - success callback called repeatedly: fun(data) 106 | * @param interval - accelerometer rate in milliseconds. 107 | * @instance 108 | * @public 109 | */ 110 | instance.accelerometerCallback = function(fun, interval) 111 | { 112 | return instance 113 | } 114 | 115 | /** 116 | * Public. Set the humidity notification callback. 117 | * @param fun - success callback called repeatedly: fun(data) 118 | * @param interval - humidity rate in milliseconds. 119 | * @instance 120 | * @public 121 | */ 122 | instance.humidityCallback = function(fun, interval) 123 | { 124 | return instance 125 | } 126 | 127 | /** 128 | * Public. Set the magnetometer notification callback. 129 | * @param fun - success callback called repeatedly: fun(data) 130 | * @param interval - magnetometer rate in milliseconds. 131 | * @instance 132 | * @public 133 | */ 134 | instance.magnetometerCallback = function(fun, interval) 135 | { 136 | return instance 137 | } 138 | 139 | /** 140 | * Public. Set the barometer notification callback. 141 | * @param fun - success callback called repeatedly: fun(data) 142 | * @param interval - barometer rate in milliseconds. 143 | * @instance 144 | * @public 145 | */ 146 | instance.barometerCallback = function(fun, interval) 147 | { 148 | return instance 149 | } 150 | 151 | /** 152 | * Public. Set the gyroscope notification callback. 153 | * @param fun - success callback called repeatedly: fun(data) 154 | * @param interval - gyroscope rate in milliseconds. 155 | * @param axes - (optional) the axes to enable ((z << 2) | (y << 1) | x) 156 | * Only available on SensorTag CC2541. 157 | * Axis parameter values are: 158 | * 1 = X only, 2 = Y only, 159 | * 3 = X and Y, 4 = Z only, 160 | * 5 = X and Z, 6 = Y and Z, 161 | * 7 = X, Y and Z. 162 | * @instance 163 | * @public 164 | */ 165 | instance.gyroscopeCallback = function(fun, interval, axes) 166 | { 167 | return instance 168 | } 169 | 170 | /** 171 | * Public. Set the luxometer notification callback. 172 | * @param fun - success callback called repeatedly: fun(data) 173 | * @param interval - luxometer rate in milliseconds. 174 | */ 175 | instance.luxometerCallback = function(fun, interval) 176 | { 177 | return instance 178 | } 179 | 180 | /** 181 | * Public. Set the keypress notification callback. 182 | * @param fun - success callback called when a key is pressed: fun(data) 183 | * @instance 184 | * @public 185 | */ 186 | instance.keypressCallback = function(fun) 187 | { 188 | return instance 189 | } 190 | 191 | /** 192 | * Public. Set the error handler function. 193 | * @param fun - error callback: fun(error) 194 | * @instance 195 | * @public 196 | */ 197 | instance.errorCallback = function(fun) 198 | { 199 | instance.errorFun = fun 200 | 201 | return instance 202 | } 203 | 204 | /** 205 | * Public. Set the status handler function. 206 | * @param fun - callback: fun(status) 207 | * @instance 208 | * @public 209 | */ 210 | instance.statusCallback = function(fun) 211 | { 212 | instance.statusFun = fun 213 | 214 | return instance 215 | } 216 | 217 | /** 218 | * Public. Call the error handler function. 219 | * @instance 220 | * @public 221 | */ 222 | instance.callErrorCallback = function(error) 223 | { 224 | instance.errorFun && instance.errorFun(error) 225 | } 226 | 227 | /** 228 | * Public. Call the status handler function. 229 | * @instance 230 | * @public 231 | */ 232 | instance.callStatusCallback = function(status) 233 | { 234 | instance.statusFun && instance.statusFun(status) 235 | } 236 | 237 | /** 238 | * Public. Get device model number. 239 | * @instance 240 | * @public 241 | */ 242 | instance.getDeviceModel = function() 243 | { 244 | return instance.deviceModel 245 | } 246 | 247 | /** 248 | * Public. Get firmware string. 249 | * @instance 250 | * @public 251 | */ 252 | instance.getFirmwareString = function() 253 | { 254 | return instance.firmwareString 255 | } 256 | 257 | /** 258 | * Public. Checks if the Temperature sensor is available. 259 | * @preturn true if available, false if not. 260 | * @instance 261 | * @public 262 | */ 263 | instance.isTemperatureAvailable = function() 264 | { 265 | return instance 266 | } 267 | 268 | /** 269 | * Public. Checks if the accelerometer sensor is available. 270 | * @preturn true if available, false if not. 271 | * @instance 272 | * @public 273 | */ 274 | instance.isAccelerometerAvailable = function() 275 | { 276 | return false 277 | } 278 | 279 | /** 280 | * Public. Checks if the humidity sensor is available. 281 | * @preturn true if available, false if not. 282 | * @instance 283 | * @public 284 | */ 285 | instance.isHumidityAvailable = function() 286 | { 287 | return false 288 | } 289 | 290 | /** 291 | * Public. Checks if the magnetometer sensor is available. 292 | * @preturn true if available, false if not. 293 | * @instance 294 | * @public 295 | */ 296 | instance.isMagnetometerAvailable = function() 297 | { 298 | return false 299 | } 300 | 301 | /** 302 | * Public. Checks if the barometer sensor is available. 303 | * @preturn true if available, false if not. 304 | * @instance 305 | * @public 306 | */ 307 | instance.isBarometerAvailable = function() 308 | { 309 | return false 310 | } 311 | 312 | /** 313 | * Public. Checks if the gyroscope sensor is available. 314 | * @preturn true if available, false if not. 315 | * @instance 316 | * @public 317 | */ 318 | instance.isGyroscopeAvailable = function() 319 | { 320 | return false 321 | } 322 | 323 | /** 324 | * Public. Checks if movement sensor is available that 325 | * combines accelerometer, gyroscope, and magnetometer. 326 | * @preturn true if available, false if not. 327 | * @instance 328 | * @public 329 | */ 330 | instance.isMovementAvailable = function() 331 | { 332 | return false 333 | } 334 | 335 | /** 336 | * Public. Checks if the luxometer sensor is available. 337 | * @preturn true if available, false if not. 338 | * @instance 339 | * @public 340 | */ 341 | instance.isLuxometerAvailable = function() 342 | { 343 | return false 344 | } 345 | 346 | /** 347 | * Public. Checks if the keypress sensor is available. 348 | * @preturn true if available, false if not. 349 | * @instance 350 | * @public 351 | */ 352 | instance.isKeypressAvailable = function() 353 | { 354 | return false 355 | } 356 | 357 | /** 358 | * Public. Turn on temperature notification. 359 | * @instance 360 | * @public 361 | */ 362 | instance.temperatureOn = function() 363 | { 364 | return instance 365 | } 366 | 367 | /** 368 | * Public. Turn off temperature notification. 369 | * @instance 370 | * @public 371 | */ 372 | instance.temperatureOff = function() 373 | { 374 | return instance 375 | } 376 | 377 | /** 378 | * Public. Turn on accelerometer notification (SensorTag 1). 379 | * @instance 380 | * @public 381 | */ 382 | instance.accelerometerOn = function() 383 | { 384 | return instance 385 | } 386 | 387 | /** 388 | * Public. Turn off accelerometer notification (SensorTag 1). 389 | * @instance 390 | * @public 391 | */ 392 | instance.accelerometerOff = function() 393 | { 394 | return instance 395 | } 396 | 397 | /** 398 | * Public. Turn on humidity notification. 399 | * @instance 400 | * @public 401 | */ 402 | instance.humidityOn = function() 403 | { 404 | return instance 405 | } 406 | 407 | /** 408 | * Public. Turn off humidity notification. 409 | * @instance 410 | * @public 411 | */ 412 | instance.humidityOff = function() 413 | { 414 | return instance 415 | } 416 | 417 | /** 418 | * Public. Turn on magnetometer notification. 419 | * @instance 420 | * @public 421 | */ 422 | instance.magnetometerOn = function() 423 | { 424 | return instance 425 | } 426 | 427 | /** 428 | * Public. Turn off magnetometer notification (SensorTag 1). 429 | * @instance 430 | * @public 431 | */ 432 | instance.magnetometerOff = function() 433 | { 434 | return instance 435 | } 436 | 437 | /** 438 | * Public. Turn on barometer notification. 439 | * @instance 440 | * @public 441 | */ 442 | instance.barometerOn = function() 443 | { 444 | return instance 445 | } 446 | 447 | /** 448 | * Public. Turn off barometer notification. 449 | * @instance 450 | * @public 451 | */ 452 | instance.barometerOff = function() 453 | { 454 | return instance 455 | } 456 | 457 | /** 458 | * Public. Turn on gyroscope notification (SensorTag 1). 459 | * @instance 460 | * @public 461 | */ 462 | instance.gyroscopeOn = function() 463 | { 464 | return instance 465 | } 466 | 467 | /** 468 | * Public. Turn off gyroscope notification (SensorTag 1). 469 | * @instance 470 | * @public 471 | */ 472 | instance.gyroscopeOff = function() 473 | { 474 | return instance 475 | } 476 | 477 | 478 | /** 479 | * Public. Turn on luxometer notification. 480 | */ 481 | instance.luxometerOn = function() 482 | { 483 | return instance 484 | } 485 | 486 | /** 487 | * Public. Turn off luxometer notification. 488 | */ 489 | instance.luxometerOff = function() 490 | { 491 | return instance 492 | } 493 | 494 | /** 495 | * Public. Turn on keypress notification. 496 | * @instance 497 | * @public 498 | */ 499 | instance.keypressOn = function() 500 | { 501 | return instance 502 | } 503 | 504 | /** 505 | * Public. Turn off keypress notification. 506 | * @instance 507 | * @public 508 | */ 509 | instance.keypressOff = function() 510 | { 511 | return instance 512 | } 513 | 514 | /** 515 | * Convert Celsius to Fahrenheit. 516 | * @param celsius Temperature in Celsius. 517 | * @returns Temperature converted to Fahrenheit. 518 | * @public 519 | */ 520 | instance.celsiusToFahrenheit = function(celsius) 521 | { 522 | return (celsius * 9 / 5) + 32 523 | } 524 | 525 | return instance 526 | } 527 | 528 | // Load TI SensorTag library components. 529 | evothings.loadScripts( 530 | [ 531 | 'libs/evothings/easyble/easyble.js', 532 | 'libs/evothings/tisensortag/tisensortag-ble.js', // Abstract object for BLE tags 533 | 'libs/evothings/tisensortag/tisensortag-ble-cc2541.js', // Specific object for CC2541 534 | 'libs/evothings/tisensortag/tisensortag-ble-cc2650.js' // Specific object for CC2650 535 | ]) 536 | -------------------------------------------------------------------------------- /libs/evothings/tisensortag/tisensortag-ble-cc2541.js: -------------------------------------------------------------------------------- 1 | // Documentation for TI SensorTag CC2541: 2 | // http://processors.wiki.ti.com/index.php/SensorTag_User_Guide 3 | // http://processors.wiki.ti.com/index.php/File:BLE_SensorTag_GATT_Server.pdf 4 | 5 | ;(function() 6 | { 7 | evothings.tisensortag.ble.CC2541 = {} 8 | 9 | /** 10 | * @namespace 11 | * @description Internal implementation of JavaScript library for the TI SensorTag CC2541. 12 | * @alias evothings.tisensortag.ble.CC2541 13 | */ 14 | var sensortag = {} 15 | 16 | evothings.tisensortag.ble.CC2541 = sensortag 17 | 18 | /** 19 | * Create a SensorTag CC2541 instance. 20 | * @returns {@link evothings.tisensortag.SensorTagInstance} 21 | * @private 22 | */ 23 | sensortag.addInstanceMethods = function(anInstance) 24 | { 25 | /** 26 | * @namespace 27 | * @alias evothings.tisensortag.SensorTagInstanceBLE_CC2541 28 | * @description SensorTag CC2541 instance object. 29 | * @public 30 | */ 31 | var instance = anInstance 32 | 33 | // Add generic BLE instance methods. 34 | evothings.tisensortag.ble.addInstanceMethods(instance) 35 | 36 | /** 37 | * The device model. 38 | * @instance 39 | * @public 40 | */ 41 | instance.deviceModel = 'CC2541' 42 | 43 | /** 44 | * Determine if a BLE device is a SensorTag CC2541. 45 | * Checks for the CC2541 using the advertised name. 46 | * @instance 47 | * @public 48 | */ 49 | instance.deviceIsSensorTag = function(device) 50 | { 51 | return (device != null) && 52 | (device.advertisementData != null) && 53 | (device.advertisementData.kCBAdvDataLocalName == 54 | 'SensorTag') 55 | } 56 | 57 | /** 58 | * Public. Set the accelerometer notification callback. 59 | * @param fun - success callback called repeatedly: fun(data) 60 | * @param interval - accelerometer rate in milliseconds. 61 | * @instance 62 | * @public 63 | */ 64 | instance.accelerometerCallback = function(fun, interval) 65 | { 66 | instance.accelerometerFun = fun 67 | instance.accelerometerConfig = [1] // on 68 | instance.accelerometerInterval = interval 69 | instance.requiredServices.push(instance.ACCELEROMETER.SERVICE) 70 | 71 | return instance 72 | } 73 | 74 | /** 75 | * Public. Set the gyroscope notification callback. 76 | * @param fun - success callback called repeatedly: fun(data) 77 | * @param interval - gyroscope rate in milliseconds. 78 | * @param axes - the axes to enable ((z << 2) | (y << 1) | x) 79 | * Axis parameter values are: 80 | * 1 = X only, 2 = Y only, 81 | * 3 = X and Y, 4 = Z only, 82 | * 5 = X and Z, 6 = Y and Z, 83 | * 7 = X, Y and Z. 84 | * @instance 85 | * @public 86 | */ 87 | instance.gyroscopeCallback = function(fun, interval, axes) 88 | { 89 | if ('undefined' == typeof axes) 90 | { 91 | axes = 7 // 7 = enable all axes 92 | } 93 | instance.gyroscopeFun = fun 94 | instance.gyroscopeConfig = [axes] 95 | instance.gyroscopeInterval = Math.max(100, interval) 96 | instance.requiredServices.push(instance.GYROSCOPE.SERVICE) 97 | 98 | return instance 99 | } 100 | 101 | /** 102 | * Public. Set the magnetometer notification callback. 103 | * @param fun - success callback called repeatedly: fun(data) 104 | * @param interval - magnetometer rate in milliseconds. 105 | * @instance 106 | * @public 107 | */ 108 | instance.magnetometerCallback = function(fun, interval) 109 | { 110 | instance.magnetometerFun = fun 111 | instance.magnetometerConfig = [1] // on 112 | instance.magnetometerInterval = interval 113 | instance.requiredServices.push(instance.MAGNETOMETER.SERVICE) 114 | 115 | return instance 116 | } 117 | 118 | /** 119 | * Internal. 120 | * @instance 121 | * @private 122 | */ 123 | instance.activateSensorsImpl = function() 124 | { 125 | // Debug logging. 126 | //console.log('-------------------- SERVICES --------------------') 127 | //sensortag.logServices(instance.device) 128 | //console.log('---------------------- END -----------------------') 129 | 130 | instance.temperatureOn() 131 | instance.humidityOn() 132 | instance.barometerOn() 133 | instance.accelerometerOn() 134 | instance.magnetometerOn() 135 | instance.gyroscopeOn() 136 | instance.keypressOn() 137 | } 138 | 139 | /** 140 | * SensorTag CC2541. 141 | * Public. Turn on accelerometer notification. 142 | * @instance 143 | * @public 144 | */ 145 | instance.accelerometerOn = function() 146 | { 147 | instance.sensorOn( 148 | instance.ACCELEROMETER, 149 | instance.accelerometerConfig, 150 | instance.accelerometerInterval, 151 | instance.accelerometerFun 152 | ) 153 | 154 | return instance 155 | } 156 | 157 | /** 158 | * SensorTag CC2541. 159 | * Public. Turn off accelerometer notification. 160 | * @instance 161 | * @public 162 | */ 163 | instance.accelerometerOff = function() 164 | { 165 | instance.sensorOff(instance.ACCELEROMETER) 166 | 167 | return instance 168 | } 169 | 170 | /** 171 | * SensorTag CC2541. 172 | * Public. Turn on gyroscope notification. 173 | * @instance 174 | * @public 175 | */ 176 | instance.gyroscopeOn = function() 177 | { 178 | instance.sensorOn( 179 | instance.GYROSCOPE, 180 | instance.gyroscopeConfig, 181 | instance.gyroscopeInterval, 182 | instance.gyroscopeFun 183 | ) 184 | 185 | return instance 186 | } 187 | 188 | /** 189 | * Public. Turn off gyroscope notification (SensorTag CC2541). 190 | * @instance 191 | * @public 192 | */ 193 | instance.gyroscopeOff = function() 194 | { 195 | instance.sensorOff(instance.GYROSCOPE) 196 | 197 | return instance 198 | } 199 | 200 | /** 201 | * Public. Turn on magnetometer notification (SensorTag CC2541). 202 | * @instance 203 | * @public 204 | */ 205 | instance.magnetometerOn = function() 206 | { 207 | instance.sensorOn( 208 | instance.MAGNETOMETER, 209 | instance.magnetometerConfig, 210 | instance.magnetometerInterval, 211 | instance.magnetometerFun 212 | ) 213 | 214 | return instance 215 | } 216 | 217 | /** 218 | * Public. Turn off magnetometer notification (SensorTag CC2541). 219 | * @instance 220 | * @public 221 | */ 222 | instance.magnetometerOff = function() 223 | { 224 | instance.sensorOff(instance.MAGNETOMETER) 225 | 226 | return instance 227 | } 228 | 229 | /** 230 | * SensorTag CC2541. 231 | * Public. Turn on barometer notification. 232 | * @instance 233 | * @public 234 | */ 235 | instance.barometerOn = function() 236 | { 237 | // First fetch barometer calibration data, 238 | // then enable the barometer. 239 | instance.barometerCalibrate(function() 240 | { 241 | instance.sensorOn( 242 | instance.BAROMETER, 243 | instance.barometerConfig, 244 | instance.barometerInterval, 245 | instance.barometerFun 246 | ) 247 | }) 248 | 249 | return instance 250 | } 251 | 252 | /** 253 | * SensorTag CC2541. 254 | * Private. Enable barometer calibration mode. 255 | * @instance 256 | * @private 257 | */ 258 | instance.barometerCalibrate = function(callback) 259 | { 260 | instance.device.writeCharacteristic( 261 | instance.BAROMETER.CONFIG, 262 | new Uint8Array([2]), 263 | function() 264 | { 265 | instance.device.readCharacteristic( 266 | instance.BAROMETER.CALIBRATION, 267 | function(data) 268 | { 269 | data = new Uint8Array(data) 270 | instance.barometerCalibrationData = 271 | [ 272 | evothings.util.littleEndianToUint16(data, 0), 273 | evothings.util.littleEndianToUint16(data, 2), 274 | evothings.util.littleEndianToUint16(data, 4), 275 | evothings.util.littleEndianToUint16(data, 6), 276 | evothings.util.littleEndianToInt16(data, 8), 277 | evothings.util.littleEndianToInt16(data, 10), 278 | evothings.util.littleEndianToInt16(data, 12), 279 | evothings.util.littleEndianToInt16(data, 14) 280 | ] 281 | callback() 282 | }, 283 | function(error) 284 | { 285 | console.log('CC2541 Barometer calibration failed: ' + error) 286 | }) 287 | }, 288 | instance.errorFun) 289 | 290 | return instance 291 | } 292 | 293 | /** 294 | * SensorTag CC2541. 295 | * Calculate accelerometer values from raw data. 296 | * @param data - an Uint8Array. 297 | * @return Object with fields: x, y, z. 298 | * @instance 299 | * @public 300 | */ 301 | instance.getAccelerometerValues = function(data) 302 | { 303 | // Set divisor based on firmware version. 304 | var divisors = {x: 16.0, y: -16.0, z: 16.0} 305 | 306 | // Calculate accelerometer values. 307 | var ax = evothings.util.littleEndianToInt8(data, 0) / divisors.x 308 | var ay = evothings.util.littleEndianToInt8(data, 1) / divisors.y 309 | var az = evothings.util.littleEndianToInt8(data, 2) / divisors.z 310 | 311 | // Return result. 312 | return { x: ax, y: ay, z: az } 313 | } 314 | 315 | /** 316 | * SensorTag CC2541. 317 | * Calculate gyroscope values from raw data. 318 | * @param data - an Uint8Array. 319 | * @return Object with fields: x, y, z. 320 | * @instance 321 | * @public 322 | */ 323 | instance.getGyroscopeValues = function(data) 324 | { 325 | // Calculate gyroscope values. NB: x,y,z has a weird order. 326 | var gy = -evothings.util.littleEndianToInt16(data, 0) * 500.0 / 65536.0 327 | var gx = evothings.util.littleEndianToInt16(data, 2) * 500.0 / 65536.0 328 | var gz = evothings.util.littleEndianToInt16(data, 4) * 500.0 / 65536.0 329 | 330 | // Return result. 331 | return { x: gx, y: gy, z: gz } 332 | } 333 | 334 | /** 335 | * SensorTag CC2541. 336 | * Calculate magnetometer values from raw data. 337 | * @param data - an Uint8Array. 338 | * @return Object with fields: x, y, z. 339 | * @instance 340 | * @public 341 | */ 342 | instance.getMagnetometerValues = function(data) 343 | { 344 | // Magnetometer values (Micro Tesla). 345 | var mx = evothings.util.littleEndianToInt16(data, 0) * (2000.0 / 65536.0) * -1 346 | var my = evothings.util.littleEndianToInt16(data, 2) * (2000.0 / 65536.0) * -1 347 | var mz = evothings.util.littleEndianToInt16(data, 4) * (2000.0 / 65536.0) 348 | 349 | // Return result. 350 | return { x: mx, y: my, z: mz } 351 | } 352 | 353 | /** 354 | * SensorTag CC2541. 355 | * Calculate barometer values from raw data. 356 | * @instance 357 | * @public 358 | */ 359 | instance.getBarometerValues = function(data) 360 | { 361 | var t = evothings.util.littleEndianToInt16(data, 0) 362 | var p = evothings.util.littleEndianToUint16(data, 2) 363 | var c = instance.barometerCalibrationData 364 | 365 | var S = c[2] + ((c[3] * t) / 131072) + ((c[4] * (t * t)) / 17179869184.0) 366 | var O = (c[5] * 16384.0) + (((c[6] * t) / 8)) + ((c[7] * (t * t)) / 524288.0) 367 | var Pa = (((S * p) + O) / 16384.0) 368 | var pInterpreted = Pa / 100.0 369 | 370 | return { pressure: pInterpreted } 371 | } 372 | 373 | /** 374 | * Calculate temperature values from raw data. 375 | * @param data - an Uint8Array. 376 | * @return Object with fields: ambientTemperature, targetTemperature. 377 | * @instance 378 | * @public 379 | */ 380 | instance.getTemperatureValues = function(data) 381 | { 382 | // Calculate ambient temperature (Celsius). 383 | var ac = evothings.util.littleEndianToUint16(data, 2) / 128.0 384 | 385 | // Calculate target temperature (Celsius, based on ambient). 386 | var Vobj2 = evothings.util.littleEndianToInt16(data, 0) * 0.00000015625 387 | var Tdie = ac + 273.15 388 | var S0 = 6.4E-14 // calibration factor 389 | var a1 = 1.750E-3 390 | var a2 = -1.678E-5 391 | var b0 = -2.940E-5 392 | var b1 = -5.700E-7 393 | var b2 = 4.630E-9 394 | var c2 = 13.4 395 | var Tref = 298.15 396 | var S = S0 * (1 + a1 * (Tdie - Tref) + a2 * Math.pow((Tdie - Tref), 2)) 397 | var Vos = b0 + b1 * (Tdie - Tref) + b2 * Math.pow((Tdie - Tref), 2) 398 | var fObj = (Vobj2 - Vos) + c2 * Math.pow((Vobj2 - Vos), 2) 399 | var tObj = Math.pow(Math.pow(Tdie, 4 ) + (fObj / S), 0.25) 400 | var tc = tObj - 273.15 401 | 402 | // Return result. 403 | return { ambientTemperature: ac, targetTemperature: tc } 404 | } 405 | 406 | /** 407 | * Public. Checks if the Temperature sensor is available. 408 | * @preturn true if available, false if not. 409 | * @instance 410 | * @public 411 | */ 412 | instance.isTemperatureAvailable = function() 413 | { 414 | return true 415 | } 416 | 417 | /** 418 | * Public. Checks if the accelerometer sensor is available. 419 | * @preturn true if available, false if not. 420 | * @instance 421 | * @public 422 | */ 423 | instance.isAccelerometerAvailable = function() 424 | { 425 | return true 426 | } 427 | 428 | /** 429 | * Public. Checks if the humidity sensor is available. 430 | * @preturn true if available, false if not. 431 | * @instance 432 | * @public 433 | */ 434 | instance.isHumidityAvailable = function() 435 | { 436 | return true 437 | } 438 | 439 | /** 440 | * Public. Checks if the magnetometer sensor is available. 441 | * @preturn true if available, false if not. 442 | * @instance 443 | * @public 444 | */ 445 | instance.isMagnetometerAvailable = function() 446 | { 447 | return true 448 | } 449 | 450 | /** 451 | * Public. Checks if the barometer sensor is available. 452 | * @preturn true if available, false if not. 453 | * @instance 454 | * @public 455 | */ 456 | instance.isBarometerAvailable = function() 457 | { 458 | return true 459 | } 460 | 461 | /** 462 | * Public. Checks if the gyroscope sensor is available. 463 | * @preturn true if available, false if not. 464 | * @instance 465 | * @public 466 | */ 467 | instance.isGyroscopeAvailable = function() 468 | { 469 | return true 470 | } 471 | 472 | /** 473 | * Public. Checks if the keypress sensor is available. 474 | * @preturn true if available, false if not. 475 | * @instance 476 | * @public 477 | */ 478 | instance.isKeypressAvailable = function() 479 | { 480 | return true 481 | } 482 | 483 | // Finally, return the SensorTag instance object. 484 | return instance 485 | } 486 | })() 487 | -------------------------------------------------------------------------------- /libs/evothings/tisensortag/tisensortag-ble-cc2650.js: -------------------------------------------------------------------------------- 1 | 2 | ;(function() 3 | { 4 | evothings.tisensortag.ble.CC2650 = {} 5 | 6 | /** 7 | * @namespace 8 | * @description Internal implementation of JavaScript library for the TI SensorTag CC2650. 9 | * @alias evothings.tisensortag.ble.CC2650 10 | */ 11 | var sensortag = {} 12 | 13 | evothings.tisensortag.ble.CC2650 = sensortag 14 | 15 | /** 16 | * Create a SensorTag CC2650 instance. 17 | * @returns {@link evothings.tisensortag.SensorTagInstanceBLE_CC2650} 18 | * @private 19 | */ 20 | sensortag.addInstanceMethods = function(anInstance) 21 | { 22 | /** 23 | * @namespace 24 | * @alias evothings.tisensortag.SensorTagInstanceBLE_CC2650 25 | * @description SensorTag CC2650 instance object. 26 | * @public 27 | */ 28 | var instance = anInstance 29 | 30 | // Add generic BLE instance methods. 31 | evothings.tisensortag.ble.addInstanceMethods(instance) 32 | 33 | /** 34 | * The device model. 35 | * @instance 36 | * @public 37 | */ 38 | instance.deviceModel = 'CC2650' 39 | 40 | /** 41 | * Determine if a BLE device is a SensorTag CC2650. 42 | * Checks for the CC2650 using the advertised name. 43 | * @instance 44 | * @public 45 | */ 46 | instance.deviceIsSensorTag = function(device) 47 | { 48 | return (device != null) && 49 | (device.advertisementData != null) && 50 | (device.advertisementData.kCBAdvDataLocalName == 51 | 'CC2650 SensorTag') 52 | } 53 | 54 | /** 55 | * Public. Set the accelerometer notification callback. 56 | * @param fun - success callback called repeatedly: fun(data) 57 | * @param interval - accelerometer rate in milliseconds. 58 | * @instance 59 | * @public 60 | */ 61 | instance.accelerometerCallback = function(fun, interval) 62 | { 63 | instance.accelerometerFun = fun 64 | 65 | // Enable movement callback. 66 | instance.setupCatchAllMovementCallback(interval) 67 | 68 | return instance 69 | } 70 | 71 | /** 72 | * Public. Set the gyroscope notification callback. 73 | * Enables all axes. 74 | * @param fun - success callback called repeatedly: fun(data) 75 | * @param interval - gyroscope rate in milliseconds. 76 | * @instance 77 | * @public 78 | */ 79 | instance.gyroscopeCallback = function(fun, interval) 80 | { 81 | instance.gyroscopeFun = fun 82 | 83 | // Enable movement callback. 84 | instance.setupCatchAllMovementCallback(interval) 85 | 86 | return instance 87 | } 88 | 89 | /** 90 | * Public. Set the magnetometer notification callback. 91 | * @param fun - success callback called repeatedly: fun(data) 92 | * @param interval - magnetometer rate in milliseconds. 93 | * @instance 94 | * @public 95 | */ 96 | instance.magnetometerCallback = function(fun, interval) 97 | { 98 | instance.magnetometerFun = fun 99 | 100 | // Enable movement callback. 101 | instance.setupCatchAllMovementCallback(interval) 102 | 103 | return instance 104 | } 105 | 106 | /** 107 | * Private. Setup the movement sensor to call accelerometer, 108 | * gyroscope and magnetometer callbacks. 109 | * @param fun - success callback called repeatedly: fun(data) 110 | * @param interval - magnetometer rate in milliseconds. 111 | * @instance 112 | * @private 113 | */ 114 | instance.setupCatchAllMovementCallback = function(interval) 115 | { 116 | // Only do this once. 117 | if (instance.catchAllMovementCallbackEnabled) { return } 118 | instance.catchAllMovementCallbackEnabled = true 119 | 120 | // Call all of the movement service's callbacks 121 | // (accelerometer, gyroscope, magnetometer) 122 | 123 | // Set the config that turns on the needed sensors. 124 | // magnetometer on: 64 (1000000) (seems to not work in ST2 FW 0.89) 125 | // 3-axis acc. on: 56 (0111000) 126 | // 3-axis gyro on: 7 (0000111) 127 | // 3-axis acc. + 3-axis gyro on: 63 (0111111) 128 | // 3-axis acc. + 3-axis gyro + magnetometer on: 127 (1111111) 129 | instance.movementCallback( 130 | function(data) 131 | { 132 | instance.accelerometerFun && instance.accelerometerFun(data) 133 | instance.magnetometerFun && instance.magnetometerFun(data) 134 | instance.gyroscopeFun && instance.gyroscopeFun(data) 135 | }, 136 | interval, 137 | 127) 138 | } 139 | 140 | /** 141 | * SensorTag CC2650. 142 | * Public. Set the movement notification callback. 143 | * Movement callbacks are routed back to accelerometer, 144 | * gyroscope, and magnetometer callbacks. 145 | * @param fun - Success callback called repeatedly: fun(data) 146 | * @param interval - Sensor rate in milliseconds. 147 | * @param sensors - Set the config that turns on the needed sensors:
148 | * Magnetometer on: 64 (1000000) (seems to not work in ST2 FW 0.89)
149 | * 3-axis acc. on: 56 (0111000)
150 | * 3-axis gyro on: 7 (0000111)
151 | * 3-axis acc. + 3-axis gyro on: 63 (0111111)
152 | * 3-axis acc. + 3-axis gyro + magnetometer on: 127 (1111111)
153 | * @instance 154 | * @public 155 | */ 156 | instance.movementCallback = function(fun, interval, sensors) 157 | { 158 | // Callback for all movement sensors (accelerometer, gyroscope, magnetometer). 159 | instance.movementFun = fun 160 | 161 | // Set the config that turns on the needed sensors. 162 | instance.movementConfig = [sensors, 0] 163 | instance.movementInterval = interval 164 | instance.requiredServices.push(instance.MOVEMENT.SERVICE) 165 | 166 | return instance 167 | } 168 | 169 | /** 170 | * Public. Set the luxometer notification callback. 171 | * @param fun - success callback called repeatedly: fun(data) 172 | * @param interval - luxometer rate in milliseconds. 173 | */ 174 | instance.luxometerCallback = function(fun, interval) 175 | { 176 | instance.luxometerFun = fun 177 | instance.luxometerConfig = [1] // on 178 | instance.luxometerInterval = Math.max(1000, interval) 179 | instance.requiredServices.push(instance.LUXOMETER.SERVICE) 180 | 181 | return instance 182 | } 183 | 184 | /** 185 | * SensorTag CC2650. 186 | * Internal. 187 | * @instance 188 | * @private 189 | */ 190 | instance.activateSensorsImpl = function() 191 | { 192 | // Debug logging. 193 | //console.log('-------------------- SERVICES --------------------') 194 | //sensortag.logServices(instance.device) 195 | //console.log('---------------------- END -----------------------') 196 | 197 | instance.temperatureOn() 198 | instance.humidityOn() 199 | instance.barometerOn() 200 | instance.luxometerOn() 201 | instance.movementOn() 202 | instance.keypressOn() 203 | } 204 | 205 | /** 206 | * SensorTag CC2650. 207 | * Public. Turn on barometer notification. 208 | * @instance 209 | * @public 210 | */ 211 | instance.barometerOn = function() 212 | { 213 | instance.sensorOn( 214 | instance.BAROMETER, 215 | instance.barometerConfig, 216 | instance.barometerInterval, 217 | instance.barometerFun 218 | ) 219 | 220 | return instance 221 | } 222 | 223 | /** 224 | * SensorTag CC2650. 225 | * Public. Turn on movement notification (SensorTag 2). 226 | * @instance 227 | * @public 228 | */ 229 | instance.movementOn = function() 230 | { 231 | instance.sensorOn( 232 | instance.MOVEMENT, 233 | instance.movementConfig, 234 | instance.movementInterval, 235 | instance.movementFun 236 | ) 237 | 238 | return instance 239 | } 240 | 241 | /** 242 | * SensorTag CC2650. 243 | * Public. Turn off movement notification (SensorTag 2). 244 | * @instance 245 | * @public 246 | */ 247 | instance.movementOff = function() 248 | { 249 | instance.sensorOff(instance.MOVEMENT) 250 | 251 | return instance 252 | } 253 | 254 | /** 255 | * SensorTag CC2650. 256 | * Public. Turn on luxometer notification. 257 | * @instance 258 | * @public 259 | */ 260 | instance.luxometerOn = function() 261 | { 262 | instance.sensorOn( 263 | instance.LUXOMETER, 264 | instance.luxometerConfig, 265 | instance.luxometerInterval, 266 | instance.luxometerFun 267 | ) 268 | 269 | return instance 270 | } 271 | 272 | /** 273 | * SensorTag CC2650. 274 | * Public. Turn off luxometer notification. 275 | * @instance 276 | * @public 277 | */ 278 | instance.luxometerOff = function() 279 | { 280 | instance.sensorOff(instance.LUXOMETER) 281 | 282 | return instance 283 | } 284 | 285 | /** 286 | * SensorTag CC2650. 287 | * Calculate temperature values from raw data. 288 | * @param data - an Uint8Array. 289 | * @return Object with fields: ambientTemperature, targetTemperature. 290 | * @instance 291 | * @public 292 | */ 293 | instance.getTemperatureValues = function(data) 294 | { 295 | // Calculate ambient temperature (Celsius). 296 | var ac = evothings.util.littleEndianToUint16(data, 2) / 128.0 297 | 298 | // Calculate target temperature (Celsius). 299 | var tc = evothings.util.littleEndianToInt16(data, 0) 300 | tc = (tc >> 2) * 0.03125 301 | 302 | // Return result. 303 | return { ambientTemperature: ac, targetTemperature: tc } 304 | } 305 | 306 | /** 307 | * SensorTag CC2650. 308 | * Calculate humidity values from raw data. 309 | * @param data - an Uint8Array. 310 | * @return Object with fields: humidityTemperature, relativeHumidity. 311 | * @instance 312 | * @public 313 | */ 314 | instance.getHumidityValues = function(data) 315 | { 316 | // Calculate the humidity temperature (Celsius). 317 | var tData = evothings.util.littleEndianToInt16(data, 0); 318 | var tc = (tData / 65536.0) * 165 - 40; 319 | 320 | // Calculate the relative humidity. 321 | var hData = evothings.util.littleEndianToUint16(data, 2); 322 | var h = hData * 100 / 65536.0; 323 | 324 | // Return result. 325 | return { humidityTemperature: tc, relativeHumidity: h } 326 | } 327 | 328 | /** 329 | * SensorTag CC2650. 330 | * Calculate accelerometer values from raw data. 331 | * @param data - an Uint8Array. 332 | * @return Object with fields: x, y, z. 333 | * @instance 334 | * @public 335 | */ 336 | instance.getAccelerometerValues = function(data) 337 | { 338 | var divisors = {x: -16384.0, y: 16384.0, z: -16384.0} 339 | 340 | // Calculate accelerometer values. 341 | var ax = evothings.util.littleEndianToInt16(data, 6) / divisors.x 342 | var ay = evothings.util.littleEndianToInt16(data, 8) / divisors.y 343 | var az = evothings.util.littleEndianToInt16(data, 10) / divisors.z 344 | 345 | // Return result. 346 | return { x: ax, y: ay, z: az } 347 | } 348 | 349 | /** 350 | * SensorTag CC2650. 351 | * Calculate gyroscope values from raw data. 352 | * @param data - an Uint8Array. 353 | * @return Object with fields: x, y, z. 354 | * @instance 355 | * @public 356 | */ 357 | instance.getGyroscopeValues = function(data) 358 | { 359 | // Calculate gyroscope values. 360 | var gx = evothings.util.littleEndianToInt16(data, 0) * 255.0 / 32768.0 361 | var gy = evothings.util.littleEndianToInt16(data, 2) * 255.0 / 32768.0 362 | var gz = evothings.util.littleEndianToInt16(data, 4) * 255.0 / 32768.0 363 | 364 | // Return result. 365 | return { x: gx, y: gy, z: gz } 366 | } 367 | 368 | /** 369 | * SensorTag CC2650. 370 | * Calculate barometer values from raw data. 371 | * @instance 372 | * @public 373 | */ 374 | instance.getBarometerValues = function(data) 375 | { 376 | var rawP = (data[5] << 16) + (data[4] << 8) + data[3]; 377 | var pInterpreted = rawP / 100.0; 378 | 379 | return { pressure: pInterpreted } 380 | } 381 | 382 | /** 383 | * SensorTag CC2650. 384 | * Calculate magnetometer values from raw data. 385 | * @param data - an Uint8Array. 386 | * @return Object with fields: x, y, z. 387 | * @instance 388 | * @public 389 | */ 390 | instance.getMagnetometerValues = function(data) 391 | { 392 | // Magnetometer values (Micro Tesla). 393 | var mx = evothings.util.littleEndianToInt16(data, 12) * (4912.0 / 32768.0) 394 | var my = evothings.util.littleEndianToInt16(data, 14) * (4912.0 / 32768.0) 395 | var mz = evothings.util.littleEndianToInt16(data, 16) * (4912.0 / 32768.0) 396 | 397 | // Return result. 398 | return { x: mx, y: my, z: mz } 399 | } 400 | 401 | /** 402 | * SensorTag CC2650. 403 | * Calculate luxometer values from raw data. 404 | * @param data - an Uint8Array. 405 | * @return Light level in lux units. 406 | * @instance 407 | * @public 408 | */ 409 | instance.getLuxometerValue = function(data) 410 | { 411 | // Calculate the light level. 412 | var value = evothings.util.littleEndianToUint16(data, 0) 413 | 414 | // Extraction of luxometer value, based on sfloatExp2ToDouble 415 | // from BLEUtility.m in Texas Instruments TI BLE SensorTag 416 | // iOS app source code. 417 | // TODO: move to util.js 418 | var mantissa = value & 0x0FFF 419 | var exponent = value >> 12 420 | 421 | magnitude = Math.pow(2, exponent) 422 | output = (mantissa * magnitude) 423 | 424 | var lux = output / 100.0 425 | 426 | // Return result. 427 | return lux 428 | } 429 | 430 | /** 431 | * Public. Checks if the Temperature sensor is available. 432 | * @preturn true if available, false if not. 433 | * @instance 434 | * @public 435 | */ 436 | instance.isTemperatureAvailable = function() 437 | { 438 | return true 439 | } 440 | 441 | /** 442 | * Public. Checks if the accelerometer sensor is available. 443 | * @preturn true if available, false if not. 444 | * @instance 445 | * @public 446 | */ 447 | instance.isAccelerometerAvailable = function() 448 | { 449 | return true 450 | } 451 | 452 | /** 453 | * Public. Checks if the humidity sensor is available. 454 | * @preturn true if available, false if not. 455 | * @instance 456 | * @public 457 | */ 458 | instance.isHumidityAvailable = function() 459 | { 460 | return true 461 | } 462 | 463 | /** 464 | * Public. Checks if the magnetometer sensor is available. 465 | * @preturn true if available, false if not. 466 | * @instance 467 | * @public 468 | */ 469 | instance.isMagnetometerAvailable = function() 470 | { 471 | return true 472 | } 473 | 474 | /** 475 | * Public. Checks if the barometer sensor is available. 476 | * @preturn true if available, false if not. 477 | * @instance 478 | * @public 479 | */ 480 | instance.isBarometerAvailable = function() 481 | { 482 | return true 483 | } 484 | 485 | /** 486 | * Public. Checks if the gyroscope sensor is available. 487 | * @preturn true if available, false if not. 488 | * @instance 489 | * @public 490 | */ 491 | instance.isGyroscopeAvailable = function() 492 | { 493 | return true 494 | } 495 | 496 | /** 497 | * Public. Checks if movement sensor is available that 498 | * combines accelerometer, gyroscope, and magnetometer. 499 | * @preturn true if available, false if not. 500 | * @instance 501 | * @public 502 | */ 503 | instance.isMovementAvailable = function() 504 | { 505 | return true 506 | } 507 | 508 | /** 509 | * Public. Checks if the luxometer sensor is available. 510 | * @preturn true if available, false if not. 511 | * @instance 512 | * @public 513 | */ 514 | instance.isLuxometerAvailable = function() 515 | { 516 | return true 517 | } 518 | 519 | /** 520 | * Public. Checks if the keypress sensor is available. 521 | * @preturn true if available, false if not. 522 | * @instance 523 | * @public 524 | */ 525 | instance.isKeypressAvailable = function() 526 | { 527 | return true 528 | } 529 | 530 | // Finally, return the SensorTag instance object. 531 | return instance 532 | } 533 | })() 534 | --------------------------------------------------------------------------------