/**
*
* 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
' + tStr +
'Pressure
' + 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 = $('