117 lines
2.5 KiB
JavaScript
117 lines
2.5 KiB
JavaScript
/**
|
|
*
|
|
* 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.data = [];
|
|
|
|
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 luxometer
|
|
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.onLuxData = function(data) {
|
|
|
|
var m, e, lux;
|
|
// Console.log(data);
|
|
|
|
var raw = new Uint16Array(data);
|
|
|
|
m = raw & 0x0FFF;
|
|
e = (raw & 0xF000) >> 12;
|
|
|
|
lux = m * (0.01 * Math.pow(2.0, e));
|
|
|
|
this.state = [lux.toFixed(2), 'lux'].join(' ');
|
|
|
|
|
|
//This.storeData(parseInt(lux));
|
|
this.storeData(lux);
|
|
|
|
this.$result.text(this.state);
|
|
|
|
// Console.log('Luxometer:', this.state);
|
|
};
|
|
|
|
this.animateGraph = function() {
|
|
this.simpleGraph(this.data, '');
|
|
};
|
|
|
|
this.insertFrame = function() {
|
|
|
|
var self = this;
|
|
|
|
// Call the parent displayForm first...
|
|
this.superClass_.insertFrame.call(self);
|
|
|
|
var lux = this.frameID + '-l';
|
|
|
|
var row = $('<div />', {class: 'mui-row'});
|
|
|
|
$('<div />',
|
|
{class: 'mui-col-xs-4 mui--text-accent', text: 'Luminosity:'}).appendTo(
|
|
row);
|
|
|
|
$('<div />',
|
|
{class: 'mui-col-xs-8 mui--text-white', id: lux}).appendTo(row);
|
|
|
|
this.$id.append(row);
|
|
|
|
var blankChart = this.generateBlankGraph();
|
|
|
|
this.$id.append(blankChart);
|
|
|
|
this.$result = $('#' + lux);
|
|
|
|
//Window.requestAnimFrame(this.animateFrame.bind(this));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
inheritsFrom(CC2650_LUX, CAPABILITY);
|