Skip to content

Commit

Permalink
Merge pull request #8 from lillialexis/front-end-lilli
Browse files Browse the repository at this point in the history
Changes for JLR demo:
  • Loading branch information
lillialexis committed Oct 26, 2015
2 parents fbfbf03 + d2324b2 commit 50a672b
Show file tree
Hide file tree
Showing 63 changed files with 819 additions and 729 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ proguard/
.idea/*

*.iml

*.DS_Store
145 changes: 0 additions & 145 deletions app/app.iml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class BeaconRanger {
private boolean started = false;
private Subscriber<? super RangeObject> sub;
private EvictingQueue<Double> ranges = null;
private EvictingQueue<Double> weightedRanges = null;
private Long lastdist = -1L;
private SharedPreferences prefs;

Expand All @@ -52,6 +53,7 @@ public BeaconRanger(Context ctx) {

numberMesurments = Integer.parseInt(prefs.getString("pref_ranging_sample_buffer", "10"));
ranges = EvictingQueue.create(numberMesurments);
weightedRanges = EvictingQueue.create(numberMesurments);
calc = new CurveFittedDistanceCalculator(0.42093, 6.9476, 0.54992);
}

Expand Down Expand Up @@ -91,17 +93,26 @@ public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
}

double mean = 0;
double weightedMean = 0;

//double newReading2 = getDistance(rssi, scanRecord[29]);
double newReading = calc.calculateDistance(scanRecord[29],rssi);
//System.out.println("RVI New reading dist : "+newReading+" : "+newReading2);
synchronized (ranges) {
final double unlockDistance = Double.parseDouble(prefs.getString("pref_auto_unlock_dist", "1"));

if (newReading > unlockDistance) weightedRanges.add(1.0);
else weightedRanges.add(0.0);

ranges.add(newReading);

if(ranges.size() == numberMesurments) { //Full
for (double d : ranges) {
mean += d;
//System.out.println("RVI Loop mean : "+mean);
}
mean = mean / numberMesurments;

mean = getMean(ranges);
weightedMean = getMean(weightedRanges);

System.out.println("Distance: " + newReading + " unlock distance: " + unlockDistance + " weighted mean: " + weightedMean);

} else {
//System.out.println("RVI Not yet full : "+ranges.size());
}
Expand All @@ -121,12 +132,22 @@ public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
ro.rssi = rssi;
ro.txPower = scanRecord[29];
ro.distance = mean;
ro.weightedDistance = weightedMean;
sub.onNext(ro);
}
}
}
};

double getMean(EvictingQueue<Double> ranges) {
double mean = 0;
for (double d : ranges) {
mean += d;
//System.out.println("RVI Loop mean : "+mean);
}
return mean / ranges.size();
}

// double getDistance(int rssi, int txPower) {
// /*
// * RSSI = TxPower - 10 * n * lg(d)
Expand Down Expand Up @@ -234,6 +255,7 @@ class RangeObject {
String id;
String addr;
double distance;
double weightedDistance;
int rssi;
int txPower;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Network is disconnected: " + networkInfo);
} else if(networkInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED) {
Log.i(TAG, "Network is connected: " + networkInfo+" type = "+networkInfo.getTypeName()+" : "+networkInfo.getSubtypeName());
Intent i = new Intent(context, RviService.class);
i.putExtra("networkinfo", networkInfo);
context.startService(i);
// Intent i = new Intent(context, RviService.class);
// i.putExtra("networkinfo", networkInfo);
// context.startService(i);
}
}
}
Expand Down
Loading

0 comments on commit 50a672b

Please sign in to comment.