Last before splitting app up

This commit is contained in:
Martin Donnelly 2016-06-01 16:03:59 +01:00
parent ee5a5f9f6f
commit ee73adae39
57 changed files with 801 additions and 702 deletions

1
.gitignore vendored
View File

@ -178,3 +178,4 @@ xcuserdata
*.xcuserstate
dist
www/libs

View File

@ -18,10 +18,45 @@
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
<icon src="res/android/android-chrome-36x36.png" density="ldpi"/>
<icon src="res/android/mipmap-mdpi/ic_launcher.png" density="mdpi"/>
<icon src="res/android/mipmap-hdpi/ic_launcher.png" density="hdpi"/>
<icon src="res/android/mipmap-xhdpi/ic_launcher.png" density="xhdpi"/>
<icon src="res/android/mipmap-xxhdpi/ic_launcher.png" density="xxhdpi"/>
<icon src="res/android/mipmap-xxxhdpi/ic_launcher.png" density="xxxhdpi"/>
</platform>
<platform name="ios">
<preference name="StatusBarStyle" value="lightcontent"/>
<preference name="DisallowOverscroll" value="true" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<!-- iOS 8.0+ -->
<!-- iPhone 6 Plus -->
<icon src="res/ios/icon-60@3x.png" width="180" height="180"/>
<!-- iOS 7.0+ -->
<!-- iPhone / iPod Touch -->
<icon src="res/ios/icon-60.png" width="60" height="60"/>
<icon src="res/ios/icon-60@2x.png" width="120" height="120"/>
<!-- iPad -->
<icon src="res/ios/icon-76.png" width="76" height="76"/>
<icon src="res/ios/icon-76@2x.png" width="152" height="152"/>
<!-- iOS 6.1 -->
<!-- Spotlight Icon -->
<icon src="res/ios/icon-40.png" width="40" height="40"/>
<icon src="res/ios/icon-40@2x.png" width="80" height="80"/>
<!-- iPhone / iPod Touch -->
<icon src="res/ios/icon.png" width="57" height="57"/>
<icon src="res/ios/icon@2x.png" width="114" height="114"/>
<!-- iPad -->
<icon src="res/ios/icon-72.png" width="72" height="72"/>
<icon src="res/ios/icon-72@2x.png" width="144" height="144"/>
<!-- iPhone Spotlight and Settings Icon -->
<icon src="res/ios/icon-small.png" width="29" height="29"/>
<icon src="res/ios/icon-small@2x.png" width="58" height="58"/>
<!-- iPad Spotlight and Settings Icon -->
<icon src="res/ios/icon-50.png" width="50" height="50"/>
<icon src="res/ios/icon-50@2x.png" width="100" height="100"/>
</platform>
<engine name="ios" spec="~4.1.1" />
<engine name="android" spec="~5.1.1" />

15
custom.scss Normal file
View File

@ -0,0 +1,15 @@
@import "www/libs/mui/src/sass/mui/colors";
$mui-body-bg-color: mui-color('grey', '100');
//$mui-accent-color: #bad649;
$mui-accent-color: #004c6d;
$mui-btn-accent-font-color: #004c6d;
//$mui-accent-color-dark: mui-color('green', 'A100');
$mui-accent-color-dark: #004c6d;
$mui-accent-color-light: mui-color('green', 'A400');
$mui-tab-font-color: rgba(255, 255, 255, 0.87);
$mui-appbar-bg-color: #004c6d;
// import MUI SASS
@import "www/libs/mui/src/sass/mui";

View File

