Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2032 Fixes crash which occurred in the oscilloscope #2102

Merged
merged 1 commit into from
Apr 23, 2020
Merged
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
15 changes: 8 additions & 7 deletions app/src/main/java/io/pslab/activity/OscilloscopeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.math3.complex.Complex;

import java.util.ArrayList;
Expand Down Expand Up @@ -978,7 +979,7 @@ protected Void doInBackground(String... channels) {
String[] xDataString = null;
maxAmp = 0;
scienceLab.captureTraces(4, samples, timeGap, channel, isTriggerSelected, null);
Thread.sleep((long)(samples*timeGap*1e-3));
Thread.sleep((long) (samples * timeGap * 1e-3));
for (int i = 0; i < noOfChannels; i++) {
entries.add(new ArrayList<>());
channel = channels[i];
Expand Down Expand Up @@ -1052,12 +1053,12 @@ protected Void doInBackground(String... channels) {
double max = xData[xData.length - 1];
for (int j = 0; j < 500; j++) {
double x = j * max / 500;
double t = 2*Math.PI*freq*(x - phase);
double t = 2 * Math.PI * freq * (x - phase);
double y;
if (t%(2*Math.PI) < 2*Math.PI*dc) {
if (t % (2 * Math.PI) < 2 * Math.PI * dc) {
y = offset + amp;
} else {
y = offset - 2*amp;
y = offset - 2 * amp;
}
curveFitEntries.get(curveFitEntries.size() - 1).add(new Entry((float) x, (float) y));
}
Expand Down Expand Up @@ -1097,7 +1098,7 @@ protected Void doInBackground(String... channels) {
float audioValue = (float) map(buffer[i], -32768, 32767, -3, 3);
if (!isFourierTransformSelected) {
if (noOfChannels == 1) {
xDataString[i] = String.valueOf(2.0*i);
xDataString[i] = String.valueOf(2.0 * i);
}
entries.get(entries.size() - 1).add(new Entry(i, audioValue));
} else {
Expand All @@ -1117,9 +1118,9 @@ protected Void doInBackground(String... channels) {

}
if (isRecording) {
loggingXdata = String.join(" ", xDataString);
loggingXdata = StringUtils.join(" ", xDataString);
for (int i = 0; i < yDataString.size(); i++) {
loggingYdata[i] = String.join(" ", yDataString.get(i));
loggingYdata[i] = StringUtils.join(" ", yDataString.get(i));
}
runOnUiThread(new Runnable() {
@Override
Expand Down