2016-05-20 23:51:30 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* User: Martin Donnelly
|
|
|
|
* Date: 2016-05-20
|
|
|
|
* Time: 10:13
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/* global CAPABILITY, inheritsFrom */
|
|
|
|
/* global ble */
|
|
|
|
/* jshint browser: true , devel: true*/
|
|
|
|
|
|
|
|
var CC2650_HUM = function(deviceId) {
|
|
|
|
'use strict';
|
|
|
|
this.name = 'Humidity';
|
|
|
|
this.deviceID = deviceId;
|
|
|
|
this.capabilityID = 'F000AA20-0451-4000-B000-000000000000';
|
|
|
|
this.serviceDef = {
|
|
|
|
service: 'F000AA20-0451-4000-B000-000000000000',
|
|
|
|
data: 'F000AA21-0451-4000-B000-000000000000',
|
|
|
|
notification: 'F0002902-0451-4000-B000-000000000000',
|
|
|
|
configuration: 'F000AA22-0451-4000-B000-000000000000',
|
|
|
|
period: 'F000AA23-0451-4000-B000-000000000000'
|
|
|
|
|
|
|
|
};
|
2016-05-27 08:25:10 +00:00
|
|
|
this.data = {temp: [], humidity: []};
|
2016-05-20 23:51:30 +00:00
|
|
|
this.$result = {temp: null, humidity: null};
|
|
|
|
|
|
|
|
this.startService = function() {
|
|
|
|
'use strict';
|
|
|
|
if (this.deviceID !== null) {
|
|
|
|
|
|
|
|
console.log('Starting CC2650 Humidity Service on ', this.deviceID);
|
|
|
|
console.log(this.serviceDef);
|
|
|
|
this.insertFrame();
|
|
|
|
|
|
|
|
ble.startNotification(this.deviceID,
|
|
|
|
this.serviceDef.service,
|
|
|
|
this.serviceDef.data,
|
|
|
|
this.onHumidityData.bind(this),
|
|
|
|
this.onError);
|
|
|
|
|
|
|
|
//Turn on barometer
|
|
|
|
var humidityConfig = new Uint8Array(1);
|
|
|
|
humidityConfig[0] = 0x01;
|
|
|
|
ble.write(this.deviceID,
|
|
|
|
this.serviceDef.service,
|
|
|
|
this.serviceDef.configuration,
|
|
|
|
humidityConfig.buffer,
|
|
|
|
function() { console.log('Started Humidity.'); },
|
|
|
|
this.onError);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2016-05-27 08:25:10 +00:00
|
|
|
|
2016-05-20 23:51:30 +00:00
|
|
|
this.onHumidityData = function(data) {
|
|
|
|
var hStr;
|
|
|
|
var tStr;
|
2016-05-27 08:25:10 +00:00
|
|
|
// Console.log(data);
|
2016-05-20 23:51:30 +00:00
|
|
|
var message;
|
|
|
|
var raw = new Uint16Array(data);
|
|
|
|
|
|
|
|
//-- calculate temperature [°C]
|
|
|
|
var temp = (raw[0] / 65536) * 165 - 40;
|
|
|
|
|
|
|
|
//-- calculate relative humidity [%RH]
|
|
|
|
var hum = (raw[1] / 65536) * 100;
|
|
|
|
|
2016-05-27 08:25:10 +00:00
|
|
|
tStr = temp.toFixed(2) + '°C';
|
|
|
|
hStr = hum.toFixed(2) + '%RH';
|
|
|
|
|
|
|
|
message = 'Temperature <br/>' + tStr + 'Humidity <br/>' + hStr;
|
|
|
|
|
|
|
|
// This.data.temp = this.storeData(parseInt(temp), this.data.temp);
|
|
|
|
// this.data.humidity = this.storeData(parseInt(hum), this.data.humidity);
|
|
|
|
|
|
|
|
this.data.temp = this.storeData(temp, this.data.temp);
|
|
|
|
this.data.humidity = this.storeData(hum, this.data.humidity);
|
2016-05-20 23:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
this.$result.temp.text(tStr);
|
|
|
|
this.$result.humidity.text(hStr);
|
|
|
|
|
|
|
|
this.state = message;
|
|
|
|
|
2016-05-27 08:25:10 +00:00
|
|
|
// Console.log('Barometer:', this.state);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.animateGraph = function() {
|
|
|
|
this.simpleGraph(this.data.temp, 'temp');
|
|
|
|
this.simpleGraph(this.data.humidity, 'humidity');
|
2016-05-20 23:51:30 +00:00
|
|
|
};
|
|
|
|
|
2016-05-27 08:25:10 +00:00
|
|
|
|
2016-05-20 23:51:30 +00:00
|
|
|
this.insertFrame = function() {
|
|
|
|
|
|
|
|
var self = this;
|
2016-05-27 08:25:10 +00:00
|
|
|
var blankChart;
|
|
|
|
|
2016-05-20 23:51:30 +00:00
|
|
|
// Call the parent displayForm first...
|
|
|
|
this.superClass_.insertFrame.call(self);
|
|
|
|
|
|
|
|
var temp = this.frameID + '-t';
|
|
|
|
var humidity = this.frameID + '-h';
|
|
|
|
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: 'Humidity:'
|
|
|
|
}).appendTo(row);
|
|
|
|
|
|
|
|
$('<div />',
|
|
|
|
{class: 'mui-col-xs-3 mui--text-white', id: humidity}).appendTo(row);
|
|
|
|
|
|
|
|
this.$id.append(row);
|
2016-05-27 08:25:10 +00:00
|
|
|
|
|
|
|
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: 'Humidity','data-mui-toggle': 'tab', 'data-mui-controls': (humidity + '-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('humidity');
|
|
|
|
this.$id.append($('<div>',{class: 'mui-tabs__pane',id: (humidity + '-pane')}).append(blankChart));
|
|
|
|
|
|
|
|
// this.$id.append(blankChart);
|
|
|
|
|
2016-05-20 23:51:30 +00:00
|
|
|
this.$result.temp = $('#' + temp);
|
|
|
|
this.$result.humidity = $('#' + humidity);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inheritsFrom(CC2650_HUM, CAPABILITY);
|