Skip to content

Commit

Permalink
Merge branch 'fix/CM13-disablebluetooth-crash'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Kearl committed Dec 4, 2016
2 parents 882c6be + 1bf683f commit df64c0a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
15 changes: 13 additions & 2 deletions run_cordova.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/bin/sh
set -e # stop on errors
cd www/js

# add a variable to our index containing the git hash
cp index.js noGitIndex.js
echo window.gitRevision = \"$(git rev-parse --short HEAD)\"\; | cat - index.js > temp && mv temp index.js

coffee --compile mm.coffee
browserify index.js -o bundle.js
cd ../..
cordova run --device
rm www/js/bundle.js
rm www/js/mm.js

cd www/js

rm bundle.js
rm mm.js

# forget our temporary index
mv noGitIndex.js index.js
42 changes: 26 additions & 16 deletions www/js/badgeDialogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function Scan() {
this.ts = -1;
this.voltage = -1;
this.numDevices = -1;
this.scans = [];
this.scans = {};

/**
*Sets the header of the chunk
Expand Down Expand Up @@ -142,7 +142,7 @@ function Scan() {
}.bind(this);

/*
* @return the samples of this chunk
* @return the scans in this chunk
*/
this.getScans = function(){
return this.scans;
Expand All @@ -152,11 +152,19 @@ function Scan() {
* @param newData the byte array that represents more samples
*/
this.addScans = function(newData) {
Array.prototype.push.apply(this.scans, newData);
//Array.prototype.push.apply(this.scans, newData);
//this.samples = this.samples.concat(newData);
if (this.scans.length > this.numDevices) {

for (var id in newData) {
if (newData.hasOwnProperty(id)) {
this.scans[id] = newData[id]
}
}


if (Object.keys(this.scans).length> this.numDevices) {
// error
console.error("Too many samples in chunk!",this.scans.length);
console.error("Too many samples in chunk!", Object.keys(this.scans).length);
}

}.bind(this);
Expand All @@ -168,20 +176,20 @@ function Scan() {
this.ts = -1;
this.voltage = -1;
this.numDevices = -1;
this.scans = [];
this.scans = {};
}.bind(this);

this.completed = function() {
return this.scans.length >= this.numDevices;
return Object.keys(this.scans).length >= this.numDevices;
}

this.toDict = function (member) {
return {
voltage:this.voltage,
timestamp:this.ts,
num_devices:this.numDevices,
scans:this.scans,
member: member.key
rssi_distances:this.scans,
member: member.key,
badge_address:member.badgeId
};
}.bind(this);
}
Expand Down Expand Up @@ -507,13 +515,15 @@ function BadgeDialogue(badge) {
var scan_arr = struct.Unpack("<" + toUnpack, data);


var unpacked = []
var unpacked = {}
for (var i = 0; i < scan_arr.length; i+= 3 ) {
unpacked.push(
{'id' : scan_arr[i],
'rssi': scan_arr[i+1],
'scans': scan_arr[i+2]
})
var id = scan_arr[i]
var rssi = scan_arr[i+1]
var count = scan_arr[i+2]
unpacked[id] = {
'rssi': rssi,
'scans': count
}
}

this.workingScanChunk.addScans(unpacked);
Expand Down
15 changes: 13 additions & 2 deletions www/js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

require('q');
var qbluetoothle = require('./qbluetoothle');
var Badge = require('./badge');
Expand Down Expand Up @@ -161,7 +162,7 @@ function Meeting(group, members, type, moderator, description, location) {

this.logScanChunk = function(chunk, member) {
var chunk_data = chunk.toDict(member);
this.writeLog("scan received", chunk_data);
this.writeLog("proximity received", chunk_data);
console.log("scan received", chunk_data);

}.bind(this);
Expand Down Expand Up @@ -254,6 +255,7 @@ function Meeting(group, members, type, moderator, description, location) {
'uuid': this.uuid,
'start_time':new Date()/1000,
'log_version':"2.0",
'hub_version':window.gitRevision,
'moderator':this.moderator,
'location':this.location,
'description': this.description.replace(/\s\s+/g, ' '),
Expand Down Expand Up @@ -390,7 +392,16 @@ mainPage = new Page("main",
if (app.bluetoothInitialized) {
// after bluetooth is disabled, it's automatically re-enabled.
//this.beginRefreshData();
app.disableBluetooth();
if (device.version[0] == '4') {
app.disableBluetooth();
}
else {
clearInterval(app.badgeScanIntervalID);
app.badgeScanIntervalID = setInterval(function() {
app.scanForBadges();
}, BADGE_SCAN_INTERVAL);
app.scanForBadges();
}
}
},
function onHide() {
Expand Down

0 comments on commit df64c0a

Please sign in to comment.