Use timeout to break out of possible infinite loop waiting for sensor to start.

This commit is contained in:
Bryce Curtis 2010-09-15 14:17:40 -05:00
parent 03f6267c82
commit c050e00b8f
2 changed files with 12 additions and 2 deletions

View File

@ -105,13 +105,18 @@ public class AccelListener implements SensorEventListener, Plugin{
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
}
// Wait until running
while (this.status == STARTING) {
long timeout = 2000;
while ((this.status == STARTING) && (timeout > 0)) {
timeout = timeout - 100;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (timeout == 0) {
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
}
}
JSONObject r = new JSONObject();
r.put("x", this.x);

View File

@ -98,13 +98,18 @@ public class CompassListener implements SensorEventListener, Plugin{
return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
}
// Wait until running
while (this.status == STARTING) {
long timeout = 2000;
while ((this.status == STARTING) && (timeout > 0)) {
timeout = timeout - 100;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (timeout == 0) {
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
}
}
float f = this.getHeading();
return new PluginResult(status, f);