@ -1,16 +1,9 @@
body {
font-family: Ubuntu, "Helvetica Neue", Helvetica, arial, sans-serif;
background-color: #004c6d;
}
#weatherIcon {
margin-left:25%;
margin-right:25%;
height:70px;
width:70px;
}
#lightR, #projR { color: red !important; }
#lightG, #projG { color: green !important; }
@ -23,21 +16,7 @@ body {
float: right;
}
/*.lightBG {
background-color: rgba(255, 255, 0, 0.3);
}
.heatingBG {
background-color: rgba(255, 0, 255, 0.3);
}
.projectorBG {
background-color: rgba(0, 255, 255, 0.3);
}*/
.mui-panel {
background-color: #015579;
}
.h105 {
height: 100px;
@ -47,9 +26,6 @@ body {
overflow: hidden;
}
.mui--text-title {
color: #ffffff;
}
.item_content {
height: 100px;
@ -212,50 +188,6 @@ body {
}
}
.material-icons {
color: #e5f7fd;
}
.material-icons.md-18 { font-size: 18px; }
.material-icons.md-24 { font-size: 24px; }
.material-icons.md-36 { font-size: 36px; }
.material-icons.md-48 { font-size: 48px; }
.material-icons.md-100 { font-size: 100px; }
/* Rules for using icons as black on a light background. */
.material-icons.md-dark { color: rgba(0, 0, 0, 0.54); }
.material-icons.md-dark.md-inactive { color: rgba(0, 0, 0, 0.26); }
/* Rules for using icons as white on a dark background. */
.material-icons.md-light { color: rgba(255, 255, 255, 1); }
.material-icons.md-light.md-inactive { color: rgba(255, 255, 255, 0.3); }
.material-icons.md-bulb {
content: "&#xE90F;"
}
/*
fan : toys
<i class="material-icons">&#xE332;</i>
bulb : lightbulb_outline
<i class="material-icons">&#xE90F;</i>
calendar: event_note
<i class="material-icons">&#xE616;</i>
projector: cast
<i class="material-icons">&#xE307;</i>
*/
.md-display {
opacity: 1;
@ -305,3 +237,24 @@ projector: cast
85% { opacity: 1; }
100% { transform: scale(1); filter: blur(5px); opacity: 0; }
}
header {
position: fixed;
top: 0;
z-index: 1;
right:0;
transition: left .2s;
width:100%;
}
.mui-tabs__bar > li.tabOnWhite > a
{
color:#78909C;
}
.mui-tabs__bar > li.mui--is-active.tabOnWhite > a
{
color:#2196F3;
}

View File

@ -379,7 +379,7 @@ body {
font-weight: 400;
line-height: 1.429;
color: rgba(0, 0, 0, 0.87);
background-color: #FFF; }
background-color: #F5F5F5; }
input,
button,
@ -497,7 +497,7 @@ h4, h5, h6 {
top: 64px; } }
.mui-appbar {
background-color: #2196F3;
background-color: #004c6d;
color: #FFF; }
/**
@ -655,21 +655,21 @@ h4, h5, h6 {
.mui-btn--accent {
color: #004c6d;
background-color: #bad649; }
background-color: #004c6d; }
.mui-btn--accent:hover, .mui-btn--accent:focus, .mui-btn--accent:active {
color: #004c6d;
background-color: #c2db5e; }
background-color: #005e87; }
.mui-btn--accent[disabled]:hover, .mui-btn--accent[disabled]:focus, .mui-btn--accent[disabled]:active {
color: #004c6d;
background-color: #bad649; }
background-color: #004c6d; }
.mui-btn--accent.mui-btn--flat {
color: #bad649;
color: #004c6d;
background-color: transparent; }
.mui-btn--accent.mui-btn--flat:hover, .mui-btn--accent.mui-btn--flat:focus, .mui-btn--accent.mui-btn--flat:active {
color: #bad649;
color: #004c6d;
background-color: #f2f2f2; }
.mui-btn--accent.mui-btn--flat[disabled]:hover, .mui-btn--accent.mui-btn--flat[disabled]:focus, .mui-btn--accent.mui-btn--flat[disabled]:active {
color: #bad649;
color: #004c6d;
background-color: transparent; }
.mui-btn--small {
@ -1266,7 +1266,7 @@ h4, h5, h6 {
.mui-select__menu {
position: absolute;
z-index: 1;
z-index: 2;
min-width: 100%;
overflow-y: auto;
padding: 8px 0;
@ -1596,13 +1596,13 @@ th {
color: rgba(255, 255, 255, 0.3); }
.mui--text-accent {
color: rgba(186, 214, 73, 0.87); }
color: rgba(0, 76, 109, 0.87); }
.mui--text-accent-secondary {
color: rgba(186, 214, 73, 0.54); }
color: rgba(0, 76, 109, 0.54); }
.mui--text-accent-hint {
color: rgba(186, 214, 73, 0.38); }
color: rgba(0, 76, 109, 0.38); }
.mui--text-black {
color: #000; }

View File

@ -1,5 +1,4 @@
<!DOCTYPE html>
<!--
<!DOCTYPE html><!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@ -18,7 +17,7 @@
under the License.
-->
<html>
<head>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
@ -28,10 +27,12 @@
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet"
href="http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700"
type="text/css">
@ -47,72 +48,72 @@
<link href="css/ripple.css" rel="stylesheet" type="text/css"/>
<link href="css/progress.css" rel="stylesheet" type="text/css"/>
<title>Sensor Toy</title>
</head>
<body>
</head>
<body class="mui--no-user-select">
<header id="header">
<div class="mui-appbar">
<ul id='app-tabs' class="mui-tabs__bar mui--z1 mui--appbar-height">
<li class="mui--is-active"><a data-mui-toggle="tab"
data-mui-controls="pane-default-1">Devices</a>
</li>
<!--<li><a data-mui-toggle="tab" data-mui-controls="pane-default-2">Tab-2</a>
</li>
<li><a data-mui-toggle="tab" data-mui-controls="pane-default-3">Tab-3</a>
</li>-->
</ul>
</div>
</header>
<div class="mui--appbar-height"></div>
<div id="tab-panes" class='' style="height:100%;">
<div class="mui-tabs__pane mui--is-active" id="pane-default-1">
<div id='app' class="mui-container">
<div>
<div class="mui-row mui--appbar-height mui--appbar-line-height">
<div class="mui-col-xs-6 mui--text-subhead">
<span class="">Devices</span>
</div>
<div class="mui-col-xs-6 mui--text-right">
<button class="mui-btn mui-btn--small mui-btn--primary"
id="scan">Scan
</button>
<button class="mui-btn mui-btn--small mui-btn--danger" id="stop"
style="display: none;">Stop
</button>
</div>
</div>
<div style="margin: 0.5rem 0 1rem 0;">
<div class="progress" id='ripple' style="display: none;">
<div class="indeterminate"></div>
</div>
</div>
<div id='app' class="mui-container">
<div class="mui-panel">
<div class="mui-row">
<div class="mui-col-xs-6">
<button class="mui-btn mui-btn--primary" id="scan">Scan</button>
<button class="mui-btn mui-btn--danger" id="stop" style="display: none;">Stop</button>
</div>
<div class="mui-col-xs-6">
<button class="mui-btn mui-btn--accent" id="longScan">Long</button>
<div id="scanResults"></div>
</div>
</div>
</div>
<div id="scanResults">
</div>
<table class="mui-table mui--text-white" id="results">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>RSI</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
<div id="frames" class="mui-container">
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="libs/mui/packages/cdn/js/mui.js"></script>
<script type="text/javascript" src="libs/bluebird/js/browser/bluebird.js"></script>
<script type="text/javascript" src="js/standards/bluetooth_company_identifiers.js"></script>
<script type="text/javascript" src="js/standards/capability.js"></script>
<script type="text/javascript" src="js/standards/battery.js"></script>
<script type="text/javascript" src="js/standards/button.js"></script>
<script type="text/javascript" src="js/mandecoder.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_accelerometer.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_barometer.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_luxometer.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_thermopile.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_humidity.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="libs/mui/packages/cdn/js/mui.js"></script>
<script type="text/javascript"
src="libs/bluebird/js/browser/bluebird.js"></script>
<script type="text/javascript"
src="js/standards/bluetooth_company_identifiers.js"></script>
<script type="text/javascript" src="js/standards/capability.js"></script>
<script type="text/javascript" src="js/standards/battery.js"></script>
<script type="text/javascript" src="js/standards/button.js"></script>
<script type="text/javascript" src="js/mandecoder.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_accelerometer.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_barometer.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_luxometer.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_thermopile.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_humidity.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_ACCEL = function(deviceId) {
var CC2650_ACCEL = function(p) {
'use strict';
this.name = 'Accelerometer';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA80-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA80-0451-4000-B000-000000000000',
@ -26,6 +28,7 @@ var CC2650_ACCEL = function(deviceId) {
this.$id = {};
this.$result = {};
this.setFrame();
this.sensorMpu9250GyroConvert = function(data) {
return data / (65536 / 500);
@ -89,7 +92,6 @@ var CC2650_ACCEL = function(deviceId) {
console.log('Starting CC2650 Accelerometer Service on ', this.deviceID);
console.log(this.serviceDef);
//Ble.startNotification(this.deviceID, , this.onButtonData.bind(this), this.onError);
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onAccelerometerData.bind(this), this.onError);
@ -139,7 +141,7 @@ var CC2650_ACCEL = function(deviceId) {
$('<div />', { class: 'mui-row'}).append($('<div />', { class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title})).appendTo(frame);
$('#frames').append(frame);
this.$frame.append(frame);
this.$id[modeID] = $('#' + this.frames[modeID]);
// Call the parent displayForm first...
@ -152,12 +154,11 @@ var CC2650_ACCEL = function(deviceId) {
this.$id[modeID].append(row);
row = $('<div />', {class: 'mui-row'});
$('<div />', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-x' }).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-y'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-z'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-x' }).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-y'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-z'}).appendTo(row);
this.$id[modeID].append(row);
@ -170,3 +171,5 @@ var CC2650_ACCEL = function(deviceId) {
inheritsFrom(CC2650_ACCEL, CAPABILITY);
capabilityManager.register({id:'F000AA80-0451-4000-B000-000000000000', module:CC2650_ACCEL});

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_BAR = function(deviceId) {
var CC2650_BAR = function(p) {
'use strict';
this.name = 'Barometer';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA40-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA40-0451-4000-B000-000000000000',
@ -24,6 +26,7 @@ var CC2650_BAR = function(deviceId) {
};
this.data = {temp: [], pressure: []};
this.$result = {temp: null, pressure: null};
this.setFrame();
this.startService = function() {
'use strict';
@ -53,7 +56,6 @@ var CC2650_BAR = function(deviceId) {
this.onBarometerData = function(data) {
var pStr;
var tStr;
// Console.log(data);
var message;
var a = new Uint8Array(data);
@ -68,8 +70,6 @@ var CC2650_BAR = function(deviceId) {
message = 'Temperature <br/>' + tStr +
'Pressure <br/>' + pStr ;
// This.data.temp = this.storeData(parseInt(temp), this.data.temp);
// this.data.pressure = this.storeData(parseInt(pressure), this.data.pressure);
this.data.temp = this.storeData(temp, this.data.temp);
this.data.pressure = this.storeData(pressure, this.data.pressure);
@ -103,30 +103,27 @@ var CC2650_BAR = function(deviceId) {
$('<div />', { class: 'mui-col-xs-3 mui--text-accent', text: 'Temp:'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: temp}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', id: temp}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-accent', text: 'Pressure:'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: pressure}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', id: pressure}).appendTo(row);
this.$id.append(row);
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>').append($('<a>',{text:'Pressure','data-mui-toggle': 'tab', 'data-mui-controls': (pressure + '-pane')})).appendTo(tabBody);
$('<li>',{class: 'mui--is-active tabOnWhite'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>',{class: 'tabOnWhite'}).append($('<a>',{text:'Pressure','data-mui-toggle': 'tab', 'data-mui-controls': (pressure + '-pane')})).appendTo(tabBody);
this.$id.append(tabBody);
blankChart = this.generateBlankGraph('temp');
// this.$id.append(blankChart);
this.$id.append($('<div>',{'class':'mui-tabs__pane mui--is-active',id:(temp + '-pane')}).append(blankChart));
blankChart = this.generateBlankGraph('pressure');
// this.$id.append(blankChart);
this.$id.append($('<div>',{'class':'mui-tabs__pane',id:(pressure + '-pane')}).append(blankChart));
this.$result.temp = $('#' + temp);
this.$result.pressure = $('#' + pressure);
@ -136,3 +133,5 @@ var CC2650_BAR = function(deviceId) {
inheritsFrom(CC2650_BAR, CAPABILITY);
capabilityManager.register({id:'F000AA40-0451-4000-B000-000000000000', module:CC2650_BAR});

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_LUX = function(deviceId) {
var CC2650_LUX = function(p) {
'use strict';
this.name = 'Luxometer';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA70-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA70-0451-4000-B000-000000000000',
@ -25,6 +27,7 @@ var CC2650_LUX = function(deviceId) {
this.$result = {temp: null, pressure: null};
this.data = [];
this.setFrame();
this.startService = function() {
'use strict';
@ -57,7 +60,6 @@ var CC2650_LUX = function(deviceId) {
this.onLuxData = function(data) {
var m, e, lux;
// Console.log(data);
var raw = new Uint16Array(data);
@ -68,13 +70,9 @@ var CC2650_LUX = function(deviceId) {
this.state = [lux.toFixed(2), 'lux'].join(' ');
//This.storeData(parseInt(lux));
this.storeData(lux);
this.$result.text(this.state);
// Console.log('Luxometer:', this.state);
};
this.animateGraph = function() {
@ -97,7 +95,7 @@ var CC2650_LUX = function(deviceId) {
row);
$('<div />',
{class: 'mui-col-xs-8 mui--text-white', id: lux}).appendTo(row);
{class: 'mui-col-xs-8 mui--text-dark', id: lux}).appendTo(row);
this.$id.append(row);
@ -107,10 +105,9 @@ var CC2650_LUX = function(deviceId) {
this.$result = $('#' + lux);
//Window.requestAnimFrame(this.animateFrame.bind(this));
};
};
inheritsFrom(CC2650_LUX, CAPABILITY);
capabilityManager.register({id:'F000AA70-0451-4000-B000-000000000000', module:CC2650_LUX});

View File

@ -17,14 +17,15 @@
* under the License.
*/
/* global BATTERY, BUTTON */
/* global BATTERY, BUTTON, bt_company_ids, ble, LocalFileSystem, capabilityManager */
var app = {
stop: false,
log: {},
activeServices: [],
activeServices: {},
list: {},
foundDevices: {},
manufactureDecoder: new MANUFACTUREDECODER(),
// Application Constructor
@ -91,26 +92,30 @@ var app = {
company = bt_company_ids.find(cid);
switch (manID) {
case '004c':
case '004c': {
decoded = app.manufactureDecoder.decodeIbeacon(bin);
decoded.company = company;
return decoded;
break;
case '1235':
}
case '1235': {
decoded = app.manufactureDecoder.decodeSiliconLabsSensorPuck(bin);
decoded.company = company;
return decoded;
break;
case '0060':
}
case '0060': {
decoded = app.manufactureDecoder.decodeSansible(bin);
decoded.company = company;
return decoded;
break;
default:
console.log('Unknown manID: ', manID);
}
return {company: company};
default: {
console.log('Unknown manID: ', manID);
decoded = {company: company};
}
}
return decoded;
},
makeHexBuffer: function(buffer) {
'use strict';
@ -131,6 +136,7 @@ var app = {
buildNewDeviceResultPanel: function(device) {
'use strict';
var newPanel, newRow;
var otherData = device.otherData;
var newId = 'd-' + device.id.replace(/:/g, '');
var title = device.hasOwnProperty('name') ? device.name : '*** Unknown';
@ -152,8 +158,54 @@ var app = {
newPanel.append(newRow);
return newPanel;
if (typeof otherData !== 'undefined' && otherData !== null) {
if (otherData.hasOwnProperty('msg')) {
newRow = $('<div>',{class: 'mui-row'});
newRow.append($('<div>',{class: 'mui-col-xs-3',text: 'Data:'}));
newRow.append($('<div>',{class: 'mui-col-xs-8',text: otherData.msg}));
newPanel.append(newRow);
}
}
return newPanel;
},
extractPData: function(prev) {
'use strict';
if (typeof prev === 'undefined' || prev === null) {
return {};
}
return prev.pData;
},
processPData: function(newData, oldData) {
'use strict';
var output = {};
var wa = [];
if (newData.data === null) {
return {};
}
for (var key in newData.data) {
if (newData.data.hasOwnProperty(key)) {
if (Object.keys(oldData).indexOf(key) !== -1) {
wa = oldData[key];
}
if (wa.length === 99) {
wa = wa.slice(1);
}
wa.push(newData.data[key]);
output[key] = wa;
}
}
return output;
},
doScan: function(mode) {
'use strict';
@ -172,24 +224,28 @@ var app = {
var newTR;
var newId;
var _device = device;
var $newID;
_device.pData = {};
otherData = null;
msgText = '';
console.log(JSON.stringify(device));
// console.log(JSON.stringify(_device));
newId = 'd-' + device.id.replace(/:/g, '');
newId = 'd-' + _device.id.replace(/:/g, '');
console.log(newId);
this.list[newId] = device.id;
this.list[newId] = _device.id;
if (device.hasOwnProperty('advertising')) {
if (_device.hasOwnProperty('advertising')) {
advertBuffer = app.arrayBufferToIntArray(device.advertising);
advertBuffer = app.arrayBufferToIntArray(_device.advertising);
hexBuffer = app.makeHexBuffer(advertBuffer);
parsed = app.parseAdvertisingData(advertBuffer);
//Console.log(parsed);
// Console.log(parsed);
if (parsed.hasOwnProperty('9')) {
@ -211,55 +267,35 @@ var app = {
_device.parsed = parsed;
}
if (typeof otherData !== 'undefined' && otherData !== null) {
if (otherData.hasOwnProperty('msg')) {
msgText = ' - ' + otherData.msg;
}
}
/*
NewTR = $('<tr id="' + newId + '" class="clickRow">');
newTR.append($('<td>').text(device.id));
if (device.hasOwnProperty('name')) {
newTR.append($('<td>').text(device.name + msgText));
} else {
newTR.append($('<td>').text('*** Unknown' + msgText));
}
newTR.append($('<td>').text(device.rssi));
*/
newTR = app.buildNewDeviceResultPanel(device);
/* If ($('tr#' + newId).length > 0) {
$('tr#' + newId).replaceWith(newTR);
} else {
$('#tbody').append(newTR);
}
*/
if ($('div#' + newId).length > 0) {
$('div#' + newId).replaceWith(newTR);
$newID = $('div#' + newId);
if ($newID.length > 0) {
$newID.replaceWith(newTR);
} else {
$('#scanResults').append(newTR);
}
// $('#output').append(JSON.stringify(device) + '<br/>');
//$('#output').append(JSON.stringify(device) + '<br/>');
var oldPdata = app.extractPData(app.log[newId]);
var newPData = app.processPData(otherData, oldPdata);
// console.log(newPData);
_device.pData = newPData;
app.log[newId] = _device;
app.foundDevices[newId] = _device;
console.log(JSON.stringify(_device));
// console.log(JSON.stringify(_device));
}.bind(this), function(e) {
'use strict';
console.error(e);
});
var _t = [5000,60000,200][mode];
setTimeout(ble.stopScan,
_t,
function() { console.log('Scan complete');
@ -368,7 +404,6 @@ var app = {
$('#scanResults').on('click', 'div.mui-panel.deviceRow', function() {
'use strict';
var tID = $(this).context.id;
var id = self.list[tID];
console.log(tID, id);
@ -377,7 +412,31 @@ var app = {
self.connect(id);
});
}, // Deviceready Event Handler
},
addTab: function(tID) {
var appTabs = $('#app-tabs');
var panes = $('#tab-panes');
var paneID = 'pane-' + tID;
var id = app.list[tID];
var _device = app.foundDevices[tID];
var _name = _device.name || _device.id;
console.log('Found:', _device);
$('<div>', {class: 'mui-tabs__pane', id: paneID}).appendTo(panes);
var li = $('<li>').append($('<a>',{'data-mui-toggle': 'tab', 'data-mui-controls': paneID, text: _name }));
appTabs.append(li);
return paneID;
},
// Deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
@ -405,85 +464,64 @@ var app = {
}
window.requestAnimFrame(app.doAnimate.bind(this));
}
, connect: function(deviceId) {
},
connect: function(deviceId) {
$('#results').slideUp();
console.log('Connect to ', deviceId);
var tID = 'd-' + deviceId.replace(/:/g, '');
var onConnect = function(a) {
var services = [];
'use strict';
console.log('A:', a);
services = a.services;
console.log('Searching services for ', tID);
var usedServices = [];
var target = app.addTab(tID);
var _params = {
deviceID: deviceId,
target: target
};
for (var t = 0; t < services.length; t++) {
var ident = services[t].toUpperCase();
switch (ident) {
case '180F':
var batteryStat = new BATTERY(deviceId);
batteryStat.startService();
// BatteryStat.readBatteryState();
app.activeServices.push(batteryStat);
var SERVICE = capabilityManager.discover(ident);
break;
case 'FFE0':
var buttonState = new BUTTON(deviceId);
buttonState.startService();
app.activeServices.push(buttonState);
break;
if (SERVICE !== null) {
case 'F000AA80-0451-4000-B000-000000000000':
var cc2650_accel = new CC2650_ACCEL(deviceId);
cc2650_accel.startService();
app.activeServices.push(cc2650_accel);
break;
case 'F000AA40-0451-4000-B000-000000000000':
var cc2650_bar = new CC2650_BAR(deviceId);
cc2650_bar.startService();
app.activeServices.push(cc2650_bar);
break;
case 'F000AA70-0451-4000-B000-000000000000':
var cc2650_lux = new CC2650_LUX(deviceId);
cc2650_lux.startService();
app.activeServices.push(cc2650_lux);
break;
case 'F000AA00-0451-4000-B000-000000000000':
var cc2650_tmp = new CC2650_TMP(deviceId);
cc2650_tmp.startService();
app.activeServices.push(cc2650_tmp);
break;
case 'F000AA20-0451-4000-B000-000000000000':
var cc2650_hum = new CC2650_HUM(deviceId);
cc2650_hum.startService();
app.activeServices.push(cc2650_hum);
break;
default:
var newService = new SERVICE(_params);
newService.startService();
usedServices.push(newService);
} else {
console.error('Unknown service: ', ident);
}
}
// Starting animation..
app.activeServices[tID] = usedServices;
mui.tabs.activate(target);
window.requestAnimFrame(app.doAnimate.bind(this));
};
if (!app.activeServices.hasOwnProperty(tID)) {
ble.connect(deviceId, onConnect, function(e) {
'use strict';
console.log(e);
console.error(e);
});
}
}, onError: function(reason) {
console.error('ERROR: ' + reason); // Real apps should use notification.alert
}, updateGyro: function(g) {
@ -492,7 +530,6 @@ var app = {
}
};
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
@ -502,6 +539,4 @@ window.requestAnimFrame = (function() {
};
})();
app.initialize();

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var BUTTON = function(deviceId) {
var BUTTON = function(p) {
'use strict';
this.name = 'Button';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'FFE0';
this.serviceDef = {
service: 'FFE0',
@ -25,6 +27,8 @@ var BUTTON = function(deviceId) {
REED_SWITCH: 4 // 0100
};
this.setFrame();
this.onButtonData = function(data) {
console.log('+ onButtonData');
console.log(data);
@ -83,7 +87,7 @@ var BUTTON = function(deviceId) {
$('<div />', { class: 'mui-col-xs-4 mui--text-accent', text: 'Status:'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-8 mui--text-white', id: detail}).appendTo(row);
$('<div />', { class: 'mui-col-xs-8 mui--text-dark', id: detail}).appendTo(row);
this.$id.append(row);
this.$result = $('#'+detail);
@ -94,3 +98,4 @@ var BUTTON = function(deviceId) {
inheritsFrom(BUTTON, CAPABILITY);
capabilityManager.register({id: 'FFE0', module: BUTTON});

View File

@ -6,6 +6,23 @@
*
*/
'use strict';
var capabilityManager = {
capabilityList : [],
register : function(details) {
console.log('Registered:', details );
this.capabilityList.push(details);
},
discover : function(id) {
var wanted = this.capabilityList.filter(function(obj) {
return obj.id === id;
});
return wanted.length === 1 ? wanted[0].module : null;
}
};
var CAPABILITY = function(p) {
this.name = '-CAPABILITY-';
this.capabilityID = p.capabilityID || null;
@ -22,6 +39,13 @@ var CAPABILITY = function(p) {
this.ctx = null;
this.first = false;
this.target = null;
this.$frame = null;
capabilityManager.register({id:this.capabilityID, module:this});
};
CAPABILITY.prototype.setFrame = function() {
this.$frame = (this.target !== null) ? $('#'+ this.target) : null;
};
CAPABILITY.prototype.setInternalID = function() {
@ -51,7 +75,7 @@ CAPABILITY.prototype.insertFrame = function() {
$('<div />', { class: 'mui-row'}).append($('<div />', { class: 'mui-col-xs-12 mui--text-title', text: title})).appendTo(frame);
$('#frames').append(frame);
this.$frame.append(frame);
this.$id = $('#' + this.frameID);
};
@ -122,7 +146,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
line.setAttributeNS(null,'y1','12');
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'y2', '12');
line.setAttributeNS(null,'style','stroke:#bad649;stroke-width:2;');
line.setAttributeNS(null,'style','stroke:#004c6d;stroke-width:2;');
svg.appendChild(line);
@ -132,7 +156,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
line.setAttributeNS(null,'y1','136');
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'y2', '136');
line.setAttributeNS(null,'style','stroke:#bad649;stroke-width:2;');
line.setAttributeNS(null,'style','stroke:#004c6d;stroke-width:2;');
svg.appendChild(line);
@ -142,7 +166,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
text.setAttributeNS(null,'x','36');
text.setAttributeNS(null,'y','15');
text.setAttributeNS(null,'text-anchor', 'end');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #bad649;text-align:right;');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #004c6d;text-align:right;');
text.textContent = '000';
svg.appendChild(text);
@ -153,7 +177,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
text.setAttributeNS(null,'x','36');
text.setAttributeNS(null,'y','140');
text.setAttributeNS(null,'text-anchor', 'end');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #bad649;text-align:right;');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #004c6d;text-align:right;');
text.textContent = '0';
svg.appendChild(text);
@ -162,7 +186,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
polyline.setAttributeNS(null,'id',lineID);
polyline.setAttributeNS(null,'fill','none');
polyline.setAttributeNS(null,'stroke','#e5f7fd');
polyline.setAttributeNS(null,'stroke','#2196F3');
//#e5f7fd
// old #B5C7FF
polyline.setAttributeNS(null,'text-anchor', 'end');

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -13,6 +13,12 @@
<param name="android-package" value="com.megster.cordova.ble.central.BLECentralPlugin" />
</feature>
<allow-intent href="market:*" />
<icon density="ldpi" src="res/android/android-chrome-36x36.png" />
<icon density="mdpi" src="res/android/mipmap-mdpi/ic_launcher.png" />
<icon density="hdpi" src="res/android/mipmap-hdpi/ic_launcher.png" />
<icon density="xhdpi" src="res/android/mipmap-xhdpi/ic_launcher.png" />
<icon density="xxhdpi" src="res/android/mipmap-xxhdpi/ic_launcher.png" />
<icon density="xxxhdpi" src="res/android/mipmap-xxxhdpi/ic_launcher.png" />
<name>Sensortoy</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
res/ios/Default-667h.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
res/ios/Default-736h.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
res/ios/Default~iphone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

BIN
res/ios/icon-60.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

BIN
res/ios/icon-60@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

BIN
res/ios/icon-60@3x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
res/ios/icon-72.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

BIN
res/ios/icon-72@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

BIN
res/ios/icon-76.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

BIN
res/ios/icon-76@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 B

BIN
res/ios/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

BIN
res/ios/icon@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

View File

@ -1,16 +1,9 @@
body {
font-family: Ubuntu, "Helvetica Neue", Helvetica, arial, sans-serif;
background-color: #004c6d;
}
#weatherIcon {
margin-left:25%;
margin-right:25%;
height:70px;
width:70px;
}
#lightR, #projR { color: red !important; }
#lightG, #projG { color: green !important; }
@ -23,21 +16,7 @@ body {
float: right;
}
/*.lightBG {
background-color: rgba(255, 255, 0, 0.3);
}
.heatingBG {
background-color: rgba(255, 0, 255, 0.3);
}
.projectorBG {
background-color: rgba(0, 255, 255, 0.3);
}*/
.mui-panel {
background-color: #015579;
}
.h105 {
height: 100px;
@ -47,9 +26,6 @@ body {
overflow: hidden;
}
.mui--text-title {
color: #ffffff;
}
.item_content {
height: 100px;
@ -212,50 +188,6 @@ body {
}
}
.material-icons {
color: #e5f7fd;
}
.material-icons.md-18 { font-size: 18px; }
.material-icons.md-24 { font-size: 24px; }
.material-icons.md-36 { font-size: 36px; }
.material-icons.md-48 { font-size: 48px; }
.material-icons.md-100 { font-size: 100px; }
/* Rules for using icons as black on a light background. */
.material-icons.md-dark { color: rgba(0, 0, 0, 0.54); }
.material-icons.md-dark.md-inactive { color: rgba(0, 0, 0, 0.26); }
/* Rules for using icons as white on a dark background. */
.material-icons.md-light { color: rgba(255, 255, 255, 1); }
.material-icons.md-light.md-inactive { color: rgba(255, 255, 255, 0.3); }
.material-icons.md-bulb {
content: "&#xE90F;"
}
/*
fan : toys
<i class="material-icons">&#xE332;</i>
bulb : lightbulb_outline
<i class="material-icons">&#xE90F;</i>
calendar: event_note
<i class="material-icons">&#xE616;</i>
projector: cast
<i class="material-icons">&#xE307;</i>
*/
.md-display {
opacity: 1;
@ -305,3 +237,24 @@ projector: cast
85% { opacity: 1; }
100% { transform: scale(1); filter: blur(5px); opacity: 0; }
}
header {
position: fixed;
top: 0;
z-index: 1;
right:0;
transition: left .2s;
width:100%;
}
.mui-tabs__bar > li.tabOnWhite > a
{
color:#78909C;
}
.mui-tabs__bar > li.mui--is-active.tabOnWhite > a
{
color:#2196F3;
}

View File

@ -379,7 +379,7 @@ body {
font-weight: 400;
line-height: 1.429;
color: rgba(0, 0, 0, 0.87);
background-color: #FFF; }
background-color: #F5F5F5; }
input,
button,
@ -497,7 +497,7 @@ h4, h5, h6 {
top: 64px; } }
.mui-appbar {
background-color: #2196F3;
background-color: #004c6d;
color: #FFF; }
/**
@ -655,21 +655,21 @@ h4, h5, h6 {
.mui-btn--accent {
color: #004c6d;
background-color: #bad649; }
background-color: #004c6d; }
.mui-btn--accent:hover, .mui-btn--accent:focus, .mui-btn--accent:active {
color: #004c6d;
background-color: #c2db5e; }
background-color: #005e87; }
.mui-btn--accent[disabled]:hover, .mui-btn--accent[disabled]:focus, .mui-btn--accent[disabled]:active {
color: #004c6d;
background-color: #bad649; }
background-color: #004c6d; }
.mui-btn--accent.mui-btn--flat {
color: #bad649;
color: #004c6d;
background-color: transparent; }
.mui-btn--accent.mui-btn--flat:hover, .mui-btn--accent.mui-btn--flat:focus, .mui-btn--accent.mui-btn--flat:active {
color: #bad649;
color: #004c6d;
background-color: #f2f2f2; }
.mui-btn--accent.mui-btn--flat[disabled]:hover, .mui-btn--accent.mui-btn--flat[disabled]:focus, .mui-btn--accent.mui-btn--flat[disabled]:active {
color: #bad649;
color: #004c6d;
background-color: transparent; }
.mui-btn--small {
@ -1266,7 +1266,7 @@ h4, h5, h6 {
.mui-select__menu {
position: absolute;
z-index: 1;
z-index: 2;
min-width: 100%;
overflow-y: auto;
padding: 8px 0;
@ -1596,13 +1596,13 @@ th {
color: rgba(255, 255, 255, 0.3); }
.mui--text-accent {
color: rgba(186, 214, 73, 0.87); }
color: rgba(0, 76, 109, 0.87); }
.mui--text-accent-secondary {
color: rgba(186, 214, 73, 0.54); }
color: rgba(0, 76, 109, 0.54); }
.mui--text-accent-hint {
color: rgba(186, 214, 73, 0.38); }
color: rgba(0, 76, 109, 0.38); }
.mui--text-black {
color: #000; }

View File

@ -1,5 +1,4 @@
<!DOCTYPE html>
<!--
<!DOCTYPE html><!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@ -18,7 +17,7 @@
under the License.
-->
<html>
<head>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
@ -28,10 +27,12 @@
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet"
href="http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700"
type="text/css">
@ -47,72 +48,72 @@
<link href="css/ripple.css" rel="stylesheet" type="text/css"/>
<link href="css/progress.css" rel="stylesheet" type="text/css"/>
<title>Sensor Toy</title>
</head>
<body>
</head>
<body class="mui--no-user-select">
<header id="header">
<div class="mui-appbar">
<ul id='app-tabs' class="mui-tabs__bar mui--z1 mui--appbar-height">
<li class="mui--is-active"><a data-mui-toggle="tab"
data-mui-controls="pane-default-1">Devices</a>
</li>
<!--<li><a data-mui-toggle="tab" data-mui-controls="pane-default-2">Tab-2</a>
</li>
<li><a data-mui-toggle="tab" data-mui-controls="pane-default-3">Tab-3</a>
</li>-->
</ul>
</div>
</header>
<div class="mui--appbar-height"></div>
<div id="tab-panes" class='' style="height:100%;">
<div class="mui-tabs__pane mui--is-active" id="pane-default-1">
<div id='app' class="mui-container">
<div>
<div class="mui-row mui--appbar-height mui--appbar-line-height">
<div class="mui-col-xs-6 mui--text-subhead">
<span class="">Devices</span>
</div>
<div class="mui-col-xs-6 mui--text-right">
<button class="mui-btn mui-btn--small mui-btn--primary"
id="scan">Scan
</button>
<button class="mui-btn mui-btn--small mui-btn--danger" id="stop"
style="display: none;">Stop
</button>
</div>
</div>
<div style="margin: 0.5rem 0 1rem 0;">
<div class="progress" id='ripple' style="display: none;">
<div class="indeterminate"></div>
</div>
</div>
<div id='app' class="mui-container">
<div class="mui-panel">
<div class="mui-row">
<div class="mui-col-xs-6">
<button class="mui-btn mui-btn--primary" id="scan">Scan</button>
<button class="mui-btn mui-btn--danger" id="stop" style="display: none;">Stop</button>
</div>
<div class="mui-col-xs-6">
<button class="mui-btn mui-btn--accent" id="longScan">Long</button>
<div id="scanResults"></div>
</div>
</div>
</div>
<div id="scanResults">
</div>
<table class="mui-table mui--text-white" id="results">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>RSI</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
<div id="frames" class="mui-container">
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="libs/mui/packages/cdn/js/mui.js"></script>
<script type="text/javascript" src="libs/bluebird/js/browser/bluebird.js"></script>
<script type="text/javascript" src="js/standards/bluetooth_company_identifiers.js"></script>
<script type="text/javascript" src="js/standards/capability.js"></script>
<script type="text/javascript" src="js/standards/battery.js"></script>
<script type="text/javascript" src="js/standards/button.js"></script>
<script type="text/javascript" src="js/mandecoder.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_accelerometer.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_barometer.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_luxometer.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_thermopile.js"></script>
<script type="text/javascript" src="js/device/CC2650/cc2650_humidity.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="libs/mui/packages/cdn/js/mui.js"></script>
<script type="text/javascript"
src="libs/bluebird/js/browser/bluebird.js"></script>
<script type="text/javascript"
src="js/standards/bluetooth_company_identifiers.js"></script>
<script type="text/javascript" src="js/standards/capability.js"></script>
<script type="text/javascript" src="js/standards/battery.js"></script>
<script type="text/javascript" src="js/standards/button.js"></script>
<script type="text/javascript" src="js/mandecoder.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_accelerometer.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_barometer.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_luxometer.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_thermopile.js"></script>
<script type="text/javascript"
src="js/device/CC2650/cc2650_humidity.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_ACCEL = function(deviceId) {
var CC2650_ACCEL = function(p) {
'use strict';
this.name = 'Accelerometer';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA80-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA80-0451-4000-B000-000000000000',
@ -26,6 +28,7 @@ var CC2650_ACCEL = function(deviceId) {
this.$id = {};
this.$result = {};
this.setFrame();
this.sensorMpu9250GyroConvert = function(data) {
return data / (65536 / 500);
@ -89,7 +92,6 @@ var CC2650_ACCEL = function(deviceId) {
console.log('Starting CC2650 Accelerometer Service on ', this.deviceID);
console.log(this.serviceDef);
//Ble.startNotification(this.deviceID, , this.onButtonData.bind(this), this.onError);
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onAccelerometerData.bind(this), this.onError);
@ -139,7 +141,7 @@ var CC2650_ACCEL = function(deviceId) {
$('<div />', { class: 'mui-row'}).append($('<div />', { class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title})).appendTo(frame);
$('#frames').append(frame);
this.$frame.append(frame);
this.$id[modeID] = $('#' + this.frames[modeID]);
// Call the parent displayForm first...
@ -152,12 +154,11 @@ var CC2650_ACCEL = function(deviceId) {
this.$id[modeID].append(row);
row = $('<div />', {class: 'mui-row'});
$('<div />', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-x' }).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-y'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-z'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-x' }).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-y'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-z'}).appendTo(row);
this.$id[modeID].append(row);
@ -170,3 +171,5 @@ var CC2650_ACCEL = function(deviceId) {
inheritsFrom(CC2650_ACCEL, CAPABILITY);
capabilityManager.register({id:'F000AA80-0451-4000-B000-000000000000', module:CC2650_ACCEL});

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_BAR = function(deviceId) {
var CC2650_BAR = function(p) {
'use strict';
this.name = 'Barometer';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA40-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA40-0451-4000-B000-000000000000',
@ -24,6 +26,7 @@ var CC2650_BAR = function(deviceId) {
};
this.data = {temp: [], pressure: []};
this.$result = {temp: null, pressure: null};
this.setFrame();
this.startService = function() {
'use strict';
@ -53,7 +56,6 @@ var CC2650_BAR = function(deviceId) {
this.onBarometerData = function(data) {
var pStr;
var tStr;
// Console.log(data);
var message;
var a = new Uint8Array(data);
@ -68,8 +70,6 @@ var CC2650_BAR = function(deviceId) {
message = 'Temperature <br/>' + tStr +
'Pressure <br/>' + pStr ;
// This.data.temp = this.storeData(parseInt(temp), this.data.temp);
// this.data.pressure = this.storeData(parseInt(pressure), this.data.pressure);
this.data.temp = this.storeData(temp, this.data.temp);
this.data.pressure = this.storeData(pressure, this.data.pressure);
@ -103,30 +103,27 @@ var CC2650_BAR = function(deviceId) {
$('<div />', { class: 'mui-col-xs-3 mui--text-accent', text: 'Temp:'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: temp}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', id: temp}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-accent', text: 'Pressure:'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: pressure}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-dark', id: pressure}).appendTo(row);
this.$id.append(row);
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>').append($('<a>',{text:'Pressure','data-mui-toggle': 'tab', 'data-mui-controls': (pressure + '-pane')})).appendTo(tabBody);
$('<li>',{class: 'mui--is-active tabOnWhite'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>',{class: 'tabOnWhite'}).append($('<a>',{text:'Pressure','data-mui-toggle': 'tab', 'data-mui-controls': (pressure + '-pane')})).appendTo(tabBody);
this.$id.append(tabBody);
blankChart = this.generateBlankGraph('temp');
// this.$id.append(blankChart);
this.$id.append($('<div>',{'class':'mui-tabs__pane mui--is-active',id:(temp + '-pane')}).append(blankChart));
blankChart = this.generateBlankGraph('pressure');
// this.$id.append(blankChart);
this.$id.append($('<div>',{'class':'mui-tabs__pane',id:(pressure + '-pane')}).append(blankChart));
this.$result.temp = $('#' + temp);
this.$result.pressure = $('#' + pressure);
@ -136,3 +133,5 @@ var CC2650_BAR = function(deviceId) {
inheritsFrom(CC2650_BAR, CAPABILITY);
capabilityManager.register({id:'F000AA40-0451-4000-B000-000000000000', module:CC2650_BAR});

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_HUM = function(deviceId) {
var CC2650_HUM = function(p) {
'use strict';
this.name = 'Humidity';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA20-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA20-0451-4000-B000-000000000000',
@ -24,6 +26,7 @@ var CC2650_HUM = function(deviceId) {
};
this.data = {temp: [], humidity: []};
this.$result = {temp: null, humidity: null};
this.setFrame();
this.startService = function() {
'use strict';
@ -71,9 +74,6 @@ var CC2650_HUM = function(deviceId) {
message = 'Temperature <br/>' + tStr + 'Humidity <br/>' + hStr;
// This.data.temp = this.storeData(parseInt(temp), this.data.temp);
// this.data.humidity = this.storeData(parseInt(hum), this.data.humidity);
this.data.temp = this.storeData(temp, this.data.temp);
this.data.humidity = this.storeData(hum, this.data.humidity);
@ -108,7 +108,7 @@ var CC2650_HUM = function(deviceId) {
{class: 'mui-col-xs-3 mui--text-accent', text: 'Temp:'}).appendTo(row);
$('<div />',
{class: 'mui-col-xs-3 mui--text-white', id: temp}).appendTo(row);
{class: 'mui-col-xs-3 mui--text-dark', id: temp}).appendTo(row);
$('<div />',
{
class: 'mui-col-xs-3 mui--text-accent',
@ -116,25 +116,22 @@ var CC2650_HUM = function(deviceId) {
}).appendTo(row);
$('<div />',
{class: 'mui-col-xs-3 mui--text-white', id: humidity}).appendTo(row);
{class: 'mui-col-xs-3 mui--text-dark', id: humidity}).appendTo(row);
this.$id.append(row);
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text: 'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>').append($('<a>',{text: 'Humidity','data-mui-toggle': 'tab', 'data-mui-controls': (humidity + '-pane')})).appendTo(tabBody);
$('<li>',{class: 'mui--is-active tabOnWhite'}).append($('<a>',{text: 'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>',{class: 'tabOnWhite'}).append($('<a>',{text: 'Humidity','data-mui-toggle': 'tab', 'data-mui-controls': (humidity + '-pane')})).appendTo(tabBody);
this.$id.append(tabBody);
blankChart = this.generateBlankGraph('temp');
// This.$id.append(blankChart);
this.$id.append($('<div>',{class: 'mui-tabs__pane mui--is-active',id: (temp + '-pane')}).append(blankChart));
blankChart = this.generateBlankGraph('humidity');
this.$id.append($('<div>',{class: 'mui-tabs__pane',id: (humidity + '-pane')}).append(blankChart));
// this.$id.append(blankChart);
this.$result.temp = $('#' + temp);
this.$result.humidity = $('#' + humidity);
@ -143,3 +140,5 @@ var CC2650_HUM = function(deviceId) {
};
inheritsFrom(CC2650_HUM, CAPABILITY);
capabilityManager.register({id:'F000AA20-0451-4000-B000-000000000000', module:CC2650_HUM});

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_LUX = function(deviceId) {
var CC2650_LUX = function(p) {
'use strict';
this.name = 'Luxometer';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA70-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA70-0451-4000-B000-000000000000',
@ -25,6 +27,7 @@ var CC2650_LUX = function(deviceId) {
this.$result = {temp: null, pressure: null};
this.data = [];
this.setFrame();
this.startService = function() {
'use strict';
@ -57,7 +60,6 @@ var CC2650_LUX = function(deviceId) {
this.onLuxData = function(data) {
var m, e, lux;
// Console.log(data);
var raw = new Uint16Array(data);
@ -68,13 +70,9 @@ var CC2650_LUX = function(deviceId) {
this.state = [lux.toFixed(2), 'lux'].join(' ');
//This.storeData(parseInt(lux));
this.storeData(lux);
this.$result.text(this.state);
// Console.log('Luxometer:', this.state);
};
this.animateGraph = function() {
@ -97,7 +95,7 @@ var CC2650_LUX = function(deviceId) {
row);
$('<div />',
{class: 'mui-col-xs-8 mui--text-white', id: lux}).appendTo(row);
{class: 'mui-col-xs-8 mui--text-dark', id: lux}).appendTo(row);
this.$id.append(row);
@ -107,10 +105,9 @@ var CC2650_LUX = function(deviceId) {
this.$result = $('#' + lux);
//Window.requestAnimFrame(this.animateFrame.bind(this));
};
};
inheritsFrom(CC2650_LUX, CAPABILITY);
capabilityManager.register({id:'F000AA70-0451-4000-B000-000000000000', module:CC2650_LUX});

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_TMP = function(deviceId) {
var CC2650_TMP = function(p) {
'use strict';
this.name = 'Thermopile';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'F000AA00-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA00-0451-4000-B000-000000000000',
@ -25,6 +27,7 @@ var CC2650_TMP = function(deviceId) {
this.data = {temp: [], ambient: []};
this.$result = {temp: null, ambient: null};
this.setFrame();
this.startService = function() {
'use strict';
@ -81,7 +84,6 @@ var CC2650_TMP = function(deviceId) {
this.$result.temp.text(tStr);
this.$result.ambient.text(aStr);
// Console.log('Thermopile:', this.state);
};
this.animateGraph = function() {
@ -97,6 +99,7 @@ var CC2650_TMP = function(deviceId) {
var self = this;
// Console.log('Overloading...');
// Call the parent displayForm first...
this.superClass_.insertFrame.call(self);
var temp = this.frameID + '-t';
@ -107,7 +110,7 @@ var CC2650_TMP = function(deviceId) {
{class: 'mui-col-xs-3 mui--text-accent', text: 'Temp:'}).appendTo(row);
$('<div />',
{class: 'mui-col-xs-3 mui--text-white', id: temp}).appendTo(row);
{class: 'mui-col-xs-3 mui--text-dark', id: temp}).appendTo(row);
$('<div />',
{
class: 'mui-col-xs-3 mui--text-accent',
@ -115,32 +118,23 @@ var CC2650_TMP = function(deviceId) {
}).appendTo(row);
$('<div />',
{class: 'mui-col-xs-3 mui--text-white', id: amb}).appendTo(row);
{class: 'mui-col-xs-3 mui--text-dark', id: amb}).appendTo(row);
this.$id.append(row);
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>').append($('<a>',{text:'Ambient','data-mui-toggle': 'tab', 'data-mui-controls': (amb + '-pane')})).appendTo(tabBody);
$('<li>',{class: 'mui--is-active tabOnWhite'}).append($('<a>',{ text: 'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
$('<li>', {class: 'tabOnWhite'}).append($('<a>',{ text: 'Ambient','data-mui-toggle': 'tab', 'data-mui-controls': (amb + '-pane')})).appendTo(tabBody);
this.$id.append(tabBody);
/*
<div class="mui-tabs__pane mui--is-active" id="pane-justified-1">Pane-1</div>
<div class="mui-tabs__pane" id="pane-justified-2">Pane-2</div>
*/
blankChart = this.generateBlankGraph('temp');
//this.$id.append(blankChart);
this.$id.append($('<div>',{'class':'mui-tabs__pane mui--is-active',id:(temp + '-pane')}).append(blankChart));
this.$id.append($('<div>',{class: 'mui-tabs__pane mui--is-active',id: (temp + '-pane')}).append(blankChart));
blankChart = this.generateBlankGraph('ambient');
//this.$id.append(blankChart);
this.$id.append($('<div>',{'class':'mui-tabs__pane',id:(amb + '-pane')}).append(blankChart));
this.$id.append($('<div>',{class: 'mui-tabs__pane',id: (amb + '-pane')}).append(blankChart));
this.$result.temp = $('#' + temp);
this.$result.ambient = $('#' + amb);
@ -150,3 +144,5 @@ var CC2650_TMP = function(deviceId) {
};
inheritsFrom(CC2650_TMP, CAPABILITY);
capabilityManager.register({id: 'F000AA00-0451-4000-B000-000000000000', module: CC2650_TMP});

View File

@ -17,14 +17,15 @@
* under the License.
*/
/* global BATTERY, BUTTON */
/* global BATTERY, BUTTON, bt_company_ids, ble, LocalFileSystem, capabilityManager */
var app = {
stop: false,
log: {},
activeServices: [],
activeServices: {},
list: {},
foundDevices: {},
manufactureDecoder: new MANUFACTUREDECODER(),
// Application Constructor
@ -91,26 +92,30 @@ var app = {
company = bt_company_ids.find(cid);
switch (manID) {
case '004c':
case '004c': {
decoded = app.manufactureDecoder.decodeIbeacon(bin);
decoded.company = company;
return decoded;
break;
case '1235':
}
case '1235': {
decoded = app.manufactureDecoder.decodeSiliconLabsSensorPuck(bin);
decoded.company = company;
return decoded;
break;
case '0060':
}
case '0060': {
decoded = app.manufactureDecoder.decodeSansible(bin);
decoded.company = company;
return decoded;
break;
default:
console.log('Unknown manID: ', manID);
}
return {company: company};
default: {
console.log('Unknown manID: ', manID);
decoded = {company: company};
}
}
return decoded;
},
makeHexBuffer: function(buffer) {
'use strict';
@ -131,6 +136,7 @@ var app = {
buildNewDeviceResultPanel: function(device) {
'use strict';
var newPanel, newRow;
var otherData = device.otherData;
var newId = 'd-' + device.id.replace(/:/g, '');
var title = device.hasOwnProperty('name') ? device.name : '*** Unknown';
@ -152,8 +158,54 @@ var app = {
newPanel.append(newRow);
return newPanel;
if (typeof otherData !== 'undefined' && otherData !== null) {
if (otherData.hasOwnProperty('msg')) {
newRow = $('<div>',{class: 'mui-row'});
newRow.append($('<div>',{class: 'mui-col-xs-3',text: 'Data:'}));
newRow.append($('<div>',{class: 'mui-col-xs-8',text: otherData.msg}));
newPanel.append(newRow);
}
}
return newPanel;
},
extractPData: function(prev) {
'use strict';
if (typeof prev === 'undefined' || prev === null) {
return {};
}
return prev.pData;
},
processPData: function(newData, oldData) {
'use strict';
var output = {};
var wa = [];
if (newData.data === null) {
return {};
}
for (var key in newData.data) {
if (newData.data.hasOwnProperty(key)) {
if (Object.keys(oldData).indexOf(key) !== -1) {
wa = oldData[key];
}
if (wa.length === 99) {
wa = wa.slice(1);
}
wa.push(newData.data[key]);
output[key] = wa;
}
}
return output;
},
doScan: function(mode) {
'use strict';
@ -172,24 +224,26 @@ var app = {
var newTR;
var newId;
var _device = device;
var $newID;
_device.pData = {};
otherData = null;
msgText = '';
console.log(JSON.stringify(device));
newId = 'd-' + device.id.replace(/:/g, '');
console.log(newId);
newId = 'd-' + _device.id.replace(/:/g, '');
this.list[newId] = device.id;
this.list[newId] = _device.id;
if (device.hasOwnProperty('advertising')) {
if (_device.hasOwnProperty('advertising')) {
advertBuffer = app.arrayBufferToIntArray(device.advertising);
advertBuffer = app.arrayBufferToIntArray(_device.advertising);
hexBuffer = app.makeHexBuffer(advertBuffer);
parsed = app.parseAdvertisingData(advertBuffer);
//Console.log(parsed);
// Console.log(parsed);
if (parsed.hasOwnProperty('9')) {
@ -211,55 +265,35 @@ var app = {
_device.parsed = parsed;
}
if (typeof otherData !== 'undefined' && otherData !== null) {
if (otherData.hasOwnProperty('msg')) {
msgText = ' - ' + otherData.msg;
}
}
/*
NewTR = $('<tr id="' + newId + '" class="clickRow">');
newTR.append($('<td>').text(device.id));
if (device.hasOwnProperty('name')) {
newTR.append($('<td>').text(device.name + msgText));
} else {
newTR.append($('<td>').text('*** Unknown' + msgText));
}
newTR.append($('<td>').text(device.rssi));
*/
newTR = app.buildNewDeviceResultPanel(device);
/* If ($('tr#' + newId).length > 0) {
$('tr#' + newId).replaceWith(newTR);
} else {
$('#tbody').append(newTR);
}
*/
if ($('div#' + newId).length > 0) {
$('div#' + newId).replaceWith(newTR);
$newID = $('div#' + newId);
if ($newID.length > 0) {
$newID.replaceWith(newTR);
} else {
$('#scanResults').append(newTR);
}
// $('#output').append(JSON.stringify(device) + '<br/>');
//$('#output').append(JSON.stringify(device) + '<br/>');
var oldPdata = app.extractPData(app.log[newId]);
var newPData = app.processPData(otherData, oldPdata);
// Console.log(newPData);
_device.pData = newPData;
app.log[newId] = _device;
app.foundDevices[newId] = _device;
console.log(JSON.stringify(_device));
// Console.log(JSON.stringify(_device));
}.bind(this), function(e) {
'use strict';
console.error(e);
});
var _t = [5000,60000,200][mode];
setTimeout(ble.stopScan,
_t,
function() { console.log('Scan complete');
@ -368,7 +402,6 @@ var app = {
$('#scanResults').on('click', 'div.mui-panel.deviceRow', function() {
'use strict';
var tID = $(this).context.id;
var id = self.list[tID];
console.log(tID, id);
@ -377,7 +410,31 @@ var app = {
self.connect(id);
});
}, // Deviceready Event Handler
},
addTab: function(tID) {
var appTabs = $('#app-tabs');
var panes = $('#tab-panes');
var paneID = 'pane-' + tID;
var id = app.list[tID];
var _device = app.foundDevices[tID];
var _name = _device.name || _device.id;
console.log('Found:', _device);
$('<div>', {class: 'mui-tabs__pane', id: paneID}).appendTo(panes);
var li = $('<li>').append($('<a>',{'data-mui-toggle': 'tab', 'data-mui-controls': paneID, text: _name }));
appTabs.append(li);
return paneID;
},
// Deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
@ -405,85 +462,64 @@ var app = {
}
window.requestAnimFrame(app.doAnimate.bind(this));
}
, connect: function(deviceId) {
},
connect: function(deviceId) {
$('#results').slideUp();
console.log('Connect to ', deviceId);
var tID = 'd-' + deviceId.replace(/:/g, '');
var onConnect = function(a) {
var services = [];
'use strict';
console.log('A:', a);
services = a.services;
console.log('Searching services for ', tID);
var usedServices = [];
var target = app.addTab(tID);
var _params = {
deviceID: deviceId,
target: target
};
for (var t = 0; t < services.length; t++) {
var ident = services[t].toUpperCase();
switch (ident) {
case '180F':
var batteryStat = new BATTERY(deviceId);
batteryStat.startService();
// BatteryStat.readBatteryState();
app.activeServices.push(batteryStat);
var SERVICE = capabilityManager.discover(ident);
break;
case 'FFE0':
var buttonState = new BUTTON(deviceId);
buttonState.startService();
app.activeServices.push(buttonState);
break;
if (SERVICE !== null) {
case 'F000AA80-0451-4000-B000-000000000000':
var cc2650_accel = new CC2650_ACCEL(deviceId);
cc2650_accel.startService();
app.activeServices.push(cc2650_accel);
break;
case 'F000AA40-0451-4000-B000-000000000000':
var cc2650_bar = new CC2650_BAR(deviceId);
cc2650_bar.startService();
app.activeServices.push(cc2650_bar);
break;
case 'F000AA70-0451-4000-B000-000000000000':
var cc2650_lux = new CC2650_LUX(deviceId);
cc2650_lux.startService();
app.activeServices.push(cc2650_lux);
break;
case 'F000AA00-0451-4000-B000-000000000000':
var cc2650_tmp = new CC2650_TMP(deviceId);
cc2650_tmp.startService();
app.activeServices.push(cc2650_tmp);
break;
case 'F000AA20-0451-4000-B000-000000000000':
var cc2650_hum = new CC2650_HUM(deviceId);
cc2650_hum.startService();
app.activeServices.push(cc2650_hum);
break;
default:
var newService = new SERVICE(_params);
newService.startService();
usedServices.push(newService);
} else {
console.error('Unknown service: ', ident);
}
}
// Starting animation..
app.activeServices[tID] = usedServices;
mui.tabs.activate(target);
window.requestAnimFrame(app.doAnimate.bind(this));
};
if (!app.activeServices.hasOwnProperty(tID)) {
ble.connect(deviceId, onConnect, function(e) {
'use strict';
console.log(e);
console.error(e);
});
}
}, onError: function(reason) {
console.error('ERROR: ' + reason); // Real apps should use notification.alert
}, updateGyro: function(g) {
@ -492,7 +528,6 @@ var app = {
}
};
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
@ -502,6 +537,4 @@ window.requestAnimFrame = (function() {
};
})();
app.initialize();

View File

@ -35,17 +35,17 @@ var MANUFACTUREDECODER = function() {
};
this.decodeSiliconLabsSensorPuck = function(data) {
var bin = data;
var obj = {};
var obj = {data:{}};
//obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4);
obj.manID = this.getManID(bin);
obj.a = (bin[3] << 8) | bin[2];
obj.b = (bin[5] << 8) | bin[4];
obj.humidity = (bin[7] << 8) | bin[6];
obj.temp = (bin[9] << 8) | bin[8];
obj.data.humidity = (bin[7] << 8) | bin[6];
obj.data.temp = (bin[9] << 8) | bin[8];
obj.c = (bin[11] << 8) | bin[10];
obj.d = (bin[13] << 8) | bin[12];
obj.msg = 'Humidity: ' + (obj.humidity / 10) + ', temp: ' + (obj.temp / 10);
obj.msg = 'Humidity: ' + (obj.data.humidity / 10) + ', temp: ' + (obj.data.temp / 10);
return obj;
};
@ -53,14 +53,14 @@ var MANUFACTUREDECODER = function() {
this.decodeSansible = function(data) {
var bin = data;
var obj = {};
var obj = {data:{}};
// obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4);
obj.manID = this.getManID(bin);
obj.p1 = ((bin[2] << 16) | bin[3] << 8 | bin[4])
obj.p2 = ((bin[5] << 16) | bin[6] << 8 | bin[7])
obj.data.p1 = ((bin[2] << 16) | bin[3] << 8 | bin[4]);
obj.data.p2 = ((bin[5] << 16) | bin[6] << 8 | bin[7]);
obj.msg = 'Left: ' + (obj.p1 / 100) + ' hPa, Right: ' + (obj.p2 / 100) + ' hPa';
obj.msg = 'Left: ' + (obj.data.p1 / 100) + ' hPa, Right: ' + (obj.data.p2 / 100) + ' hPa';
return obj;
};

View File

@ -53,9 +53,9 @@ var BATTERY = function() {
this.onError);
}
};
};
inheritsFrom(BATTERY, CAPABILITY);
capabilityManager.register({id: '180F', module: BATTERY});

View File

@ -9,10 +9,12 @@
/* global ble */
/* jshint browser: true , devel: true*/
var BUTTON = function(deviceId) {
var BUTTON = function(p) {
'use strict';
this.name = 'Button';
this.deviceID = deviceId;
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'FFE0';
this.serviceDef = {
service: 'FFE0',
@ -25,6 +27,8 @@ var BUTTON = function(deviceId) {
REED_SWITCH: 4 // 0100
};
this.setFrame();
this.onButtonData = function(data) {
console.log('+ onButtonData');
console.log(data);
@ -83,7 +87,7 @@ var BUTTON = function(deviceId) {
$('<div />', { class: 'mui-col-xs-4 mui--text-accent', text: 'Status:'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-8 mui--text-white', id: detail}).appendTo(row);
$('<div />', { class: 'mui-col-xs-8 mui--text-dark', id: detail}).appendTo(row);
this.$id.append(row);
this.$result = $('#'+detail);
@ -94,3 +98,4 @@ var BUTTON = function(deviceId) {
inheritsFrom(BUTTON, CAPABILITY);
capabilityManager.register({id: 'FFE0', module: BUTTON});

View File

@ -6,6 +6,23 @@
*
*/
'use strict';
var capabilityManager = {
capabilityList : [],
register : function(details) {
console.log('Registered:', details );
this.capabilityList.push(details);
},
discover : function(id) {
var wanted = this.capabilityList.filter(function(obj) {
return obj.id === id;
});
return wanted.length === 1 ? wanted[0].module : null;
}
};
var CAPABILITY = function(p) {
this.name = '-CAPABILITY-';
this.capabilityID = p.capabilityID || null;
@ -22,6 +39,13 @@ var CAPABILITY = function(p) {
this.ctx = null;
this.first = false;
this.target = null;
this.$frame = null;
capabilityManager.register({id:this.capabilityID, module:this});
};
CAPABILITY.prototype.setFrame = function() {
this.$frame = (this.target !== null) ? $('#'+ this.target) : null;
};
CAPABILITY.prototype.setInternalID = function() {
@ -51,7 +75,7 @@ CAPABILITY.prototype.insertFrame = function() {
$('<div />', { class: 'mui-row'}).append($('<div />', { class: 'mui-col-xs-12 mui--text-title', text: title})).appendTo(frame);
$('#frames').append(frame);
this.$frame.append(frame);
this.$id = $('#' + this.frameID);
};
@ -122,7 +146,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
line.setAttributeNS(null,'y1','12');
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'y2', '12');
line.setAttributeNS(null,'style','stroke:#bad649;stroke-width:2;');
line.setAttributeNS(null,'style','stroke:#004c6d;stroke-width:2;');
svg.appendChild(line);
@ -132,7 +156,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
line.setAttributeNS(null,'y1','136');
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'y2', '136');
line.setAttributeNS(null,'style','stroke:#bad649;stroke-width:2;');
line.setAttributeNS(null,'style','stroke:#004c6d;stroke-width:2;');
svg.appendChild(line);
@ -142,7 +166,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
text.setAttributeNS(null,'x','36');
text.setAttributeNS(null,'y','15');
text.setAttributeNS(null,'text-anchor', 'end');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #bad649;text-align:right;');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #004c6d;text-align:right;');
text.textContent = '000';
svg.appendChild(text);
@ -153,7 +177,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
text.setAttributeNS(null,'x','36');
text.setAttributeNS(null,'y','140');
text.setAttributeNS(null,'text-anchor', 'end');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #bad649;text-align:right;');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #004c6d;text-align:right;');
text.textContent = '0';
svg.appendChild(text);
@ -162,7 +186,7 @@ CAPABILITY.prototype.generateBlankGraph = function(subID) {
polyline.setAttributeNS(null,'id',lineID);
polyline.setAttributeNS(null,'fill','none');
polyline.setAttributeNS(null,'stroke','#e5f7fd');
polyline.setAttributeNS(null,'stroke','#2196F3');
//#e5f7fd
// old #B5C7FF
polyline.setAttributeNS(null,'text-anchor', 'end');

View File

@ -0,0 +1,15 @@
/**
*
* User: Martin Donnelly
* Date: 2016-06-01
* Time: 13:30
*
*/
var GADGET = function(p) {
'use strict';
this._gadget = p;
};