Skip to content

Commit 362af34

Browse files
committed
Fix NullPointerError when loading EMG Settings
1 parent 41646e2 commit 362af34

4 files changed

Lines changed: 37 additions & 14 deletions

File tree

OpenBCI_GUI/EmgSettings.pde

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ class EmgSettings {
2525
outputError("Emg Settings: Loaded EMG Settings file has different number of channels than the current board.");
2626
return false;
2727
}
28-
values = tempValues;
28+
//Explicitely copy values over to avoid reference issues
29+
//(e.g. values = tempValues "nukes" the old values object)
30+
values.smoothing = tempValues.smoothing;
31+
values.uvLimit = tempValues.uvLimit;
32+
values.creepIncreasing = tempValues.creepIncreasing;
33+
values.creepDecreasing = tempValues.creepDecreasing;
34+
values.minimumDeltaUV = tempValues.minimumDeltaUV;
35+
values.lowerThresholdMinimum = tempValues.lowerThresholdMinimum;
2936
return true;
3037
} catch (IOException e) {
3138
e.printStackTrace();

OpenBCI_GUI/EmgSettingsValues.pde

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class EmgSettingsValues {
1515
public EmgMinimumDeltaUV[] minimumDeltaUV;
1616
public EmgLowerThresholdMinimum[] lowerThresholdMinimum;
1717
//Normalized output which is passed to Networking
18-
float[] outputNormalized;
18+
private transient float[] outputNormalized;
1919
//These values change during calculations
20-
float[] upperThreshold;
21-
float[] lowerThreshold;
22-
float[] averageuV;
20+
private transient float[] upperThreshold;
21+
private transient float[] lowerThreshold;
22+
private transient float[] averageuV;
2323

24-
private int channelCount;
24+
private transient int channelCount;
2525

2626
EmgSettingsValues() {
2727

@@ -101,4 +101,20 @@ class EmgSettingsValues {
101101
}
102102
}
103103
}
104+
105+
public float getOutputNormalized(int channel) {
106+
return outputNormalized[channel];
107+
}
108+
109+
public float getAverageuV(int channel) {
110+
return averageuV[channel];
111+
}
112+
113+
public float getUpperThreshold(int channel) {
114+
return upperThreshold[channel];
115+
}
116+
117+
public float getLowerThreshold(int channel) {
118+
return lowerThreshold[channel];
119+
}
104120
}

OpenBCI_GUI/W_EMG.pde

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,17 @@ class W_emg extends Widget {
122122
//realtime
123123
fill(channelColors[colorIndex], 200);
124124
noStroke();
125-
circle(2*colOffset/8, rowOffset / 2, scaleFactor * emgSettingsValues.averageuV[channel]);
125+
circle(2*colOffset/8, rowOffset / 2, scaleFactor * emgSettingsValues.getAverageuV(channel));
126126

127127
//circle for outer threshold
128128
noFill();
129129
strokeWeight(1);
130130
stroke(OPENBCI_DARKBLUE, 150);
131-
circle(2*colOffset/8, rowOffset / 2, scaleFactor * emgSettingsValues.upperThreshold[channel]);
131+
circle(2*colOffset/8, rowOffset / 2, scaleFactor * emgSettingsValues.getUpperThreshold(channel));
132132

133133
//circle for inner threshold
134134
stroke(OPENBCI_DARKBLUE, 150);
135-
circle(2*colOffset/8, rowOffset / 2, scaleFactor * emgSettingsValues.lowerThreshold[channel]);
135+
circle(2*colOffset/8, rowOffset / 2, scaleFactor * emgSettingsValues.getLowerThreshold(channel));
136136

137137
int _x = int(5*colOffset/8);
138138
int _y = int(2 * rowOffset / 8);
@@ -142,7 +142,7 @@ class W_emg extends Widget {
142142
//draw normalized bar graph of uV w/ matching channel color
143143
noStroke();
144144
fill(channelColors[colorIndex], 200);
145-
rect(_x, 3*_y + 1, _w, map(emgSettingsValues.outputNormalized[channel], 0, 1, 0, (-1) * int((4*rowOffset/8))));
145+
rect(_x, 3*_y + 1, _w, map(emgSettingsValues.getOutputNormalized(channel), 0, 1, 0, (-1) * int((4*rowOffset/8))));
146146

147147
//draw background bar container for mapped uV value indication
148148
strokeWeight(1);

OpenBCI_GUI/W_Networking.pde

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ class Stream extends Thread {
16731673
for (int i = 0; i < numExgChannels; i++) {
16741674
msg.clearArguments();
16751675
msg.setAddrPattern(baseOscAddress + "/emg/" + i);
1676-
msg.add(emgSettingsValues.outputNormalized[i]);
1676+
msg.add(emgSettingsValues.getOutputNormalized(i));
16771677
try {
16781678
this.osc.send(msg, this.oscNetAddress);
16791679
} catch (Exception e) {
@@ -1683,7 +1683,7 @@ class Stream extends Thread {
16831683
} else if (this.protocol.equals("UDP")) {
16841684
String outputter = "{\"type\":\"emg\",\"data\":[";
16851685
for (int i = 0; i < numExgChannels; i++) {
1686-
outputter += str(emgSettingsValues.outputNormalized[i]);
1686+
outputter += str(emgSettingsValues.getOutputNormalized(i));
16871687
if (i != numExgChannels - 1) {
16881688
outputter += ",";
16891689
} else {
@@ -1697,13 +1697,13 @@ class Stream extends Thread {
16971697
}
16981698
} else if (this.protocol.equals("LSL")) {
16991699
for (int i = 0; i < numExgChannels; i++) {
1700-
dataToSend[i] = emgSettingsValues.outputNormalized[i];
1700+
dataToSend[i] = emgSettingsValues.getOutputNormalized(i);
17011701
}
17021702
outlet_data.push_sample(dataToSend);
17031703
} else if (this.protocol.equals("Serial")) {
17041704
serialMessage = "";
17051705
for (int i = 0; i < numExgChannels; i++) {
1706-
float emg_normalized = emgSettingsValues.outputNormalized[i];
1706+
float emg_normalized = emgSettingsValues.getOutputNormalized(i);
17071707
String emg_normalized_3dec = threeDecimalPlaces.format(emg_normalized);
17081708
serialMessage += emg_normalized_3dec;
17091709
if (i != numExgChannels - 1) {

0 commit comments

Comments
 (0)