',{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 = $('
');
- newTR.append($('').text(device.id));
-
- if (device.hasOwnProperty('name')) {
- newTR.append($(' | ').text(device.name + msgText));
- } else {
- newTR.append($(' | ').text('*** Unknown' + msgText));
- }
-
- newTR.append($(' | ').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) + ' ');
- //$('#output').append(JSON.stringify(device) + ' ');
+ 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);
+
+ $('', {class: 'mui-tabs__pane', id: paneID}).appendTo(panes);
+
+
+ var li = $(' ').append($('',{'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,84 +462,63 @@ 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:
- console.error('Unknown service: ', ident);
+ 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));
};
- ble.connect(deviceId, onConnect, function(e) {
- 'use strict';
- console.error(e);
- });
+ 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
@@ -492,7 +528,6 @@ var app = {
}
};
-
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
@@ -502,6 +537,4 @@ window.requestAnimFrame = (function() {
};
})();
-
-
app.initialize();
diff --git a/www/js/mandecoder.js b/www/js/mandecoder.js
index 1530a32..ce6b69f 100644
--- a/www/js/mandecoder.js
+++ b/www/js/mandecoder.js
@@ -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;
};
diff --git a/www/js/standards/battery.js b/www/js/standards/battery.js
index 0b8ad9a..8b56bc6 100644
--- a/www/js/standards/battery.js
+++ b/www/js/standards/battery.js
@@ -53,9 +53,9 @@ var BATTERY = function() {
this.onError);
}
-
};
};
inheritsFrom(BATTERY, CAPABILITY);
+capabilityManager.register({id: '180F', module: BATTERY});
diff --git a/www/js/standards/button.js b/www/js/standards/button.js
index cadf69a..a143800 100644
--- a/www/js/standards/button.js
+++ b/www/js/standards/button.js
@@ -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) {
$('', { class: 'mui-col-xs-4 mui--text-accent', text: 'Status:'}).appendTo(row);
- $('', { class: 'mui-col-xs-8 mui--text-white', id: detail}).appendTo(row);
+ $('', { 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});
diff --git a/www/js/standards/capability.js b/www/js/standards/capability.js
index 49147fd..0810b29 100644
--- a/www/js/standards/capability.js
+++ b/www/js/standards/capability.js
@@ -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() {
$('', { class: 'mui-row'}).append($('', { 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');
diff --git a/www/js/standards/gadget.js b/www/js/standards/gadget.js
new file mode 100644
index 0000000..a5a19ff
--- /dev/null
+++ b/www/js/standards/gadget.js
@@ -0,0 +1,15 @@
+/**
+ *
+ * User: Martin Donnelly
+ * Date: 2016-06-01
+ * Time: 13:30
+ *
+ */
+
+var GADGET = function(p) {
+ 'use strict';
+
+
+ this._gadget = p;
+
+};
|