Skip to content

Commit df64c0a

Browse files
author
Jackson Kearl
committed
Merge branch 'fix/CM13-disablebluetooth-crash'
2 parents 882c6be + 1bf683f commit df64c0a

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

run_cordova.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
#!/bin/sh
22
set -e # stop on errors
33
cd www/js
4+
5+
# add a variable to our index containing the git hash
6+
cp index.js noGitIndex.js
7+
echo window.gitRevision = \"$(git rev-parse --short HEAD)\"\; | cat - index.js > temp && mv temp index.js
8+
49
coffee --compile mm.coffee
510
browserify index.js -o bundle.js
611
cd ../..
712
cordova run --device
8-
rm www/js/bundle.js
9-
rm www/js/mm.js
13+
14+
cd www/js
15+
16+
rm bundle.js
17+
rm mm.js
18+
19+
# forget our temporary index
20+
mv noGitIndex.js index.js

www/js/badgeDialogue.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function Scan() {
111111
this.ts = -1;
112112
this.voltage = -1;
113113
this.numDevices = -1;
114-
this.scans = [];
114+
this.scans = {};
115115

116116
/**
117117
*Sets the header of the chunk
@@ -142,7 +142,7 @@ function Scan() {
142142
}.bind(this);
143143

144144
/*
145-
* @return the samples of this chunk
145+
* @return the scans in this chunk
146146
*/
147147
this.getScans = function(){
148148
return this.scans;
@@ -152,11 +152,19 @@ function Scan() {
152152
* @param newData the byte array that represents more samples
153153
*/
154154
this.addScans = function(newData) {
155-
Array.prototype.push.apply(this.scans, newData);
155+
//Array.prototype.push.apply(this.scans, newData);
156156
//this.samples = this.samples.concat(newData);
157-
if (this.scans.length > this.numDevices) {
157+
158+
for (var id in newData) {
159+
if (newData.hasOwnProperty(id)) {
160+
this.scans[id] = newData[id]
161+
}
162+
}
163+
164+
165+
if (Object.keys(this.scans).length> this.numDevices) {
158166
// error
159-
console.error("Too many samples in chunk!",this.scans.length);
167+
console.error("Too many samples in chunk!", Object.keys(this.scans).length);
160168
}
161169

162170
}.bind(this);
@@ -168,20 +176,20 @@ function Scan() {
168176
this.ts = -1;
169177
this.voltage = -1;
170178
this.numDevices = -1;
171-
this.scans = [];
179+
this.scans = {};
172180
}.bind(this);
173181

174182
this.completed = function() {
175-
return this.scans.length >= this.numDevices;
183+
return Object.keys(this.scans).length >= this.numDevices;
176184
}
177185

178186
this.toDict = function (member) {
179187
return {
180188
voltage:this.voltage,
181189
timestamp:this.ts,
182-
num_devices:this.numDevices,
183-
scans:this.scans,
184-
member: member.key
190+
rssi_distances:this.scans,
191+
member: member.key,
192+
badge_address:member.badgeId
185193
};
186194
}.bind(this);
187195
}
@@ -507,13 +515,15 @@ function BadgeDialogue(badge) {
507515
var scan_arr = struct.Unpack("<" + toUnpack, data);
508516

509517

510-
var unpacked = []
518+
var unpacked = {}
511519
for (var i = 0; i < scan_arr.length; i+= 3 ) {
512-
unpacked.push(
513-
{'id' : scan_arr[i],
514-
'rssi': scan_arr[i+1],
515-
'scans': scan_arr[i+2]
516-
})
520+
var id = scan_arr[i]
521+
var rssi = scan_arr[i+1]
522+
var count = scan_arr[i+2]
523+
unpacked[id] = {
524+
'rssi': rssi,
525+
'scans': count
526+
}
517527
}
518528

519529
this.workingScanChunk.addScans(unpacked);

www/js/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
require('q');
23
var qbluetoothle = require('./qbluetoothle');
34
var Badge = require('./badge');
@@ -161,7 +162,7 @@ function Meeting(group, members, type, moderator, description, location) {
161162

162163
this.logScanChunk = function(chunk, member) {
163164
var chunk_data = chunk.toDict(member);
164-
this.writeLog("scan received", chunk_data);
165+
this.writeLog("proximity received", chunk_data);
165166
console.log("scan received", chunk_data);
166167

167168
}.bind(this);
@@ -254,6 +255,7 @@ function Meeting(group, members, type, moderator, description, location) {
254255
'uuid': this.uuid,
255256
'start_time':new Date()/1000,
256257
'log_version':"2.0",
258+
'hub_version':window.gitRevision,
257259
'moderator':this.moderator,
258260
'location':this.location,
259261
'description': this.description.replace(/\s\s+/g, ' '),
@@ -390,7 +392,16 @@ mainPage = new Page("main",
390392
if (app.bluetoothInitialized) {
391393
// after bluetooth is disabled, it's automatically re-enabled.
392394
//this.beginRefreshData();
393-
app.disableBluetooth();
395+
if (device.version[0] == '4') {
396+
app.disableBluetooth();
397+
}
398+
else {
399+
clearInterval(app.badgeScanIntervalID);
400+
app.badgeScanIntervalID = setInterval(function() {
401+
app.scanForBadges();
402+
}, BADGE_SCAN_INTERVAL);
403+
app.scanForBadges();
404+
}
394405
}
395406
},
396407
function onHide() {

0 commit comments

Comments
 (0)