More work
This commit is contained in:
parent
9512ee3a42
commit
2101b03490
@ -26,4 +26,6 @@
|
||||
<engine name="ios" spec="~4.1.1" />
|
||||
<engine name="android" spec="~5.1.1" />
|
||||
<plugin name="cordova-plugin-ble-central" spec="~1.1.0" />
|
||||
<plugin name="cordova-plugin-file" spec="~4.2.0" />
|
||||
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
|
||||
</widget>
|
||||
|
0
gulpfile.js
Normal file
0
gulpfile.js
Normal file
@ -18,3 +18,6 @@ Silicon Labs Sensor Puck
|
||||
|
||||
|
||||
google science journal
|
||||
|
||||
|
||||
[https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/](Cordova file plugin)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -14,4 +14,5 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
</manifest>
|
||||
|
@ -11,6 +11,10 @@
|
||||
{
|
||||
"xml": "<feature name=\"Whitelist\"><param name=\"android-package\" value=\"org.apache.cordova.whitelist.WhitelistPlugin\" /><param name=\"onload\" value=\"true\" /></feature>",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"xml": "<feature name=\"File\"><param name=\"android-package\" value=\"org.apache.cordova.file.FileUtils\" /><param name=\"onload\" value=\"true\" /></feature>",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
"/widget": [
|
||||
@ -36,6 +40,12 @@
|
||||
"xml": "<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" />",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
"/*": [
|
||||
{
|
||||
"xml": "<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />",
|
||||
"count": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -50,6 +60,9 @@
|
||||
},
|
||||
"cordova-plugin-ble-central": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
},
|
||||
"cordova-plugin-file": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
}
|
||||
},
|
||||
"dependent_plugins": {},
|
||||
@ -60,11 +73,163 @@
|
||||
"clobbers": [
|
||||
"ble"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/android/FileSystem.js",
|
||||
"id": "cordova-plugin-file.androidFileSystem",
|
||||
"merges": [
|
||||
"FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
|
||||
"id": "cordova-plugin-file.fileSystems-roots",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
}
|
||||
],
|
||||
"plugin_metadata": {
|
||||
"cordova-plugin-whitelist": "1.2.2",
|
||||
"cordova-plugin-compat": "1.0.0",
|
||||
"cordova-plugin-ble-central": "1.1.0"
|
||||
"cordova-plugin-ble-central": "1.1.0",
|
||||
"cordova-plugin-file": "4.2.0"
|
||||
}
|
||||
}
|
154
platforms/android/assets/www/cordova_plugins.js
vendored
154
platforms/android/assets/www/cordova_plugins.js
vendored
@ -6,6 +6,157 @@ module.exports = [
|
||||
"clobbers": [
|
||||
"ble"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/android/FileSystem.js",
|
||||
"id": "cordova-plugin-file.androidFileSystem",
|
||||
"merges": [
|
||||
"FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
|
||||
"id": "cordova-plugin-file.fileSystems-roots",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
}
|
||||
];
|
||||
module.exports.metadata =
|
||||
@ -13,7 +164,8 @@ module.exports.metadata =
|
||||
{
|
||||
"cordova-plugin-whitelist": "1.2.2",
|
||||
"cordova-plugin-compat": "1.0.0",
|
||||
"cordova-plugin-ble-central": "1.1.0"
|
||||
"cordova-plugin-ble-central": "1.1.0",
|
||||
"cordova-plugin-file": "4.2.0"
|
||||
};
|
||||
// BOTTOM OF METADATA
|
||||
});
|
@ -278,3 +278,30 @@ projector: cast
|
||||
-webkit-line-clamp: 1;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.pulser {
|
||||
display: block;
|
||||
margin-top:10%;
|
||||
border-radius: 100px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 10px solid #C5F4EB;
|
||||
-webkit-animation: pulse 0.75s ease-in infinite;
|
||||
-moz-animation: pulse 0.75s ease-in infinite;
|
||||
animation: pulse 0.75s ease-in infinite;
|
||||
}
|
||||
@-webkit-keyframes pulse {
|
||||
0% { -webkit-transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { -webkit-transform: scale(1); -webkit-filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
@-moz-keyframes pulse {
|
||||
0% { -moz-transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { -moz-transform: scale(1); -moz-filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
@keyframes pulse {
|
||||
0% { transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { transform: scale(1); filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
|
@ -1331,7 +1331,7 @@ th {
|
||||
text-transform: uppercase;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
color: rgba(0, 0, 0, 0.87);
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
cursor: default;
|
||||
height: 48px;
|
||||
line-height: 48px;
|
||||
|
@ -41,16 +41,36 @@
|
||||
rel="stylesheet">
|
||||
<!-- endbuild -->
|
||||
<!-- build:css -->
|
||||
<link href="css/mui.css" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" href="fonts/fonts.css">
|
||||
<link href="css/mui.custom.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/app.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/ripple.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/progress.css" rel="stylesheet" type="text/css"/>
|
||||
<title>Sensor Toy</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="margin: 0.5rem 0 1rem 0;">
|
||||
<div class="progress" id='ripple' style="display: none;">
|
||||
<div class="indeterminate"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id='app' class="mui-container">
|
||||
|
||||
<div class="mui-panel">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-6">
|
||||
<button class="mui-btn mui-btn--primary" id="scan">Scan</button>
|
||||
<button class="mui-btn mui-btn--danger" id="stop" style="display: none;">Stop</button>
|
||||
</div>
|
||||
|
||||
<div class="mui-col-xs-6">
|
||||
<button class="mui-btn mui-btn--accent" id="longScan">Long</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<table class="mui-table mui--text-white" id="results">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -74,17 +94,21 @@
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="libs/jquery/dist/jquery.js"></script>
|
||||
<script type="text/javascript" src="libs/mui/packages/cdn/js/mui.js"></script>
|
||||
<script type="text/javascript" src="libs/bluebird/js/browser/bluebird.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/standards/bluetooth_company_identifiers.js"></script>
|
||||
<script type="text/javascript" src="js/standards/capability.js"></script>
|
||||
<script type="text/javascript" src="js/standards/battery.js"></script>
|
||||
<script type="text/javascript" src="js/standards/button.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/mandecoder.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_accelerometer.js"></script>
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_barometer.js"></script>
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_luxometer.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_thermopile.js"></script>
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_humidity.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
</body>
|
||||
|
@ -37,7 +37,7 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
};
|
||||
|
||||
this.onAccelerometerData = function(data) {
|
||||
console.log(data);
|
||||
// Console.log(data);
|
||||
var message;
|
||||
var a = new Int16Array(data);
|
||||
|
||||
@ -80,7 +80,7 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
this.$result[this.frames.magID + '-y'].text(a[4]);
|
||||
this.$result[this.frames.magID + '-z'].text(a[5]);
|
||||
|
||||
console.log(this.state);
|
||||
// Console.log(this.state);
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
@ -93,8 +93,6 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
|
||||
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
|
||||
@ -115,6 +113,11 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
// Nothing to animate yet
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
this.insertFrame = function(mode) {
|
||||
|
@ -22,11 +22,9 @@ var CC2650_BAR = function(deviceId) {
|
||||
period: 'F000AA43-0451-4000-B000-000000000000'
|
||||
|
||||
};
|
||||
|
||||
this.data = {temp: [], pressure: []};
|
||||
this.$result = {temp: null, pressure: null};
|
||||
|
||||
|
||||
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
if (this.deviceID !== null) {
|
||||
@ -43,7 +41,6 @@ var CC2650_BAR = function(deviceId) {
|
||||
ble.write(this.deviceID, this.serviceDef.service, this.serviceDef.configuration, barometerConfig.buffer,
|
||||
function() { console.log('Started barometer.'); },this.onError);
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@ -56,30 +53,47 @@ var CC2650_BAR = function(deviceId) {
|
||||
this.onBarometerData = function(data) {
|
||||
var pStr;
|
||||
var tStr;
|
||||
console.log(data);
|
||||
// Console.log(data);
|
||||
var message;
|
||||
var a = new Uint8Array(data);
|
||||
|
||||
//0-2 Temp
|
||||
//3-5 Pressure
|
||||
tStr = this.sensorBarometerConvert(a[0] | (a[1] << 8) | (a[2] << 16)) + '°C';
|
||||
pStr = this.sensorBarometerConvert(a[3] | (a[4] << 8) | (a[5] << 16)) + 'hPa';
|
||||
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));
|
||||
tStr = temp + '°C';
|
||||
pStr = pressure + 'hPa';
|
||||
|
||||
message = 'Temperature <br/>' + tStr +
|
||||
'Pressure <br/>' + 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.$result.temp.text(tStr);
|
||||
this.$result.pressure.text(pStr);
|
||||
|
||||
this.state = message;
|
||||
|
||||
console.log('Barometer:', this.state);
|
||||
// Console.log('Barometer:', this.state);
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
this.simpleGraph(this.data.temp, 'temp');
|
||||
this.simpleGraph(this.data.pressure, 'pressure');
|
||||
};
|
||||
|
||||
|
||||
this.insertFrame = function() {
|
||||
|
||||
var self = this;
|
||||
console.log('Overloading...');
|
||||
var blankChart;
|
||||
|
||||
// Call the parent displayForm first...
|
||||
this.superClass_.insertFrame.call(self);
|
||||
|
||||
@ -95,6 +109,24 @@ var CC2650_BAR = function(deviceId) {
|
||||
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: pressure}).appendTo(row);
|
||||
|
||||
this.$id.append(row);
|
||||
|
||||
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
|
||||
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
|
||||
$('<li>').append($('<a>',{text:'Pressure','data-mui-toggle': 'tab', 'data-mui-controls': (pressure + '-pane')})).appendTo(tabBody);
|
||||
|
||||
this.$id.append(tabBody);
|
||||
|
||||
blankChart = this.generateBlankGraph('temp');
|
||||
|
||||
// this.$id.append(blankChart);
|
||||
this.$id.append($('<div>',{'class':'mui-tabs__pane mui--is-active',id:(temp + '-pane')}).append(blankChart));
|
||||
|
||||
blankChart = this.generateBlankGraph('pressure');
|
||||
|
||||
// this.$id.append(blankChart);
|
||||
this.$id.append($('<div>',{'class':'mui-tabs__pane',id:(pressure + '-pane')}).append(blankChart));
|
||||
|
||||
|
||||
this.$result.temp = $('#' + temp);
|
||||
this.$result.pressure = $('#' + pressure);
|
||||
|
||||
|
@ -24,8 +24,7 @@ var CC2650_LUX = function(deviceId) {
|
||||
};
|
||||
|
||||
this.$result = {temp: null, pressure: null};
|
||||
|
||||
|
||||
this.data = [];
|
||||
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
@ -33,71 +32,85 @@ var CC2650_LUX = function(deviceId) {
|
||||
|
||||
console.log('Starting CC2650 Luxometer Service on ', this.deviceID);
|
||||
console.log(this.serviceDef);
|
||||
//this.insertFrame();
|
||||
this.insertFrame();
|
||||
|
||||
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onLuxData.bind(this), this.onError);
|
||||
ble.startNotification(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.data,
|
||||
this.onLuxData.bind(this),
|
||||
this.onError);
|
||||
|
||||
//Turn on barometer
|
||||
//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);
|
||||
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 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.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.animateGraph = function() {
|
||||
this.simpleGraph(this.data, '');
|
||||
};
|
||||
|
||||
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 lux = this.frameID + '-l';
|
||||
|
||||
var row = $('<div />', {class: 'mui-row'});
|
||||
|
||||
$('<div />', { class: 'mui-col-xs-3 mui--text-accent', text: 'Temp:'}).appendTo(row);
|
||||
$('<div />',
|
||||
{class: 'mui-col-xs-4 mui--text-accent', text: 'Luminosity:'}).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);
|
||||
$('<div />',
|
||||
{class: 'mui-col-xs-8 mui--text-white', id: lux}).appendTo(row);
|
||||
|
||||
this.$id.append(row);
|
||||
this.$result.temp = $('#' + temp);
|
||||
this.$result.pressure = $('#' + pressure);
|
||||
|
||||
var blankChart = this.generateBlankGraph();
|
||||
|
||||
this.$id.append(blankChart);
|
||||
|
||||
this.$result = $('#' + lux);
|
||||
|
||||
//Window.requestAnimFrame(this.animateFrame.bind(this));
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
inheritsFrom(CC2650_LUX, CAPABILITY);
|
||||
|
@ -20,84 +20,297 @@
|
||||
/* global BATTERY, BUTTON */
|
||||
|
||||
var app = {
|
||||
stop: false,
|
||||
log: {},
|
||||
activeServices: [],
|
||||
serviceList: {
|
||||
1800: 'Generic Access',
|
||||
1801: 'Generic Attribute',
|
||||
'180a': 'Device Information',
|
||||
|
||||
FFE0: 'Button',
|
||||
'F000AA00-0451-4000-B000-000000000000': 'Temperature',
|
||||
'F000AA20-0451-4000-B000-000000000000': 'Humidity',
|
||||
'F000AA80-0451-4000-B000-000000000000': 'Accelerometer',
|
||||
'F000AA40-0451-4000-B000-000000000000': 'Barometer'
|
||||
|
||||
},
|
||||
list: {},
|
||||
button: {
|
||||
service: 'FFE0',
|
||||
data: 'FFE1', // Bit 2: side key, Bit 1- right key, Bit 0 –left key
|
||||
},
|
||||
accelerometer: {
|
||||
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
|
||||
},
|
||||
barometer: {
|
||||
service: 'F000AA40-0451-4000-B000-000000000000',
|
||||
data: 'F000AA41-0451-4000-B000-000000000000',
|
||||
notification: 'F0002902-0451-4000-B000-000000000000',
|
||||
configuration: 'F000AA42-0451-4000-B000-000000000000',
|
||||
period: 'F000AA43-0451-4000-B000-000000000000'
|
||||
|
||||
},
|
||||
manufactureDecoder: new MANUFACTUREDECODER(),
|
||||
// Application Constructor
|
||||
initialize: function() {
|
||||
this.bindEvents();
|
||||
},
|
||||
doScan: function() {
|
||||
|
||||
arrayBufferToIntArray: function(buffer) {
|
||||
var result;
|
||||
|
||||
if (buffer) {
|
||||
var typedArray = new Uint8Array(buffer);
|
||||
result = [];
|
||||
for (var i = 0; i < typedArray.length; i++) {
|
||||
result[i] = typedArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
parseAdvertisingData: function(bytes) {
|
||||
var length, type, data, i = 0, advertisementData = {};
|
||||
|
||||
while (length !== 0) {
|
||||
|
||||
length = bytes[i] & 0xFF;
|
||||
i++;
|
||||
|
||||
type = bytes[i] & 0xFF;
|
||||
i++;
|
||||
|
||||
data = bytes.slice(i, i + length - 1); // Length includes type byte, but not length byte
|
||||
i += length - 2; // Move to end of data
|
||||
i++;
|
||||
|
||||
advertisementData[type] = data;
|
||||
}
|
||||
|
||||
return advertisementData;
|
||||
},
|
||||
handle255: function(buffer) {
|
||||
'use strict';
|
||||
|
||||
var company;
|
||||
var cid;
|
||||
var manID;
|
||||
var bin = buffer;
|
||||
var decoded = {};
|
||||
|
||||
console.log('Block255', bin);
|
||||
var manSpec = bin.map(function(i) {
|
||||
|
||||
return i.toString(16) + ' ';
|
||||
});
|
||||
|
||||
console.log('manSpec: ', manSpec);
|
||||
manID = app.manufactureDecoder.getManID(bin);
|
||||
|
||||
console.log('ManID:', manID);
|
||||
|
||||
cid = '0x' + manID;
|
||||
|
||||
company = bt_company_ids.find(cid);
|
||||
|
||||
switch (manID) {
|
||||
case '004c':
|
||||
decoded = app.manufactureDecoder.decodeIbeacon(bin);
|
||||
decoded.company = company;
|
||||
return decoded;
|
||||
break;
|
||||
case '1235':
|
||||
decoded = app.manufactureDecoder.decodeSiliconLabsSensorPuck(bin);
|
||||
decoded.company = company;
|
||||
return decoded;
|
||||
break;
|
||||
case '0060':
|
||||
decoded = app.manufactureDecoder.decodeSansible(bin);
|
||||
decoded.company = company;
|
||||
return decoded;
|
||||
|
||||
break;
|
||||
default:
|
||||
console.log('Unknown manID: ', manID);
|
||||
}
|
||||
return {company:company};
|
||||
},
|
||||
makeHexBuffer : function(buffer) {
|
||||
'use strict';
|
||||
var hexBuffer = buffer.map(function(i) {
|
||||
return ('00' + i.toString(16)).slice(-2) + ',';
|
||||
});
|
||||
return hexBuffer;
|
||||
},
|
||||
makeChars : function(buffer) {
|
||||
'use strict';
|
||||
var output = buffer.map(function(i) {
|
||||
|
||||
return String.fromCharCode(i);
|
||||
});
|
||||
|
||||
return output;
|
||||
},
|
||||
doScan: function(mode) {
|
||||
'use strict';
|
||||
|
||||
$('#ripple').show();
|
||||
if (mode !== 2) {
|
||||
$('#tbody').empty();
|
||||
}
|
||||
|
||||
var otherData = null;
|
||||
var msgText = '';
|
||||
ble.startScan([], function(device) {
|
||||
var parsed;
|
||||
var hexBuffer;
|
||||
var advertBuffer;
|
||||
var newTR;
|
||||
var newId;
|
||||
var _device = device;
|
||||
otherData = null;
|
||||
msgText = '';
|
||||
console.log(JSON.stringify(device));
|
||||
|
||||
var newId = device.id.replace(/:/g, '');
|
||||
newId = device.id.replace(/:/g, '');
|
||||
console.log(newId);
|
||||
|
||||
this.list[newId] = device.id;
|
||||
|
||||
var newTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
newTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
|
||||
newTR.append($('<td>').text(device.id));
|
||||
|
||||
if (device.hasOwnProperty('advertising')) {
|
||||
|
||||
advertBuffer = app.arrayBufferToIntArray(device.advertising);
|
||||
/*var hexBuffer = advertBuffer.map(function(i) {
|
||||
return ('00' + i.toString(16)).slice(-2) + ',';
|
||||
});*/
|
||||
|
||||
hexBuffer = app.makeHexBuffer(advertBuffer);
|
||||
|
||||
parsed = app.parseAdvertisingData(advertBuffer);
|
||||
|
||||
//Console.log(parsed);
|
||||
|
||||
if (parsed.hasOwnProperty('9')) {
|
||||
|
||||
/*var name = parsed['9'].map(function(i) {
|
||||
|
||||
return String.fromCharCode(i);
|
||||
});*/
|
||||
|
||||
var name = app.makeChars(parsed['9']);
|
||||
|
||||
_device.name = name.join('');
|
||||
console.log('Name: ', name.join(''));
|
||||
|
||||
}
|
||||
|
||||
if (parsed.hasOwnProperty('255')) {
|
||||
|
||||
otherData = app.handle255(parsed['255']);
|
||||
console.log(otherData);
|
||||
_device.otherData = otherData;
|
||||
}
|
||||
_device.advertBuffer = advertBuffer;
|
||||
_device.hexBuffer = hexBuffer;
|
||||
_device.parsed = parsed;
|
||||
}
|
||||
|
||||
if (typeof otherData !== 'undefined' && otherData !== null) {
|
||||
if (otherData.hasOwnProperty('msg')) {
|
||||
msgText = ' - ' + otherData.msg;
|
||||
}
|
||||
}
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name));
|
||||
newTR.append($('<td>').text(device.name + msgText));
|
||||
} else {
|
||||
newTR.append($('<td>').text('*** Unknown'));
|
||||
newTR.append($('<td>').text('*** Unknown' + msgText));
|
||||
}
|
||||
|
||||
newTR.append($('<td>').text(device.rssi));
|
||||
|
||||
$('#tbody').append(newTR);
|
||||
|
||||
$('#output').append(JSON.stringify(device) + '<br/>');
|
||||
if ($('tr#' + newId).length > 0) {
|
||||
$('tr#' + newId).replaceWith(newTR);
|
||||
} else {
|
||||
$('#tbody').append(newTR);
|
||||
}
|
||||
|
||||
|
||||
//$('#output').append(JSON.stringify(device) + '<br/>');
|
||||
|
||||
app.log[newId] = _device;
|
||||
|
||||
console.log(JSON.stringify(_device));
|
||||
|
||||
}.bind(this), function(e) {
|
||||
'use strict';
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
var _t = [5000,60000,200][mode];
|
||||
|
||||
|
||||
setTimeout(ble.stopScan,
|
||||
5000,
|
||||
function() { console.log('Scan complete'); },
|
||||
function() { console.log('stopScan failed'); }
|
||||
);
|
||||
_t,
|
||||
function() { console.log('Scan complete');
|
||||
|
||||
if (mode === 1) {
|
||||
app.saveLog();
|
||||
$('#ripple').hide();
|
||||
}
|
||||
|
||||
if (mode === 2) {
|
||||
if (app.stop == false) {
|
||||
setTimeout(function() {
|
||||
app.doScan(2);
|
||||
}.bind(this), 200);
|
||||
} else {
|
||||
app.saveLog();
|
||||
$('#ripple').hide();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
function() { console.log('stopScan failed');
|
||||
$('#ripple').hide();
|
||||
});
|
||||
|
||||
},
|
||||
writeFile: function(fileEntry, dataObj) {
|
||||
// Create a FileWriter object for our FileEntry (log.txt).
|
||||
fileEntry.createWriter(function(fileWriter) {
|
||||
|
||||
fileWriter.onwriteend = function() {
|
||||
console.log('Successful file write...');
|
||||
// ReadFile(fileEntry);
|
||||
};
|
||||
|
||||
fileWriter.onerror = function(e) {
|
||||
console.error('Failed file write: ' + e.toString());
|
||||
};
|
||||
|
||||
// If data object is not passed in,
|
||||
// create a new Blob instead.
|
||||
if (!dataObj) {
|
||||
dataObj = new Blob(['some file data'], { type: 'text/plain' });
|
||||
}
|
||||
|
||||
fileWriter.write(dataObj);
|
||||
});
|
||||
},
|
||||
saveLog: function() {
|
||||
'use strict';
|
||||
var dt = new Date().toISOString().replace(/:|-/g,'').replace(/(\.\w+)/g,'');
|
||||
var payload = JSON.stringify(app.log);
|
||||
var filename = 'sensortoy-' + dt + '.json';
|
||||
|
||||
// Var dataObj = new Blob(payload, { type: 'text/plain' });
|
||||
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
|
||||
|
||||
console.log('file system open: ' + fs.name);
|
||||
fs.root.getFile(filename, { create: true, exclusive: false }, function(fileEntry) {
|
||||
|
||||
console.log('fileEntry is file?' + fileEntry.isFile.toString());
|
||||
// FileEntry.name == 'someFile.txt'
|
||||
// fileEntry.fullPath == '/someFile.txt'
|
||||
console.log('Path: ', fileEntry.fullPath);
|
||||
app.writeFile(fileEntry, payload);
|
||||
|
||||
app.log = [];
|
||||
|
||||
}, app.onError);
|
||||
|
||||
}, app.onError);
|
||||
},
|
||||
forceStop: function() {
|
||||
'use strict';
|
||||
app.stop = true;
|
||||
$('#scan').show();
|
||||
$('#stop').hide();
|
||||
},
|
||||
|
||||
// Bind Event Listeners
|
||||
//
|
||||
// Bind any events that are required on startup. Common events are:
|
||||
@ -107,12 +320,24 @@ var app = {
|
||||
document.addEventListener('deviceready', this.onDeviceReady, false);
|
||||
$('#scan').on('click', function() {
|
||||
'use strict';
|
||||
this.doScan();
|
||||
this.stop = false;
|
||||
this.doScan(2);
|
||||
$('#scan').hide();
|
||||
$('#stop').show();
|
||||
}.bind(this));
|
||||
|
||||
$('#stop').on('click', function() {
|
||||
'use strict';
|
||||
app.forceStop();
|
||||
|
||||
}.bind(this));
|
||||
|
||||
$('#tbody').on('click','tr', function() {
|
||||
$('#longScan').on('click', function() {
|
||||
'use strict';
|
||||
this.doScan(1);
|
||||
}.bind(this));
|
||||
|
||||
$('#tbody').on('click', 'tr', function() {
|
||||
'use strict';
|
||||
var tID = $(this).context.id;
|
||||
|
||||
@ -120,35 +345,41 @@ var app = {
|
||||
|
||||
console.log(tID, id);
|
||||
|
||||
app.forceStop();
|
||||
self.connect(id);
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
// Deviceready Event Handler
|
||||
}, // Deviceready Event Handler
|
||||
//
|
||||
// The scope of 'this' is the event. In order to call the 'receivedEvent'
|
||||
// function, we must explicitly call 'app.receivedEvent(...);'
|
||||
onDeviceReady: function() {
|
||||
|
||||
|
||||
|
||||
}, serviceDiscovery: function(services) {
|
||||
'use strict';
|
||||
|
||||
console.log(services);
|
||||
|
||||
},
|
||||
sensorMpu9250GyroConvert: function(data) {
|
||||
}, sensorMpu9250GyroConvert: function(data) {
|
||||
return data / (65536 / 500);
|
||||
},
|
||||
|
||||
sensorMpu9250AccConvert: function(data) {
|
||||
// Change /2 to match accel range...i.e. 16 g would be /16
|
||||
return data / (32768 / 2);
|
||||
},
|
||||
|
||||
doAnimate: function() {
|
||||
'use strict';
|
||||
// Console.log('Animate..');
|
||||
for (var t = 0; t < app.activeServices.length;t++) {
|
||||
app.activeServices[t].animateGraph();
|
||||
}
|
||||
|
||||
,connect: function(deviceId) {
|
||||
window.requestAnimFrame(app.doAnimate.bind(this));
|
||||
}
|
||||
|
||||
, connect: function(deviceId) {
|
||||
|
||||
$('#results').slideUp();
|
||||
console.log('Connect to ', deviceId);
|
||||
@ -162,7 +393,7 @@ var app = {
|
||||
|
||||
services = a.services;
|
||||
|
||||
for (var t = 0; t < services.length;t++) {
|
||||
for (var t = 0; t < services.length; t++) {
|
||||
|
||||
var ident = services[t].toUpperCase();
|
||||
|
||||
@ -170,7 +401,7 @@ var app = {
|
||||
case '180F':
|
||||
var batteryStat = new BATTERY(deviceId);
|
||||
batteryStat.startService();
|
||||
batteryStat.readBatteryState();
|
||||
// batteryStat.readBatteryState();
|
||||
app.activeServices.push(batteryStat);
|
||||
|
||||
break;
|
||||
@ -198,12 +429,26 @@ var app = {
|
||||
app.activeServices.push(cc2650_lux);
|
||||
break;
|
||||
|
||||
case 'F000AA00-0451-4000-B000-000000000000':
|
||||
var cc2650_tmp = new CC2650_TMP(deviceId);
|
||||
cc2650_tmp.startService();
|
||||
app.activeServices.push(cc2650_tmp);
|
||||
break;
|
||||
|
||||
|
||||
case 'F000AA20-0451-4000-B000-000000000000':
|
||||
var cc2650_hum = new CC2650_HUM(deviceId);
|
||||
cc2650_hum.startService();
|
||||
app.activeServices.push(cc2650_hum);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('Unknown service: ', ident);
|
||||
console.error('Unknown service: ', ident);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Starting animation..
|
||||
window.requestAnimFrame(app.doAnimate.bind(this));
|
||||
};
|
||||
|
||||
ble.connect(deviceId, onConnect, function(e) {
|
||||
@ -211,14 +456,24 @@ var app = {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
},
|
||||
onError: function(reason) {
|
||||
}, onError: function(reason) {
|
||||
console.error('ERROR: ' + reason); // Real apps should use notification.alert
|
||||
},
|
||||
updateGyro: function(g) {
|
||||
}, updateGyro: function(g) {
|
||||
'use strict';
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
window.requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
function(callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
|
||||
app.initialize();
|
||||
|
@ -18,6 +18,10 @@ var CAPABILITY = function(p) {
|
||||
|
||||
this.deviceID = null;
|
||||
|
||||
this.data = [];
|
||||
this.ctx = null;
|
||||
this.first = false;
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.setInternalID = function() {
|
||||
@ -64,7 +68,174 @@ CAPABILITY.prototype.onError = function(e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.storeData = function(data, alt) {
|
||||
|
||||
if (!this.first) {
|
||||
this.first = true;
|
||||
return [];
|
||||
}
|
||||
var target = alt || this.data;
|
||||
|
||||
if (target.length === 99) {
|
||||
target = target.slice(1);
|
||||
}
|
||||
|
||||
target.push(data);
|
||||
if (alt) {
|
||||
return target;
|
||||
} else {
|
||||
this.data = target;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.startGraph = function(id) {
|
||||
|
||||
var c;
|
||||
c = id[0].getContext('2d');
|
||||
this.ctx = c;
|
||||
|
||||
this.ctx.fillStyle = '#ffffff';
|
||||
this.ctx.fillRect(0,0,300,150);
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.generateBlankGraph = function(subID) {
|
||||
|
||||
var _subID = subID || '';
|
||||
var xmlns = 'http://www.w3.org/2000/svg';
|
||||
|
||||
var svgID = this.frameID + _subID + '-svg';
|
||||
var text1ID = this.frameID + _subID + '-txt1';
|
||||
var lineID = this.frameID + _subID + '-line';
|
||||
|
||||
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');
|
||||
|
||||
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:#bad649;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:#bad649;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: #bad649;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: #bad649;text-align:right;');
|
||||
text.textContent = '0';
|
||||
|
||||
svg.appendChild(text);
|
||||
|
||||
var polyline = document.createElementNS(xmlns,'polyline');
|
||||
|
||||
polyline.setAttributeNS(null,'id',lineID);
|
||||
polyline.setAttributeNS(null,'fill','none');
|
||||
polyline.setAttributeNS(null,'stroke','#e5f7fd');
|
||||
//#e5f7fd
|
||||
// old #B5C7FF
|
||||
polyline.setAttributeNS(null,'text-anchor', 'end');
|
||||
polyline.setAttributeNS(null,'stroke-width','2');
|
||||
|
||||
svg.appendChild(polyline);
|
||||
|
||||
return svg;
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.animateGraph = function() {
|
||||
//This.simpleGraph(this.data);
|
||||
};
|
||||
|
||||
|
||||
CAPABILITY.prototype.simpleGraph = function(data, subID) {
|
||||
|
||||
var _subID;
|
||||
var _data;
|
||||
var text1ID;
|
||||
var lineID;
|
||||
|
||||
_data = data || this.data;
|
||||
|
||||
_subID = subID || '';
|
||||
|
||||
lineID = [this.frameID , _subID , '-line'].join('');
|
||||
text1ID = [this.frameID , _subID , '-txt1'].join('');
|
||||
|
||||
if (_data.length > 0) {
|
||||
var ceiling = _data.reduce(function(p, v) {
|
||||
return (p > v ? p : v);
|
||||
});
|
||||
|
||||
/* Var floor = _data.reduce(function(p, v) {
|
||||
return (p < v ? p : v);
|
||||
});
|
||||
*/
|
||||
|
||||
var calcArray = [];
|
||||
|
||||
var ceilingLimit = Math.floor(ceiling / 10) * 10;
|
||||
if (ceilingLimit < ceiling) {
|
||||
ceilingLimit = Math.floor((ceiling + (ceiling * 0.25)) / 10) * 10;
|
||||
}
|
||||
|
||||
if (ceilingLimit < 30) {
|
||||
ceilingLimit = 30;
|
||||
}
|
||||
|
||||
var scale = 124 / ceilingLimit;
|
||||
// Var xstep = (280 - 46) / 100;
|
||||
var xstep = 2.34;
|
||||
var startX = 46 + (100 - _data.length) * xstep;
|
||||
|
||||
for (var x = 0;x < _data.length;x++) {
|
||||
|
||||
calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (136 - ((_data[x]) * scale)).toFixed(2));
|
||||
|
||||
}
|
||||
|
||||
var elm = document.getElementById(lineID);
|
||||
|
||||
elm.setAttribute('points',calcArray.join(' '));
|
||||
|
||||
elm = document.getElementById(text1ID);
|
||||
|
||||
elm.textContent = ceilingLimit;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -1,19 +1,31 @@
|
||||
<script>
|
||||
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
|
||||
|
||||
// http://www.ti.com/lit/ds/symlink/opt3001.pdf
|
||||
var x = 15390;
|
||||
var v = 15 << 10;
|
||||
|
||||
var v = 15390;
|
||||
console.log(v.toString(2));
|
||||
var r = x & v;
|
||||
var o = x & ~v;
|
||||
|
||||
console.log('x',x.toString(2));
|
||||
|
||||
console.log('r',r.toString(2));
|
||||
console.log('o',o.toString(2));
|
||||
var m;
|
||||
for (var t=0;t<16;t++)
|
||||
{
|
||||
m = v >> t;
|
||||
m = v >>> t;
|
||||
|
||||
console.log(m.toString(2), t);
|
||||
console.log(x.toString(2));
|
||||
}
|
||||
|
||||
for (var t=0;t<16;t++)
|
||||
{
|
||||
m = v << t;
|
||||
console.log(m.toString(2));
|
||||
console.log(m.toString(2), t);
|
||||
console.log(x.toString(2));
|
||||
}
|
||||
|
||||
|
||||
|
154
platforms/android/platform_www/cordova_plugins.js
vendored
154
platforms/android/platform_www/cordova_plugins.js
vendored
@ -6,6 +6,157 @@ module.exports = [
|
||||
"clobbers": [
|
||||
"ble"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/android/FileSystem.js",
|
||||
"id": "cordova-plugin-file.androidFileSystem",
|
||||
"merges": [
|
||||
"FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
|
||||
"id": "cordova-plugin-file.fileSystems-roots",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
}
|
||||
];
|
||||
module.exports.metadata =
|
||||
@ -13,7 +164,8 @@ module.exports.metadata =
|
||||
{
|
||||
"cordova-plugin-whitelist": "1.2.2",
|
||||
"cordova-plugin-compat": "1.0.0",
|
||||
"cordova-plugin-ble-central": "1.1.0"
|
||||
"cordova-plugin-ble-central": "1.1.0",
|
||||
"cordova-plugin-file": "4.2.0"
|
||||
};
|
||||
// BOTTOM OF METADATA
|
||||
});
|
@ -5,6 +5,10 @@
|
||||
<param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
<feature name="File">
|
||||
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
<feature name="BLE">
|
||||
<param name="android-package" value="com.megster.cordova.ble.central.BLECentralPlugin" />
|
||||
</feature>
|
||||
@ -24,4 +28,5 @@
|
||||
<allow-intent href="sms:*" />
|
||||
<allow-intent href="mailto:*" />
|
||||
<allow-intent href="geo:*" />
|
||||
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
|
||||
</widget>
|
||||
|
@ -19,6 +19,9 @@
|
||||
76EA67463712454E97394649 /* CBPeripheral+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8121E3457B8C4D788EA22698 /* CBPeripheral+Extensions.m */; };
|
||||
017F086543FC4DEE9C59951D /* BLECommandContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4138900674A48B22BE1DA /* BLECommandContext.m */; };
|
||||
58A10D8DD5CC4FE590CFC1AC /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F9CCB268B3249E78264944E /* CoreBluetooth.framework */; };
|
||||
8133BB75956A4B3D9041CDEB /* CDVFile.m in Sources */ = {isa = PBXBuildFile; fileRef = CD0540EE3BB84FEB9D80207C /* CDVFile.m */; };
|
||||
2F69CAFCDF7041BF8EEF9E10 /* CDVLocalFilesystem.m in Sources */ = {isa = PBXBuildFile; fileRef = BF6C111A8ABF493F9CFAD599 /* CDVLocalFilesystem.m */; };
|
||||
D8A12904BC024C6CB9F27CF6 /* CDVAssetLibraryFilesystem.m in Sources */ = {isa = PBXBuildFile; fileRef = AF593BFBE5B74A0F8829A8B4 /* CDVAssetLibraryFilesystem.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -65,6 +68,12 @@
|
||||
610C4C484CCE4B1E8E70D9FB /* CBPeripheral+Extensions.h */ = {isa = PBXFileReference; name = "CBPeripheral+Extensions.h"; path = "cordova-plugin-ble-central/BLECentralPlugin/CBPeripheral+Extensions.h"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; };
|
||||
9B771CC64C684C64A7122EB1 /* BLECommandContext.h */ = {isa = PBXFileReference; name = "BLECommandContext.h"; path = "cordova-plugin-ble-central/BLECentralPlugin/BLECommandContext.h"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; };
|
||||
0F9CCB268B3249E78264944E /* CoreBluetooth.framework */ = {isa = PBXFileReference; name = "CoreBluetooth.framework"; path = "System/Library/Frameworks/CoreBluetooth.framework"; sourceTree = SDKROOT; fileEncoding = undefined; lastKnownFileType = wrapper.framework; explicitFileType = undefined; includeInIndex = 0; };
|
||||
CD0540EE3BB84FEB9D80207C /* CDVFile.m */ = {isa = PBXFileReference; name = "CDVFile.m"; path = "cordova-plugin-file/CDVFile.m"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; explicitFileType = undefined; includeInIndex = 0; };
|
||||
BF6C111A8ABF493F9CFAD599 /* CDVLocalFilesystem.m */ = {isa = PBXFileReference; name = "CDVLocalFilesystem.m"; path = "cordova-plugin-file/CDVLocalFilesystem.m"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; explicitFileType = undefined; includeInIndex = 0; };
|
||||
AF593BFBE5B74A0F8829A8B4 /* CDVAssetLibraryFilesystem.m */ = {isa = PBXFileReference; name = "CDVAssetLibraryFilesystem.m"; path = "cordova-plugin-file/CDVAssetLibraryFilesystem.m"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; explicitFileType = undefined; includeInIndex = 0; };
|
||||
59D0E567446345F8906117A1 /* CDVFile.h */ = {isa = PBXFileReference; name = "CDVFile.h"; path = "cordova-plugin-file/CDVFile.h"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; };
|
||||
0A058DF503B048619AB9C937 /* CDVLocalFilesystem.h */ = {isa = PBXFileReference; name = "CDVLocalFilesystem.h"; path = "cordova-plugin-file/CDVLocalFilesystem.h"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; };
|
||||
266CC34DDEFA486FB0CBF3AD /* CDVAssetLibraryFilesystem.h */ = {isa = PBXFileReference; name = "CDVAssetLibraryFilesystem.h"; path = "cordova-plugin-file/CDVAssetLibraryFilesystem.h"; sourceTree = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -175,6 +184,12 @@
|
||||
634B46E16FCC444B981FB53B /* BLECentralPlugin.h */,
|
||||
610C4C484CCE4B1E8E70D9FB /* CBPeripheral+Extensions.h */,
|
||||
9B771CC64C684C64A7122EB1 /* BLECommandContext.h */,
|
||||
CD0540EE3BB84FEB9D80207C /* CDVFile.m */,
|
||||
BF6C111A8ABF493F9CFAD599 /* CDVLocalFilesystem.m */,
|
||||
AF593BFBE5B74A0F8829A8B4 /* CDVAssetLibraryFilesystem.m */,
|
||||
59D0E567446345F8906117A1 /* CDVFile.h */,
|
||||
0A058DF503B048619AB9C937 /* CDVLocalFilesystem.h */,
|
||||
266CC34DDEFA486FB0CBF3AD /* CDVAssetLibraryFilesystem.h */,
|
||||
);
|
||||
name = Plugins;
|
||||
path = "Sensortoy/Plugins";
|
||||
@ -292,6 +307,9 @@
|
||||
9C1D935B60664D2480D5B342 /* BLECentralPlugin.m in Sources */,
|
||||
76EA67463712454E97394649 /* CBPeripheral+Extensions.m in Sources */,
|
||||
017F086543FC4DEE9C59951D /* BLECommandContext.m in Sources */,
|
||||
8133BB75956A4B3D9041CDEB /* CDVFile.m in Sources */,
|
||||
2F69CAFCDF7041BF8EEF9E10 /* CDVLocalFilesystem.m in Sources */,
|
||||
D8A12904BC024C6CB9F27CF6 /* CDVAssetLibraryFilesystem.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -18,6 +18,10 @@
|
||||
<feature name="BLE">
|
||||
<param name="ios-package" onload="true" value="BLECentralPlugin" />
|
||||
</feature>
|
||||
<feature name="File">
|
||||
<param name="ios-package" value="CDVFile" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
<name>Sensortoy</name>
|
||||
<description>
|
||||
A sample Apache Cordova application that responds to the deviceready event.
|
||||
|
@ -12,6 +12,12 @@
|
||||
"xml": "<feature name=\"BLE\"><param name=\"ios-package\" onload=\"true\" value=\"BLECentralPlugin\" /></feature>",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
"/*": [
|
||||
{
|
||||
"xml": "<feature name=\"File\"><param name=\"ios-package\" value=\"CDVFile\" /><param name=\"onload\" value=\"true\" /></feature>",
|
||||
"count": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -26,6 +32,9 @@
|
||||
},
|
||||
"cordova-plugin-ble-central": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
},
|
||||
"cordova-plugin-file": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
}
|
||||
},
|
||||
"dependent_plugins": {},
|
||||
@ -37,11 +46,185 @@
|
||||
"clobbers": [
|
||||
"ble"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems",
|
||||
"pluginId": "cordova-plugin-file"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ios/FileSystem.js",
|
||||
"id": "cordova-plugin-file.iosFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
|
||||
"id": "cordova-plugin-file.fileSystems-roots",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
}
|
||||
],
|
||||
"plugin_metadata": {
|
||||
"cordova-plugin-whitelist": "1.2.2",
|
||||
"cordova-plugin-compat": "1.0.0",
|
||||
"cordova-plugin-ble-central": "1.1.0"
|
||||
"cordova-plugin-ble-central": "1.1.0",
|
||||
"cordova-plugin-file": "4.2.0"
|
||||
}
|
||||
}
|
176
platforms/ios/platform_www/cordova_plugins.js
vendored
176
platforms/ios/platform_www/cordova_plugins.js
vendored
@ -7,6 +7,179 @@ module.exports = [
|
||||
"clobbers": [
|
||||
"ble"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems",
|
||||
"pluginId": "cordova-plugin-file"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ios/FileSystem.js",
|
||||
"id": "cordova-plugin-file.iosFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
|
||||
"id": "cordova-plugin-file.fileSystems-roots",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
}
|
||||
];
|
||||
module.exports.metadata =
|
||||
@ -14,7 +187,8 @@ module.exports.metadata =
|
||||
{
|
||||
"cordova-plugin-whitelist": "1.2.2",
|
||||
"cordova-plugin-compat": "1.0.0",
|
||||
"cordova-plugin-ble-central": "1.1.0"
|
||||
"cordova-plugin-ble-central": "1.1.0",
|
||||
"cordova-plugin-file": "4.2.0"
|
||||
}
|
||||
// BOTTOM OF METADATA
|
||||
});
|
176
platforms/ios/www/cordova_plugins.js
vendored
176
platforms/ios/www/cordova_plugins.js
vendored
@ -7,6 +7,179 @@ module.exports = [
|
||||
"clobbers": [
|
||||
"ble"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems",
|
||||
"pluginId": "cordova-plugin-file"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ios/FileSystem.js",
|
||||
"id": "cordova-plugin-file.iosFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
|
||||
"id": "cordova-plugin-file.fileSystems-roots",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
}
|
||||
];
|
||||
module.exports.metadata =
|
||||
@ -14,7 +187,8 @@ module.exports.metadata =
|
||||
{
|
||||
"cordova-plugin-whitelist": "1.2.2",
|
||||
"cordova-plugin-compat": "1.0.0",
|
||||
"cordova-plugin-ble-central": "1.1.0"
|
||||
"cordova-plugin-ble-central": "1.1.0",
|
||||
"cordova-plugin-file": "4.2.0"
|
||||
}
|
||||
// BOTTOM OF METADATA
|
||||
});
|
@ -278,3 +278,30 @@ projector: cast
|
||||
-webkit-line-clamp: 1;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.pulser {
|
||||
display: block;
|
||||
margin-top:10%;
|
||||
border-radius: 100px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 10px solid #C5F4EB;
|
||||
-webkit-animation: pulse 0.75s ease-in infinite;
|
||||
-moz-animation: pulse 0.75s ease-in infinite;
|
||||
animation: pulse 0.75s ease-in infinite;
|
||||
}
|
||||
@-webkit-keyframes pulse {
|
||||
0% { -webkit-transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { -webkit-transform: scale(1); -webkit-filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
@-moz-keyframes pulse {
|
||||
0% { -moz-transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { -moz-transform: scale(1); -moz-filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
@keyframes pulse {
|
||||
0% { transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { transform: scale(1); filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
|
@ -43,13 +43,23 @@
|
||||
<!-- build:css -->
|
||||
<link href="css/mui.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/app.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/ripple.css" rel="stylesheet" type="text/css"/>
|
||||
<title>Sensor Toy</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id='app' class="mui-container">
|
||||
|
||||
<div class="mui-panel">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-8">
|
||||
<button class="mui-btn mui-btn--primary" id="scan">Scan</button>
|
||||
</div>
|
||||
<div class="mui-col-xs-4">
|
||||
<div id='ripple' class="pulser" style="display: none;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<table class="mui-table mui--text-white" id="results">
|
||||
<thead>
|
||||
@ -80,10 +90,13 @@
|
||||
<script type="text/javascript" src="js/standards/battery.js"></script>
|
||||
<script type="text/javascript" src="js/standards/button.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/mandecoder.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_accelerometer.js"></script>
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_barometer.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_luxometer.js"></script>
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_thermopile.js"></script>
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_humidity.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
</body>
|
||||
|
@ -115,6 +115,11 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
// nothing to animate yet
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
this.insertFrame = function(mode) {
|
||||
|
@ -22,16 +22,14 @@ var CC2650_BAR = function(deviceId) {
|
||||
period: 'F000AA43-0451-4000-B000-000000000000'
|
||||
|
||||
};
|
||||
|
||||
this.data = {temp: [], pressure: []};
|
||||
this.$result = {temp: null, pressure: null};
|
||||
|
||||
|
||||
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
if (this.deviceID !== null) {
|
||||
|
||||
console.log('Starting CC2650 Accelerometer Service on ', this.deviceID);
|
||||
console.log('Starting CC2650 Barometer Service on ', this.deviceID);
|
||||
console.log(this.serviceDef);
|
||||
this.insertFrame();
|
||||
|
||||
@ -43,7 +41,6 @@ var CC2650_BAR = function(deviceId) {
|
||||
ble.write(this.deviceID, this.serviceDef.service, this.serviceDef.configuration, barometerConfig.buffer,
|
||||
function() { console.log('Started barometer.'); },this.onError);
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@ -62,12 +59,22 @@ var CC2650_BAR = function(deviceId) {
|
||||
|
||||
//0-2 Temp
|
||||
//3-5 Pressure
|
||||
tStr = this.sensorBarometerConvert(a[0] | (a[1] << 8) | (a[2] << 16)) + '°C';
|
||||
pStr = this.sensorBarometerConvert(a[3] | (a[4] << 8) | (a[5] << 16)) + 'hPa';
|
||||
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));
|
||||
tStr = temp + '°C';
|
||||
pStr = pressure + 'hPa';
|
||||
|
||||
message = 'Temperature <br/>' + tStr +
|
||||
'Pressure <br/>' + 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.$result.temp.text(tStr);
|
||||
this.$result.pressure.text(pStr);
|
||||
|
||||
@ -76,9 +83,16 @@ var CC2650_BAR = function(deviceId) {
|
||||
console.log('Barometer:', this.state);
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
this.simpleGraph(this.data.temp, 'temp');
|
||||
this.simpleGraph(this.data.pressure, 'pressure');
|
||||
};
|
||||
|
||||
|
||||
this.insertFrame = function() {
|
||||
|
||||
var self = this;
|
||||
var blankChart;
|
||||
console.log('Overloading...');
|
||||
// Call the parent displayForm first...
|
||||
this.superClass_.insertFrame.call(self);
|
||||
@ -95,6 +109,16 @@ var CC2650_BAR = function(deviceId) {
|
||||
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: pressure}).appendTo(row);
|
||||
|
||||
this.$id.append(row);
|
||||
|
||||
blankChart = this.generateBlankGraph('temp');
|
||||
|
||||
this.$id.append(blankChart);
|
||||
|
||||
blankChart = this.generateBlankGraph('pressure');
|
||||
|
||||
this.$id.append(blankChart);
|
||||
|
||||
|
||||
this.$result.temp = $('#' + temp);
|
||||
this.$result.pressure = $('#' + pressure);
|
||||
|
||||
|
@ -21,47 +21,87 @@
|
||||
|
||||
var app = {
|
||||
activeServices: [],
|
||||
serviceList: {
|
||||
1800: 'Generic Access',
|
||||
1801: 'Generic Attribute',
|
||||
'180a': 'Device Information',
|
||||
|
||||
FFE0: 'Button',
|
||||
'F000AA00-0451-4000-B000-000000000000': 'Temperature',
|
||||
'F000AA20-0451-4000-B000-000000000000': 'Humidity',
|
||||
'F000AA80-0451-4000-B000-000000000000': 'Accelerometer',
|
||||
'F000AA40-0451-4000-B000-000000000000': 'Barometer'
|
||||
|
||||
},
|
||||
list: {},
|
||||
button: {
|
||||
service: 'FFE0',
|
||||
data: 'FFE1', // Bit 2: side key, Bit 1- right key, Bit 0 –left key
|
||||
},
|
||||
accelerometer: {
|
||||
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
|
||||
},
|
||||
barometer: {
|
||||
service: 'F000AA40-0451-4000-B000-000000000000',
|
||||
data: 'F000AA41-0451-4000-B000-000000000000',
|
||||
notification: 'F0002902-0451-4000-B000-000000000000',
|
||||
configuration: 'F000AA42-0451-4000-B000-000000000000',
|
||||
period: 'F000AA43-0451-4000-B000-000000000000'
|
||||
|
||||
},
|
||||
manufactureDecoder: new MANUFACTUREDECODER(),
|
||||
// Application Constructor
|
||||
initialize: function() {
|
||||
this.bindEvents();
|
||||
},
|
||||
|
||||
arrayBufferToIntArray: function(buffer) {
|
||||
var result;
|
||||
|
||||
if (buffer) {
|
||||
var typedArray = new Uint8Array(buffer);
|
||||
result = [];
|
||||
for (var i = 0; i < typedArray.length; i++) {
|
||||
result[i] = typedArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
parseAdvertisingData: function(bytes) {
|
||||
var length, type, data, i = 0, advertisementData = {};
|
||||
|
||||
while (length !== 0) {
|
||||
|
||||
length = bytes[i] & 0xFF;
|
||||
i++;
|
||||
|
||||
type = bytes[i] & 0xFF;
|
||||
i++;
|
||||
|
||||
data = bytes.slice(i, i + length - 1); // Length includes type byte, but not length byte
|
||||
i += length - 2; // Move to end of data
|
||||
i++;
|
||||
|
||||
advertisementData[type] = data;
|
||||
}
|
||||
|
||||
return advertisementData;
|
||||
},
|
||||
handle255: function(buffer) {
|
||||
'use strict';
|
||||
|
||||
var bin = buffer;
|
||||
|
||||
console.log('Block255', bin);
|
||||
var manSpec = bin.map(function(i) {
|
||||
|
||||
return i.toString(16) + ' ';
|
||||
});
|
||||
|
||||
console.log('manSpec: ', manSpec);
|
||||
var manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4);
|
||||
|
||||
console.log('ManID:', manID);
|
||||
|
||||
switch (manID) {
|
||||
case '004c':
|
||||
return app.manufactureDecoder.decodeIbeacon(bin);
|
||||
break;
|
||||
case '1235':
|
||||
return app.manufactureDecoder.decodeSiliconLabsSensorPuck(bin);
|
||||
break;
|
||||
default:
|
||||
console.log('Unknown manID: ', manID);
|
||||
}
|
||||
return {}
|
||||
},
|
||||
doScan: function() {
|
||||
'use strict';
|
||||
|
||||
$('#ripple').show();
|
||||
$('#tbody').empty();
|
||||
var otherData = null;
|
||||
var msgText = '';
|
||||
ble.startScan([], function(device) {
|
||||
otherData = null;
|
||||
msgText = '';
|
||||
console.log(JSON.stringify(device));
|
||||
|
||||
var newId = device.id.replace(/:/g, '');
|
||||
@ -73,10 +113,44 @@ var app = {
|
||||
|
||||
newTR.append($('<td>').text(device.id));
|
||||
|
||||
if (device.hasOwnProperty('advertising')) {
|
||||
|
||||
var advertBuffer = app.arrayBufferToIntArray(device.advertising);
|
||||
|
||||
var parsed = app.parseAdvertisingData(advertBuffer);
|
||||
|
||||
//console.log(parsed);
|
||||
|
||||
if (parsed.hasOwnProperty('9')) {
|
||||
|
||||
var name = parsed['9'].map(function(i) {
|
||||
|
||||
return String.fromCharCode(i);
|
||||
});
|
||||
|
||||
console.log('Name: ', name.join(''));
|
||||
|
||||
}
|
||||
|
||||
if (parsed.hasOwnProperty('255')) {
|
||||
|
||||
otherData = app.handle255(parsed['255']);
|
||||
console.log(otherData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof otherData !== 'undefined' && otherData !== null)
|
||||
{
|
||||
if (otherData.hasOwnProperty('msg')) {
|
||||
msgText = ' - ' + otherData.msg;
|
||||
}
|
||||
}
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name));
|
||||
newTR.append($('<td>').text(device.name + msgText));
|
||||
} else {
|
||||
newTR.append($('<td>').text('*** Unknown'));
|
||||
newTR.append($('<td>').text('*** Unknown' + msgText));
|
||||
}
|
||||
|
||||
newTR.append($('<td>').text(device.rssi));
|
||||
@ -90,15 +164,16 @@ var app = {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
|
||||
setTimeout(ble.stopScan,
|
||||
5000,
|
||||
function() { console.log('Scan complete'); },
|
||||
function() { console.log('stopScan failed'); }
|
||||
);
|
||||
|
||||
function() { console.log('Scan complete');
|
||||
$('#ripple').hide();
|
||||
},
|
||||
// Bind Event Listeners
|
||||
function() { console.log('stopScan failed');
|
||||
$('#ripple').hide();
|
||||
});
|
||||
|
||||
}, // Bind Event Listeners
|
||||
//
|
||||
// Bind any events that are required on startup. Common events are:
|
||||
// 'load', 'deviceready', 'offline', and 'online'.
|
||||
@ -110,9 +185,7 @@ var app = {
|
||||
this.doScan();
|
||||
}.bind(this));
|
||||
|
||||
|
||||
|
||||
$('#tbody').on('click','tr', function() {
|
||||
$('#tbody').on('click', 'tr', function() {
|
||||
'use strict';
|
||||
var tID = $(this).context.id;
|
||||
|
||||
@ -123,32 +196,37 @@ var app = {
|
||||
self.connect(id);
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
// Deviceready Event Handler
|
||||
}, // Deviceready Event Handler
|
||||
//
|
||||
// The scope of 'this' is the event. In order to call the 'receivedEvent'
|
||||
// function, we must explicitly call 'app.receivedEvent(...);'
|
||||
onDeviceReady: function() {
|
||||
|
||||
|
||||
|
||||
}, serviceDiscovery: function(services) {
|
||||
'use strict';
|
||||
|
||||
console.log(services);
|
||||
|
||||
},
|
||||
sensorMpu9250GyroConvert: function(data) {
|
||||
}, sensorMpu9250GyroConvert: function(data) {
|
||||
return data / (65536 / 500);
|
||||
},
|
||||
|
||||
sensorMpu9250AccConvert: function(data) {
|
||||
// Change /2 to match accel range...i.e. 16 g would be /16
|
||||
return data / (32768 / 2);
|
||||
},
|
||||
|
||||
doAnimate: function() {
|
||||
'use strict';
|
||||
console.log('Animate..');
|
||||
for (var t = 0; t < app.activeServices.length;t++) {
|
||||
app.activeServices[t].animateGraph();
|
||||
}
|
||||
|
||||
,connect: function(deviceId) {
|
||||
window.requestAnimFrame(app.doAnimate.bind(this));
|
||||
}
|
||||
|
||||
, connect: function(deviceId) {
|
||||
|
||||
$('#results').slideUp();
|
||||
console.log('Connect to ', deviceId);
|
||||
@ -162,7 +240,7 @@ var app = {
|
||||
|
||||
services = a.services;
|
||||
|
||||
for (var t = 0; t < services.length;t++) {
|
||||
for (var t = 0; t < services.length; t++) {
|
||||
|
||||
var ident = services[t].toUpperCase();
|
||||
|
||||
@ -192,12 +270,32 @@ var app = {
|
||||
app.activeServices.push(cc2650_bar);
|
||||
break;
|
||||
|
||||
case 'F000AA70-0451-4000-B000-000000000000':
|
||||
var cc2650_lux = new CC2650_LUX(deviceId);
|
||||
cc2650_lux.startService();
|
||||
app.activeServices.push(cc2650_lux);
|
||||
break;
|
||||
|
||||
case 'F000AA00-0451-4000-B000-000000000000':
|
||||
var cc2650_tmp = new CC2650_TMP(deviceId);
|
||||
cc2650_tmp.startService();
|
||||
app.activeServices.push(cc2650_tmp);
|
||||
break;
|
||||
|
||||
|
||||
case 'F000AA20-0451-4000-B000-000000000000':
|
||||
var cc2650_hum = new CC2650_HUM(deviceId);
|
||||
cc2650_hum.startService();
|
||||
app.activeServices.push(cc2650_hum);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('Unknown service: ', ident);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Starting animation..
|
||||
window.requestAnimFrame(app.doAnimate.bind(this));
|
||||
};
|
||||
|
||||
ble.connect(deviceId, onConnect, function(e) {
|
||||
@ -205,14 +303,24 @@ var app = {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
},
|
||||
onError: function(reason) {
|
||||
}, onError: function(reason) {
|
||||
console.error('ERROR: ' + reason); // Real apps should use notification.alert
|
||||
},
|
||||
updateGyro: function(g) {
|
||||
}, updateGyro: function(g) {
|
||||
'use strict';
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
window.requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
function(callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
|
||||
app.initialize();
|
||||
|
@ -18,6 +18,10 @@ var CAPABILITY = function(p) {
|
||||
|
||||
this.deviceID = null;
|
||||
|
||||
this.data = [];
|
||||
this.ctx = null;
|
||||
this.first = false;
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.setInternalID = function() {
|
||||
@ -64,7 +68,174 @@ CAPABILITY.prototype.onError = function(e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.storeData = function(data, alt) {
|
||||
|
||||
if (!this.first) {
|
||||
this.first = true;
|
||||
return [];
|
||||
}
|
||||
var target = alt || this.data;
|
||||
|
||||
if (target.length === 99) {
|
||||
target = target.slice(1);
|
||||
}
|
||||
|
||||
target.push(data);
|
||||
if (alt) {
|
||||
return target;
|
||||
} else {
|
||||
this.data = target;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.startGraph = function(id) {
|
||||
|
||||
var c;
|
||||
c = id[0].getContext('2d');
|
||||
this.ctx = c;
|
||||
|
||||
this.ctx.fillStyle = '#ffffff';
|
||||
this.ctx.fillRect(0,0,300,150);
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.generateBlankGraph = function(subID) {
|
||||
|
||||
var _subID = subID || '';
|
||||
var xmlns = 'http://www.w3.org/2000/svg';
|
||||
|
||||
var svgID = this.frameID + _subID + '-svg';
|
||||
var text1ID = this.frameID + _subID + '-txt1';
|
||||
var lineID = this.frameID + _subID + '-line';
|
||||
|
||||
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');
|
||||
|
||||
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:#bad649;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:#bad649;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:sans-serif;font-size:12;fill: #bad649;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:sans-serif;font-size:12;fill: #bad649;text-align:right;');
|
||||
text.textContent = '0';
|
||||
|
||||
svg.appendChild(text);
|
||||
|
||||
var polyline = document.createElementNS(xmlns,'polyline');
|
||||
|
||||
polyline.setAttributeNS(null,'id',lineID);
|
||||
polyline.setAttributeNS(null,'fill','none');
|
||||
polyline.setAttributeNS(null,'stroke','#e5f7fd');
|
||||
//#e5f7fd
|
||||
// old #B5C7FF
|
||||
polyline.setAttributeNS(null,'text-anchor', 'end');
|
||||
polyline.setAttributeNS(null,'stroke-width','2');
|
||||
|
||||
svg.appendChild(polyline);
|
||||
|
||||
return svg;
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.animateGraph = function() {
|
||||
//this.simpleGraph(this.data);
|
||||
};
|
||||
|
||||
|
||||
CAPABILITY.prototype.simpleGraph = function(data, subID) {
|
||||
|
||||
var text1ID;
|
||||
var lineID;
|
||||
|
||||
var _data = data || this.data;
|
||||
|
||||
|
||||
var _subID = subID || '';
|
||||
|
||||
lineID = this.frameID + _subID + '-line';
|
||||
text1ID = this.frameID + _subID + '-txt1';
|
||||
|
||||
console.log('Drawing: ', subID);
|
||||
if (_data.length > 0) {
|
||||
var ceiling = _data.reduce(function(p, v) {
|
||||
return (p > v ? p : v);
|
||||
});
|
||||
|
||||
var floor = _data.reduce(function(p, v) {
|
||||
return (p < v ? p : v);
|
||||
});
|
||||
|
||||
|
||||
var calcArray = [];
|
||||
|
||||
var ceilingLimit = Math.floor(ceiling / 10) * 10;
|
||||
if (ceilingLimit < ceiling) {
|
||||
ceilingLimit = Math.floor((ceiling + (ceiling * 0.25)) / 10) * 10;
|
||||
}
|
||||
|
||||
if (ceilingLimit < 30) {
|
||||
ceilingLimit = 30;
|
||||
}
|
||||
|
||||
var scale = 124 / ceilingLimit;
|
||||
var xstep = (300 - 46) / 100;
|
||||
var startX = 46 + (100 - _data.length) * xstep;
|
||||
|
||||
for (var x = 0;x < _data.length;x++) {
|
||||
|
||||
calcArray.push((startX + (x * 2.54)).toFixed(2) + ',' + (136 - ((_data[x]) * scale)).toFixed(2));
|
||||
|
||||
}
|
||||
|
||||
var elm = document.getElementById(lineID);
|
||||
|
||||
elm.setAttribute('points',calcArray.join(' '));
|
||||
|
||||
elm = document.getElementById(text1ID);
|
||||
|
||||
elm.textContent = ceilingLimit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -1,168 +1,34 @@
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
Customize this policy to fit your own app's needs. For more guidance, see:
|
||||
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
|
||||
Some notes:
|
||||
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
|
||||
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
|
||||
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
|
||||
* Enable inline JS: add 'unsafe-inline' to default-src
|
||||
-->
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta name="viewport"
|
||||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<link rel="stylesheet"
|
||||
href="http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700"
|
||||
type="text/css">
|
||||
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Condensed"
|
||||
rel="stylesheet" type="text/css">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
||||
rel="stylesheet">
|
||||
<!-- endbuild -->
|
||||
<!-- build:css -->
|
||||
<link href="css/mui.css" rel="stylesheet" type="text/css">
|
||||
<link href="css/app.css" rel="stylesheet" type="text/css">
|
||||
<title>Sensor Toy</title>
|
||||
<script src="file:///android_asset/www/cordova_plugins.js"></script>
|
||||
<script
|
||||
src="file:///android_asset/www/plugins/cordova-plugin-ble-central/www/ble.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" class="mui-container">
|
||||
<div class="mui-panel">
|
||||
<button class="mui-btn mui-btn--primary" id="scan">Scan</button>
|
||||
</div>
|
||||
<table class="mui-table" id="results" style="display: none;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>RSI</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
<tr id="C5857DA96046" class="clickRow">
|
||||
<td>C5:85:7D:A9:60:46</td>
|
||||
<td>EST</td>
|
||||
<td>-95</td>
|
||||
</tr>
|
||||
<tr id="FA49B934F9B4" class="clickRow">
|
||||
<td>FA:49:B9:34:F9:B4</td>
|
||||
<td>Flex</td>
|
||||
<td>-84</td>
|
||||
</tr>
|
||||
<tr id="D481CAE06DA6" class="clickRow">
|
||||
<td>D4:81:CA:E0:6D:A6</td>
|
||||
<td>*** Unknown</td>
|
||||
<td>-61</td>
|
||||
</tr>
|
||||
<tr id="B0B448BE1787" class="clickRow">
|
||||
<td>B0:B4:48:BE:17:87</td>
|
||||
<td>CC2650 SensorTag</td>
|
||||
<td>-58</td>
|
||||
</tr>
|
||||
<tr id="E2A6C6D55B5E" class="clickRow">
|
||||
<td>E2:A6:C6:D5:5B:5E</td>
|
||||
<td>jaalee</td>
|
||||
<td>-64</td>
|
||||
</tr>
|
||||
<tr id="C8B4C678218F" class="clickRow">
|
||||
<td>C8:B4:C6:78:21:8F</td>
|
||||
<td>EST</td>
|
||||
<td>-88</td>
|
||||
</tr>
|
||||
<tr id="C5019E466A82" class="clickRow">
|
||||
<td>C5:01:9E:46:6A:82</td>
|
||||
<td>EST</td>
|
||||
<td>-89</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="frames" class="mui-container">
|
||||
<div class="mui-panel" id="f-1w31tsbk562-gyro">
|
||||
<div class="mui-row">
|
||||
<div class="mui--text-title">Gyroscope - B0:B4:48:BE:17:87</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-3 mui--text-accent">X</div>
|
||||
<div class="mui-col-xs-3 mui--text-accent">Y</div>
|
||||
<div class="mui-col-xs-3 mui--text-accent">Z</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-3 mui--text-white"
|
||||
id="f-1w31tsbk562-gyro-x">-0.19073
|
||||
</div>
|
||||
<div class="mui-col-xs-3 mui--text-white"
|
||||
id="f-1w31tsbk562-gyro-y">-0.15259
|
||||
</div>
|
||||
<div class="mui-col-xs-3 mui--text-white"
|
||||
id="f-1w31tsbk562-gyro-z">-0.07629
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-panel" id="f-1w31tsbk562-accel">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-12 mui--text-white mui--text-title">Accelerometer - B0:B4:48:BE:17:87</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-3 mui--text-accent">X</div>
|
||||
<div class="mui-col-xs-3 mui--text-accent">Y</div>
|
||||
<div class="mui-col-xs-3 mui--text-accent">Z</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-3 mui--text-white"
|
||||
id="f-1w31tsbk562-accel-x">-0.00073
|
||||
</div>
|
||||
<div class="mui-col-xs-3 mui--text-white"
|
||||
id="f-1w31tsbk562-accel-y">0.00153
|
||||
</div>
|
||||
<div class="mui-col-xs-3 mui--text-white"
|
||||
id="f-1w31tsbk562-accel-z">-0.25513
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-panel" id="f-1w31tsbk562-mag">
|
||||
<div class="mui-row">
|
||||
<div class="mui--text-title">Magnetometer - B0:B4:48:BE:17:87</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-3 mui--text-accent">X</div>
|
||||
<div class="mui-col-xs-3 mui--text-accent">Y</div>
|
||||
<div class="mui-col-xs-3 mui--text-accent">Z</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-3 mui--text-white" id="f-1w31tsbk562-mag-x">-12
|
||||
</div>
|
||||
<div class="mui-col-xs-3 mui--text-white" id="f-1w31tsbk562-mag-y">25
|
||||
</div>
|
||||
<div class="mui-col-xs-3 mui--text-white" id="f-1w31tsbk562-mag-z">-4180
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-panel" id="f-fcgnr6zzsw">
|
||||
<div class="mui-row">
|
||||
<div class="mui--text-title">Button - B0:B4:48:BE:17:87</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-4 mui--text-accent">Status:</div>
|
||||
<div class="mui-col-xs-8 mui--text-white" id="f-fcgnr6zzsw-d"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="libs/jquery/dist/jquery.js"></script>
|
||||
<script type="text/javascript"
|
||||
src="libs/bluebird/js/browser/bluebird.js"></script>
|
||||
<script type="text/javascript" src="js/standards/capability.js"></script>
|
||||
<script type="text/javascript" src="js/standards/battery.js"></script>
|
||||
<script type="text/javascript" src="js/standards/button.js"></script>
|
||||
<script type="text/javascript"
|
||||
src="js/device/CC2650/cc2650_accelerometer.js"></script>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<script>
|
||||
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
|
||||
|
||||
// http://www.ti.com/lit/ds/symlink/opt3001.pdf
|
||||
var x = 15390;
|
||||
var v = 15 << 10;
|
||||
|
||||
var r = x & v;
|
||||
var o = x & ~v;
|
||||
|
||||
console.log('x',x.toString(2));
|
||||
|
||||
console.log('r',r.toString(2));
|
||||
console.log('o',o.toString(2));
|
||||
var m;
|
||||
for (var t=0;t<16;t++)
|
||||
{
|
||||
m = v >>> t;
|
||||
|
||||
console.log(m.toString(2), t);
|
||||
console.log(x.toString(2));
|
||||
}
|
||||
|
||||
for (var t=0;t<16;t++)
|
||||
{
|
||||
m = v << t;
|
||||
console.log(m.toString(2), t);
|
||||
console.log(x.toString(2));
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
a[0] | (a[1] << 8)
|
||||
|
@ -12,6 +12,9 @@
|
||||
},
|
||||
"cordova-plugin-ble-central": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
},
|
||||
"cordova-plugin-file": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
}
|
||||
},
|
||||
"dependent_plugins": {
|
||||
|
@ -22,5 +22,13 @@
|
||||
},
|
||||
"is_top_level": false,
|
||||
"variables": {}
|
||||
},
|
||||
"cordova-plugin-file": {
|
||||
"source": {
|
||||
"type": "registry",
|
||||
"id": "cordova-plugin-file"
|
||||
},
|
||||
"is_top_level": true,
|
||||
"variables": {}
|
||||
}
|
||||
}
|
@ -12,6 +12,9 @@
|
||||
},
|
||||
"cordova-plugin-ble-central": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
},
|
||||
"cordova-plugin-file": {
|
||||
"PACKAGE_NAME": "org.censis.sensortoy"
|
||||
}
|
||||
},
|
||||
"dependent_plugins": {
|
||||
|
@ -278,3 +278,30 @@ projector: cast
|
||||
-webkit-line-clamp: 1;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.pulser {
|
||||
display: block;
|
||||
margin-top:10%;
|
||||
border-radius: 100px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 10px solid #C5F4EB;
|
||||
-webkit-animation: pulse 0.75s ease-in infinite;
|
||||
-moz-animation: pulse 0.75s ease-in infinite;
|
||||
animation: pulse 0.75s ease-in infinite;
|
||||
}
|
||||
@-webkit-keyframes pulse {
|
||||
0% { -webkit-transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { -webkit-transform: scale(1); -webkit-filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
@-moz-keyframes pulse {
|
||||
0% { -moz-transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { -moz-transform: scale(1); -moz-filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
@keyframes pulse {
|
||||
0% { transform: scale(0); }
|
||||
85% { opacity: 1; }
|
||||
100% { transform: scale(1); filter: blur(5px); opacity: 0; }
|
||||
}
|
||||
|
@ -1331,7 +1331,7 @@ th {
|
||||
text-transform: uppercase;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
color: rgba(0, 0, 0, 0.87);
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
cursor: default;
|
||||
height: 48px;
|
||||
line-height: 48px;
|
||||
|
94
www/css/progress.css
Normal file
94
www/css/progress.css
Normal file
@ -0,0 +1,94 @@
|
||||
/* Progress Bar */
|
||||
.progress {
|
||||
position: relative;
|
||||
height: 4px;
|
||||
display: block;
|
||||
width: 100%;
|
||||
background-color: #acece6;
|
||||
border-radius: 2px;
|
||||
background-clip: padding-box;
|
||||
/* margin: 0.5rem 0 1rem 0; */
|
||||
overflow: hidden; }
|
||||
|
||||
.progress .determinate {
|
||||
position: absolute;
|
||||
background-color: inherit;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background-color: #26a69a;
|
||||
transition: width .3s linear; }
|
||||
|
||||
.progress .indeterminate {
|
||||
background-color: #26a69a; }
|
||||
|
||||
.progress .indeterminate:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
background-color: inherit;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
will-change: left, right;
|
||||
-webkit-animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
|
||||
animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite; }
|
||||
|
||||
.progress .indeterminate:after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
background-color: inherit;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
will-change: left, right;
|
||||
-webkit-animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
|
||||
animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
|
||||
-webkit-animation-delay: 1.15s;
|
||||
animation-delay: 1.15s; }
|
||||
|
||||
@-webkit-keyframes indeterminate {
|
||||
0% {
|
||||
left: -35%;
|
||||
right: 100%; }
|
||||
60% {
|
||||
left: 100%;
|
||||
right: -90%; }
|
||||
100% {
|
||||
left: 100%;
|
||||
right: -90%; }
|
||||
}
|
||||
|
||||
@keyframes indeterminate {
|
||||
0% {
|
||||
left: -35%;
|
||||
right: 100%; }
|
||||
60% {
|
||||
left: 100%;
|
||||
right: -90%; }
|
||||
100% {
|
||||
left: 100%;
|
||||
right: -90%; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes indeterminate-short {
|
||||
0% {
|
||||
left: -200%;
|
||||
right: 100%; }
|
||||
60% {
|
||||
left: 107%;
|
||||
right: -8%; }
|
||||
100% {
|
||||
left: 107%;
|
||||
right: -8%; }
|
||||
}
|
||||
|
||||
@keyframes indeterminate-short {
|
||||
0% {
|
||||
left: -200%;
|
||||
right: 100%; }
|
||||
60% {
|
||||
left: 107%;
|
||||
right: -8%; }
|
||||
100% {
|
||||
left: 107%;
|
||||
right: -8%; }
|
||||
}
|
195
www/css/ripple.css
Normal file
195
www/css/ripple.css
Normal file
@ -0,0 +1,195 @@
|
||||
|
||||
@-webkit-keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@-moz-keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@-ms-keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@-moz-keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@-o-keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@keyframes uil-ripple {
|
||||
0% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
33% {
|
||||
width: 44%;
|
||||
height: 44%;
|
||||
margin: -22% 0 0 -22%;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
width: 88%;
|
||||
height: 88%;
|
||||
margin: -44% 0 0 -44%;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
.uil-ripple-css {
|
||||
background: none;
|
||||
position: relative;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
}
|
||||
.uil-ripple-css div {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
border-radius: 50%;
|
||||
border-width: 12px;
|
||||
border-style: solid;
|
||||
-ms-animation: uil-ripple 2s ease-out infinite;
|
||||
-moz-animation: uil-ripple 2s ease-out infinite;
|
||||
-webkit-animation: uil-ripple 2s ease-out infinite;
|
||||
-o-animation: uil-ripple 2s ease-out infinite;
|
||||
animation: uil-ripple 2s ease-out infinite;
|
||||
}
|
||||
.uil-ripple-css div:nth-of-type(1) {
|
||||
border-color: #afafb7;
|
||||
}
|
||||
.uil-ripple-css div:nth-of-type(2) {
|
||||
border-color: #5cffd6;
|
||||
-ms-animation-delay: 1s;
|
||||
-moz-animation-delay: 1s;
|
||||
-webkit-animation-delay: 1s;
|
||||
-o-animation-delay: 1s;
|
||||
animation-delay: 1s;
|
||||
}
|
BIN
www/fonts/Material_Icons-normal-400.woff
Normal file
BIN
www/fonts/Material_Icons-normal-400.woff
Normal file
Binary file not shown.
BIN
www/fonts/Ubuntu-normal-300.woff
Normal file
BIN
www/fonts/Ubuntu-normal-300.woff
Normal file
Binary file not shown.
BIN
www/fonts/Ubuntu-normal-400.woff
Normal file
BIN
www/fonts/Ubuntu-normal-400.woff
Normal file
Binary file not shown.
BIN
www/fonts/Ubuntu-normal-500.woff
Normal file
BIN
www/fonts/Ubuntu-normal-500.woff
Normal file
Binary file not shown.
BIN
www/fonts/Ubuntu-normal-700.woff
Normal file
BIN
www/fonts/Ubuntu-normal-700.woff
Normal file
Binary file not shown.
BIN
www/fonts/Ubuntu_Condensed-normal-400.woff
Normal file
BIN
www/fonts/Ubuntu_Condensed-normal-400.woff
Normal file
Binary file not shown.
41
www/fonts/fonts.css
Normal file
41
www/fonts/fonts.css
Normal file
@ -0,0 +1,41 @@
|
||||
@font-face {
|
||||
font-family: 'Material Icons';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url(Material_Icons-normal-400.woff) format('woff');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Ubuntu';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
src: url(Ubuntu-normal-300.woff) format('woff');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Ubuntu';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url(Ubuntu-normal-400.woff) format('woff');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Ubuntu';
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
src: url(Ubuntu-normal-500.woff) format('woff');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Ubuntu';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: url(Ubuntu-normal-700.woff) format('woff');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Ubuntu Condensed';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url(Ubuntu_Condensed-normal-400.woff) format('woff');
|
||||
}
|
@ -41,16 +41,36 @@
|
||||
rel="stylesheet">
|
||||
<!-- endbuild -->
|
||||
<!-- build:css -->
|
||||
<link href="css/mui.css" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" href="fonts/fonts.css">
|
||||
<link href="css/mui.custom.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/app.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/ripple.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/progress.css" rel="stylesheet" type="text/css"/>
|
||||
<title>Sensor Toy</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="margin: 0.5rem 0 1rem 0;">
|
||||
<div class="progress" id='ripple' style="display: none;">
|
||||
<div class="indeterminate"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id='app' class="mui-container">
|
||||
|
||||
<div class="mui-panel">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-xs-6">
|
||||
<button class="mui-btn mui-btn--primary" id="scan">Scan</button>
|
||||
<button class="mui-btn mui-btn--danger" id="stop" style="display: none;">Stop</button>
|
||||
</div>
|
||||
|
||||
<div class="mui-col-xs-6">
|
||||
<button class="mui-btn mui-btn--accent" id="longScan">Long</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<table class="mui-table mui--text-white" id="results">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -74,12 +94,15 @@
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="libs/jquery/dist/jquery.js"></script>
|
||||
<script type="text/javascript" src="libs/mui/packages/cdn/js/mui.js"></script>
|
||||
<script type="text/javascript" src="libs/bluebird/js/browser/bluebird.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/standards/bluetooth_company_identifiers.js"></script>
|
||||
<script type="text/javascript" src="js/standards/capability.js"></script>
|
||||
<script type="text/javascript" src="js/standards/battery.js"></script>
|
||||
<script type="text/javascript" src="js/standards/button.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/mandecoder.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_accelerometer.js"></script>
|
||||
<script type="text/javascript" src="js/device/CC2650/cc2650_barometer.js"></script>
|
||||
|
@ -37,7 +37,7 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
};
|
||||
|
||||
this.onAccelerometerData = function(data) {
|
||||
console.log(data);
|
||||
// Console.log(data);
|
||||
var message;
|
||||
var a = new Int16Array(data);
|
||||
|
||||
@ -80,7 +80,7 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
this.$result[this.frames.magID + '-y'].text(a[4]);
|
||||
this.$result[this.frames.magID + '-z'].text(a[5]);
|
||||
|
||||
console.log(this.state);
|
||||
// Console.log(this.state);
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
@ -93,8 +93,6 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
|
||||
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
|
||||
@ -115,6 +113,11 @@ var CC2650_ACCEL = function(deviceId) {
|
||||
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
// Nothing to animate yet
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
this.insertFrame = function(mode) {
|
||||
|
@ -22,7 +22,7 @@ var CC2650_BAR = function(deviceId) {
|
||||
period: 'F000AA43-0451-4000-B000-000000000000'
|
||||
|
||||
};
|
||||
|
||||
this.data = {temp: [], pressure: []};
|
||||
this.$result = {temp: null, pressure: null};
|
||||
|
||||
this.startService = function() {
|
||||
@ -53,30 +53,47 @@ var CC2650_BAR = function(deviceId) {
|
||||
this.onBarometerData = function(data) {
|
||||
var pStr;
|
||||
var tStr;
|
||||
console.log(data);
|
||||
// Console.log(data);
|
||||
var message;
|
||||
var a = new Uint8Array(data);
|
||||
|
||||
//0-2 Temp
|
||||
//3-5 Pressure
|
||||
tStr = this.sensorBarometerConvert(a[0] | (a[1] << 8) | (a[2] << 16)) + '°C';
|
||||
pStr = this.sensorBarometerConvert(a[3] | (a[4] << 8) | (a[5] << 16)) + 'hPa';
|
||||
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));
|
||||
tStr = temp + '°C';
|
||||
pStr = pressure + 'hPa';
|
||||
|
||||
message = 'Temperature <br/>' + tStr +
|
||||
'Pressure <br/>' + 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.$result.temp.text(tStr);
|
||||
this.$result.pressure.text(pStr);
|
||||
|
||||
this.state = message;
|
||||
|
||||
console.log('Barometer:', this.state);
|
||||
// Console.log('Barometer:', this.state);
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
this.simpleGraph(this.data.temp, 'temp');
|
||||
this.simpleGraph(this.data.pressure, 'pressure');
|
||||
};
|
||||
|
||||
|
||||
this.insertFrame = function() {
|
||||
|
||||
var self = this;
|
||||
console.log('Overloading...');
|
||||
var blankChart;
|
||||
|
||||
// Call the parent displayForm first...
|
||||
this.superClass_.insertFrame.call(self);
|
||||
|
||||
@ -92,6 +109,24 @@ var CC2650_BAR = function(deviceId) {
|
||||
$('<div />', { class: 'mui-col-xs-3 mui--text-white', id: pressure}).appendTo(row);
|
||||
|
||||
this.$id.append(row);
|
||||
|
||||
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
|
||||
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
|
||||
$('<li>').append($('<a>',{text:'Pressure','data-mui-toggle': 'tab', 'data-mui-controls': (pressure + '-pane')})).appendTo(tabBody);
|
||||
|
||||
this.$id.append(tabBody);
|
||||
|
||||
blankChart = this.generateBlankGraph('temp');
|
||||
|
||||
// this.$id.append(blankChart);
|
||||
this.$id.append($('<div>',{'class':'mui-tabs__pane mui--is-active',id:(temp + '-pane')}).append(blankChart));
|
||||
|
||||
blankChart = this.generateBlankGraph('pressure');
|
||||
|
||||
// this.$id.append(blankChart);
|
||||
this.$id.append($('<div>',{'class':'mui-tabs__pane',id:(pressure + '-pane')}).append(blankChart));
|
||||
|
||||
|
||||
this.$result.temp = $('#' + temp);
|
||||
this.$result.pressure = $('#' + pressure);
|
||||
|
||||
|
@ -22,7 +22,7 @@ var CC2650_HUM = function(deviceId) {
|
||||
period: 'F000AA23-0451-4000-B000-000000000000'
|
||||
|
||||
};
|
||||
|
||||
this.data = {temp: [], humidity: []};
|
||||
this.$result = {temp: null, humidity: null};
|
||||
|
||||
this.startService = function() {
|
||||
@ -56,7 +56,7 @@ var CC2650_HUM = function(deviceId) {
|
||||
this.onHumidityData = function(data) {
|
||||
var hStr;
|
||||
var tStr;
|
||||
console.log(data);
|
||||
// Console.log(data);
|
||||
var message;
|
||||
var raw = new Uint16Array(data);
|
||||
|
||||
@ -66,23 +66,37 @@ var CC2650_HUM = function(deviceId) {
|
||||
//-- calculate relative humidity [%RH]
|
||||
var hum = (raw[1] / 65536) * 100;
|
||||
|
||||
tStr = temp + '°C';
|
||||
hStr = hum + '%RH';
|
||||
tStr = temp.toFixed(2) + '°C';
|
||||
hStr = hum.toFixed(2) + '%RH';
|
||||
|
||||
message = 'Temperature <br/>' + tStr + 'Humidity <br/>' + hStr;
|
||||
|
||||
// This.data.temp = this.storeData(parseInt(temp), this.data.temp);
|
||||
// this.data.humidity = this.storeData(parseInt(hum), this.data.humidity);
|
||||
|
||||
this.data.temp = this.storeData(temp, this.data.temp);
|
||||
this.data.humidity = this.storeData(hum, this.data.humidity);
|
||||
|
||||
message = 'Temperature <br/>' + tStr + 'Humidity <br/>' + pStr;
|
||||
|
||||
this.$result.temp.text(tStr);
|
||||
this.$result.humidity.text(hStr);
|
||||
|
||||
this.state = message;
|
||||
|
||||
console.log('Barometer:', this.state);
|
||||
// Console.log('Barometer:', this.state);
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
this.simpleGraph(this.data.temp, 'temp');
|
||||
this.simpleGraph(this.data.humidity, 'humidity');
|
||||
};
|
||||
|
||||
|
||||
this.insertFrame = function() {
|
||||
|
||||
var self = this;
|
||||
console.log('Overloading...');
|
||||
var blankChart;
|
||||
|
||||
// Call the parent displayForm first...
|
||||
this.superClass_.insertFrame.call(self);
|
||||
|
||||
@ -105,6 +119,22 @@ var CC2650_HUM = function(deviceId) {
|
||||
{class: 'mui-col-xs-3 mui--text-white', id: humidity}).appendTo(row);
|
||||
|
||||
this.$id.append(row);
|
||||
|
||||
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
|
||||
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text: 'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
|
||||
$('<li>').append($('<a>',{text: 'Humidity','data-mui-toggle': 'tab', 'data-mui-controls': (humidity + '-pane')})).appendTo(tabBody);
|
||||
this.$id.append(tabBody);
|
||||
|
||||
blankChart = this.generateBlankGraph('temp');
|
||||
|
||||
// This.$id.append(blankChart);
|
||||
this.$id.append($('<div>',{class: 'mui-tabs__pane mui--is-active',id: (temp + '-pane')}).append(blankChart));
|
||||
|
||||
blankChart = this.generateBlankGraph('humidity');
|
||||
this.$id.append($('<div>',{class: 'mui-tabs__pane',id: (humidity + '-pane')}).append(blankChart));
|
||||
|
||||
// this.$id.append(blankChart);
|
||||
|
||||
this.$result.temp = $('#' + temp);
|
||||
this.$result.humidity = $('#' + humidity);
|
||||
|
||||
|
@ -24,6 +24,7 @@ var CC2650_LUX = function(deviceId) {
|
||||
};
|
||||
|
||||
this.$result = {temp: null, pressure: null};
|
||||
this.data = [];
|
||||
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
@ -56,7 +57,7 @@ var CC2650_LUX = function(deviceId) {
|
||||
this.onLuxData = function(data) {
|
||||
|
||||
var m, e, lux;
|
||||
console.log(data);
|
||||
// Console.log(data);
|
||||
|
||||
var raw = new Uint16Array(data);
|
||||
|
||||
@ -65,17 +66,25 @@ var CC2650_LUX = function(deviceId) {
|
||||
|
||||
lux = m * (0.01 * Math.pow(2.0, e));
|
||||
|
||||
this.state = [lux, 'lux'].join(' ');
|
||||
this.state = [lux.toFixed(2), 'lux'].join(' ');
|
||||
|
||||
|
||||
//This.storeData(parseInt(lux));
|
||||
this.storeData(lux);
|
||||
|
||||
this.$result.text(this.state);
|
||||
|
||||
console.log('Luxometer:', this.state);
|
||||
// Console.log('Luxometer:', this.state);
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
this.simpleGraph(this.data, '');
|
||||
};
|
||||
|
||||
this.insertFrame = function() {
|
||||
|
||||
var self = this;
|
||||
console.log('Overloading...');
|
||||
|
||||
// Call the parent displayForm first...
|
||||
this.superClass_.insertFrame.call(self);
|
||||
|
||||
@ -91,8 +100,15 @@ var CC2650_LUX = function(deviceId) {
|
||||
{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));
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -15,14 +15,15 @@ var CC2650_TMP = function(deviceId) {
|
||||
this.deviceID = deviceId;
|
||||
this.capabilityID = 'F000AA00-0451-4000-B000-000000000000';
|
||||
this.serviceDef = {
|
||||
service: 'F000AA01-0451-4000-B000-000000000000',
|
||||
data: 'F000AA71-0451-4000-B000-000000000000',
|
||||
service: 'F000AA00-0451-4000-B000-000000000000',
|
||||
data: 'F000AA01-0451-4000-B000-000000000000',
|
||||
notification: 'F0002902-0451-4000-B000-000000000000',
|
||||
configuration: 'F0000AA02-0451-4000-B000-000000000000',
|
||||
configuration: 'F000AA02-0451-4000-B000-000000000000',
|
||||
period: 'F000AA03-0451-4000-B000-000000000000'
|
||||
|
||||
};
|
||||
|
||||
this.data = {temp: [], ambient: []};
|
||||
this.$result = {temp: null, ambient: null};
|
||||
|
||||
this.startService = function() {
|
||||
@ -68,21 +69,33 @@ var CC2650_TMP = function(deviceId) {
|
||||
|
||||
ambTemp = it * scale_lsb;
|
||||
|
||||
var tStr = objTemp + '°C';
|
||||
var aStr = ambTemp + '°C';
|
||||
var tStr = objTemp.toFixed(2) + '°C';
|
||||
var aStr = ambTemp.toFixed(2) + '°C';
|
||||
|
||||
this.state = ['Temp: ', tStr, ', Ambient:', aStr].join(' ');
|
||||
|
||||
this.data.temp = this.storeData(objTemp, this.data.temp);
|
||||
this.data.ambient = this.storeData(ambTemp, this.data.ambient);
|
||||
|
||||
|
||||
this.$result.temp.text(tStr);
|
||||
this.$result.ambient.text(aStr);
|
||||
|
||||
console.log('Thermopile:', this.state);
|
||||
// Console.log('Thermopile:', this.state);
|
||||
};
|
||||
|
||||
this.animateGraph = function() {
|
||||
this.simpleGraph(this.data.temp, 'temp');
|
||||
this.simpleGraph(this.data.ambient, 'ambient');
|
||||
};
|
||||
|
||||
|
||||
|
||||
this.insertFrame = function() {
|
||||
|
||||
var blankChart;
|
||||
var self = this;
|
||||
console.log('Overloading...');
|
||||
// Console.log('Overloading...');
|
||||
// Call the parent displayForm first...
|
||||
this.superClass_.insertFrame.call(self);
|
||||
|
||||
@ -98,13 +111,37 @@ var CC2650_TMP = function(deviceId) {
|
||||
$('<div />',
|
||||
{
|
||||
class: 'mui-col-xs-3 mui--text-accent',
|
||||
text: 'Ambient::'
|
||||
text: 'Ambient:'
|
||||
}).appendTo(row);
|
||||
|
||||
$('<div />',
|
||||
{class: 'mui-col-xs-3 mui--text-white', id: amb}).appendTo(row);
|
||||
|
||||
this.$id.append(row);
|
||||
|
||||
var tabBody = $('<ul>',{class: 'mui-tabs__bar mui-tabs__bar--justified'});
|
||||
$('<li>',{class: 'mui--is-active'}).append($('<a>',{text:'Temperature','data-mui-toggle': 'tab', 'data-mui-controls': (temp + '-pane')})).appendTo(tabBody);
|
||||
$('<li>').append($('<a>',{text:'Ambient','data-mui-toggle': 'tab', 'data-mui-controls': (amb + '-pane')})).appendTo(tabBody);
|
||||
|
||||
this.$id.append(tabBody);
|
||||
|
||||
|
||||
/*
|
||||
<div class="mui-tabs__pane mui--is-active" id="pane-justified-1">Pane-1</div>
|
||||
<div class="mui-tabs__pane" id="pane-justified-2">Pane-2</div>
|
||||
|
||||
*/
|
||||
|
||||
blankChart = this.generateBlankGraph('temp');
|
||||
//this.$id.append(blankChart);
|
||||
|
||||
this.$id.append($('<div>',{'class':'mui-tabs__pane mui--is-active',id:(temp + '-pane')}).append(blankChart));
|
||||
|
||||
blankChart = this.generateBlankGraph('ambient');
|
||||
|
||||
//this.$id.append(blankChart);
|
||||
this.$id.append($('<div>',{'class':'mui-tabs__pane',id:(amb + '-pane')}).append(blankChart));
|
||||
|
||||
this.$result.temp = $('#' + temp);
|
||||
this.$result.ambient = $('#' + amb);
|
||||
|
||||
|
312
www/js/index.js
312
www/js/index.js
@ -20,53 +20,290 @@
|
||||
/* global BATTERY, BUTTON */
|
||||
|
||||
var app = {
|
||||
stop: false,
|
||||
log: {},
|
||||
activeServices: [],
|
||||
|
||||
list: {},
|
||||
|
||||
manufactureDecoder: new MANUFACTUREDECODER(),
|
||||
// Application Constructor
|
||||
initialize: function() {
|
||||
this.bindEvents();
|
||||
}, doScan: function() {
|
||||
},
|
||||
|
||||
arrayBufferToIntArray: function(buffer) {
|
||||
var result;
|
||||
|
||||
if (buffer) {
|
||||
var typedArray = new Uint8Array(buffer);
|
||||
result = [];
|
||||
for (var i = 0; i < typedArray.length; i++) {
|
||||
result[i] = typedArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
parseAdvertisingData: function(bytes) {
|
||||
var length, type, data, i = 0, advertisementData = {};
|
||||
|
||||
while (length !== 0) {
|
||||
|
||||
length = bytes[i] & 0xFF;
|
||||
i++;
|
||||
|
||||
type = bytes[i] & 0xFF;
|
||||
i++;
|
||||
|
||||
data = bytes.slice(i, i + length - 1); // Length includes type byte, but not length byte
|
||||
i += length - 2; // Move to end of data
|
||||
i++;
|
||||
|
||||
advertisementData[type] = data;
|
||||
}
|
||||
|
||||
return advertisementData;
|
||||
},
|
||||
handle255: function(buffer) {
|
||||
'use strict';
|
||||
|
||||
var company;
|
||||
var cid;
|
||||
var manID;
|
||||
var bin = buffer;
|
||||
var decoded = {};
|
||||
|
||||
console.log('Block255', bin);
|
||||
var manSpec = bin.map(function(i) {
|
||||
|
||||
return i.toString(16) + ' ';
|
||||
});
|
||||
|
||||
console.log('manSpec: ', manSpec);
|
||||
manID = app.manufactureDecoder.getManID(bin);
|
||||
|
||||
console.log('ManID:', manID);
|
||||
|
||||
cid = '0x' + manID;
|
||||
|
||||
company = bt_company_ids.find(cid);
|
||||
|
||||
switch (manID) {
|
||||
case '004c':
|
||||
decoded = app.manufactureDecoder.decodeIbeacon(bin);
|
||||
decoded.company = company;
|
||||
return decoded;
|
||||
break;
|
||||
case '1235':
|
||||
decoded = app.manufactureDecoder.decodeSiliconLabsSensorPuck(bin);
|
||||
decoded.company = company;
|
||||
return decoded;
|
||||
break;
|
||||
case '0060':
|
||||
decoded = app.manufactureDecoder.decodeSansible(bin);
|
||||
decoded.company = company;
|
||||
return decoded;
|
||||
|
||||
break;
|
||||
default:
|
||||
console.log('Unknown manID: ', manID);
|
||||
}
|
||||
return {company:company};
|
||||
},
|
||||
makeHexBuffer : function(buffer) {
|
||||
'use strict';
|
||||
var hexBuffer = buffer.map(function(i) {
|
||||
return ('00' + i.toString(16)).slice(-2) + ',';
|
||||
});
|
||||
return hexBuffer;
|
||||
},
|
||||
makeChars : function(buffer) {
|
||||
'use strict';
|
||||
var output = buffer.map(function(i) {
|
||||
|
||||
return String.fromCharCode(i);
|
||||
});
|
||||
|
||||
return output;
|
||||
},
|
||||
doScan: function(mode) {
|
||||
'use strict';
|
||||
|
||||
$('#ripple').show();
|
||||
if (mode !== 2) {
|
||||
$('#tbody').empty();
|
||||
}
|
||||
|
||||
var otherData = null;
|
||||
var msgText = '';
|
||||
ble.startScan([], function(device) {
|
||||
var parsed;
|
||||
var hexBuffer;
|
||||
var advertBuffer;
|
||||
var newTR;
|
||||
var newId;
|
||||
var _device = device;
|
||||
otherData = null;
|
||||
msgText = '';
|
||||
console.log(JSON.stringify(device));
|
||||
|
||||
var newId = device.id.replace(/:/g, '');
|
||||
newId = device.id.replace(/:/g, '');
|
||||
console.log(newId);
|
||||
|
||||
this.list[newId] = device.id;
|
||||
|
||||
var newTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
newTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
|
||||
newTR.append($('<td>').text(device.id));
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name));
|
||||
if (device.hasOwnProperty('advertising')) {
|
||||
|
||||
advertBuffer = app.arrayBufferToIntArray(device.advertising);
|
||||
|
||||
hexBuffer = app.makeHexBuffer(advertBuffer);
|
||||
|
||||
parsed = app.parseAdvertisingData(advertBuffer);
|
||||
|
||||
//Console.log(parsed);
|
||||
|
||||
if (parsed.hasOwnProperty('9')) {
|
||||
|
||||
var name = app.makeChars(parsed['9']);
|
||||
|
||||
_device.name = name.join('');
|
||||
console.log('Name: ', name.join(''));
|
||||
|
||||
}
|
||||
else {
|
||||
newTR.append($('<td>').text('*** Unknown'));
|
||||
|
||||
if (parsed.hasOwnProperty('255')) {
|
||||
|
||||
otherData = app.handle255(parsed['255']);
|
||||
console.log(otherData);
|
||||
_device.otherData = otherData;
|
||||
}
|
||||
_device.advertBuffer = advertBuffer;
|
||||
_device.hexBuffer = hexBuffer;
|
||||
_device.parsed = parsed;
|
||||
}
|
||||
|
||||
if (typeof otherData !== 'undefined' && otherData !== null) {
|
||||
if (otherData.hasOwnProperty('msg')) {
|
||||
msgText = ' - ' + otherData.msg;
|
||||
}
|
||||
}
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name + msgText));
|
||||
} else {
|
||||
newTR.append($('<td>').text('*** Unknown' + msgText));
|
||||
}
|
||||
|
||||
newTR.append($('<td>').text(device.rssi));
|
||||
|
||||
$('#tbody').append(newTR);
|
||||
|
||||
$('#output').append(JSON.stringify(device) + '<br/>');
|
||||
if ($('tr#' + newId).length > 0) {
|
||||
$('tr#' + newId).replaceWith(newTR);
|
||||
} else {
|
||||
$('#tbody').append(newTR);
|
||||
}
|
||||
|
||||
|
||||
//$('#output').append(JSON.stringify(device) + '<br/>');
|
||||
|
||||
app.log[newId] = _device;
|
||||
|
||||
console.log(JSON.stringify(_device));
|
||||
|
||||
}.bind(this), function(e) {
|
||||
'use strict';
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
setTimeout(ble.stopScan,
|
||||
5000,
|
||||
function() { console.log('Scan complete'); },
|
||||
function() { console.log('stopScan failed'); });
|
||||
var _t = [5000,60000,200][mode];
|
||||
|
||||
}, // Bind Event Listeners
|
||||
|
||||
setTimeout(ble.stopScan,
|
||||
_t,
|
||||
function() { console.log('Scan complete');
|
||||
|
||||
if (mode === 1) {
|
||||
app.saveLog();
|
||||
$('#ripple').hide();
|
||||
}
|
||||
|
||||
if (mode === 2) {
|
||||
if (!app.stop) {
|
||||
setTimeout(function() {
|
||||
app.doScan(2);
|
||||
}.bind(this), 200);
|
||||
} else {
|
||||
app.saveLog();
|
||||
$('#ripple').hide();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
function() { console.log('stopScan failed');
|
||||
$('#ripple').hide();
|
||||
});
|
||||
|
||||
},
|
||||
writeFile: function(fileEntry, dataObj) {
|
||||
// Create a FileWriter object for our FileEntry (log.txt).
|
||||
fileEntry.createWriter(function(fileWriter) {
|
||||
|
||||
fileWriter.onwriteend = function() {
|
||||
console.log('Successful file write...');
|
||||
// ReadFile(fileEntry);
|
||||
};
|
||||
|
||||
fileWriter.onerror = function(e) {
|
||||
console.error('Failed file write: ' + e.toString());
|
||||
};
|
||||
|
||||
// If data object is not passed in,
|
||||
// create a new Blob instead.
|
||||
if (!dataObj) {
|
||||
dataObj = new Blob(['some file data'], { type: 'text/plain' });
|
||||
}
|
||||
|
||||
fileWriter.write(dataObj);
|
||||
});
|
||||
},
|
||||
saveLog: function() {
|
||||
'use strict';
|
||||
var dt = new Date().toISOString().replace(/:|-/g,'').replace(/(\.\w+)/g,'');
|
||||
var payload = JSON.stringify(app.log);
|
||||
var filename = 'sensortoy-' + dt + '.json';
|
||||
|
||||
// Var dataObj = new Blob(payload, { type: 'text/plain' });
|
||||
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
|
||||
|
||||
console.log('file system open: ' + fs.name);
|
||||
fs.root.getFile(filename, { create: true, exclusive: false }, function(fileEntry) {
|
||||
|
||||
console.log('fileEntry is file?' + fileEntry.isFile.toString());
|
||||
// FileEntry.name == 'someFile.txt'
|
||||
// fileEntry.fullPath == '/someFile.txt'
|
||||
console.log('Path: ', fileEntry.fullPath);
|
||||
app.writeFile(fileEntry, payload);
|
||||
|
||||
app.log = [];
|
||||
|
||||
}, app.onError);
|
||||
|
||||
}, app.onError);
|
||||
},
|
||||
forceStop: function() {
|
||||
'use strict';
|
||||
app.stop = true;
|
||||
$('#scan').show();
|
||||
$('#stop').hide();
|
||||
},
|
||||
|
||||
// Bind Event Listeners
|
||||
//
|
||||
// Bind any events that are required on startup. Common events are:
|
||||
// 'load', 'deviceready', 'offline', and 'online'.
|
||||
@ -75,7 +312,21 @@ var app = {
|
||||
document.addEventListener('deviceready', this.onDeviceReady, false);
|
||||
$('#scan').on('click', function() {
|
||||
'use strict';
|
||||
this.doScan();
|
||||
this.stop = false;
|
||||
this.doScan(2);
|
||||
$('#scan').hide();
|
||||
$('#stop').show();
|
||||
}.bind(this));
|
||||
|
||||
$('#stop').on('click', function() {
|
||||
'use strict';
|
||||
app.forceStop();
|
||||
|
||||
}.bind(this));
|
||||
|
||||
$('#longScan').on('click', function() {
|
||||
'use strict';
|
||||
this.doScan(1);
|
||||
}.bind(this));
|
||||
|
||||
$('#tbody').on('click', 'tr', function() {
|
||||
@ -86,6 +337,7 @@ var app = {
|
||||
|
||||
console.log(tID, id);
|
||||
|
||||
app.forceStop();
|
||||
self.connect(id);
|
||||
});
|
||||
|
||||
@ -107,6 +359,16 @@ var app = {
|
||||
sensorMpu9250AccConvert: function(data) {
|
||||
// Change /2 to match accel range...i.e. 16 g would be /16
|
||||
return data / (32768 / 2);
|
||||
},
|
||||
|
||||
doAnimate: function() {
|
||||
'use strict';
|
||||
// Console.log('Animate..');
|
||||
for (var t = 0; t < app.activeServices.length;t++) {
|
||||
app.activeServices[t].animateGraph();
|
||||
}
|
||||
|
||||
window.requestAnimFrame(app.doAnimate.bind(this));
|
||||
}
|
||||
|
||||
, connect: function(deviceId) {
|
||||
@ -131,7 +393,7 @@ var app = {
|
||||
case '180F':
|
||||
var batteryStat = new BATTERY(deviceId);
|
||||
batteryStat.startService();
|
||||
batteryStat.readBatteryState();
|
||||
// batteryStat.readBatteryState();
|
||||
app.activeServices.push(batteryStat);
|
||||
|
||||
break;
|
||||
@ -164,6 +426,8 @@ var app = {
|
||||
cc2650_tmp.startService();
|
||||
app.activeServices.push(cc2650_tmp);
|
||||
break;
|
||||
|
||||
|
||||
case 'F000AA20-0451-4000-B000-000000000000':
|
||||
var cc2650_hum = new CC2650_HUM(deviceId);
|
||||
cc2650_hum.startService();
|
||||
@ -171,10 +435,12 @@ var app = {
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('Unknown service: ', ident);
|
||||
console.error('Unknown service: ', ident);
|
||||
}
|
||||
}
|
||||
|
||||
// Starting animation..
|
||||
window.requestAnimFrame(app.doAnimate.bind(this));
|
||||
};
|
||||
|
||||
ble.connect(deviceId, onConnect, function(e) {
|
||||
@ -190,4 +456,16 @@ var app = {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
window.requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
function(callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
|
||||
app.initialize();
|
||||
|
69
www/js/mandecoder.js
Normal file
69
www/js/mandecoder.js
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
*
|
||||
* User: Martin Donnelly
|
||||
* Date: 2016-05-24
|
||||
* Time: 14:21
|
||||
*
|
||||
*/
|
||||
var MANUFACTUREDECODER = function() {
|
||||
'use strict';
|
||||
|
||||
this.getManID = function(data) {
|
||||
return ('0000' + ((data[1] << 8) | data[0]).toString(16)).slice(-4).toUpperCase();
|
||||
},
|
||||
this.decodeIbeacon = function(data) {
|
||||
|
||||
// Not decoding anything yet.
|
||||
// https://support.kontakt.io/hc/en-gb/articles/201492492-iBeacon-advertising-packet-structure
|
||||
var bin = data;
|
||||
var obj = { msg: '(iBeacon)'};
|
||||
// obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4);
|
||||
obj.manID = this.getManID(bin);
|
||||
var uuid = [];
|
||||
uuid.push(bin[4].toString(16) + bin[5].toString(16) + bin[6].toString(16) + bin[7].toString(16)) ;
|
||||
|
||||
uuid.push(bin[8].toString(16) + bin[9].toString(16)) ;
|
||||
uuid.push(bin[10].toString(16) + bin[11].toString(16)) ;
|
||||
uuid.push(bin[12].toString(16) + bin[13].toString(16)) ;
|
||||
|
||||
uuid.push(bin[14].toString(16) + bin[15].toString(16) + bin[16].toString(16) + bin[17].toString(16) + bin[18].toString(16) + bin[19].toString(16)) ;
|
||||
|
||||
obj.uuid = uuid.join('-');
|
||||
|
||||
|
||||
return obj;
|
||||
};
|
||||
this.decodeSiliconLabsSensorPuck = function(data) {
|
||||
var bin = data;
|
||||
var obj = {};
|
||||
//obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4);
|
||||
obj.manID = this.getManID(bin);
|
||||
obj.a = (bin[3] << 8) | bin[2];
|
||||
obj.b = (bin[5] << 8) | bin[4];
|
||||
obj.humidity = (bin[7] << 8) | bin[6];
|
||||
obj.temp = (bin[9] << 8) | bin[8];
|
||||
obj.c = (bin[11] << 8) | bin[10];
|
||||
obj.d = (bin[13] << 8) | bin[12];
|
||||
|
||||
obj.msg = 'Humidity: ' + (obj.humidity / 10) + ', temp: ' + (obj.temp / 10);
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
this.decodeSansible = function(data) {
|
||||
var bin = data;
|
||||
var obj = {};
|
||||
// obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4);
|
||||
obj.manID = this.getManID(bin);
|
||||
|
||||
obj.p1 = ((bin[2] << 16) | bin[3] << 8 | bin[4])
|
||||
obj.p2 = ((bin[5] << 16) | bin[6] << 8 | bin[7])
|
||||
|
||||
obj.msg = 'Left: ' + (obj.p1 / 100) + ' hPa, Right: ' + (obj.p2 / 100) + ' hPa';
|
||||
return obj;
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
@ -13,8 +13,7 @@ var BATTERY = function() {
|
||||
this.name = 'Battery';
|
||||
this.capabilityID = '180F';
|
||||
this.serviceDef = {
|
||||
service: '180F',
|
||||
level: '2A19'
|
||||
service: '180F', level: '2A19'
|
||||
};
|
||||
|
||||
this.onBatteryLevelChange = function(data) {
|
||||
@ -25,7 +24,11 @@ var BATTERY = function() {
|
||||
};
|
||||
this.readBatteryState = function() {
|
||||
console.log('readBatteryState');
|
||||
ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.level, this.onReadBatteryLevel.bind(this), this.onError);
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.level,
|
||||
this.onReadBatteryLevel.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
this.onReadBatteryLevel = function(data) {
|
||||
@ -38,15 +41,21 @@ var BATTERY = function() {
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
if (this.deviceID !== null) {
|
||||
console.log('Starting Battery Service');
|
||||
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.level, this.onBatteryLevelChange.bind(this), this.onError);
|
||||
}
|
||||
console.log('Starting Battery Service on ', this.deviceID);
|
||||
console.log(this.serviceDef);
|
||||
|
||||
this.insertFrame();
|
||||
|
||||
ble.startNotification(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.level,
|
||||
this.onBatteryLevelChange.bind(this),
|
||||
this.onError);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
inheritsFrom(BATTERY, CAPABILITY);
|
||||
|
3232
www/js/standards/bluetooth_company_identifiers.js
Normal file
3232
www/js/standards/bluetooth_company_identifiers.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,10 @@ var CAPABILITY = function(p) {
|
||||
|
||||
this.deviceID = null;
|
||||
|
||||
this.data = [];
|
||||
this.ctx = null;
|
||||
this.first = false;
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.setInternalID = function() {
|
||||
@ -64,7 +68,174 @@ CAPABILITY.prototype.onError = function(e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.storeData = function(data, alt) {
|
||||
|
||||
if (!this.first) {
|
||||
this.first = true;
|
||||
return [];
|
||||
}
|
||||
var target = alt || this.data;
|
||||
|
||||
if (target.length === 99) {
|
||||
target = target.slice(1);
|
||||
}
|
||||
|
||||
target.push(data);
|
||||
if (alt) {
|
||||
return target;
|
||||
} else {
|
||||
this.data = target;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.startGraph = function(id) {
|
||||
|
||||
var c;
|
||||
c = id[0].getContext('2d');
|
||||
this.ctx = c;
|
||||
|
||||
this.ctx.fillStyle = '#ffffff';
|
||||
this.ctx.fillRect(0,0,300,150);
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.generateBlankGraph = function(subID) {
|
||||
|
||||
var _subID = subID || '';
|
||||
var xmlns = 'http://www.w3.org/2000/svg';
|
||||
|
||||
var svgID = this.frameID + _subID + '-svg';
|
||||
var text1ID = this.frameID + _subID + '-txt1';
|
||||
var lineID = this.frameID + _subID + '-line';
|
||||
|
||||
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');
|
||||
|
||||
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:#bad649;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:#bad649;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: #bad649;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: #bad649;text-align:right;');
|
||||
text.textContent = '0';
|
||||
|
||||
svg.appendChild(text);
|
||||
|
||||
var polyline = document.createElementNS(xmlns,'polyline');
|
||||
|
||||
polyline.setAttributeNS(null,'id',lineID);
|
||||
polyline.setAttributeNS(null,'fill','none');
|
||||
polyline.setAttributeNS(null,'stroke','#e5f7fd');
|
||||
//#e5f7fd
|
||||
// old #B5C7FF
|
||||
polyline.setAttributeNS(null,'text-anchor', 'end');
|
||||
polyline.setAttributeNS(null,'stroke-width','2');
|
||||
|
||||
svg.appendChild(polyline);
|
||||
|
||||
return svg;
|
||||
|
||||
};
|
||||
|
||||
CAPABILITY.prototype.animateGraph = function() {
|
||||
//This.simpleGraph(this.data);
|
||||
};
|
||||
|
||||
|
||||
CAPABILITY.prototype.simpleGraph = function(data, subID) {
|
||||
|
||||
var _subID;
|
||||
var _data;
|
||||
var text1ID;
|
||||
var lineID;
|
||||
|
||||
_data = data || this.data;
|
||||
|
||||
_subID = subID || '';
|
||||
|
||||
lineID = [this.frameID , _subID , '-line'].join('');
|
||||
text1ID = [this.frameID , _subID , '-txt1'].join('');
|
||||
|
||||
if (_data.length > 0) {
|
||||
var ceiling = _data.reduce(function(p, v) {
|
||||
return (p > v ? p : v);
|
||||
});
|
||||
|
||||
/* Var floor = _data.reduce(function(p, v) {
|
||||
return (p < v ? p : v);
|
||||
});
|
||||
*/
|
||||
|
||||
var calcArray = [];
|
||||
|
||||
var ceilingLimit = Math.floor(ceiling / 10) * 10;
|
||||
if (ceilingLimit < ceiling) {
|
||||
ceilingLimit = Math.floor((ceiling + (ceiling * 0.25)) / 10) * 10;
|
||||
}
|
||||
|
||||
if (ceilingLimit < 30) {
|
||||
ceilingLimit = 30;
|
||||
}
|
||||
|
||||
var scale = 124 / ceilingLimit;
|
||||
// Var xstep = (280 - 46) / 100;
|
||||
var xstep = 2.34;
|
||||
var startX = 46 + (100 - _data.length) * xstep;
|
||||
|
||||
for (var x = 0;x < _data.length;x++) {
|
||||
|
||||
calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (136 - ((_data[x]) * scale)).toFixed(2));
|
||||
|
||||
}
|
||||
|
||||
var elm = document.getElementById(lineID);
|
||||
|
||||
elm.setAttribute('points',calcArray.join(' '));
|
||||
|
||||
elm = document.getElementById(text1ID);
|
||||
|
||||
elm.textContent = ceilingLimit;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
803
www/libs/smoothie.js
Normal file
803
www/libs/smoothie.js
Normal file
@ -0,0 +1,803 @@
|
||||
// MIT License:
|
||||
//
|
||||
// Copyright (c) 2010-2013, Joe Walnes
|
||||
// 2013-2014, Drew Noakes
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
/**
|
||||
* Smoothie Charts - http://smoothiecharts.org/
|
||||
* (c) 2010-2013, Joe Walnes
|
||||
* 2013-2014, Drew Noakes
|
||||
*
|
||||
* v1.0: Main charting library, by Joe Walnes
|
||||
* v1.1: Auto scaling of axis, by Neil Dunn
|
||||
* v1.2: fps (frames per second) option, by Mathias Petterson
|
||||
* v1.3: Fix for divide by zero, by Paul Nikitochkin
|
||||
* v1.4: Set minimum, top-scale padding, remove timeseries, add optional timer to reset bounds, by Kelley Reynolds
|
||||
* v1.5: Set default frames per second to 50... smoother.
|
||||
* .start(), .stop() methods for conserving CPU, by Dmitry Vyal
|
||||
* options.interpolation = 'bezier' or 'line', by Dmitry Vyal
|
||||
* options.maxValue to fix scale, by Dmitry Vyal
|
||||
* v1.6: minValue/maxValue will always get converted to floats, by Przemek Matylla
|
||||
* v1.7: options.grid.fillStyle may be a transparent color, by Dmitry A. Shashkin
|
||||
* Smooth rescaling, by Kostas Michalopoulos
|
||||
* v1.8: Set max length to customize number of live points in the dataset with options.maxDataSetLength, by Krishna Narni
|
||||
* v1.9: Display timestamps along the bottom, by Nick and Stev-io
|
||||
* (https://groups.google.com/forum/?fromgroups#!topic/smoothie-charts/-Ywse8FCpKI%5B1-25%5D)
|
||||
* Refactored by Krishna Narni, to support timestamp formatting function
|
||||
* v1.10: Switch to requestAnimationFrame, removed the now obsoleted options.fps, by Gergely Imreh
|
||||
* v1.11: options.grid.sharpLines option added, by @drewnoakes
|
||||
* Addressed warning seen in Firefox when seriesOption.fillStyle undefined, by @drewnoakes
|
||||
* v1.12: Support for horizontalLines added, by @drewnoakes
|
||||
* Support for yRangeFunction callback added, by @drewnoakes
|
||||
* v1.13: Fixed typo (#32), by @alnikitich
|
||||
* v1.14: Timer cleared when last TimeSeries removed (#23), by @davidgaleano
|
||||
* Fixed diagonal line on chart at start/end of data stream, by @drewnoakes
|
||||
* v1.15: Support for npm package (#18), by @dominictarr
|
||||
* Fixed broken removeTimeSeries function (#24) by @davidgaleano
|
||||
* Minor performance and tidying, by @drewnoakes
|
||||
* v1.16: Bug fix introduced in v1.14 relating to timer creation/clearance (#23), by @drewnoakes
|
||||
* TimeSeries.append now deals with out-of-order timestamps, and can merge duplicates, by @zacwitte (#12)
|
||||
* Documentation and some local variable renaming for clarity, by @drewnoakes
|
||||
* v1.17: Allow control over font size (#10), by @drewnoakes
|
||||
* Timestamp text won't overlap, by @drewnoakes
|
||||
* v1.18: Allow control of max/min label precision, by @drewnoakes
|
||||
* Added 'borderVisible' chart option, by @drewnoakes
|
||||
* Allow drawing series with fill but no stroke (line), by @drewnoakes
|
||||
* v1.19: Avoid unnecessary repaints, and fixed flicker in old browsers having multiple charts in document (#40), by @asbai
|
||||
* v1.20: Add SmoothieChart.getTimeSeriesOptions and SmoothieChart.bringToFront functions, by @drewnoakes
|
||||
* v1.21: Add 'step' interpolation mode, by @drewnoakes
|
||||
* v1.22: Add support for different pixel ratios. Also add optional y limit formatters, by @copacetic
|
||||
* v1.23: Fix bug introduced in v1.22 (#44), by @drewnoakes
|
||||
* v1.24: Fix bug introduced in v1.23, re-adding parseFloat to y-axis formatter defaults, by @siggy_sf
|
||||
* v1.25: Fix bug seen when adding a data point to TimeSeries which is older than the current data, by @Nking92
|
||||
* Draw time labels on top of series, by @comolosabia
|
||||
* Add TimeSeries.clear function, by @drewnoakes
|
||||
* v1.26: Add support for resizing on high device pixel ratio screens, by @copacetic
|
||||
* v1.27: Fix bug introduced in v1.26 for non whole number devicePixelRatio values, by @zmbush
|
||||
* v1.28: Add 'minValueScale' option, by @megawac
|
||||
*/
|
||||
|
||||
;(function(exports) {
|
||||
|
||||
var Util = {
|
||||
extend: function() {
|
||||
arguments[0] = arguments[0] || {};
|
||||
for (var i = 1; i < arguments.length; i++)
|
||||
{
|
||||
for (var key in arguments[i])
|
||||
{
|
||||
if (arguments[i].hasOwnProperty(key))
|
||||
{
|
||||
if (typeof(arguments[i][key]) === 'object') {
|
||||
if (arguments[i][key] instanceof Array) {
|
||||
arguments[0][key] = arguments[i][key];
|
||||
} else {
|
||||
arguments[0][key] = Util.extend(arguments[0][key], arguments[i][key]);
|
||||
}
|
||||
} else {
|
||||
arguments[0][key] = arguments[i][key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return arguments[0];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialises a new <code>TimeSeries</code> with optional data options.
|
||||
*
|
||||
* Options are of the form (defaults shown):
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* resetBounds: true, // enables/disables automatic scaling of the y-axis
|
||||
* resetBoundsInterval: 3000 // the period between scaling calculations, in millis
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Presentation options for TimeSeries are specified as an argument to <code>SmoothieChart.addTimeSeries</code>.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function TimeSeries(options) {
|
||||
this.options = Util.extend({}, TimeSeries.defaultOptions, options);
|
||||
this.clear();
|
||||
}
|
||||
|
||||
TimeSeries.defaultOptions = {
|
||||
resetBoundsInterval: 3000,
|
||||
resetBounds: true
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears all data and state from this TimeSeries object.
|
||||
*/
|
||||
TimeSeries.prototype.clear = function() {
|
||||
this.data = [];
|
||||
this.maxValue = Number.NaN; // The maximum value ever seen in this TimeSeries.
|
||||
this.minValue = Number.NaN; // The minimum value ever seen in this TimeSeries.
|
||||
};
|
||||
|
||||
/**
|
||||
* Recalculate the min/max values for this <code>TimeSeries</code> object.
|
||||
*
|
||||
* This causes the graph to scale itself in the y-axis.
|
||||
*/
|
||||
TimeSeries.prototype.resetBounds = function() {
|
||||
if (this.data.length) {
|
||||
// Walk through all data points, finding the min/max value
|
||||
this.maxValue = this.data[0][1];
|
||||
this.minValue = this.data[0][1];
|
||||
for (var i = 1; i < this.data.length; i++) {
|
||||
var value = this.data[i][1];
|
||||
if (value > this.maxValue) {
|
||||
this.maxValue = value;
|
||||
}
|
||||
if (value < this.minValue) {
|
||||
this.minValue = value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No data exists, so set min/max to NaN
|
||||
this.maxValue = Number.NaN;
|
||||
this.minValue = Number.NaN;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a new data point to the <code>TimeSeries</code>, preserving chronological order.
|
||||
*
|
||||
* @param timestamp the position, in time, of this data point
|
||||
* @param value the value of this data point
|
||||
* @param sumRepeatedTimeStampValues if <code>timestamp</code> has an exact match in the series, this flag controls
|
||||
* whether it is replaced, or the values summed (defaults to false.)
|
||||
*/
|
||||
TimeSeries.prototype.append = function(timestamp, value, sumRepeatedTimeStampValues) {
|
||||
// Rewind until we hit an older timestamp
|
||||
var i = this.data.length - 1;
|
||||
while (i >= 0 && this.data[i][0] > timestamp) {
|
||||
i--;
|
||||
}
|
||||
|
||||
if (i === -1) {
|
||||
// This new item is the oldest data
|
||||
this.data.splice(0, 0, [timestamp, value]);
|
||||
} else if (this.data.length > 0 && this.data[i][0] === timestamp) {
|
||||
// Update existing values in the array
|
||||
if (sumRepeatedTimeStampValues) {
|
||||
// Sum this value into the existing 'bucket'
|
||||
this.data[i][1] += value;
|
||||
value = this.data[i][1];
|
||||
} else {
|
||||
// Replace the previous value
|
||||
this.data[i][1] = value;
|
||||
}
|
||||
} else if (i < this.data.length - 1) {
|
||||
// Splice into the correct position to keep timestamps in order
|
||||
this.data.splice(i + 1, 0, [timestamp, value]);
|
||||
} else {
|
||||
// Add to the end of the array
|
||||
this.data.push([timestamp, value]);
|
||||
}
|
||||
|
||||
this.maxValue = isNaN(this.maxValue) ? value : Math.max(this.maxValue, value);
|
||||
this.minValue = isNaN(this.minValue) ? value : Math.min(this.minValue, value);
|
||||
};
|
||||
|
||||
TimeSeries.prototype.dropOldData = function(oldestValidTime, maxDataSetLength) {
|
||||
// We must always keep one expired data point as we need this to draw the
|
||||
// line that comes into the chart from the left, but any points prior to that can be removed.
|
||||
var removeCount = 0;
|
||||
while (this.data.length - removeCount >= maxDataSetLength && this.data[removeCount + 1][0] < oldestValidTime) {
|
||||
removeCount++;
|
||||
}
|
||||
if (removeCount !== 0) {
|
||||
this.data.splice(0, removeCount);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialises a new <code>SmoothieChart</code>.
|
||||
*
|
||||
* Options are optional, and should be of the form below. Just specify the values you
|
||||
* need and the rest will be given sensible defaults as shown:
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* minValue: undefined, // specify to clamp the lower y-axis to a given value
|
||||
* maxValue: undefined, // specify to clamp the upper y-axis to a given value
|
||||
* maxValueScale: 1, // allows proportional padding to be added above the chart. for 10% padding, specify 1.1.
|
||||
* minValueScale: 1, // allows proportional padding to be added below the chart. for 10% padding, specify 1.1.
|
||||
* yRangeFunction: undefined, // function({min: , max: }) { return {min: , max: }; }
|
||||
* scaleSmoothing: 0.125, // controls the rate at which y-value zoom animation occurs
|
||||
* millisPerPixel: 20, // sets the speed at which the chart pans by
|
||||
* enableDpiScaling: true, // support rendering at different DPI depending on the device
|
||||
* yMinFormatter: function(min, precision) { // callback function that formats the min y value label
|
||||
* return parseFloat(min).toFixed(precision);
|
||||
* },
|
||||
* yMaxFormatter: function(max, precision) { // callback function that formats the max y value label
|
||||
* return parseFloat(max).toFixed(precision);
|
||||
* },
|
||||
* maxDataSetLength: 2,
|
||||
* interpolation: 'bezier' // one of 'bezier', 'linear', or 'step'
|
||||
* timestampFormatter: null, // optional function to format time stamps for bottom of chart
|
||||
* // you may use SmoothieChart.timeFormatter, or your own: function(date) { return ''; }
|
||||
* scrollBackwards: false, // reverse the scroll direction of the chart
|
||||
* horizontalLines: [], // [ { value: 0, color: '#ffffff', lineWidth: 1 } ]
|
||||
* grid:
|
||||
* {
|
||||
* fillStyle: '#000000', // the background colour of the chart
|
||||
* lineWidth: 1, // the pixel width of grid lines
|
||||
* strokeStyle: '#777777', // colour of grid lines
|
||||
* millisPerLine: 1000, // distance between vertical grid lines
|
||||
* sharpLines: false, // controls whether grid lines are 1px sharp, or softened
|
||||
* verticalSections: 2, // number of vertical sections marked out by horizontal grid lines
|
||||
* borderVisible: true // whether the grid lines trace the border of the chart or not
|
||||
* },
|
||||
* labels
|
||||
* {
|
||||
* disabled: false, // enables/disables labels showing the min/max values
|
||||
* fillStyle: '#ffffff', // colour for text of labels,
|
||||
* fontSize: 15,
|
||||
* fontFamily: 'sans-serif',
|
||||
* precision: 2
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function SmoothieChart(options) {
|
||||
this.options = Util.extend({}, SmoothieChart.defaultChartOptions, options);
|
||||
this.seriesSet = [];
|
||||
this.currentValueRange = 1;
|
||||
this.currentVisMinValue = 0;
|
||||
this.lastRenderTimeMillis = 0;
|
||||
}
|
||||
|
||||
SmoothieChart.defaultChartOptions = {
|
||||
millisPerPixel: 20,
|
||||
enableDpiScaling: true,
|
||||
yMinFormatter: function(min, precision) {
|
||||
return parseFloat(min).toFixed(precision);
|
||||
},
|
||||
yMaxFormatter: function(max, precision) {
|
||||
return parseFloat(max).toFixed(precision);
|
||||
},
|
||||
maxValueScale: 1,
|
||||
minValueScale: 1,
|
||||
interpolation: 'bezier',
|
||||
scaleSmoothing: 0.125,
|
||||
maxDataSetLength: 2,
|
||||
scrollBackwards: false,
|
||||
grid: {
|
||||
fillStyle: '#000000',
|
||||
strokeStyle: '#777777',
|
||||
lineWidth: 1,
|
||||
sharpLines: false,
|
||||
millisPerLine: 1000,
|
||||
verticalSections: 2,
|
||||
borderVisible: true
|
||||
},
|
||||
labels: {
|
||||
fillStyle: '#ffffff',
|
||||
disabled: false,
|
||||
fontSize: 10,
|
||||
fontFamily: 'monospace',
|
||||
precision: 2
|
||||
},
|
||||
horizontalLines: []
|
||||
};
|
||||
|
||||
// Based on http://inspirit.github.com/jsfeat/js/compatibility.js
|
||||
SmoothieChart.AnimateCompatibility = (function() {
|
||||
var requestAnimationFrame = function(callback, element) {
|
||||
var requestAnimationFrame =
|
||||
window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function(callback) {
|
||||
return window.setTimeout(function() {
|
||||
callback(new Date().getTime());
|
||||
}, 16);
|
||||
};
|
||||
return requestAnimationFrame.call(window, callback, element);
|
||||
},
|
||||
cancelAnimationFrame = function(id) {
|
||||
var cancelAnimationFrame =
|
||||
window.cancelAnimationFrame ||
|
||||
function(id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
return cancelAnimationFrame.call(window, id);
|
||||
};
|
||||
|
||||
return {
|
||||
requestAnimationFrame: requestAnimationFrame,
|
||||
cancelAnimationFrame: cancelAnimationFrame
|
||||
};
|
||||
})();
|
||||
|
||||
SmoothieChart.defaultSeriesPresentationOptions = {
|
||||
lineWidth: 1,
|
||||
strokeStyle: '#ffffff'
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a <code>TimeSeries</code> to this chart, with optional presentation options.
|
||||
*
|
||||
* Presentation options should be of the form (defaults shown):
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* lineWidth: 1,
|
||||
* strokeStyle: '#ffffff',
|
||||
* fillStyle: undefined
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
SmoothieChart.prototype.addTimeSeries = function(timeSeries, options) {
|
||||
this.seriesSet.push({timeSeries: timeSeries, options: Util.extend({}, SmoothieChart.defaultSeriesPresentationOptions, options)});
|
||||
if (timeSeries.options.resetBounds && timeSeries.options.resetBoundsInterval > 0) {
|
||||
timeSeries.resetBoundsTimerId = setInterval(
|
||||
function() {
|
||||
timeSeries.resetBounds();
|
||||
},
|
||||
timeSeries.options.resetBoundsInterval
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the specified <code>TimeSeries</code> from the chart.
|
||||
*/
|
||||
SmoothieChart.prototype.removeTimeSeries = function(timeSeries) {
|
||||
// Find the correct timeseries to remove, and remove it
|
||||
var numSeries = this.seriesSet.length;
|
||||
for (var i = 0; i < numSeries; i++) {
|
||||
if (this.seriesSet[i].timeSeries === timeSeries) {
|
||||
this.seriesSet.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If a timer was operating for that timeseries, remove it
|
||||
if (timeSeries.resetBoundsTimerId) {
|
||||
// Stop resetting the bounds, if we were
|
||||
clearInterval(timeSeries.resetBoundsTimerId);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets render options for the specified <code>TimeSeries</code>.
|
||||
*
|
||||
* As you may use a single <code>TimeSeries</code> in multiple charts with different formatting in each usage,
|
||||
* these settings are stored in the chart.
|
||||
*/
|
||||
SmoothieChart.prototype.getTimeSeriesOptions = function(timeSeries) {
|
||||
// Find the correct timeseries to remove, and remove it
|
||||
var numSeries = this.seriesSet.length;
|
||||
for (var i = 0; i < numSeries; i++) {
|
||||
if (this.seriesSet[i].timeSeries === timeSeries) {
|
||||
return this.seriesSet[i].options;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Brings the specified <code>TimeSeries</code> to the top of the chart. It will be rendered last.
|
||||
*/
|
||||
SmoothieChart.prototype.bringToFront = function(timeSeries) {
|
||||
// Find the correct timeseries to remove, and remove it
|
||||
var numSeries = this.seriesSet.length;
|
||||
for (var i = 0; i < numSeries; i++) {
|
||||
if (this.seriesSet[i].timeSeries === timeSeries) {
|
||||
var set = this.seriesSet.splice(i, 1);
|
||||
this.seriesSet.push(set[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Instructs the <code>SmoothieChart</code> to start rendering to the provided canvas, with specified delay.
|
||||
*
|
||||
* @param canvas the target canvas element
|
||||
* @param delayMillis an amount of time to wait before a data point is shown. This can prevent the end of the series
|
||||
* from appearing on screen, with new values flashing into view, at the expense of some latency.
|
||||
*/
|
||||
SmoothieChart.prototype.streamTo = function(canvas, delayMillis) {
|
||||
this.canvas = canvas;
|
||||
this.delay = delayMillis;
|
||||
this.start();
|
||||
};
|
||||
|
||||
/**
|
||||
* Make sure the canvas has the optimal resolution for the device's pixel ratio.
|
||||
*/
|
||||
SmoothieChart.prototype.resize = function() {
|
||||
// TODO this function doesn't handle the value of enableDpiScaling changing during execution
|
||||
if (!this.options.enableDpiScaling || !window || window.devicePixelRatio === 1)
|
||||
return;
|
||||
|
||||
var dpr = window.devicePixelRatio;
|
||||
var width = parseInt(this.canvas.getAttribute('width'));
|
||||
var height = parseInt(this.canvas.getAttribute('height'));
|
||||
|
||||
if (!this.originalWidth || (Math.floor(this.originalWidth * dpr) !== width)) {
|
||||
this.originalWidth = width;
|
||||
this.canvas.setAttribute('width', (Math.floor(width * dpr)).toString());
|
||||
this.canvas.style.width = width + 'px';
|
||||
this.canvas.getContext('2d').scale(dpr, dpr);
|
||||
}
|
||||
|
||||
if (!this.originalHeight || (Math.floor(this.originalHeight * dpr) !== height)) {
|
||||
this.originalHeight = height;
|
||||
this.canvas.setAttribute('height', (Math.floor(height * dpr)).toString());
|
||||
this.canvas.style.height = height + 'px';
|
||||
this.canvas.getContext('2d').scale(dpr, dpr);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts the animation of this chart.
|
||||
*/
|
||||
SmoothieChart.prototype.start = function() {
|
||||
if (this.frame) {
|
||||
// We're already running, so just return
|
||||
return;
|
||||
}
|
||||
|
||||
// Renders a frame, and queues the next frame for later rendering
|
||||
var animate = function() {
|
||||
this.frame = SmoothieChart.AnimateCompatibility.requestAnimationFrame(function() {
|
||||
this.render();
|
||||
animate();
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
|
||||
animate();
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the animation of this chart.
|
||||
*/
|
||||
SmoothieChart.prototype.stop = function() {
|
||||
if (this.frame) {
|
||||
SmoothieChart.AnimateCompatibility.cancelAnimationFrame(this.frame);
|
||||
delete this.frame;
|
||||
}
|
||||
};
|
||||
|
||||
SmoothieChart.prototype.updateValueRange = function() {
|
||||
// Calculate the current scale of the chart, from all time series.
|
||||
var chartOptions = this.options,
|
||||
chartMaxValue = Number.NaN,
|
||||
chartMinValue = Number.NaN;
|
||||
|
||||
for (var d = 0; d < this.seriesSet.length; d++) {
|
||||
// TODO(ndunn): We could calculate / track these values as they stream in.
|
||||
var timeSeries = this.seriesSet[d].timeSeries;
|
||||
if (!isNaN(timeSeries.maxValue)) {
|
||||
chartMaxValue = !isNaN(chartMaxValue) ? Math.max(chartMaxValue, timeSeries.maxValue) : timeSeries.maxValue;
|
||||
}
|
||||
|
||||
if (!isNaN(timeSeries.minValue)) {
|
||||
chartMinValue = !isNaN(chartMinValue) ? Math.min(chartMinValue, timeSeries.minValue) : timeSeries.minValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Scale the chartMaxValue to add padding at the top if required
|
||||
if (chartOptions.maxValue != null) {
|
||||
chartMaxValue = chartOptions.maxValue;
|
||||
} else {
|
||||
chartMaxValue *= chartOptions.maxValueScale;
|
||||
}
|
||||
|
||||
// Set the minimum if we've specified one
|
||||
if (chartOptions.minValue != null) {
|
||||
chartMinValue = chartOptions.minValue;
|
||||
} else {
|
||||
chartMinValue -= Math.abs(chartMinValue * chartOptions.minValueScale - chartMinValue);
|
||||
}
|
||||
|
||||
// If a custom range function is set, call it
|
||||
if (this.options.yRangeFunction) {
|
||||
var range = this.options.yRangeFunction({min: chartMinValue, max: chartMaxValue});
|
||||
chartMinValue = range.min;
|
||||
chartMaxValue = range.max;
|
||||
}
|
||||
|
||||
if (!isNaN(chartMaxValue) && !isNaN(chartMinValue)) {
|
||||
var targetValueRange = chartMaxValue - chartMinValue;
|
||||
var valueRangeDiff = (targetValueRange - this.currentValueRange);
|
||||
var minValueDiff = (chartMinValue - this.currentVisMinValue);
|
||||
this.isAnimatingScale = Math.abs(valueRangeDiff) > 0.1 || Math.abs(minValueDiff) > 0.1;
|
||||
this.currentValueRange += chartOptions.scaleSmoothing * valueRangeDiff;
|
||||
this.currentVisMinValue += chartOptions.scaleSmoothing * minValueDiff;
|
||||
}
|
||||
|
||||
this.valueRange = { min: chartMinValue, max: chartMaxValue };
|
||||
};
|
||||
|
||||
SmoothieChart.prototype.render = function(canvas, time) {
|
||||
var nowMillis = new Date().getTime();
|
||||
|
||||
if (!this.isAnimatingScale) {
|
||||
// We're not animating. We can use the last render time and the scroll speed to work out whether
|
||||
// we actually need to paint anything yet. If not, we can return immediately.
|
||||
|
||||
// Render at least every 1/6th of a second. The canvas may be resized, which there is
|
||||
// no reliable way to detect.
|
||||
var maxIdleMillis = Math.min(1000/6, this.options.millisPerPixel);
|
||||
|
||||
if (nowMillis - this.lastRenderTimeMillis < maxIdleMillis) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.resize();
|
||||
|
||||
this.lastRenderTimeMillis = nowMillis;
|
||||
|
||||
canvas = canvas || this.canvas;
|
||||
time = time || nowMillis - (this.delay || 0);
|
||||
|
||||
// Round time down to pixel granularity, so motion appears smoother.
|
||||
time -= time % this.options.millisPerPixel;
|
||||
|
||||
var context = canvas.getContext('2d'),
|
||||
chartOptions = this.options,
|
||||
dimensions = { top: 0, left: 0, width: canvas.clientWidth, height: canvas.clientHeight },
|
||||
// Calculate the threshold time for the oldest data points.
|
||||
oldestValidTime = time - (dimensions.width * chartOptions.millisPerPixel),
|
||||
valueToYPixel = function(value) {
|
||||
var offset = value - this.currentVisMinValue;
|
||||
return this.currentValueRange === 0
|
||||
? dimensions.height
|
||||
: dimensions.height - (Math.round((offset / this.currentValueRange) * dimensions.height));
|
||||
}.bind(this),
|
||||
timeToXPixel = function(t) {
|
||||
if(chartOptions.scrollBackwards) {
|
||||
return Math.round((time - t) / chartOptions.millisPerPixel);
|
||||
}
|
||||
return Math.round(dimensions.width - ((time - t) / chartOptions.millisPerPixel));
|
||||
};
|
||||
|
||||
this.updateValueRange();
|
||||
|
||||
context.font = chartOptions.labels.fontSize + 'px ' + chartOptions.labels.fontFamily;
|
||||
|
||||
// Save the state of the canvas context, any transformations applied in this method
|
||||
// will get removed from the stack at the end of this method when .restore() is called.
|
||||
context.save();
|
||||
|
||||
// Move the origin.
|
||||
context.translate(dimensions.left, dimensions.top);
|
||||
|
||||
// Create a clipped rectangle - anything we draw will be constrained to this rectangle.
|
||||
// This prevents the occasional pixels from curves near the edges overrunning and creating
|
||||
// screen cheese (that phrase should need no explanation).
|
||||
context.beginPath();
|
||||
context.rect(0, 0, dimensions.width, dimensions.height);
|
||||
context.clip();
|
||||
|
||||
// Clear the working area.
|
||||
context.save();
|
||||
context.fillStyle = chartOptions.grid.fillStyle;
|
||||
context.clearRect(0, 0, dimensions.width, dimensions.height);
|
||||
context.fillRect(0, 0, dimensions.width, dimensions.height);
|
||||
context.restore();
|
||||
|
||||
// Grid lines...
|
||||
context.save();
|
||||
context.lineWidth = chartOptions.grid.lineWidth;
|
||||
context.strokeStyle = chartOptions.grid.strokeStyle;
|
||||
// Vertical (time) dividers.
|
||||
if (chartOptions.grid.millisPerLine > 0) {
|
||||
context.beginPath();
|
||||
for (var t = time - (time % chartOptions.grid.millisPerLine);
|
||||
t >= oldestValidTime;
|
||||
t -= chartOptions.grid.millisPerLine) {
|
||||
var gx = timeToXPixel(t);
|
||||
if (chartOptions.grid.sharpLines) {
|
||||
gx -= 0.5;
|
||||
}
|
||||
context.moveTo(gx, 0);
|
||||
context.lineTo(gx, dimensions.height);
|
||||
}
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
// Horizontal (value) dividers.
|
||||
for (var v = 1; v < chartOptions.grid.verticalSections; v++) {
|
||||
var gy = Math.round(v * dimensions.height / chartOptions.grid.verticalSections);
|
||||
if (chartOptions.grid.sharpLines) {
|
||||
gy -= 0.5;
|
||||
}
|
||||
context.beginPath();
|
||||
context.moveTo(0, gy);
|
||||
context.lineTo(dimensions.width, gy);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
// Bounding rectangle.
|
||||
if (chartOptions.grid.borderVisible) {
|
||||
context.beginPath();
|
||||
context.strokeRect(0, 0, dimensions.width, dimensions.height);
|
||||
context.closePath();
|
||||
}
|
||||
context.restore();
|
||||
|
||||
// Draw any horizontal lines...
|
||||
if (chartOptions.horizontalLines && chartOptions.horizontalLines.length) {
|
||||
for (var hl = 0; hl < chartOptions.horizontalLines.length; hl++) {
|
||||
var line = chartOptions.horizontalLines[hl],
|
||||
hly = Math.round(valueToYPixel(line.value)) - 0.5;
|
||||
context.strokeStyle = line.color || '#ffffff';
|
||||
context.lineWidth = line.lineWidth || 1;
|
||||
context.beginPath();
|
||||
context.moveTo(0, hly);
|
||||
context.lineTo(dimensions.width, hly);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
}
|
||||
|
||||
// For each data set...
|
||||
for (var d = 0; d < this.seriesSet.length; d++) {
|
||||
context.save();
|
||||
var timeSeries = this.seriesSet[d].timeSeries,
|
||||
dataSet = timeSeries.data,
|
||||
seriesOptions = this.seriesSet[d].options;
|
||||
|
||||
// Delete old data that's moved off the left of the chart.
|
||||
timeSeries.dropOldData(oldestValidTime, chartOptions.maxDataSetLength);
|
||||
|
||||
// Set style for this dataSet.
|
||||
context.lineWidth = seriesOptions.lineWidth;
|
||||
context.strokeStyle = seriesOptions.strokeStyle;
|
||||
// Draw the line...
|
||||
context.beginPath();
|
||||
// Retain lastX, lastY for calculating the control points of bezier curves.
|
||||
var firstX = 0, lastX = 0, lastY = 0;
|
||||
for (var i = 0; i < dataSet.length && dataSet.length !== 1; i++) {
|
||||
var x = timeToXPixel(dataSet[i][0]),
|
||||
y = valueToYPixel(dataSet[i][1]);
|
||||
|
||||
if (i === 0) {
|
||||
firstX = x;
|
||||
context.moveTo(x, y);
|
||||
} else {
|
||||
switch (chartOptions.interpolation) {
|
||||
case "linear":
|
||||
case "line": {
|
||||
context.lineTo(x,y);
|
||||
break;
|
||||
}
|
||||
case "bezier":
|
||||
default: {
|
||||
// Great explanation of Bezier curves: http://en.wikipedia.org/wiki/Bezier_curve#Quadratic_curves
|
||||
//
|
||||
// Assuming A was the last point in the line plotted and B is the new point,
|
||||
// we draw a curve with control points P and Q as below.
|
||||
//
|
||||
// A---P
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// Q---B
|
||||
//
|
||||
// Importantly, A and P are at the same y coordinate, as are B and Q. This is
|
||||
// so adjacent curves appear to flow as one.
|
||||
//
|
||||
context.bezierCurveTo( // startPoint (A) is implicit from last iteration of loop
|
||||
Math.round((lastX + x) / 2), lastY, // controlPoint1 (P)
|
||||
Math.round((lastX + x)) / 2, y, // controlPoint2 (Q)
|
||||
x, y); // endPoint (B)
|
||||
break;
|
||||
}
|
||||
case "step": {
|
||||
context.lineTo(x,lastY);
|
||||
context.lineTo(x,y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastX = x; lastY = y;
|
||||
}
|
||||
|
||||
if (dataSet.length > 1) {
|
||||
if (seriesOptions.fillStyle) {
|
||||
// Close up the fill region.
|
||||
context.lineTo(dimensions.width + seriesOptions.lineWidth + 1, lastY);
|
||||
context.lineTo(dimensions.width + seriesOptions.lineWidth + 1, dimensions.height + seriesOptions.lineWidth + 1);
|
||||
context.lineTo(firstX, dimensions.height + seriesOptions.lineWidth);
|
||||
context.fillStyle = seriesOptions.fillStyle;
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (seriesOptions.strokeStyle && seriesOptions.strokeStyle !== 'none') {
|
||||
context.stroke();
|
||||
}
|
||||
context.closePath();
|
||||
}
|
||||
context.restore();
|
||||
}
|
||||
|
||||
// Draw the axis values on the chart.
|
||||
if (!chartOptions.labels.disabled && !isNaN(this.valueRange.min) && !isNaN(this.valueRange.max)) {
|
||||
var maxValueString = chartOptions.yMaxFormatter(this.valueRange.max, chartOptions.labels.precision),
|
||||
minValueString = chartOptions.yMinFormatter(this.valueRange.min, chartOptions.labels.precision),
|
||||
labelPos = chartOptions.scrollBackwards ? 0 : dimensions.width - context.measureText(maxValueString).width - 2;
|
||||
context.fillStyle = chartOptions.labels.fillStyle;
|
||||
context.fillText(maxValueString, labelPos, chartOptions.labels.fontSize);
|
||||
context.fillText(minValueString, labelPos, dimensions.height - 2);
|
||||
}
|
||||
|
||||
// Display timestamps along x-axis at the bottom of the chart.
|
||||
if (chartOptions.timestampFormatter && chartOptions.grid.millisPerLine > 0) {
|
||||
var textUntilX = chartOptions.scrollBackwards
|
||||
? context.measureText(minValueString).width
|
||||
: dimensions.width - context.measureText(minValueString).width + 4;
|
||||
for (var t = time - (time % chartOptions.grid.millisPerLine);
|
||||
t >= oldestValidTime;
|
||||
t -= chartOptions.grid.millisPerLine) {
|
||||
var gx = timeToXPixel(t);
|
||||
// Only draw the timestamp if it won't overlap with the previously drawn one.
|
||||
if ((!chartOptions.scrollBackwards && gx < textUntilX) || (chartOptions.scrollBackwards && gx > textUntilX)) {
|
||||
// Formats the timestamp based on user specified formatting function
|
||||
// SmoothieChart.timeFormatter function above is one such formatting option
|
||||
var tx = new Date(t),
|
||||
ts = chartOptions.timestampFormatter(tx),
|
||||
tsWidth = context.measureText(ts).width;
|
||||
|
||||
textUntilX = chartOptions.scrollBackwards
|
||||
? gx + tsWidth + 2
|
||||
: gx - tsWidth - 2;
|
||||
|
||||
context.fillStyle = chartOptions.labels.fillStyle;
|
||||
if(chartOptions.scrollBackwards) {
|
||||
context.fillText(ts, gx, dimensions.height - 2);
|
||||
} else {
|
||||
context.fillText(ts, gx - tsWidth, dimensions.height - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.restore(); // See .save() above.
|
||||
};
|
||||
|
||||
// Sample timestamp formatting function
|
||||
SmoothieChart.timeFormatter = function(date) {
|
||||
function pad2(number) { return (number < 10 ? '0' : '') + number }
|
||||
return pad2(date.getHours()) + ':' + pad2(date.getMinutes()) + ':' + pad2(date.getSeconds());
|
||||
};
|
||||
|
||||
exports.TimeSeries = TimeSeries;
|
||||
exports.SmoothieChart = SmoothieChart;
|
||||
|
||||
})(typeof exports === 'undefined' ? this : exports);
|
Loading…
Reference in New Issue
Block a user