diff --git a/.gitignore b/.gitignore index 28b3f7c..ded1302 100644 --- a/.gitignore +++ b/.gitignore @@ -181,3 +181,50 @@ dist www/libs /www/ /app/libs/ +### Android template +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Intellij +*.iml +.idea/workspace.xml + +# Keystore files +*.jks +### Dropbox template +# Dropbox settings and caches +.dropbox +.dropbox.attr +.dropbox.cache + diff --git a/custom.scss b/app/css/custom.scss similarity index 83% rename from custom.scss rename to app/css/custom.scss index 6097b2f..8d1af65 100644 --- a/custom.scss +++ b/app/css/custom.scss @@ -1,4 +1,4 @@ -@import "www/libs/mui/src/sass/mui/colors"; +@import "app/libs/mui/src/sass/mui/colors"; $mui-body-bg-color: mui-color('grey', '100'); @@ -12,4 +12,4 @@ $mui-tab-font-color: rgba(255, 255, 255, 0.87); $mui-appbar-bg-color: #004c6d; // import MUI SASS -@import "www/libs/mui/src/sass/mui"; +@import "app/libs/mui/src/sass/mui"; diff --git a/app/index.html b/app/index.html index 6fc3cae..10cc4ad 100644 --- a/app/index.html +++ b/app/index.html @@ -33,20 +33,18 @@ - - - + + + + + + - - + Sensor Toy @@ -56,10 +54,6 @@
  • Devices
  • - @@ -94,16 +88,24 @@ + + + + + + + + + + + + diff --git a/app/js/device/CC2650/cc2650_accelerometer.js b/app/js/device/CC2650/cc2650_accelerometer.js index 653abfa..8b1cfe8 100644 --- a/app/js/device/CC2650/cc2650_accelerometer.js +++ b/app/js/device/CC2650/cc2650_accelerometer.js @@ -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,155 +18,386 @@ 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.setFrame(); this.sensorMpu9250GyroConvert = function(data) { - return data / (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 / (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] + } }; + return calcData; + }; this.onAccelerometerData = function(data) { - // Console.log(data); - var message; - var a = new Int16Array(data); + // Console.log(data); + var message; + var calcData; - // 0 gyro x - // 1 gyro y - // 2 gyro z - // 3 accel x - // 4 accel y - // 5 accel z - // 6 mag x - // 7 mag y - // 8 mag z + function gString(v) { + return [v.toFixed(3),'G'].join(''); + } - // TODO get a template to line this up - // TODO round or format numbers for better display - message = 'Gyro
    ' + - 'X: ' + this.sensorMpu9250GyroConvert(a[0]).toFixed(5) + '
    ' + - '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[3] + '
    ' + - 'Y: ' + a[4] + '
    ' + - 'Z: ' + a[5] + '
    ' ; + function aString(v) { + return [v.toFixed(3),'\'/s'].join(''); + } - this.state = message; + function mString(v) { + return [v.toFixed(3),'mT'].join(''); + } + calcData = this.processData(data); - this.$result[this.frames.gyroID + '-x'].text(this.sensorMpu9250GyroConvert(a[0]).toFixed(5)); - this.$result[this.frames.gyroID + '-y'].text(this.sensorMpu9250GyroConvert(a[1]).toFixed(5)); - this.$result[this.frames.gyroID + '-z'].text(this.sensorMpu9250GyroConvert(a[2]).toFixed(5)); + message = 'Gyro
    ' + 'X: ' + calcData.gyro.x + '
    ' + 'Y: ' + calcData.gyro.y + '
    ' + 'Z: ' + calcData.gyro.z + '
    ' + 'Accel
    ' + 'X: ' + calcData.accel.x + '
    ' + 'Y: ' + calcData.accel.y + '
    ' + 'Z: ' + calcData.accel.z + '
    ' + 'Mag
    ' + 'X: ' + calcData.mag.x + '
    ' + 'Y: ' + calcData.mag.y + '
    ' + 'Z: ' + calcData.mag.z + '
    '; - this.$result[this.frames.accelID + '-x'].text(this.sensorMpu9250AccConvert(a[3]).toFixed(5)); - this.$result[this.frames.accelID + '-y'].text(this.sensorMpu9250AccConvert(a[4]).toFixed(5)); - this.$result[this.frames.accelID + '-z'].text(this.sensorMpu9250AccConvert(a[5]).toFixed(5)); + this.state = message; - this.$result[this.frames.magID + '-x'].text(a[3]); - this.$result[this.frames.magID + '-y'].text(a[4]); - this.$result[this.frames.magID + '-z'].text(a[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)); - // Console.log(this.state); - }; + 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.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.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.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(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) { + + var _subID = subID || ''; + var xlineID = this.frameID + _subID + '-x-line'; + var ylineID = this.frameID + _subID + '-y-line'; + var zlineID = this.frameID + _subID + '-z-line'; + + 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)'); + svg = this.graphAddLine(svg, zlineID, 'rgba(0,0,255,0.5)'); + + return svg; + + }; + + this.startCalibrate = function() { + console.log('Start calibrate'); + + alert('Mag Calibration: Wave device in a figure eight until done!'); + }; 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'}; - - console.log('FrameID: ' , this.frames[modeID]); - - title = [titles[mode], ' - ', this.deviceID].join(' '); - - frame = $('
    ', { - class: 'mui-panel', id: this.frames[modeID] - }); - - $('
    ', { class: 'mui-row'}).append($('
    ', { 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 = $('
    ', {class: 'mui-row'}); - - $('
    ', { class: 'mui-col-xs-3 mui--text-accent', text: 'X'}).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-accent', text: 'Y'}).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-accent', text: 'Z'}).appendTo(row); - - this.$id[modeID].append(row); - - row = $('
    ', {class: 'mui-row'}); - - $('
    ', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-x' }).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-dark', text: '--', id: this.frames[modeID] + '-y'}).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-dark', 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'); + 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 = $('
    ', { + class: 'mui-panel', id: this.frames[modeID] + }); + + if (mode === 'mag') { + var elm = $('
    ', {class: 'mui-row'}); + var button = $(' -
    -
    - -
    + + + + + + + + + Sensor Toy + + +
    +
    +
    +
    +
    +
    +
    +
    + Devices +
    +
    + +
    - -
    - - - - - - - - - - - -
    IDNameRSI
    - +
    +
    - -
    +
    +
    +
    +
    +
    + -
    + + + + + - - - + + + + + + + - - - + + + + + + + - - - - - - - - - - + + + + diff --git a/platforms/ios/www/js/device/CC2650/cc2650_accelerometer.js b/platforms/ios/www/js/device/CC2650/cc2650_accelerometer.js index 996e6ef..508054a 100644 --- a/platforms/ios/www/js/device/CC2650/cc2650_accelerometer.js +++ b/platforms/ios/www/js/device/CC2650/cc2650_accelerometer.js @@ -5,170 +5,385 @@ * Time: 10:13 * */ -/* global CAPABILITY, inheritsFrom */ +/* global CAPABILITY, inheritsFrom, capabilityManager */ /* global ble */ /* jshint browser: true , devel: true*/ -var CC2650_ACCEL = function(deviceId) { +var CC2650_ACCEL; +CC2650_ACCEL = function(p) { 'use strict'; this.name = 'Accelerometer'; - this.deviceID = deviceId; + this.deviceID = p.deviceID || null; + this.target = p.target || null; + 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.setFrame(); this.sensorMpu9250GyroConvert = function(data) { - return data / (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 / (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] + } }; + return calcData; + }; this.onAccelerometerData = function(data) { - console.log(data); - var message; - var a = new Int16Array(data); + // Console.log(data); + var message; + var calcData; - //0 gyro x - //1 gyro y - //2 gyro z - //3 accel x - //4 accel y - //5 accel z - //6 mag x - //7 mag y - //8 mag z + function gString(v) { + return [v.toFixed(3),'G'].join(''); + } - // TODO get a template to line this up - // TODO round or format numbers for better display - message = 'Gyro
    ' + - 'X: ' + this.sensorMpu9250GyroConvert(a[0]).toFixed(5) + '
    ' + - '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[3] + '
    ' + - 'Y: ' + a[4] + '
    ' + - 'Z: ' + a[5] + '
    ' ; + function aString(v) { + return [v.toFixed(3),'\'/s'].join(''); + } - this.state = message; + function mString(v) { + return [v.toFixed(3),'mT'].join(''); + } + calcData = this.processData(data); - this.$result[this.frames.gyroID + '-x'].text(this.sensorMpu9250GyroConvert(a[0]).toFixed(5)); - this.$result[this.frames.gyroID + '-y'].text(this.sensorMpu9250GyroConvert(a[1]).toFixed(5)); - this.$result[this.frames.gyroID + '-z'].text(this.sensorMpu9250GyroConvert(a[2]).toFixed(5)); + message = 'Gyro
    ' + 'X: ' + calcData.gyro.x + '
    ' + 'Y: ' + calcData.gyro.y + '
    ' + 'Z: ' + calcData.gyro.z + '
    ' + 'Accel
    ' + 'X: ' + calcData.accel.x + '
    ' + 'Y: ' + calcData.accel.y + '
    ' + 'Z: ' + calcData.accel.z + '
    ' + 'Mag
    ' + 'X: ' + calcData.mag.x + '
    ' + 'Y: ' + calcData.mag.y + '
    ' + 'Z: ' + calcData.mag.z + '
    '; - this.$result[this.frames.accelID + '-x'].text(this.sensorMpu9250AccConvert(a[3]).toFixed(5)); - this.$result[this.frames.accelID + '-y'].text(this.sensorMpu9250AccConvert(a[4]).toFixed(5)); - this.$result[this.frames.accelID + '-z'].text(this.sensorMpu9250AccConvert(a[5]).toFixed(5)); + this.state = message; - this.$result[this.frames.magID + '-x'].text(a[3]); - this.$result[this.frames.magID + '-y'].text(a[4]); - this.$result[this.frames.magID + '-z'].text(a[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)); - console.log(this.state); - }; + 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.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.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.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(JSON.stringify(this.data)); + // Console.log(this.state); + }; this.startService = function() { - 'use strict'; - if (this.deviceID !== null) { - console.log('Starting CC2650 Accelerometer Service on ', this.deviceID); - console.log(this.serviceDef); - //Ble.startNotification(this.deviceID, , this.onButtonData.bind(this), this.onError); + if (this.deviceID !== null) { - ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onAccelerometerData.bind(this), this.onError); + console.log('Starting CC2650 Accelerometer Service on ', this.deviceID); + console.log(this.serviceDef); + + this.setInternalID(); + this.insertFrame('gyro'); + this.insertFrame('accel'); + this.insertFrame('mag'); + + ble.startNotification(this.deviceID, + this.serviceDef.service, + this.serviceDef.data, + this.onAccelerometerData.bind(this), + this.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']; - // 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); + _data = data || this.data; - 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); + _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) { + + var _subID = subID || ''; + var xlineID = this.frameID + _subID + '-x-line'; + var ylineID = this.frameID + _subID + '-y-line'; + var zlineID = this.frameID + _subID + '-z-line'; + + 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)'); + svg = this.graphAddLine(svg, zlineID, 'rgba(0,0,255,0.5)'); + + return svg; + + }; 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'}; - - console.log('FrameID: ' , this.frames[modeID]); - - title = [titles[mode], ' - ', this.deviceID].join(' '); - - frame = $('
    ', { - class: 'mui-panel', id: this.frames[modeID] - }); - - $('
    ', { class: 'mui-row'}).append($('
    ', { class: 'mui-col-xs-12 mui--text-title mui-ellipsis-2', text: title})).appendTo(frame); - - $('#frames').append(frame); - this.$id[modeID] = $('#' + this.frames[modeID]); - - // Call the parent displayForm first... - - var row = $('
    ', {class: 'mui-row'}); - - $('
    ', { class: 'mui-col-xs-3 mui--text-accent', text: 'X'}).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-accent', text: 'Y'}).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-accent', text: 'Z'}).appendTo(row); - - this.$id[modeID].append(row); - - - row = $('
    ', {class: 'mui-row'}); - - $('
    ', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-x' }).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-white', text: '--', id: this.frames[modeID] + '-y'}).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-white', 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'); + 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 = $('
    ', { + class: 'mui-panel', id: this.frames[modeID] + }); + + $('
    ', {class: 'mui-row'}).append($('
    ', { + 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 = $('
    ', {class: 'mui-row'}); + + $('
    ', { + class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'X' + }).appendTo(row); + $('
    ', { + class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Y' + }).appendTo(row); + $('
    ', { + class: 'mui-col-xs-4 mui--text-accent mui--text-center', text: 'Z' + }).appendTo(row); + + this.$id[modeID].append(row); + + row = $('
    ', {class: 'mui-row'}); + + $('
    ', { + class: 'mui-col-xs-4 mui--text-dark mui--text-center', + text: '--', + id: this.frames[modeID] + '-x' + }).appendTo(row); + $('
    ', { + class: 'mui-col-xs-4 mui--text-dark mui--text-center', + text: '--', + id: this.frames[modeID] + '-y' + }).appendTo(row); + $('
    ', { + 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 = $('
    ', {class: 'mui-row'}); + + var _graph = this.generateBlankGraph(mode); + row.append($('
    ', {class: 'mui-col-sm-12'}).append(_graph)); + + this.$id[modeID].append(row); + }; }; inheritsFrom(CC2650_ACCEL, CAPABILITY); + +capabilityManager.register({id: 'F000AA80-0451-4000-B000-000000000000', module: CC2650_ACCEL}); diff --git a/platforms/ios/www/js/device/CC2650/cc2650_barometer.js b/platforms/ios/www/js/device/CC2650/cc2650_barometer.js index 16dae7d..fd37cb6 100644 --- a/platforms/ios/www/js/device/CC2650/cc2650_barometer.js +++ b/platforms/ios/www/js/device/CC2650/cc2650_barometer.js @@ -5,14 +5,16 @@ * Time: 10:13 * */ -/* global CAPABILITY, inheritsFrom */ +/* global CAPABILITY, inheritsFrom, capabilityManager, device */ /* global ble */ /* jshint browser: true , devel: true*/ -var CC2650_BAR = function(deviceId) { +var CC2650_BAR = function(p) { 'use strict'; this.name = 'Barometer'; - this.deviceID = deviceId; + this.deviceID = p.deviceID || null; + this.target = p.target || null; + this.capabilityID = 'F000AA40-0451-4000-B000-000000000000'; this.serviceDef = { service: 'F000AA40-0451-4000-B000-000000000000', @@ -24,9 +26,10 @@ var CC2650_BAR = function(deviceId) { }; this.data = {temp: [], pressure: []}; this.$result = {temp: null, pressure: null}; + this.setFrame(); this.startService = function() { - 'use strict'; + if (this.deviceID !== null) { console.log('Starting CC2650 Barometer Service on ', this.deviceID); @@ -35,7 +38,7 @@ var CC2650_BAR = function(deviceId) { ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onBarometerData.bind(this), this.onError); - //Turn on barometer + // Turn on barometer var barometerConfig = new Uint8Array(1); barometerConfig[0] = 0x01; ble.write(this.deviceID, this.serviceDef.service, this.serviceDef.configuration, barometerConfig.buffer, @@ -53,12 +56,11 @@ var CC2650_BAR = function(deviceId) { this.onBarometerData = function(data) { var pStr; var tStr; - console.log(data); var message; var a = new Uint8Array(data); - //0-2 Temp - //3-5 Pressure + // 0-2 Temp + // 3-5 Pressure var temp, pressure; temp = this.sensorBarometerConvert(a[0] | (a[1] << 8) | (a[2] << 16)); pressure = this.sensorBarometerConvert(a[3] | (a[4] << 8) | (a[5] << 16)); @@ -68,11 +70,9 @@ var CC2650_BAR = function(deviceId) { message = 'Temperature
    ' + tStr + 'Pressure
    ' + pStr ; -// this.data.temp = this.storeData(parseInt(temp), this.data.temp); -// this.data.pressure = this.storeData(parseInt(pressure), this.data.pressure); - this.data.temp = this.storeData(temp, this.data.temp); - this.data.pressure = this.storeData(pressure, this.data.pressure); + this.data.temp = this.storeData(temp, this.data.temp); + this.data.pressure = this.storeData(pressure, this.data.pressure); this.$result.temp.text(tStr); @@ -80,7 +80,7 @@ var CC2650_BAR = function(deviceId) { this.state = message; - console.log('Barometer:', this.state); + // Console.log('Barometer:', this.state); }; this.animateGraph = function() { @@ -93,7 +93,7 @@ var CC2650_BAR = function(deviceId) { var self = this; var blankChart; - console.log('Overloading...'); + // Call the parent displayForm first... this.superClass_.insertFrame.call(self); @@ -101,24 +101,56 @@ var CC2650_BAR = function(deviceId) { var pressure = this.frameID + '-p'; var row = $('
    ', {class: 'mui-row'}); - $('
    ', { class: 'mui-col-xs-3 mui--text-accent', text: 'Temp:'}).appendTo(row); + $('
    ', { class: 'mui-col-xs-3 mui--text-accent mui--text-right', 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: 'Pressure:'}).appendTo(row); + $('
    ', { class: 'mui-col-xs-3 mui--text-dark', id: temp}).appendTo(row); + $('
    ', { class: 'mui-col-xs-3 mui--text-accent mui--text-right', text: 'Pressure:'}).appendTo(row); - $('
    ', { class: 'mui-col-xs-3 mui--text-white', id: pressure}).appendTo(row); + $('
    ', { class: 'mui-col-xs-3 mui--text-dark', id: pressure}).appendTo(row); this.$id.append(row); - blankChart = this.generateBlankGraph('temp'); + if (/ipad/i.test(device.model)) { - this.$id.append(blankChart); + tabBody = $('
    ', {class: 'mui-row'}); - blankChart = this.generateBlankGraph('pressure'); + tabBody.append($('
    ',{class: 'mui-col-md-6'}).append(this.generateBlankGraph('temp'))) ; + tabBody.append($('
    ',{class: 'mui-col-md-6'}).append(this.generateBlankGraph('pressure'))) ; + this.$id.append(tabBody); - this.$id.append(blankChart); + } else { + var tabBody = $('