/**
*
* User: Martin Donnelly
* Date: 2016-05-20
* Time: 10:13
*
*/
/* global CAPABILITY, inheritsFrom, capabilityManager, EJS */
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_BAR = function(p) {
'use strict';
this.name = 'Barometer';
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',
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.setFrame();
this.startService = function() {
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;
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(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');*/
var arcTemp = this.frameID + 'temp-arc';
var arcPressure = this.frameID + 'pressure-arc';
this.updateArc(this.data.temp, 'temp' , arcTemp, '°C', 50);
this.updateArc(this.data.pressure, 'pressure' , arcPressure, 'hPa');
};
this.insertFrame = function() {
var self = this;
// Call the parent displayForm first...
this.superClass_.insertFrame.call(self);
var temp = this.frameID + '-t';
var pressure = this.frameID + '-p';
var arcB = this.frameID + 'temp-arcB';
var arcTemp = this.frameID + 'temp-arc';
var pressureArcB = this.frameID + 'pressure-arcB';
var arcPressure = this.frameID + 'pressure-arc';
var settings = {data: {baseID: this.frameID}};
var html = new EJS({url: './partials/cc2650_barometer_dial.ejs'}).render(settings);
this.$id.append(html);
document.getElementById(arcB).setAttribute('d', this.describeArc(150, 150, 100, 0, 240));
document.getElementById(arcTemp).setAttribute('d', this.describeArc(150, 150, 100, 0, this.setArc(0)));
document.getElementById(pressureArcB).setAttribute('d', this.describeArc(150, 150, 100, 0, 240));
document.getElementById(arcPressure).setAttribute('d', this.describeArc(150, 150, 100, 0, this.setArc(0)));
/* Var row = $('