sensortoy/www/js/device/CC2650/cc2650_luxometer.js

104 lines
2.7 KiB
JavaScript
Raw Normal View History

2016-05-20 16:10:40 +00:00
/**
*
* User: Martin Donnelly
* Date: 2016-05-20
* Time: 10:13
*
*/
/* global CAPABILITY, inheritsFrom */
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_LUX = function(deviceId) {
'use strict';
this.name = 'Luxometer';
this.deviceID = deviceId;
this.capabilityID = 'F000AA70-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA70-0451-4000-B000-000000000000',
data: 'F000AA71-0451-4000-B000-000000000000',
notification: 'F0002902-0451-4000-B000-000000000000',
configuration: 'F000AA72-0451-4000-B000-000000000000',
period: 'F000AA73-0451-4000-B000-000000000000'
};
this.$result = {temp: null, pressure: null};
this.startService = function() {
'use strict';
if (this.deviceID !== null) {
console.log('Starting CC2650 Luxometer Service on ', this.deviceID);
console.log(this.serviceDef);
//this.insertFrame();
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onLuxData.bind(this), this.onError);
//Turn on barometer
var luxConfig = new Uint8Array(1);
luxConfig[0] = 0x01;
ble.write(this.deviceID, this.serviceDef.service, this.serviceDef.configuration, luxConfig.buffer,
function() { console.log('Started luxometer.'); },this.onError);
}
};
this.sensorBarometerConvert = function(data) {
return (data / 100);
};
this.onLuxData = function(data) {
var pStr;
var tStr;
console.log(data);
var message;
var a = new Uint8Array(data);
var b = new Uint16Array(data);
console.log('lux a',a[0],a[1]);
console.log('lux b',b[0]);
console.log('lux b',b[0].toString(2));
var m = b[0] | b[0] << 4;
console.log(m.toString(2));
//0-2 Temp
//3-5 Pressure
console.log('Luxometer:', 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 pressure = this.frameID + '-p';
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', text: 'Pressure:'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: pressure}).appendTo(row);
this.$id.append(row);
this.$result.temp = $('#' + temp);
this.$result.pressure = $('#' + pressure);
};
};
inheritsFrom(CC2650_LUX, CAPABILITY);