139 lines
4.3 KiB
JavaScript
139 lines
4.3 KiB
JavaScript
/**
|
|
*
|
|
* User: Martin Donnelly
|
|
* Date: 2016-05-20
|
|
* Time: 10:13
|
|
*
|
|
*/
|
|
/* global CAPABILITY, inheritsFrom */
|
|
/* global ble */
|
|
/* jshint browser: true , devel: true*/
|
|
|
|
var CC2650_BAR = function(deviceId) {
|
|
'use strict';
|
|
this.name = 'Barometer';
|
|
this.deviceID = deviceId;
|
|
this.capabilityID = 'F000AA40-0451-4000-B000-000000000000';
|
|
this.serviceDef = {
|
|
service: 'F000AA40-0451-4000-B000-000000000000',
|
|
data: 'F000AA41-0451-4000-B000-000000000000',
|
|
notification: 'F0002902-0451-4000-B000-000000000000',
|
|
configuration: 'F000AA42-0451-4000-B000-000000000000',
|
|
period: 'F000AA43-0451-4000-B000-000000000000'
|
|
|
|
};
|
|
this.data = {temp: [], pressure: []};
|
|
this.$result = {temp: null, pressure: null};
|
|
|
|
this.startService = function() {
|
|
'use strict';
|
|
if (this.deviceID !== null) {
|
|
|
|
console.log('Starting CC2650 Barometer Service on ', this.deviceID);
|
|
console.log(this.serviceDef);
|
|
this.insertFrame();
|
|
|
|
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onBarometerData.bind(this), this.onError);
|
|
|
|
//Turn on barometer
|
|
var barometerConfig = new Uint8Array(1);
|
|
barometerConfig[0] = 0x01;
|
|
ble.write(this.deviceID, this.serviceDef.service, this.serviceDef.configuration, barometerConfig.buffer,
|
|
function() { console.log('Started barometer.'); },this.onError);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.sensorBarometerConvert = function(data) {
|
|
return (data / 100);
|
|
|
|
};
|
|
|
|
this.onBarometerData = function(data) {
|
|
var pStr;
|
|
var tStr;
|
|
// Console.log(data);
|
|
var message;
|
|
var a = new Uint8Array(data);
|
|
|
|
//0-2 Temp
|
|
//3-5 Pressure
|
|
var temp, pressure;
|
|
temp = this.sensorBarometerConvert(a[0] | (a[1] << 8) | (a[2] << 16));
|
|
pressure = this.sensorBarometerConvert(a[3] | (a[4] << 8) | (a[5] << 16));
|
|
tStr = temp + '°C';
|
|
pStr = pressure + 'hPa';
|
|
|
|
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);
|
|
|
|
|
|
this.$result.temp.text(tStr);
|
|
this.$result.pressure.text(pStr);
|
|
|
|
this.state = message;
|
|
|
|
// Console.log('Barometer:', this.state);
|
|
};
|
|
|
|
this.animateGraph = function() {
|
|
this.simpleGraph(this.data.temp, 'temp');
|
|
this.simpleGraph(this.data.pressure, 'pressure');
|
|
};
|
|
|
|
|
|
this.insertFrame = function() {
|
|
|
|
var self = this;
|
|
var blankChart;
|
|
|
|
// Call the parent displayForm first...
|
|
this.superClass_.insertFrame.call(self);
|
|
|
|
var temp = this.frameID + '-t';
|
|
var pressure = this.frameID + '-p';
|
|
var row = $('<div />', {class: 'mui-row'});
|
|
|
|
$('<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-accent', text: 'Pressure:'}).appendTo(row);
|
|
|
|
$('<div />', { class: 'mui-col-xs-3 mui--text-white', 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);
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
inheritsFrom(CC2650_BAR, CAPABILITY);
|