From ebd9c0d876bcaa08b9cb9cf872d7223c1a94bf47 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 24 Jul 2017 13:16:35 +0200 Subject: [PATCH] Add wait time between reconnects. Might improve GL#34. --- .../de/jotomo/ruffyscripter/RuffyScripter.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 32cbf60ea3..e382398f9a 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -46,6 +46,7 @@ public class RuffyScripter { private volatile Command activeCmd = null; private volatile boolean connected = false; + private volatile long lastDisconnected = 0; public RuffyScripter(final IRuffyService ruffyService) { this.ruffyService = ruffyService; @@ -72,7 +73,9 @@ public class RuffyScripter { lastDisconnect = now; ruffyService.doRTDisconnect(); 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) { // TODO do we need to catch this exception somewhere else too? right now it's @@ -291,6 +294,15 @@ public class RuffyScripter { 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; log.debug("Connect init successful: " + connectInitSuccessful); log.debug("Waiting for first menu update to be sent");