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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user