From c0d72ec2179f5d7d2b72667c570cccaef82534ed Mon Sep 17 00:00:00 2001 From: maxieds Date: Wed, 17 Jan 2018 02:55:25 -0500 Subject: [PATCH] Fixed tryAcquire bug for the serial port lock when updating the status at the top of the window (was causing some freezes). --- app/build.gradle | 4 ++-- .../com/maxieds/chameleonminilivedebugger/ChameleonIO.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f6d1052..d599506 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.maxieds.chameleonminilivedebugger" minSdkVersion 21 targetSdkVersion 25 - versionCode 21 - versionName "0.2.5" + versionCode 23 + versionName "0.2.6" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java index 46e3306..f8fcb57 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java @@ -41,6 +41,7 @@ public class ChameleonIO { * Default timeout to use when communicating with the device. */ public static final int TIMEOUT = 2000; + public static final int LOCK_TIMEOUT = 350; /** * Static constants for storing state of the device. @@ -187,7 +188,10 @@ public void run() { */ private void updateAllStatus() { try { - LiveLoggerActivity.serialPortLock.tryAcquire(ChameleonIO.TIMEOUT, TimeUnit.MILLISECONDS); + if(!LiveLoggerActivity.serialPortLock.tryAcquire(ChameleonIO.LOCK_TIMEOUT, TimeUnit.MILLISECONDS)) { + statsUpdateHandler.postDelayed(statsUpdateRunnable, STATS_UPDATE_INTERVAL / 4); + return; + } } catch(InterruptedException ie) { return; }