Skip to content

Commit

Permalink
fix: fix invalid values for Vpp and Vp- in Oscilloscope (#2568)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcnause authored Nov 10, 2024
1 parent 4b59ea5 commit 3cf6349
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
35 changes: 23 additions & 12 deletions app/src/main/java/io/pslab/activity/OscilloscopeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1126,23 +1126,34 @@ protected void onPostExecute(Void aVoid) {
if (!isFourierTransformSelected) {
for (int i = 0; i < Math.min(entries.size(), paramsChannels.length); i++) {
CHANNEL channel = CHANNEL.valueOf(paramsChannels[i]);
double minY = Double.MAX_VALUE;
double maxY = -1 * Double.MIN_VALUE;
double minY;
double maxY;
double yRange;
double[] voltage = new double[512];
ArrayList<Entry> entryArrayList = dataEntries.get(i);
for (int j = 0; j < entryArrayList.size(); j++) {
Entry entry = entryArrayList.get(j);
if (j < voltage.length - 1) {
voltage[j] = entry.getY();
}
if (entry.getY() > maxY) {
maxY = entry.getY();
}
if (entry.getY() < minY) {
minY = entry.getY();

if (entryArrayList.isEmpty()) {
minY = 0;
maxY = 0;
} else {
minY = Double.MAX_VALUE;
maxY = -1 * Double.MAX_VALUE;

for (int j = 0; j < entryArrayList.size(); j++) {
Entry entry = entryArrayList.get(j);
float y = entry.getY();
if (j < voltage.length - 1) {
voltage[j] = y;
}
if (y > maxY) {
maxY = y;
}
if (y < minY) {
minY = y;
}
}
}

final double frequency;
if (Objects.equals(dataParamsChannels[i], CHANNEL.MIC.toString())) {
frequency = analyticsClass.findFrequency(voltage, ((double) 1 / SAMPLING_RATE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setMeasurements(@NonNull String channelString, @NonNull Integer chan
double period = OscilloscopeMeasurements.channel.get(channel).get(ChannelMeasurements.PERIOD);
double positivePeak = OscilloscopeMeasurements.channel.get(channel).get(ChannelMeasurements.POSITIVE_PEAK);
double negativePeak = OscilloscopeMeasurements.channel.get(channel).get(ChannelMeasurements.NEGATIVE_PEAK);
DecimalFormat df = new DecimalFormat("#.##");
DecimalFormat df = new DecimalFormat("0.00");
df.setRoundingMode(RoundingMode.CEILING);
if (frequency >= 1000) {
frequency /= 1000;
Expand Down

0 comments on commit 3cf6349

Please sign in to comment.