”2016-06-08”

This commit is contained in:
Martin Donnelly 2016-06-08 16:45:06 +01:00
parent e80c00e850
commit 1f362f4fbe
10 changed files with 459 additions and 224 deletions

View File

@ -198,22 +198,16 @@ CC2650_ACCEL = function(p) {
}
}
console.log('accel max:', max);
ceiling = max;
/* if (ceiling < this.previousCeil) {
ceiling = ceiling + ((this.previousCeil - ceiling) / 2);
ceiling = (Math.ceil((Math.round(ceiling) + 1) / 10));
}*/
floor = ceiling * -1;
ceilingLimit = ceiling;
var scalePos = (124 / 2) / ceiling;
var scaleNeg = (124 / 2) / floor;
// Var xstep = (280 - 46) / 100;
var xstep = 2.34;
var xstep = (680 - 46) / 100;
//Var xstep = 2.34;
for (lineMode = 0; lineMode < parts.length; lineMode++) {
@ -259,7 +253,7 @@ CC2650_ACCEL = function(p) {
};
this.generateBlankGraphBase = function(subID) {
this.generateBlankGraphBase = function(subID, settings) {
var _subID = subID || '';
var xmlns = 'http://www.w3.org/2000/svg';
@ -268,16 +262,28 @@ CC2650_ACCEL = function(p) {
var text1ID = this.frameID + _subID + '-txt1';
var text2ID = this.frameID + _subID + '-txt2';
var _width = settings.width || 300;
var _height = settings.height || 150;
var _fill = settings.fill || 'blue';
var svg = document.createElementNS(xmlns, 'svg');
svg.setAttributeNS(xmlns, 'id', svgID);
svg.setAttributeNS(xmlns, 'width', '300');
svg.setAttributeNS(xmlns, 'height', '150');
svg.setAttributeNS(xmlns, 'fill', 'blue');
svg.setAttribute('id', svgID);
// Svg.setAttribute(xmlns, 'version', '1.1');
svg.setAttribute('width', _width.toString());
svg.setAttribute('height', _height.toString());
svg.setAttribute('fill', _fill);
svg = this.graphAddXAxis(svg, {y: 12, colour: '#004c6d', id: text1ID});
svg = this.graphAddXAxis(svg, {y: 136, colour: '#004c6d', id: text2ID});
svg = this.graphAddXAxis(svg, {y: 71, colour: '#004c6d', text: '0'});
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
svg.setAttributeNS(xmlns, 'viewBox', '0 0 700 150');
// Svg.setAttributeNS(xmlns, 'style', 'width:700px;height:150px;');
svg = this.graphAddXAxis(svg, {y: 12, x2: 680, colour: '#004c6d', id: text1ID});
svg = this.graphAddXAxis(svg, {y: 136, x2: 680, colour: '#004c6d', id: text2ID});
svg = this.graphAddXAxis(svg, {y: 71, x2: 680, colour: '#004c6d', text: '0'});
return svg;
@ -290,7 +296,7 @@ CC2650_ACCEL = function(p) {
var ylineID = this.frameID + _subID + '-y-line';
var zlineID = this.frameID + _subID + '-z-line';
var svg = this.generateBlankGraphBase(_subID);
var svg = this.generateBlankGraphBase(_subID,{width: '700',height: 150});
svg = this.graphAddLine(svg, xlineID, 'rgba(255,0,0,0.5)');
svg = this.graphAddLine(svg, ylineID, 'rgba(0,255,0,0.5)');
@ -300,6 +306,12 @@ CC2650_ACCEL = function(p) {
};
this.startCalibrate = function() {
console.log('Start calibrate');
alert('Mag Calibration: Wave device in a figure eight until done!');
};
this.insertFrame = function(mode) {
var frame;
@ -320,10 +332,22 @@ CC2650_ACCEL = function(p) {
class: 'mui-panel', id: this.frames[modeID]
});
$('<div />', {class: 'mui-row'}).append($('<div />', {
class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title
})).appendTo(frame);
if (mode === 'mag') {
var elm = $('<div />', {class: 'mui-row'});
var button = $('<button />',{class: 'mui-btn mui-btn--raised', id: modeID + '-cal', text: 'Calibrate', click: this.startCalibrate.bind(this)});
elm.append($('<div />', { class: 'mui-col-xs-8 mui--text-title mui-ellipsis-2', text: title}));
// elm.append($('<div />', {class: 'mui-col-xs-4 mui--text-right'}).append(button));
frame.append(elm);
} else {
$('<div />', {class: 'mui-row'}).append($('<div />', {
class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title
})).appendTo(frame);
}
this.$frame.append(frame);
this.$id[modeID] = $('#' + this.frames[modeID]);
@ -370,7 +394,7 @@ CC2650_ACCEL = function(p) {
row = $('<div />', {class: 'mui-row'});
var _graph = this.generateBlankGraph(mode);
row.append($('<div>', {class: 'mui-col-md-12'}).append(_graph));
row.append($('<div>', {class: 'mui-col-sm-12'}).append(_graph));
this.$id[modeID].append(row);
};

View File

@ -169,6 +169,7 @@ CAPABILITY.prototype.graphAddXAxis = function(svg, settings) {
var _svg = svg;
var y = settings.y || 0;
var y2 = y + 3;
var x2 = settings.x2 || 280;
var colour = settings.colour || '#ff0000';
var id = settings.id;
var textContent = settings.text || '-';
@ -179,7 +180,7 @@ CAPABILITY.prototype.graphAddXAxis = function(svg, settings) {
line.setAttributeNS(null,'x1','46');
line.setAttributeNS(null,'y1', y);
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'x2', x2);
line.setAttributeNS(null,'y2', y);
line.setAttributeNS(null,'style',lineStyle);

View File

@ -198,22 +198,16 @@ CC2650_ACCEL = function(p) {
}
}
console.log('accel max:', max);
ceiling = max;
/* if (ceiling < this.previousCeil) {
ceiling = ceiling + ((this.previousCeil - ceiling) / 2);
ceiling = (Math.ceil((Math.round(ceiling) + 1) / 10));
}*/
floor = ceiling * -1;
ceilingLimit = ceiling;
var scalePos = (124 / 2) / ceiling;
var scaleNeg = (124 / 2) / floor;
// Var xstep = (280 - 46) / 100;
var xstep = 2.34;
var xstep = (680 - 46) / 100;
//Var xstep = 2.34;
for (lineMode = 0; lineMode < parts.length; lineMode++) {
@ -259,7 +253,7 @@ CC2650_ACCEL = function(p) {
};
this.generateBlankGraphBase = function(subID) {
this.generateBlankGraphBase = function(subID, settings) {
var _subID = subID || '';
var xmlns = 'http://www.w3.org/2000/svg';
@ -268,16 +262,28 @@ CC2650_ACCEL = function(p) {
var text1ID = this.frameID + _subID + '-txt1';
var text2ID = this.frameID + _subID + '-txt2';
var _width = settings.width || 300;
var _height = settings.height || 150;
var _fill = settings.fill || 'blue';
var svg = document.createElementNS(xmlns, 'svg');
svg.setAttributeNS(xmlns, 'id', svgID);
svg.setAttributeNS(xmlns, 'width', '300');
svg.setAttributeNS(xmlns, 'height', '150');
svg.setAttributeNS(xmlns, 'fill', 'blue');
svg.setAttribute('id', svgID);
// Svg.setAttribute(xmlns, 'version', '1.1');
svg.setAttribute('width', _width.toString());
svg.setAttribute('height', _height.toString());
svg.setAttribute('fill', _fill);
svg = this.graphAddXAxis(svg, {y: 12, colour: '#004c6d', id: text1ID});
svg = this.graphAddXAxis(svg, {y: 136, colour: '#004c6d', id: text2ID});
svg = this.graphAddXAxis(svg, {y: 71, colour: '#004c6d', text: '0'});
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
svg.setAttributeNS(xmlns, 'viewBox', '0 0 700 150');
// Svg.setAttributeNS(xmlns, 'style', 'width:700px;height:150px;');
svg = this.graphAddXAxis(svg, {y: 12, x2: 680, colour: '#004c6d', id: text1ID});
svg = this.graphAddXAxis(svg, {y: 136, x2: 680, colour: '#004c6d', id: text2ID});
svg = this.graphAddXAxis(svg, {y: 71, x2: 680, colour: '#004c6d', text: '0'});
return svg;
@ -290,7 +296,7 @@ CC2650_ACCEL = function(p) {
var ylineID = this.frameID + _subID + '-y-line';
var zlineID = this.frameID + _subID + '-z-line';
var svg = this.generateBlankGraphBase(_subID);
var svg = this.generateBlankGraphBase(_subID,{width: '700',height: 150});
svg = this.graphAddLine(svg, xlineID, 'rgba(255,0,0,0.5)');
svg = this.graphAddLine(svg, ylineID, 'rgba(0,255,0,0.5)');
@ -300,6 +306,12 @@ CC2650_ACCEL = function(p) {
};
this.startCalibrate = function() {
console.log('Start calibrate');
alert('Mag Calibration: Wave device in a figure eight until done!');
};
this.insertFrame = function(mode) {
var frame;
@ -320,10 +332,22 @@ CC2650_ACCEL = function(p) {
class: 'mui-panel', id: this.frames[modeID]
});
$('<div />', {class: 'mui-row'}).append($('<div />', {
class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title
})).appendTo(frame);
if (mode === 'mag') {
var elm = $('<div />', {class: 'mui-row'});
var button = $('<button />',{class: 'mui-btn mui-btn--raised', id: modeID + '-cal', text: 'Calibrate', click: this.startCalibrate.bind(this)});
elm.append($('<div />', { class: 'mui-col-xs-8 mui--text-title mui-ellipsis-2', text: title}));
elm.append($('<div />', {class: 'mui-col-xs-4 mui--text-right'}).append(button));
frame.append(elm);
} else {
$('<div />', {class: 'mui-row'}).append($('<div />', {
class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title
})).appendTo(frame);
}
this.$frame.append(frame);
this.$id[modeID] = $('#' + this.frames[modeID]);
@ -370,7 +394,7 @@ CC2650_ACCEL = function(p) {
row = $('<div />', {class: 'mui-row'});
var _graph = this.generateBlankGraph(mode);
row.append($('<div>', {class: 'mui-col-md-12'}).append(_graph));
row.append($('<div>', {class: 'mui-col-sm-12'}).append(_graph));
this.$id[modeID].append(row);
};

View File

@ -169,6 +169,7 @@ CAPABILITY.prototype.graphAddXAxis = function(svg, settings) {
var _svg = svg;
var y = settings.y || 0;
var y2 = y + 3;
var x2 = settings.x2 || 280;
var colour = settings.colour || '#ff0000';
var id = settings.id;
var textContent = settings.text || '-';
@ -179,7 +180,7 @@ CAPABILITY.prototype.graphAddXAxis = function(svg, settings) {
line.setAttributeNS(null,'x1','46');
line.setAttributeNS(null,'y1', y);
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'x2', x2);
line.setAttributeNS(null,'y2', y);
line.setAttributeNS(null,'style',lineStyle);

View File

@ -9,7 +9,8 @@
/* global ble */
/* jshint browser: true , devel: true*/
var CC2650_ACCEL = function(p) {
var CC2650_ACCEL;
CC2650_ACCEL = function(p) {
'use strict';
this.name = 'Accelerometer';
this.deviceID = p.deviceID || null;
@ -17,131 +18,276 @@ var CC2650_ACCEL = function(p) {
this.capabilityID = 'F000AA80-0451-4000-B000-000000000000';
this.serviceDef = {
service: 'F000AA80-0451-4000-B000-000000000000',
data: 'F000AA81-0451-4000-B000-000000000000', // Read/notify 3 bytes X : Y : Z
notification: 'F0002902-0451-4000-B000-000000000000',
configuration: 'F000AA82-0451-4000-B000-000000000000', // Read/write 1 byte
period: 'F000AA83-0451-4000-B000-000000000000' // Read/write 1 byte Period = [Input*10]ms
};
service: 'F000AA80-0451-4000-B000-000000000000',
data: 'F000AA81-0451-4000-B000-000000000000', // Read/notify 3 bytes X : Y : Z
notification: 'F0002902-0451-4000-B000-000000000000',
configuration: 'F000AA82-0451-4000-B000-000000000000', // Read/write 1 byte
period: 'F000AA83-0451-4000-B000-000000000000' // Read/write 1 byte Period = [Input*10]ms
};
this.frames = {};
this.$id = {};
this.$result = {};
this.data = {gyro: {x: [], y: [], z: []}, accel: {x: [], y: [], z: []}, mag: {x: [], y: [], z: []}};
this.data = {
gyro: {x: [], y: [], z: []},
accel: {x: [], y: [], z: []},
mag: {x: [], y: [], z: []}
};
this.setFrame();
this.sensorMpu9250GyroConvert = function(data) {
return (data * 1.0) / (65536 / 500);
};
return (data * 1.0) / (65536 / 500);
};
this.sensorMpu9250AccConvert = function(data) {
// Change /2 to match accel range...i.e. 16 g would be /16
return (data * 1.0) / (32768 / 2);
};
// Change /2 to match accel range...i.e. 16 g would be /16
return (data * 1.0) / (32768 / 2);
};
this.processData = function(data) {
var a = new Int16Array(data);
var calcData = {
gyro: {
x: this.sensorMpu9250GyroConvert(a[0]),y: this.sensorMpu9250GyroConvert(a[1]),z: this.sensorMpu9250GyroConvert(a[2])
},
accel: {
x: this.sensorMpu9250AccConvert(a[3]),y: this.sensorMpu9250AccConvert(a[4]),z: this.sensorMpu9250AccConvert(a[5])
},
mag: {
x: a[6],y: a[7],z: a[8]
}
};
gyro: {
x: this.sensorMpu9250GyroConvert(a[0]),
y: this.sensorMpu9250GyroConvert(a[1]),
z: this.sensorMpu9250GyroConvert(a[2])
}, accel: {
x: this.sensorMpu9250AccConvert(a[3]),
y: this.sensorMpu9250AccConvert(a[4]),
z: this.sensorMpu9250AccConvert(a[5])
}, mag: {
x: a[6], y: a[7], z: a[8]
}
};
return calcData;
};
this.onAccelerometerData = function(data) {
// Console.log(data);
var message;
var calcData;
// Console.log(data);
var message;
var calcData;
calcData = this.processData(data);
function gString(v) {
return [v.toFixed(3),'G'].join('');
}
message = 'Gyro <br/>' +
'X: ' + calcData.gyro.x + '<br/>' +
'Y: ' + calcData.gyro.y + '<br/>' +
'Z: ' + calcData.gyro.z + '<br/>' +
'Accel <br/>' +
'X: ' + calcData.accel.x + '<br/>' +
'Y: ' + calcData.accel.y + '<br/>' +
'Z: ' + calcData.accel.z + '<br/>' +
'Mag <br/>' +
'X: ' + calcData.mag.x + '<br/>' +
'Y: ' + calcData.mag.y + '<br/>' +
'Z: ' + calcData.mag.z + '<br/>' ;
function aString(v) {
return [v.toFixed(3),'\'/s'].join('');
}
function mString(v) {
return [v.toFixed(3),'mT'].join('');
}
calcData = this.processData(data);
this.state = message;
message = 'Gyro <br/>' + 'X: ' + calcData.gyro.x + '<br/>' + 'Y: ' + calcData.gyro.y + '<br/>' + 'Z: ' + calcData.gyro.z + '<br/>' + 'Accel <br/>' + 'X: ' + calcData.accel.x + '<br/>' + 'Y: ' + calcData.accel.y + '<br/>' + 'Z: ' + calcData.accel.z + '<br/>' + 'Mag <br/>' + 'X: ' + calcData.mag.x + '<br/>' + 'Y: ' + calcData.mag.y + '<br/>' + 'Z: ' + calcData.mag.z + '<br/>';
this.$result[this.frames.gyroID + '-x'].text(calcData.gyro.x.toFixed(5));
this.$result[this.frames.gyroID + '-y'].text(calcData.gyro.y.toFixed(5));
this.$result[this.frames.gyroID + '-z'].text(calcData.gyro.z.toFixed(5));
this.state = message;
this.$result[this.frames.accelID + '-x'].text(calcData.accel.x.toFixed(5));
this.$result[this.frames.accelID + '-y'].text(calcData.accel.y.toFixed(5));
this.$result[this.frames.accelID + '-z'].text(calcData.accel.z.toFixed(5));
this.$result[this.frames.gyroID + '-x'].text(gString(calcData.gyro.x));
this.$result[this.frames.gyroID + '-y'].text(gString(calcData.gyro.y));
this.$result[this.frames.gyroID + '-z'].text(gString(calcData.gyro.z));
this.$result[this.frames.magID + '-x'].text(calcData.mag.x);
this.$result[this.frames.magID + '-y'].text(calcData.mag.y);
this.$result[this.frames.magID + '-z'].text(calcData.mag.z);
this.$result[this.frames.accelID + '-x'].text(aString(calcData.accel.x));
this.$result[this.frames.accelID + '-y'].text(aString(calcData.accel.y));
this.$result[this.frames.accelID + '-z'].text(aString(calcData.accel.z));
this.$result[this.frames.magID + '-x'].text(mString(calcData.mag.x));
this.$result[this.frames.magID + '-y'].text(mString(calcData.mag.y));
this.$result[this.frames.magID + '-z'].text(mString(calcData.mag.z));
this.storeData(calcData.gyro.x, this.data.gyro.x);
this.storeData(calcData.gyro.y, this.data.gyro.y);
this.storeData(calcData.gyro.z, this.data.gyro.z);
this.data.gyro.x = this.storeData(calcData.gyro.x, this.data.gyro.x);
this.data.gyro.y = this.storeData(calcData.gyro.y, this.data.gyro.y);
this.data.gyro.z = this.storeData(calcData.gyro.z, this.data.gyro.z);
this.storeData(calcData.accel.x, this.data.accel.x);
this.storeData(calcData.accel.y, this.data.accel.y);
this.storeData(calcData.accel.z, this.data.accel.z);
this.data.accel.x = this.storeData(calcData.accel.x, this.data.accel.x);
this.data.accel.y = this.storeData(calcData.accel.y, this.data.accel.y);
this.data.accel.z = this.storeData(calcData.accel.z, this.data.accel.z);
this.storeData(calcData.mag.x, this.data.mag.x);
this.storeData(calcData.mag.y, this.data.mag.y);
this.storeData(calcData.mag.z, this.data.mag.z);
this.data.mag.x = this.storeData(calcData.mag.x, this.data.mag.x);
this.data.mag.y = this.storeData(calcData.mag.y, this.data.mag.y);
this.data.mag.z = this.storeData(calcData.mag.z, this.data.mag.z);
// Console.log(this.state);
};
// Console.log(JSON.stringify(this.data));
// Console.log(this.state);
};
this.startService = function() {
if (this.deviceID !== null) {
if (this.deviceID !== null) {
console.log('Starting CC2650 Accelerometer Service on ', this.deviceID);
console.log(this.serviceDef);
console.log('Starting CC2650 Accelerometer Service on ', this.deviceID);
console.log(this.serviceDef);
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onAccelerometerData.bind(this), this.onError);
this.setInternalID();
this.insertFrame('gyro');
this.insertFrame('accel');
this.insertFrame('mag');
// Turn accelerometer on
var configData = new Uint16Array(1);
// Turn on gyro, accel, and mag, 2G range, Disable wake on motion
configData[0] = 0x007F;
ble.write(this.deviceID, this.serviceDef.service, this.serviceDef.configuration, configData.buffer,
function() { console.log('Started accelerometer.'); }, this.onError);
ble.startNotification(this.deviceID,
this.serviceDef.service,
this.serviceDef.data,
this.onAccelerometerData.bind(this),
this.onError);
var periodData = new Uint8Array(1);
periodData[0] = 0x0A;
ble.write(deviceId, accelerometer.service, accelerometer.period, periodData.buffer,
function() { console.log('Configured accelerometer period.'); },app.onError);
// Turn accelerometer on
var configData = new Uint16Array(1);
// Turn on gyro, accel, and mag, 2G range, Disable wake on motion
configData[0] = 0x007F;
ble.write(this.deviceID,
this.serviceDef.service,
this.serviceDef.configuration,
configData.buffer,
function() { console.log('Started accelerometer.'); },
this.onError);
var periodData = new Uint8Array(1);
periodData[0] = 0x0A;
ble.write(this.deviceID,
this.serviceDef.service,
this.serviceDef.period,
periodData.buffer,
function() { console.log('Configured accelerometer period.'); },
this.onError);
}
};
this.advancedGraph = function(mode, data, subID) {
var lm;
var ceiling;
var elm;
var text2ID;
var ceilingLimit;
var calcArray;
var floor;
var _subID;
var _data;
var text1ID;
var lineID;
var max;
var parts = ['x', 'y', 'z'];
_data = data || this.data;
_subID = subID || '';
// LineID = [this.frameID , _subID , '-line'].join('');
text1ID = [this.frameID, _subID, '-txt1'].join('');
text2ID = [this.frameID, _subID, '-txt2'].join('');
if (_data.x.length > 0) {
max = 2;
for (var lineMode = 0; lineMode < parts.length; lineMode++) {
lm = parts[lineMode];
ceiling = _data[lm].reduce(function(p, v) {
return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v));
});
if (ceiling > 500) {
max = (ceiling > max) ? (Math.ceil((Math.round(ceiling) + 1) / 50) * 50) : max;
} else {
max = (ceiling > max) ? (Math.ceil((Math.round(ceiling) + 1) / 10) * 10) : max;
}
}
ceiling = max;
floor = ceiling * -1;
ceilingLimit = ceiling;
var scalePos = (124 / 2) / ceiling;
var scaleNeg = (124 / 2) / floor;
var xstep = (680 - 46) / 100;
//Var xstep = 2.34;
for (lineMode = 0; lineMode < parts.length; lineMode++) {
lm = parts[lineMode];
var startX = 46 + (100 - _data[lm].length) * xstep;
calcArray = [];
lineID = this.frameID + _subID + '-' + lm + '-line';
for (var x = 0; x < _data[lm].length; x++) {
calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (71 - ((_data[lm][x]) * scalePos)).toFixed(
2));
}
elm = document.getElementById(lineID);
elm.setAttribute('points', calcArray.join(' '));
}
elm = document.getElementById(text1ID);
elm.textContent = ceilingLimit;
elm = document.getElementById(text2ID);
elm.textContent = floor;
this.setInternalID();
this.insertFrame('gyro');
this.insertFrame('accel');
this.insertFrame('mag');
}
this.previousCeil = ceiling;
};
this.animateGraph = function() {
// Nothing to animate yet
// Nothing to animate yet
return -1;
};
// return -1;
this.advancedGraph(0, this.data.gyro, 'gyro');
this.advancedGraph(0, this.data.accel, 'accel');
this.advancedGraph(0, this.data.mag, 'mag');
// This.simpleGraph(this.data.temp, 'temp');
// this.simpleGraph(this.data.pressure, 'pressure');
};
this.generateBlankGraphBase = function(subID, settings) {
var _subID = subID || '';
var xmlns = 'http://www.w3.org/2000/svg';
var svgID = this.frameID + _subID + '-svg';
var text1ID = this.frameID + _subID + '-txt1';
var text2ID = this.frameID + _subID + '-txt2';
var _width = settings.width || 300;
var _height = settings.height || 150;
var _fill = settings.fill || 'blue';
var svg = document.createElementNS(xmlns, 'svg');
svg.setAttribute('id', svgID);
// Svg.setAttribute(xmlns, 'version', '1.1');
svg.setAttribute('width', _width.toString());
svg.setAttribute('height', _height.toString());
svg.setAttribute('fill', _fill);
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
svg.setAttributeNS(xmlns, 'viewBox', '0 0 700 150');
// Svg.setAttributeNS(xmlns, 'style', 'width:700px;height:150px;');
svg = this.graphAddXAxis(svg, {y: 12, x2: 680, colour: '#004c6d', id: text1ID});
svg = this.graphAddXAxis(svg, {y: 136, x2: 680, colour: '#004c6d', id: text2ID});
svg = this.graphAddXAxis(svg, {y: 71, x2: 680, colour: '#004c6d', text: '0'});
return svg;
};
this.generateBlankGraph = function(subID) {
@ -150,11 +296,11 @@ var CC2650_ACCEL = function(p) {
var ylineID = this.frameID + _subID + '-y-line';
var zlineID = this.frameID + _subID + '-z-line';
var svg = this.generateBlankGraphBase(_subID);
var svg = this.generateBlankGraphBase(_subID,{width: '700',height: 150});
svg = this.graphAddLine(svg, xlineID, '#FF0000');
svg = this.graphAddLine(svg, ylineID, '#00FF00');
svg = this.graphAddLine(svg, zlineID, '#0000FF');
svg = this.graphAddLine(svg, xlineID, 'rgba(255,0,0,0.5)');
svg = this.graphAddLine(svg, ylineID, 'rgba(0,255,0,0.5)');
svg = this.graphAddLine(svg, zlineID, 'rgba(0,0,255,0.5)');
return svg;
@ -162,55 +308,78 @@ var CC2650_ACCEL = function(p) {
this.insertFrame = function(mode) {
var frame;
var title;
var modeID = mode + 'ID';
this.frames[modeID] = this.frameID + '-' + mode;
var frame;
var title;
var modeID = mode + 'ID';
this.frames[modeID] = this.frameID + '-' + mode;
var titles = {gyro: 'Gyroscope', accel: 'Accelerometer', mag: 'Magnetometer'};
var modes = ['gyro','accel','mag'];
console.log('FrameID: ' , this.frames[modeID]);
title = [titles[mode], ' - ', this.deviceID].join(' ');
frame = $('<div />', {
class: 'mui-panel', id: this.frames[modeID]
});
$('<div />', { class: 'mui-row'}).append($('<div />', { class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title})).appendTo(frame);
this.$frame.append(frame);
this.$id[modeID] = $('#' + this.frames[modeID]);
// Call the parent displayForm first...
var row = $('<div />', {class: 'mui-row'});
$('<div />', { class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'X'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Y'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Z'}).appendTo(row);
this.$id[modeID].append(row);
row = $('<div />', {class: 'mui-row'});
$('<div />', { class: 'mui-col-xs-4 mui--text-dark mui--text-center', text: '--', id: this.frames[modeID] + '-x' }).appendTo(row);
$('<div />', { class: 'mui-col-xs-4 mui--text-dark mui--text-center', text: '--', id: this.frames[modeID] + '-y'}).appendTo(row);
$('<div />', { class: 'mui-col-xs-4 mui--text-dark mui--text-center', text: '--', id: this.frames[modeID] + '-z'}).appendTo(row);
this.$id[modeID].append(row);
this.$result[this.frames[modeID] + '-x'] = $('#' + this.frames[modeID] + '-x');
this.$result[this.frames[modeID] + '-y'] = $('#' + this.frames[modeID] + '-y');
this.$result[this.frames[modeID] + '-z'] = $('#' + this.frames[modeID] + '-z');
row = $('<div />', {class: 'mui-row'});
row.append($('<div>',{class: 'mui-col-md-12'}).append(this.generateBlankGraph(modes[mode]))) ;
this.$id[modeID].append(row);
var titles = {
gyro: 'Gyroscope', accel: 'Accelerometer', mag: 'Magnetometer'
};
var modes = ['gyro', 'accel', 'mag'];
console.log('FrameID: ', this.frames[modeID]);
title = [titles[mode], ' - ', this.deviceID].join(' ');
frame = $('<div />', {
class: 'mui-panel', id: this.frames[modeID]
});
$('<div />', {class: 'mui-row'}).append($('<div />', {
class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title
})).appendTo(frame);
this.$frame.append(frame);
this.$id[modeID] = $('#' + this.frames[modeID]);
// Call the parent displayForm first...
var row = $('<div />', {class: 'mui-row'});
$('<div />', {
class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'X'
}).appendTo(row);
$('<div />', {
class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Y'
}).appendTo(row);
$('<div />', {
class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Z'
}).appendTo(row);
this.$id[modeID].append(row);
row = $('<div />', {class: 'mui-row'});
$('<div />', {
class: 'mui-col-xs-4 mui--text-dark mui--text-center',
text: '--',
id: this.frames[modeID] + '-x'
}).appendTo(row);
$('<div />', {
class: 'mui-col-xs-4 mui--text-dark mui--text-center',
text: '--',
id: this.frames[modeID] + '-y'
}).appendTo(row);
$('<div />', {
class: 'mui-col-xs-4 mui--text-dark mui--text-center',
text: '--',
id: this.frames[modeID] + '-z'
}).appendTo(row);
this.$id[modeID].append(row);
this.$result[this.frames[modeID] + '-x'] = $('#' + this.frames[modeID] + '-x');
this.$result[this.frames[modeID] + '-y'] = $('#' + this.frames[modeID] + '-y');
this.$result[this.frames[modeID] + '-z'] = $('#' + this.frames[modeID] + '-z');
row = $('<div />', {class: 'mui-row'});
var _graph = this.generateBlankGraph(mode);
row.append($('<div>', {class: 'mui-col-sm-12'}).append(_graph));
this.$id[modeID].append(row);
};
};

View File

@ -45,6 +45,9 @@ var CAPABILITY = function(p) {
this.target = null;
this.$frame = null;
this.previousCeil = 0;
capabilityManager.register({id: this.capabilityID, module: this});
};
@ -137,6 +140,7 @@ CAPABILITY.prototype.startGraph = function(id) {
CAPABILITY.prototype.generateBlankGraphBase = function(subID) {
var _subID = subID || '';
@ -152,52 +156,52 @@ CAPABILITY.prototype.generateBlankGraphBase = function(subID) {
svg.setAttributeNS(xmlns,'height','150');
svg.setAttributeNS(xmlns,'fill', 'blue');
var line = document.createElementNS(xmlns,'line');
line.setAttributeNS(null,'x1','46');
line.setAttributeNS(null,'y1','12');
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'y2', '12');
line.setAttributeNS(null,'style','stroke:#004c6d;stroke-width:2;');
svg.appendChild(line);
line = document.createElementNS(xmlns,'line');
line.setAttributeNS(null,'x1','46');
line.setAttributeNS(null,'y1','136');
line.setAttributeNS(null,'x2','280');
line.setAttributeNS(null,'y2', '136');
line.setAttributeNS(null,'style','stroke:#004c6d;stroke-width:2;');
svg.appendChild(line);
var text = document.createElementNS(xmlns,'text');
text.setAttributeNS(null,'id',text1ID);
text.setAttributeNS(null,'x','36');
text.setAttributeNS(null,'y','15');
text.setAttributeNS(null,'text-anchor', 'end');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #004c6d;text-align:right;');
text.textContent = '000';
svg.appendChild(text);
text = document.createElementNS(xmlns,'text');
text.setAttributeNS(null,'id','text2');
text.setAttributeNS(null,'x','36');
text.setAttributeNS(null,'y','140');
text.setAttributeNS(null,'text-anchor', 'end');
text.setAttributeNS(null,'style','font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: #004c6d;text-align:right;');
text.textContent = '0';
svg.appendChild(text);
svg = this.graphAddXAxis(svg,{y: 12, colour: '#004c6d', id: text1ID});
svg = this.graphAddXAxis(svg,{y: 136, colour: '#004c6d', text: '0'});
return svg;
};
CAPABILITY.prototype.graphAddXAxis = function(svg, settings) {
var xmlns = 'http://www.w3.org/2000/svg';
var _svg = svg;
var y = settings.y || 0;
var y2 = y + 3;
var x2 = settings.x2 || 280;
var colour = settings.colour || '#ff0000';
var id = settings.id;
var textContent = settings.text || '-';
var lineStyle = ['stroke:',colour,';stroke-width:2;'].join('');
var textStyle = ['font-family:"Ubuntu Condensed",sans-serif;font-size:12;fill: ',colour,';text-align:right;'].join('');
var line = document.createElementNS(xmlns,'line');
line.setAttributeNS(null,'x1','46');
line.setAttributeNS(null,'y1', y);
line.setAttributeNS(null,'x2', x2);
line.setAttributeNS(null,'y2', y);
line.setAttributeNS(null,'style',lineStyle);
_svg.appendChild(line);
var text = document.createElementNS(xmlns,'text');
if (id !== null) {
text.setAttributeNS(null,'id',id);
}
text.setAttributeNS(null,'x','36');
text.setAttributeNS(null,'y', y2);
text.setAttributeNS(null,'text-anchor', 'end');
text.setAttributeNS(null,'style',textStyle);
text.textContent = textContent;
_svg.appendChild(text);
return _svg;
};
CAPABILITY.prototype.graphAddLine = function(svg, lineId, colour) {
var xmlns = 'http://www.w3.org/2000/svg';
var _svg = svg;
@ -240,6 +244,8 @@ CAPABILITY.prototype.animateGraph = function() {
CAPABILITY.prototype.simpleGraph = function(data, subID) {
var ceilingLimit;
var ceiling;
var _subID;
var _data;
var text1ID;
@ -253,9 +259,11 @@ CAPABILITY.prototype.simpleGraph = function(data, subID) {
text1ID = [this.frameID , _subID , '-txt1'].join('');
if (_data.length > 0) {
var ceiling = _data.reduce(function(p, v) {
return (p > v ? p : v);
});
ceiling = _data.reduce(function(p, v) {
return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v));
});
/* Var floor = _data.reduce(function(p, v) {
return (p < v ? p : v);
@ -264,6 +272,7 @@ CAPABILITY.prototype.simpleGraph = function(data, subID) {
var calcArray = [];
/*
var ceilingLimit = Math.floor(ceiling / 10) * 10;
if (ceilingLimit < ceiling) {
ceilingLimit = Math.floor((ceiling + (ceiling * 0.25)) / 10) * 10;
@ -272,6 +281,13 @@ CAPABILITY.prototype.simpleGraph = function(data, subID) {
if (ceilingLimit < 30) {
ceilingLimit = 30;
}
*/
ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 10) * 10);
if (ceilingLimit > 1000) {
ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 50) * 50);
}
var scale = 124 / ceilingLimit;
// Var xstep = (280 - 46) / 100;