sensortoy/www/js/device/CC2650/cc2650_thermopile.js

153 lines
4.0 KiB
JavaScript
Raw Normal View History

/**
*
* User: Martin Donnelly
* Date: 2016-05-20
* Time: 10:13
*
*/
/* global CAPABILITY, inheritsFrom */
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_TMP = function(deviceId) {
'use strict';
this.name = 'Thermopile';
this.deviceID = deviceId;
this.capabilityID = 'F000AA00-0451-4000-B000-000000000000';
this.serviceDef = {
2016-05-27 08:25:10 +00:00
service: 'F000AA00-0451-4000-B000-000000000000',
data: 'F000AA01-0451-4000-B000-000000000000',
notification: 'F0002902-0451-4000-B000-000000000000',
2016-05-27 08:25:10 +00:00
configuration: 'F000AA02-0451-4000-B000-000000000000',
period: 'F000AA03-0451-4000-B000-000000000000'
};
2016-05-27 08:25:10 +00:00
this.data = {temp: [], ambient: []};
this.$result = {temp: null, ambient: null};
this.startService = function() {
'use strict';
if (this.deviceID !== null) {
console.log('Starting CC2650 Thermopile Service on ', this.deviceID);
console.log(this.serviceDef);
this.insertFrame();
ble.startNotification(this.deviceID,
this.serviceDef.service,
this.serviceDef.data,
this.onThermData.bind(this),
this.onError);
//Turn on thermopile
var tmpConfig = new Uint8Array(1);
tmpConfig[0] = 0x01;
ble.write(this.deviceID,
this.serviceDef.service,
this.serviceDef.configuration,
tmpConfig.buffer,
function() { console.log('Started Thermopile.'); },
this.onError);
}
};
this.onThermData = function(data) {
var ambTemp;
var objTemp;
var scale_lsb = 0.03125;
var raw = new Uint16Array(data);
var it = raw[0] >> 2;
objTemp = it * scale_lsb;
it = raw[1] >> 2;
ambTemp = it * scale_lsb;
2016-05-27 08:25:10 +00:00
var tStr = objTemp.toFixed(2) + '°C';
var aStr = ambTemp.toFixed(2) + '°C';
this.state = ['Temp: ', tStr, ', Ambient:', aStr].join(' ');
2016-05-27 08:25:10 +00:00
this.data.temp = this.storeData(objTemp, this.data.temp);
this.data.ambient = this.storeData(ambTemp, this.data.ambient);
this.$result.temp.text(tStr);
this.$result.ambient.text(aStr);
2016-05-27 08:25:10 +00:00
// Console.log('Thermopile:', this.state);
};
this.animateGraph = function() {
this.simpleGraph(this.data.temp, 'temp');
this.simpleGraph(this.data.ambient, 'ambient');
};
2016-05-27 08:25:10 +00:00
this.insertFrame = function() {
2016-05-27 08:25:10 +00:00
var blankChart;
var self = this;
2016-05-27 08:25:10 +00:00
// Console.log('Overloading...');
// Call the parent displayForm first...
this.superClass_.insertFrame.call(self);
var temp = this.frameID + '-t';
var amb = this.frameID + '-a';
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',
2016-05-27 08:25:10 +00:00
text: 'Ambient:'
}).appendTo(row);
$('<div />',
{class: 'mui-col-xs-3 mui--text-white', id: amb}).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:'Ambient','data-mui-toggle': 'tab', 'data-mui-controls': (amb + '-pane')})).appendTo(tabBody);
this.$id.append(tabBody);
/*
<div class="mui-tabs__pane mui--is-active" id="pane-justified-1">Pane-1</div>
<div class="mui-tabs__pane" id="pane-justified-2">Pane-2</div>
*/
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('ambient');
//this.$id.append(blankChart);
this.$id.append($('<div>',{'class':'mui-tabs__pane',id:(amb + '-pane')}).append(blankChart));
this.$result.temp = $('#' + temp);
this.$result.ambient = $('#' + amb);
};
};
inheritsFrom(CC2650_TMP, CAPABILITY);