performance enhancements

memory enhancements
prevent starting sensors more than once
fix for wifi lag issues
map scaling for huge buildings
This commit is contained in:
2016-10-01 10:21:15 +02:00
parent 833327bafd
commit 44f9b6ac80
16 changed files with 197 additions and 26 deletions

View File

@@ -18,7 +18,8 @@ public class WiFi {
private static WifiManager manager;
private static BroadcastReceiver receiver;
private static Thread tHeartbeat = null;
private static long lastScanStartTS = 0;
/** called when a scan is completed successfully */
public static native void onScanComplete(final byte[] result);
@@ -48,7 +49,28 @@ public class WiFi {
act.registerReceiver(WiFi.receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
// start the first scan
triggerOneScan();
triggerOneScan();
// if the scan result takes longer than X milliseconds,
// trigger another-scan to ensure nothing is stuck
final Runnable r = new Runnable() {
public void run() {
while(true) {
final long ts = System.currentTimeMillis();
final long diff = ts - lastScanStartTS;
if (diff > 1000) { triggerOneScan(); }
try {Thread.sleep(200);} catch (final Exception e) {;}
}
}
};
// start the heartbeat once
if (tHeartbeat == null) {
tHeartbeat = new Thread(r);
tHeartbeat.start();
}
return 1337;
@@ -91,6 +113,7 @@ public class WiFi {
try {
if(!manager.startScan()) {throw new RuntimeException("Cant start WiFi!");}
lastScanStartTS = System.currentTimeMillis();
}catch (final Exception e) {
throw new RuntimeException(e);
}