Additional services added
This commit is contained in:
parent
22724e22dc
commit
4debb80da2
@ -105,6 +105,8 @@
|
||||
<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/generic_access.js"></script>
|
||||
<script type="text/javascript" src="js/standards/deviceInformation.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>
|
||||
@ -126,6 +128,8 @@
|
||||
<script type="text/javascript"
|
||||
src="js/device/fmc/TSL.js"></script>
|
||||
|
||||
<script type="text/javascript"
|
||||
src="js/device/sensorworks/bluvib.js"></script>
|
||||
|
||||
<!-- build:js -->
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
|
@ -81,10 +81,6 @@ CC2650_ACCEL = function(p) {
|
||||
}
|
||||
calcData = this.processData(data);
|
||||
|
||||
message = 'Gyro <br/>' + 'X: ' + calcData.gyro.x + '<br/>' + 'Y: ' + calcData.gyro.y + '<br/>' + 'Z: ' + calcData.gyro.z + '<br/>' + 'Accel <br/>' + 'X: ' + calcData.accel.x + '<br/>' + 'Y: ' + calcData.accel.y + '<br/>' + 'Z: ' + calcData.accel.z + '<br/>' + 'Mag <br/>' + 'X: ' + calcData.mag.x + '<br/>' + 'Y: ' + calcData.mag.y + '<br/>' + 'Z: ' + calcData.mag.z + '<br/>';
|
||||
|
||||
this.state = message;
|
||||
|
||||
this.$result[this.frames.gyroID + '-x'].text(gString(calcData.gyro.x));
|
||||
this.$result[this.frames.gyroID + '-y'].text(gString(calcData.gyro.y));
|
||||
this.$result[this.frames.gyroID + '-z'].text(gString(calcData.gyro.z));
|
||||
@ -109,8 +105,6 @@ CC2650_ACCEL = function(p) {
|
||||
this.data.mag.y = this.storeData(calcData.mag.y, this.data.mag.y);
|
||||
this.data.mag.z = this.storeData(calcData.mag.z, this.data.mag.z);
|
||||
|
||||
// Console.log(JSON.stringify(this.data));
|
||||
// Console.log(this.state);
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
@ -156,6 +150,9 @@ CC2650_ACCEL = function(p) {
|
||||
};
|
||||
|
||||
this.advancedGraphFFT = function(mode, data, subID) {
|
||||
|
||||
var startX;
|
||||
var _cdata;
|
||||
var xstep;
|
||||
var scalePos;
|
||||
var lm;
|
||||
@ -173,23 +170,25 @@ CC2650_ACCEL = function(p) {
|
||||
var yscale = 125;
|
||||
var height = 125;
|
||||
|
||||
var yOffset = 71;
|
||||
var yOffset;
|
||||
|
||||
var reducer = function(p, v) {
|
||||
return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v));
|
||||
};
|
||||
|
||||
|
||||
var parts = ['x', 'y', 'z'];
|
||||
var _newData = {x: [],y: [],z: []};
|
||||
|
||||
var fnFillNewData = function(c_value, i) {
|
||||
ceiling = reducer(c_value.real ,ceiling);
|
||||
_newData[lm].push(c_value.real);
|
||||
};
|
||||
|
||||
if (subID === 'gyro') {
|
||||
height = 300;
|
||||
yscale = 300;
|
||||
}
|
||||
|
||||
|
||||
|
||||
_data = data || this.data;
|
||||
|
||||
_subID = subID || '';
|
||||
@ -204,23 +203,13 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
for (var lineMode = 0; lineMode < parts.length; lineMode++) {
|
||||
|
||||
|
||||
lm = parts[lineMode];
|
||||
|
||||
var data = new complex_array.ComplexArray(_data[lm]);
|
||||
_cdata = new complex_array.ComplexArray(_data[lm]);
|
||||
|
||||
_cdata.FFT();
|
||||
|
||||
data.FFT();
|
||||
|
||||
data.forEach(function(c_value, i) {
|
||||
ceiling = reducer(c_value.real ,ceiling);
|
||||
_newData[lm].push(c_value.real);
|
||||
});
|
||||
|
||||
//Ceiling = _data[lm].reduce(reducer);
|
||||
|
||||
console.log('ceiling:', ceiling);
|
||||
|
||||
_cdata.forEach(fnFillNewData);
|
||||
|
||||
}
|
||||
|
||||
@ -233,9 +222,6 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
floor = ceiling * -1;
|
||||
ceilingLimit = ceiling;
|
||||
console.log('ceiling:',ceiling);
|
||||
|
||||
|
||||
|
||||
scalePos = (yscale / 2) / ceiling;
|
||||
|
||||
@ -243,14 +229,10 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
yOffset = ((height - (14 + 12)) / 2) + 12;
|
||||
|
||||
|
||||
|
||||
//Var xstep = 2.34;
|
||||
|
||||
for (lineMode = 0; lineMode < parts.length; lineMode++) {
|
||||
|
||||
lm = parts[lineMode];
|
||||
var startX = 46 + (this.maxLength - _newData[lm].length) * xstep;
|
||||
startX = 46 + (this.maxLength - _newData[lm].length) * xstep;
|
||||
|
||||
calcArray = [];
|
||||
|
||||
@ -282,6 +264,7 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
this.advancedGraph = function(mode, data, subID) {
|
||||
|
||||
var startX;
|
||||
var xstep;
|
||||
var scalePos;
|
||||
var lm;
|
||||
@ -299,20 +282,18 @@ CC2650_ACCEL = function(p) {
|
||||
var yscale = 125;
|
||||
var height = 125;
|
||||
|
||||
var yOffset = 71;
|
||||
var yOffset;
|
||||
|
||||
var reducer = function(p, v) {
|
||||
return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v));
|
||||
};
|
||||
|
||||
|
||||
var parts = ['x', 'y', 'z'];
|
||||
|
||||
_data = data || this.data;
|
||||
|
||||
_subID = subID || '';
|
||||
|
||||
// LineID = [this.frameID , _subID , '-line'].join('');
|
||||
text1ID = [this.frameID, _subID, '-txt1'].join('');
|
||||
text2ID = [this.frameID, _subID, '-txt2'].join('');
|
||||
|
||||
@ -321,16 +302,12 @@ CC2650_ACCEL = function(p) {
|
||||
yscale = 300;
|
||||
}
|
||||
|
||||
|
||||
if (_data.x.length > 0) {
|
||||
|
||||
max = 2;
|
||||
|
||||
for (var lineMode = 0; lineMode < parts.length; lineMode++) {
|
||||
lm = parts[lineMode];
|
||||
/*Ceiling = _data[lm].reduce(function(p, v) {
|
||||
return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v));
|
||||
});*/
|
||||
|
||||
ceiling = _data[lm].reduce(reducer);
|
||||
|
||||
@ -350,20 +327,20 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
xstep = (680 - 46) / this.maxLength;
|
||||
|
||||
// YOffset should be about 71;
|
||||
yOffset = ((height - (14 + 12)) / 2) + 12;
|
||||
//Var xstep = 2.34;
|
||||
|
||||
for (lineMode = 0; lineMode < parts.length; lineMode++) {
|
||||
|
||||
lm = parts[lineMode];
|
||||
var startX = 46 + (this.maxLength - _data[lm].length) * xstep;
|
||||
startX = 46 + (this.maxLength - _data[lm].length) * xstep;
|
||||
|
||||
calcArray = [];
|
||||
|
||||
lineID = this.frameID + _subID + '-' + lm + '-line';
|
||||
for (var x = 0; x < _data[lm].length; x++) {
|
||||
|
||||
calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (71 - ((_data[lm][x]) * scalePos)).toFixed(
|
||||
calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (yOffset - ((_data[lm][x]) * scalePos)).toFixed(
|
||||
2));
|
||||
|
||||
}
|
||||
@ -443,7 +420,7 @@ CC2650_ACCEL = function(p) {
|
||||
var ylineID = this.frameID + _subID + '-y-line';
|
||||
var zlineID = this.frameID + _subID + '-z-line';
|
||||
|
||||
var svg = this.generateBlankGraphBase(_subID,{width: '700',height: height});
|
||||
var svg = this.generateBlankGraphBase(_subID,{width: '700',height: _height});
|
||||
|
||||
svg = this.graphAddLine(svg, xlineID, 'rgba(255,0,99,1)');
|
||||
svg = this.graphAddLine(svg, ylineID, 'rgba(46,255,0,1)');
|
||||
@ -453,19 +430,10 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
this.startCalibrate = function() {
|
||||
console.log('Start calibrate');
|
||||
|
||||
alert('Mag Calibration: Wave device in a figure eight until done!');
|
||||
};
|
||||
|
||||
this.insertFrame = function(mode) {
|
||||
|
||||
var _graph;
|
||||
var row;
|
||||
var button;
|
||||
var elm;
|
||||
var frame;
|
||||
var title;
|
||||
@ -482,7 +450,7 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
title = [titles[mode], ' - ', this.deviceID].join(' ');
|
||||
|
||||
frame = $('<div />', {
|
||||
frame = $('<div></div>', {
|
||||
class: 'mui-panel', id: this.frames[modeID]
|
||||
});
|
||||
|
||||
@ -492,22 +460,16 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
if (mode === 'mag') {
|
||||
|
||||
elm = $('<div />', {class: 'mui-row'});
|
||||
button = $('<button />', {
|
||||
class: 'mui-btn mui-btn--raised',
|
||||
id: modeID + '-cal',
|
||||
text: 'Calibrate',
|
||||
click: this.startCalibrate.bind(this)
|
||||
});
|
||||
elm = $('<div></div>', {class: 'mui-row'});
|
||||
|
||||
elm.append($('<div />', { class: 'mui-col-xs-8 mui--text-title mui-ellipsis-2', text: title}));
|
||||
elm.append($('<div></div>', { class: 'mui-col-xs-8 mui--text-title mui-ellipsis-2', text: title}));
|
||||
|
||||
// Elm.append($('<div />', {class: 'mui-col-xs-4 mui--text-right'}).append(button));
|
||||
// Elm.append($('<div></div>', {class: 'mui-col-xs-4 mui--text-right'}).append(button));
|
||||
|
||||
frame.append(elm);
|
||||
|
||||
} else {
|
||||
$('<div />', {class: 'mui-row'}).append($('<div />', {
|
||||
$('<div></div>', {class: 'mui-row'}).append($('<div></div>', {
|
||||
class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title
|
||||
})).appendTo(frame);
|
||||
|
||||
@ -517,33 +479,33 @@ CC2650_ACCEL = function(p) {
|
||||
|
||||
// Call the parent displayForm first...
|
||||
|
||||
row = $('<div />', {class: 'mui-row'});
|
||||
row = $('<div></div>', {class: 'mui-row'});
|
||||
|
||||
$('<div />', {
|
||||
$('<div></div>', {
|
||||
class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'X'
|
||||
}).appendTo(row);
|
||||
$('<div />', {
|
||||
$('<div></div>', {
|
||||
class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Y'
|
||||
}).appendTo(row);
|
||||
$('<div />', {
|
||||
$('<div></div>', {
|
||||
class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Z'
|
||||
}).appendTo(row);
|
||||
|
||||
this.$id[modeID].append(row);
|
||||
|
||||
row = $('<div />', {class: 'mui-row'});
|
||||
row = $('<div></div>', {class: 'mui-row'});
|
||||
|
||||
$('<div />', {
|
||||
$('<div></div>', {
|
||||
class: 'mui-col-xs-4 mui--text-light mui--text-center',
|
||||
text: '--',
|
||||
id: this.frames[modeID] + '-x'
|
||||
}).appendTo(row);
|
||||
$('<div />', {
|
||||
$('<div></div>', {
|
||||
class: 'mui-col-xs-4 mui--text-light mui--text-center',
|
||||
text: '--',
|
||||
id: this.frames[modeID] + '-y'
|
||||
}).appendTo(row);
|
||||
$('<div />', {
|
||||
$('<div></div>', {
|
||||
class: 'mui-col-xs-4 mui--text-light mui--text-center',
|
||||
text: '--',
|
||||
id: this.frames[modeID] + '-z'
|
||||
@ -555,7 +517,7 @@ CC2650_ACCEL = function(p) {
|
||||
this.$result[this.frames[modeID] + '-y'] = $('#' + this.frames[modeID] + '-y');
|
||||
this.$result[this.frames[modeID] + '-z'] = $('#' + this.frames[modeID] + '-z');
|
||||
|
||||
row = $('<div />', {class: 'mui-row'});
|
||||
row = $('<div></div>', {class: 'mui-row'});
|
||||
|
||||
_graph = this.generateBlankGraph(mode, height);
|
||||
row.append($('<div>', {class: 'mui-col-sm-12'}).append(_graph));
|
||||
|
@ -81,27 +81,13 @@ var TSL = function(p) {
|
||||
*/
|
||||
this.onReadVelState = function(d) {
|
||||
var raw = new Uint8Array(d);
|
||||
var output = [], signedOutput = new Int16Array(9);
|
||||
var output = [];
|
||||
var signedOutput = new Int16Array(9);
|
||||
// Var humidity = this.convertToPercent(raw);
|
||||
console.log('Vel State:', raw);
|
||||
// This.$result.h.text(humidity.toFixed(2) + '%');
|
||||
|
||||
/* output.push(((raw[1] << 8) + (raw[0])));
|
||||
output.push(((raw[3] << 8) + (raw[2])));
|
||||
output.push(((raw[5] << 8) + (raw[4])));
|
||||
output.push(((raw[7] << 8) + (raw[6])));
|
||||
output.push(((raw[9] << 8) + (raw[8])));
|
||||
output.push(((raw[11] << 8) + (raw[10])));
|
||||
output.push(((raw[13] << 8) + (raw[12])));
|
||||
output.push(((raw[15] << 8) + (raw[14])));
|
||||
output.push(((raw[17] << 8) + (raw[16])));
|
||||
|
||||
|
||||
for (var t = 0;t < output.length;t++) {
|
||||
signedOutput[t] = (output[t] * 1.0) / (32768/ 2);
|
||||
}
|
||||
console.log(output);
|
||||
console.log(signedOutput);*/
|
||||
};
|
||||
|
||||
|
||||
@ -124,7 +110,7 @@ var TSL = function(p) {
|
||||
|
||||
|
||||
for (var t = 0;t < output.length;t++) {
|
||||
signedOutput[t] = (output[t] * 1.0) / (32768/ 2);
|
||||
signedOutput[t] = (output[t] * 1.0) / (32768 / 2);
|
||||
}
|
||||
console.log(output);
|
||||
console.log(signedOutput);
|
||||
@ -199,19 +185,16 @@ var TSL = function(p) {
|
||||
|
||||
this.onHistoryAck = function(d) {
|
||||
var raw = new Uint8Array(d);
|
||||
var raw16 = new Uint16Array(d);
|
||||
var raw16 = new Uint16Array(d);
|
||||
console.log('History Ack:', raw, raw16);
|
||||
//this.$result.temp.text(temp.toFixed(2) + '°C');
|
||||
|
||||
};
|
||||
|
||||
this.onReadHistory = function(d) {
|
||||
var raw = new Uint8Array(d);
|
||||
|
||||
console.log('History:', raw);
|
||||
//this.$result.temp.text(temp.toFixed(2) + '°C');
|
||||
this.historyloops++;
|
||||
this.historyAck();
|
||||
this.historyloops++;
|
||||
this.historyAck();
|
||||
|
||||
};
|
||||
|
||||
@ -220,30 +203,28 @@ var TSL = function(p) {
|
||||
var raw16 = new Uint16Array(d);
|
||||
|
||||
console.log('History Size:', raw, raw16);
|
||||
//this.$result.temp.text(temp.toFixed(2) + '°C');
|
||||
|
||||
this.history = new Uint8Array(raw16[0]);
|
||||
this.readHistory();
|
||||
};
|
||||
|
||||
this.historySize = function() {
|
||||
console.log('historySize');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.historySize,
|
||||
this.onHistorySize.bind(this),
|
||||
this.onError);
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.historySize,
|
||||
this.onHistorySize.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
|
||||
this.historyAck = function() {
|
||||
console.log('historyAck');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.historyAck,
|
||||
this.onHistoryAck.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
this.historyAck = function() {
|
||||
console.log('historyAck');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.historyAck,
|
||||
this.onHistoryAck.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
this.readHistory = function() {
|
||||
console.log('readHistory');
|
||||
@ -371,12 +352,12 @@ this.historyAck = function() {
|
||||
this.readHumidityMinState();
|
||||
|
||||
this.readAccelState();
|
||||
this.readVelState();
|
||||
this.readVelState();
|
||||
|
||||
this.historySize();
|
||||
// this.readHistory();
|
||||
// This.readHistory();
|
||||
|
||||
// setTimeout(this.readServices.bind(this),20000);
|
||||
// setTimeout(this.readServices.bind(this),20000);
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
|
111
app/js/device/sensorworks/bluvib.js
Normal file
111
app/js/device/sensorworks/bluvib.js
Normal file
@ -0,0 +1,111 @@
|
||||
/**
|
||||
*
|
||||
* User: Martin Donnelly
|
||||
* Date: 2016-05-20
|
||||
* Time: 10:13
|
||||
*
|
||||
*/
|
||||
/* global CAPABILITY, inheritsFrom, capabilityManager, EJS, ejs */
|
||||
/* global ble */
|
||||
/* jshint browser: true , devel: true*/
|
||||
|
||||
var BLUVIB = function(p) {
|
||||
'use strict';
|
||||
this.name = 'BLUVIB';
|
||||
this.deviceID = p.deviceID || null;
|
||||
this.target = p.target || null;
|
||||
|
||||
// 9FB70001-EF7D-40C8-9C1E-5052BC101EFA
|
||||
|
||||
this.capabilityID = '9FB70001-EF7D-40C8-9C1E-5052BC101EFA';
|
||||
this.serviceDef = {
|
||||
service: '9FB70001-EF7D-40C8-9C1E-5052BC101EFA',
|
||||
enable: '9FB70002-EF7D-40C8-9C1E-5052BC101EFA',
|
||||
notify: '9FB70003-EF7D-40C8-9C1E-5052BC101EFA',
|
||||
period: '9FB70004-EF7D-40C8-9C1E-5052BC101EFA'
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.$result = {temp: null, tempMax: null, tempMin: null};
|
||||
this.data = [];
|
||||
this.setFrame();
|
||||
this.read = {};
|
||||
|
||||
this.html = {};
|
||||
|
||||
this.history = null;
|
||||
|
||||
this.historyloops = 0;
|
||||
|
||||
|
||||
|
||||
this.onNotification = function(d) {
|
||||
|
||||
this.readRaw('BluVib', d);
|
||||
};
|
||||
|
||||
|
||||
this.readValue = function() {
|
||||
console.log('readHistory');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.history,
|
||||
this.onReadValue.bind(this),
|
||||
this.onError);
|
||||
|
||||
};
|
||||
|
||||
|
||||
this.readServices = function() {
|
||||
|
||||
this.readValue();
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
|
||||
if (this.deviceID !== null) {
|
||||
|
||||
console.log('Starting BLUVIB Service on ', this.deviceID);
|
||||
console.log(this.serviceDef);
|
||||
this.insertFrame();
|
||||
|
||||
ble.startNotification(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.notify,
|
||||
this.onNotification.bind(this),
|
||||
this.onError);
|
||||
|
||||
|
||||
var configData = new Uint16Array(1);
|
||||
// Turn on gyro, accel, and mag, 2G range, Disable wake on motion
|
||||
configData[0] = 0x0001;
|
||||
ble.write(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.enable,
|
||||
configData.buffer,
|
||||
function(m) { console.log('Started BluVib.',m); },
|
||||
this.onError);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
this.animateGraph = function() {
|
||||
return -1;
|
||||
};
|
||||
|
||||
this.insertFrame = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
// Call the parent displayForm first...
|
||||
this.superClass_.insertFrame.call(self);
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
inheritsFrom(BLUVIB, CAPABILITY);
|
||||
capabilityManager.register({id: '9FB70001-EF7D-40C8-9C1E-5052BC101EFA', module: BLUVIB});
|
@ -52,6 +52,40 @@ var CAPABILITY = function(p) {
|
||||
capabilityManager.register({id: this.capabilityID, module: this});
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.arrayToAscii = function(a) {
|
||||
|
||||
var _a = [].slice.call(a);
|
||||
_a = _a.map(function(num) {
|
||||
return String.fromCharCode(num);
|
||||
});
|
||||
|
||||
return _a.join('');
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.arrayToHex = function(a) {
|
||||
|
||||
var _a = [].slice.call(a);
|
||||
_a = _a.map(function(num) {
|
||||
return ('00' + num.toString(16)).slice(-2);
|
||||
});
|
||||
|
||||
return _a.join(', ');
|
||||
};
|
||||
|
||||
|
||||
|
||||
CAPABILITY.prototype.readRaw = function(id, data) {
|
||||
|
||||
|
||||
var a = new Uint8Array(data);
|
||||
|
||||
console.log(id, a);
|
||||
console.log(id, this.arrayToAscii(a));
|
||||
console.log(id, this.arrayToHex(a));
|
||||
console.log(data);
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.setFrame = function() {
|
||||
this.$frame = (this.target !== null) ? $('#' + this.target) : null;
|
||||
};
|
||||
|
@ -9,53 +9,67 @@
|
||||
/* global ble */
|
||||
/* jshint browser: true , devel: true*/
|
||||
|
||||
var DEVICEINFO = function() {
|
||||
var DEVICEINFO = function(p) {
|
||||
this.name = 'Device Information';
|
||||
this.deviceID = p.deviceID || null;
|
||||
this.target = p.target || null;
|
||||
|
||||
this.capabilityID = '180A';
|
||||
this.serviceDef = {
|
||||
service: '180A', manufacturer_name_string: '2A29', model_number_string: '2A24'
|
||||
service: '180A', manufacturer_name_string: '2A29', model_number_string: '2A24', system_id: '2A23',
|
||||
};
|
||||
|
||||
this.onBatteryLevelChange = function(data) {
|
||||
console.log(data);
|
||||
var a = new Uint8Array(data);
|
||||
this.state = a[0];
|
||||
console.log('onBatteryLevelChange', this.state);
|
||||
};
|
||||
this.readBatteryState = function() {
|
||||
console.log('readBatteryState');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.level,
|
||||
this.onReadBatteryLevel.bind(this),
|
||||
this.onError);
|
||||
this.data = {
|
||||
manufacturerName: '',
|
||||
modelNumber: ''
|
||||
};
|
||||
|
||||
this.onSystemID = function(data) {
|
||||
'use strict';
|
||||
this.readRaw('SystemID', data);
|
||||
};
|
||||
|
||||
this.onReadBatteryLevel = function(data) {
|
||||
console.log(data);
|
||||
this.onModelNumberString = function(data) {
|
||||
'use strict';
|
||||
var a = new Uint8Array(data);
|
||||
this.state = a[0];
|
||||
console.log('onReadBatteryLevel', this.state);
|
||||
this.data.modelNumber = this.arrayToAscii(a);
|
||||
console.log('Model Number', this.data.modelNumber);
|
||||
};
|
||||
|
||||
|
||||
this.readSystemID = function() {
|
||||
console.log('readSystemID');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.system_id,
|
||||
this.onSystemID.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
|
||||
this.readModelNumberString = function() {
|
||||
console.log('readModelNumberString');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.model_number_string,
|
||||
this.onModelNumberString.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
if (this.deviceID !== null) {
|
||||
console.log('Starting Battery Service on ', this.deviceID);
|
||||
console.log('Starting DEVICEINFO Service on ', this.deviceID);
|
||||
console.log(this.serviceDef);
|
||||
|
||||
this.insertFrame();
|
||||
this.readSystemID();
|
||||
this.readModelNumberString();
|
||||
|
||||
ble.startNotification(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.level,
|
||||
this.onBatteryLevelChange.bind(this),
|
||||
this.onError);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
inheritsFrom(BATTERY, CAPABILITY);
|
||||
capabilityManager.register({id: '180F', module: BATTERY});
|
||||
inheritsFrom(DEVICEINFO, CAPABILITY);
|
||||
capabilityManager.register({id: '180A', module: DEVICEINFO});
|
||||
|
160
app/js/standards/generic_access.js
Normal file
160
app/js/standards/generic_access.js
Normal file
@ -0,0 +1,160 @@
|
||||
/**
|
||||
*
|
||||
* User: Martin Donnelly
|
||||
* Date: 2016-05-20
|
||||
* Time: 10:13
|
||||
*
|
||||
*/
|
||||
/* global CAPABILITY, inheritsFrom, capabilityManager */
|
||||
/* global ble */
|
||||
/* jshint browser: true , devel: true*/
|
||||
|
||||
var GENERICACCESS = function(p) {
|
||||
this.name = 'GenericAccess';
|
||||
this.deviceID = p.deviceID || null;
|
||||
this.target = p.target || null;
|
||||
this.capabilityID = '1800';
|
||||
this.serviceDef = {
|
||||
service: '1800', deviceName: '2A00', appearance: '2A01', PPCP: '2A04'
|
||||
};
|
||||
|
||||
this.data = {
|
||||
deviceName: '',
|
||||
appearance: '',
|
||||
ppcp: {
|
||||
min_conn_int: 0,
|
||||
max_conn_int: 0,
|
||||
slave_latency: 0,
|
||||
conn_super_timeout_multi: 0
|
||||
}
|
||||
};
|
||||
|
||||
this.appearance_category = {
|
||||
0: 'Unknown None',
|
||||
64: 'Generic Phone',
|
||||
128: 'Generic Computer ',
|
||||
192: 'Generic Watch ',
|
||||
193: 'Watch: Sports Watch ',
|
||||
256: 'Generic Clock ',
|
||||
320: 'Generic Display ',
|
||||
384: 'Generic Remote Control ',
|
||||
448: 'Generic Eye-glasses ',
|
||||
512: 'Generic Tag ',
|
||||
576: 'Generic Keyring ',
|
||||
640: 'Generic Media Player ',
|
||||
704: 'Generic Barcode Scanner ',
|
||||
768: 'Generic Thermometer ',
|
||||
769: 'Thermometer: Ear ',
|
||||
832: 'Generic Heart rate Sensor ',
|
||||
833: 'Heart Rate Sensor: Heart Rate Belt ',
|
||||
896: 'Generic Blood Pressure ',
|
||||
897: 'Blood Pressure: Arm Blood ',
|
||||
898: 'Blood Pressure: Wrist Blood ',
|
||||
960: 'Human Interface Device (HID) ',
|
||||
961: 'Keyboard ',
|
||||
962: 'Mouse ',
|
||||
963: 'Joystick ',
|
||||
964: 'Gamepad ',
|
||||
965: 'Digitizer Tablet ',
|
||||
966: 'Card Reader ',
|
||||
967: 'Digital Pen ',
|
||||
968: 'Barcode Scanner ',
|
||||
1024: 'Generic Glucose Meter ',
|
||||
1088: 'Generic: Running Walking Sensor ',
|
||||
1089: 'Running Walking Sensor: In-Shoe Running ',
|
||||
1090: 'Running Walking Sensor: On-Shoe Running ',
|
||||
1091: 'Running Walking Sensor: On-Hip Running ',
|
||||
1152: 'Generic: Cycling ',
|
||||
1153: 'Cycling: Cycling Computer ',
|
||||
1154: 'Cycling: Speed Sensor ',
|
||||
1155: 'Cycling: Cadence Sensor ',
|
||||
1156: 'Cycling: Power Sensor ',
|
||||
1157: 'Cycling: Speed and Cadence Sensor ',
|
||||
3136: 'Generic: Pulse Oximeter ',
|
||||
3137: 'Fingertip ',
|
||||
3138: 'Wrist Worn ',
|
||||
3200: 'Generic: Weight Scale ',
|
||||
5184: 'Generic: Outdoor Sports Activity ',
|
||||
5185: 'Location Display Device ',
|
||||
5186: 'Location and Navigation Display Device ',
|
||||
5187: 'Location Pod ',
|
||||
5188: 'Location and Navigation Pod '
|
||||
};
|
||||
|
||||
this.onDeviceName = function(data) {
|
||||
var a = new Uint8Array(data);
|
||||
this.data.deviceName = this.arrayToAscii(a);
|
||||
console.log('Device Name', this.data.deviceName);
|
||||
};
|
||||
|
||||
this.onAppearance = function(data) {
|
||||
var a = new Uint16Array(data);
|
||||
var id = a[0];
|
||||
this.data.appearance = this.appearance_category[id];
|
||||
console.log('Appearance', this.data.appearance);
|
||||
};
|
||||
|
||||
this.onPPCP = function(data) {
|
||||
var a = new Uint16Array(data);
|
||||
|
||||
this.data = {
|
||||
ppcp: {
|
||||
min_conn_int: (a[0] * 1.25),
|
||||
max_conn_int: (a[1] * 1.25),
|
||||
slave_latency: a[2],
|
||||
conn_super_timeout_multi: a[3]
|
||||
}
|
||||
};
|
||||
|
||||
console.log('PPCP', this.data.ppcp);
|
||||
};
|
||||
|
||||
|
||||
this.readDeviceName = function() {
|
||||
console.log('readDeviceName');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.deviceName,
|
||||
this.onDeviceName.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
this.readAppearance = function() {
|
||||
console.log('readAppearance');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.appearance,
|
||||
this.onAppearance.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
/**
|
||||
* Peripheral Preferred Connection Parameters
|
||||
*/
|
||||
this.readPPCP = function() {
|
||||
console.log('readPPCP');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.PPCP,
|
||||
this.onPPCP.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
if (this.deviceID !== null) {
|
||||
console.log('Starting Generic Access on ', this.deviceID);
|
||||
console.log(this.serviceDef);
|
||||
|
||||
this.readDeviceName();
|
||||
this.readAppearance();
|
||||
this.readPPCP();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
inheritsFrom(GENERICACCESS, CAPABILITY);
|
||||
capabilityManager.register({id: '1800', module: GENERICACCESS});
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,134 +1 @@
|
||||
<!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
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<html>
|
||||
<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
|
||||
Some notes:
|
||||
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
|
||||
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
|
||||
* 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 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">
|
||||
<!-- build:fonts -->
|
||||
<link rel="stylesheet" href="fonts/fonts.css">
|
||||
<!-- endbuild -->
|
||||
|
||||
<!-- build:mui -->
|
||||
<link href="css/mui.custom.css" rel="stylesheet" type="text/css"/>
|
||||
<!-- endbuild -->
|
||||
<!-- build:css -->
|
||||
<link href="css/app.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/ripple.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/progress.css" rel="stylesheet" type="text/css"/>
|
||||
<!-- endbuild -->
|
||||
<title>Sensor Toy</title>
|
||||
</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>
|
||||
</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="scanResults"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
|
||||
<!-- build:vendor -->
|
||||
<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/ejs/ejs.js"></script>
|
||||
<script type="text/javascript"
|
||||
src="libs/bluebird/js/browser/bluebird.js"></script>
|
||||
|
||||
<script type="text/javascript" src="libs/jsfft/complex_array.js"></script>
|
||||
<script type="text/javascript" src="libs/jsfft/fft.js"></script>
|
||||
|
||||
<!-- endbuild -->
|
||||
|
||||
<!-- build:standards -->
|
||||
<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>
|
||||
<!-- endbuild -->
|
||||
|
||||
<!-- build:cc2650 -->
|
||||
<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>
|
||||
<!-- endbuild -->
|
||||
|
||||
<script type="text/javascript"
|
||||
src="js/device/fmc/TSL.js"></script>
|
||||
|
||||
|
||||
<!-- build:js -->
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
<!-- endbuild -->
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html><html><head><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"><link rel="stylesheet" href="fonts/fonts.css"><link rel="stylesheet" href="css/custom.css"><link rel="stylesheet" href="css/app.css"><title>Sensor Toy</title></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></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="scanResults"></div></div></div></div></div><script type="text/javascript" src="cordova.js"></script><script src="libs/vendor.js"></script><script src="js/standards.js"></script><script src="js/cc2650.js"></script><script type="text/javascript" src="js/device/fmc/TSL.js"></script><script type="text/javascript" src="js/device/sensorworks/bluvib.js"></script><script src="js/app.js"></script></body></html>
|
Loading…
Reference in New Issue
Block a user