Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ publishing {
bar(MavenPublication) {
groupId = 'com.shimmerresearch' // Replace with your package's group/organization name
artifactId = 'shimmerandroidinstrumentdriver' // Replace with the name of your package
version = '3.2.5_beta' // Replace with your package version
version = '3.2.6_beta' // Replace with your package version
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1922,4 +1922,60 @@ public void stateHandler(Object obj){
//sendMsgToHandlerListTarget(ShimmerBluetooth.MSG_IDENTIFIER_STATE_CHANGE, obj);
}

private static final byte PING_BYTE = (byte) 0xB5;
private java.util.concurrent.ScheduledExecutorService pingExec;
private java.util.concurrent.ScheduledFuture<?> pingTask;

public void startPingTask() {
if (pingExec != null && !pingExec.isShutdown()) return;

pingExec = java.util.concurrent.Executors.newSingleThreadScheduledExecutor(r -> {
Thread t = new Thread(r, "ShimmerPing");
t.setDaemon(true);
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
return t;
});

// schedule every 2 seconds
pingTask = pingExec.scheduleWithFixedDelay(() -> {
try {
if (mIsStreaming)
{
write(new byte[]{PING_BYTE});
} else {
stopPingTask();
}
} catch (Throwable e) {
// If device disconnects, stop pings
stopPingTask();
}
}, 2, 2, java.util.concurrent.TimeUnit.SECONDS);
}

public void stopPingTask() {
if (pingTask != null) pingTask.cancel(true);
if (pingExec != null) {
pingExec.shutdownNow();
pingExec = null;
}
}


@Override
public void startStreaming() throws ShimmerException {
super.startStreaming();
if (getHardwareVersion()== ShimmerVerDetails.HW_ID.SHIMMER_3R
&& isThisVerCompatibleWith(ShimmerVerDetails.FW_ID.LOGANDSTREAM, 1, 0, 46)) {
startPingTask();
}
}

@Override
public void stopStreaming(){
super.stopStreaming();
if (getHardwareVersion()== ShimmerVerDetails.HW_ID.SHIMMER_3R
&& isThisVerCompatibleWith(ShimmerVerDetails.FW_ID.LOGANDSTREAM, 1, 0, 46)) {
stopPingTask();
}
}
}