/** * * 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' }; this.data = {temp: [], humidity: []}; 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); } }; this.onHumidityData = function(data) { var hStr; var tStr; // Console.log(data); 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; tStr = temp.toFixed(2) + '°C'; hStr = hum.toFixed(2) + '%RH'; message = 'Temperature
' + tStr + 'Humidity
' + 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); this.$result.temp.text(tStr); this.$result.humidity.text(hStr); this.state = message; // Console.log('Barometer:', this.state); }; this.animateGraph = function() { this.simpleGraph(this.data.temp, 'temp'); this.simpleGraph(this.data.humidity, 'humidity'); }; this.insertFrame = function() { var self = this; var blankChart; // Call the parent displayForm first... this.superClass_.insertFrame.call(self); var temp = this.frameID + '-t'; var humidity = this.frameID + '-h'; 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: 'Humidity:' }).appendTo(row); $('
', {class: 'mui-col-xs-3 mui--text-white', id: humidity}).appendTo(row); this.$id.append(row); var tabBody = $('