/** * * 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: 'F000AA01-0451-4000-B000-000000000000', data: 'F000AA71-0451-4000-B000-000000000000', notification: 'F0002902-0451-4000-B000-000000000000', configuration: 'F0000AA02-0451-4000-B000-000000000000', period: 'F000AA03-0451-4000-B000-000000000000' }; 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 + '°C'; var aStr = ambTemp + '°C'; this.state = ['Temp: ', tStr, ', Ambient:', aStr].join(' '); this.$result.temp.text(tStr); this.$result.ambient.text(aStr); console.log('Thermopile:', this.state); }; this.insertFrame = function() { 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); this.$result.temp = $('#' + temp); this.$result.ambient = $('#' + amb); }; }; inheritsFrom(CC2650_TMP, CAPABILITY);