Add wait time between reconnects.
Might improve GL#34.
This commit is contained in:
parent
674fb398b8
commit
ebd9c0d876
|
@ -46,6 +46,7 @@ public class RuffyScripter {
|
||||||
private volatile Command activeCmd = null;
|
private volatile Command activeCmd = null;
|
||||||
|
|
||||||
private volatile boolean connected = false;
|
private volatile boolean connected = false;
|
||||||
|
private volatile long lastDisconnected = 0;
|
||||||
|
|
||||||
public RuffyScripter(final IRuffyService ruffyService) {
|
public RuffyScripter(final IRuffyService ruffyService) {
|
||||||
this.ruffyService = ruffyService;
|
this.ruffyService = ruffyService;
|
||||||
|
@ -72,7 +73,9 @@ public class RuffyScripter {
|
||||||
lastDisconnect = now;
|
lastDisconnect = now;
|
||||||
ruffyService.doRTDisconnect();
|
ruffyService.doRTDisconnect();
|
||||||
connected = false;
|
connected = false;
|
||||||
SystemClock.sleep(1000);
|
lastDisconnect = System.currentTimeMillis();
|
||||||
|
// don't attempt anything fancy in the next 10s, let the pump settle
|
||||||
|
SystemClock.sleep(10 * 1000);
|
||||||
}
|
}
|
||||||
} catch (DeadObjectException doe) {
|
} catch (DeadObjectException doe) {
|
||||||
// TODO do we need to catch this exception somewhere else too? right now it's
|
// TODO do we need to catch this exception somewhere else too? right now it's
|
||||||
|
@ -291,6 +294,15 @@ public class RuffyScripter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Occasionally the rtConnect is called a few seconds after the rtDisconnected
|
||||||
|
// callback was called, in response to your disconnect request via doRtDisconnect.
|
||||||
|
// When connecting again shortly after disconnecting, the pump sometimes fails
|
||||||
|
// to come up. So for v1, just wait. This happens rarely, so no overly fancy logic needed.
|
||||||
|
// TODO v2 see if we can do this cleaner, use isDisconnected as well maybe. GL#34.
|
||||||
|
if (System.currentTimeMillis() < lastDisconnected + 10 * 1000) {
|
||||||
|
SystemClock.sleep(10 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
boolean connectInitSuccessful = ruffyService.doRTConnect() == 0;
|
boolean connectInitSuccessful = ruffyService.doRTConnect() == 0;
|
||||||
log.debug("Connect init successful: " + connectInitSuccessful);
|
log.debug("Connect init successful: " + connectInitSuccessful);
|
||||||
log.debug("Waiting for first menu update to be sent");
|
log.debug("Waiting for first menu update to be sent");
|
||||||
|
|
Loading…
Reference in a new issue