/** * * User: Martin Donnelly * Date: 2016-05-20 * Time: 10:13 * */ /* global CAPABILITY, inheritsFrom, capabilityManager, EJS */ /* global ble */ /* jshint browser: true , devel: true*/ var CC2650_HUM = function(p) { 'use strict'; this.name = 'Humidity'; this.deviceID = p.deviceID || null; this.target = p.target || null; 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.setFrame(); this.startService = function() { 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(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'); */ var arcTemp = this.frameID + 'temp-arc'; var arcHumidity = this.frameID + 'humidity-arc'; this.updateArc(this.data.temp, 'temp' , arcTemp, '°C', 50); this.updateArc(this.data.humidity, 'humidity' , arcHumidity, '%RH', 100); }; this.insertFrame = function() { var self = this; // Call the parent displayForm first... this.superClass_.insertFrame.call(self); var temp = this.frameID + '-t'; var humidity = this.frameID + '-h'; var arcB = this.frameID + 'temp-arcB'; var arcTemp = this.frameID + 'temp-arc'; var humidityArcB = this.frameID + 'humidity-arcB'; var arcHumidity = this.frameID + 'humidity-arc'; var settings = {data: {baseID: this.frameID}}; var html = new EJS({url: './partials/cc2650_humidity_dial.ejs'}).render(settings); this.$id.append(html); document.getElementById(arcB).setAttribute('d', this.describeArc(150, 150, 100, 0, 240)); document.getElementById(arcTemp).setAttribute('d', this.describeArc(150, 150, 100, 0, this.setArc(0))); document.getElementById(humidityArcB).setAttribute('d', this.describeArc(150, 150, 100, 0, 240)); document.getElementById(arcHumidity).setAttribute('d', this.describeArc(150, 150, 100, 0, this.setArc(0))); /* Var row = $('
', {class: 'mui-row'}); $('
', {class: 'mui-col-xs-3 mui--text-accent mui--text-right', text: 'Temp:'}).appendTo(row); $('
', {class: 'mui-col-xs-3 mui--text-light', id: temp}).appendTo(row); $('
', { class: 'mui-col-xs-3 mui--text-accent mui--text-right', text: 'Humidity:' }).appendTo(row); $('
', {class: 'mui-col-xs-3 mui--text-light', id: humidity}).appendTo(row); this.$id.append(row); if (/ipad/i.test(device.model)) { tabBody = $('
', {class: 'mui-row'}); tabBody.append($('
',{class: 'mui-col-md-6'}).append(this.generateBlankGraph('temp'))) ; tabBody.append($('
',{class: 'mui-col-md-6'}).append(this.generateBlankGraph('humidity'))) ; this.$id.append(tabBody); } else { var tabBody = $('