/** * * 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 = { service: 'F000AA00-0451-4000-B000-000000000000', data: 'F000AA01-0451-4000-B000-000000000000', notification: 'F0002902-0451-4000-B000-000000000000', configuration: 'F000AA02-0451-4000-B000-000000000000', period: 'F000AA03-0451-4000-B000-000000000000' }; 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; var tStr = objTemp.toFixed(2) + '°C'; var aStr = ambTemp.toFixed(2) + '°C'; this.state = ['Temp: ', tStr, ', Ambient:', aStr].join(' '); 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); // Console.log('Thermopile:', this.state); }; this.animateGraph = function() { this.simpleGraph(this.data.temp, 'temp'); this.simpleGraph(this.data.ambient, 'ambient'); }; this.insertFrame = function() { var blankChart; var self = this; // 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 = $('
', {class: 'mui-row'}); $('
', {class: 'mui-col-xs-3 mui--text-accent', text: 'Temp:'}).appendTo(row); $('
', {class: 'mui-col-xs-3 mui--text-white', id: temp}).appendTo(row); $('
', { class: 'mui-col-xs-3 mui--text-accent', text: 'Ambient:' }).appendTo(row); $('
', {class: 'mui-col-xs-3 mui--text-white', id: amb}).appendTo(row); this.$id.append(row); var tabBody = $('