Skip to content

Commit 0afebcf

Browse files
authored
Merge pull request #1181 from OpenBCI/process-widget-data-background-networking
Process widget data in background when widgets are closed
2 parents dc5ea59 + 4abc3a4 commit 0afebcf

11 files changed

Lines changed: 1673 additions & 1430 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Update repository to Processing 4.2 #1111
55
- Add Software Marker Widget #1091
66
- Add channel labels for Cyton Digital Channels in GUI CSV files and also label unused channels #1108
7+
- Process all data in the background when widgets are closed and sending over Networking stream #1094
78

89
# v5.2.1
910

Networking-Test-Kit/LSL/lslStreamTest_3Streams.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,21 @@ def testLSLSamplingRates():
3535
if i == 0:
3636
chunk, timestamps = inlet.pull_chunk()
3737
if timestamps:
38+
print("Stream 1 Chunk: ", chunk)
3839
for sample in chunk:
39-
if sample:
40-
num_samples_1 += 1
41-
#print(sample)
40+
num_samples_1 += 1
4241
elif i == 1:
4342
chunk, timestamps_2 = inlet_2.pull_chunk()
4443
if timestamps_2:
44+
print("Stream 2 Chunk: ", chunk)
4545
for sample in chunk:
4646
num_samples_2 += 1
47-
#print(sample)
4847
elif i == 2:
4948
chunk, timestamps_3 = inlet_3.pull_chunk()
5049
if timestamps_3:
50+
print("Stream 3 Chunk: ", chunk)
5151
for sample in chunk:
5252
num_samples_3 += 1
53-
#print(sample)
5453
#print("Stream", i + 1, " == ", chunk)
5554
print( "Stream 1 Sampling Rate == ", num_samples_1 / duration_seconds, " | Type : EEG")
5655
print( "Stream 2 Sampling Rate == ", num_samples_2 / duration_seconds, " | Type : AUX")
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Example program to show how to read a GUI BandPower data over LSL."""
2+
import time
3+
from pylsl import StreamInlet, resolve_stream
4+
from time import sleep
5+
6+
# Example Sample
7+
# F
8+
#[0.0, 0.8485075831413269, 9.373364448547363, 0.0013413801789283752, 0.001849484397098422]
9+
10+
# First resolve an EEG stream on the lab network
11+
print("looking for an EEG stream...")
12+
streams = resolve_stream('type', 'EEG')
13+
14+
# Create a new inlet to read from the stream
15+
inlet = StreamInlet(streams[0])
16+
duration = 5
17+
num_channels = 8
18+
19+
sleep(1)
20+
21+
def testLSLSamplingRate():
22+
start = time.time()
23+
total_samples = 0
24+
num_samples_channel_0 = 0
25+
print( "Testing Sampling Rates..." )
26+
27+
while time.time() <= start + duration:
28+
# Get chunks of samples
29+
sample, timestamp = inlet.pull_sample()
30+
if sample:
31+
print("\nNew chunk! Sample size == {}".format(len(sample)) )
32+
total_samples += 1
33+
print(sample, timestamp)
34+
if sample[0] == 0.0:
35+
num_samples_channel_0 += 1
36+
37+
38+
print( "Valid Samples and Duration == {} / {}".format(total_samples, duration) )
39+
print( "Average Sampling Rate == {}".format(total_samples / duration) )
40+
print( "Valid Samples Channel 0 and Duration == {} / {}".format(num_samples_channel_0, duration) )
41+
print( "Average Sampling Rate Channel 0 == {}".format(num_samples_channel_0 / duration) )
42+
43+
44+
testLSLSamplingRate()

OpenBCI_GUI/DataProcessing.pde

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,13 @@ class DataProcessing {
277277
headWidePower[i] = sum/nchan; // averaging power over all channels
278278
}
279279

280-
//find strongest channel
280+
// Calculate data used for Headplot
281+
// Find strongest channel
281282
int refChanInd = findMax(data_std_uV);
282283
//println("EEG_Processing: strongest chan (one referenced) = " + (refChanInd+1));
283284
float[] refData_uV = dataProcessingFilteredBuffer[refChanInd]; //use the filtered data
284285
refData_uV = Arrays.copyOfRange(refData_uV, refData_uV.length-((int)fs_Hz), refData_uV.length); //just grab the most recent second of data
285-
286-
287-
//compute polarity of each channel
286+
// Compute polarity of each channel
288287
for (int Ichan=0; Ichan < nchan; Ichan++) {
289288
float[] fooData_filt = dataProcessingFilteredBuffer[Ichan]; //use the filtered data
290289
fooData_filt = Arrays.copyOfRange(fooData_filt, fooData_filt.length-((int)fs_Hz), fooData_filt.length); //just grab the most recent second of data
@@ -296,7 +295,18 @@ class DataProcessing {
296295
}
297296
}
298297

299-
//Compute EMG values independent of widgets
298+
/////////////////////////////////////////////////////////////
299+
// Compute widget values independent of widgets being open //
300+
// -RW #1094 //
301+
/////////////////////////////////////////////////////////////
300302
emgSettings.values.process(dataProcessingFilteredBuffer);
303+
w_focus.updateFocusWidgetData();
304+
w_bandPower.updateBandPowerWidgetData();
305+
w_emgJoystick.updateEmgJoystickWidgetData();
306+
if (w_pulsesensor != null) {
307+
w_pulsesensor.updatePulseSensorWidgetData();
308+
}
309+
310+
w_networking.updateNetworkingWidgetData();
301311
}
302312
}

0 commit comments

Comments
 (0)