Skip to content

Commit

Permalink
Merge pull request #234 from aj-ptw/development
Browse files Browse the repository at this point in the history
FIX: #233 #228
  • Loading branch information
AJ Keller authored Sep 4, 2017
2 parents 9a3e77c + 182af94 commit 6ed0753
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
7 changes: 6 additions & 1 deletion OpenBCI_GUI/ControlPanel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,12 @@ class ControlPanel {

public void initButtonPressed(){
if (initSystemButton.but_txt == "START SYSTEM") {
if (eegDataSource == DATASOURCE_CYTON && cyton.getInterface() == INTERFACE_SERIAL && openBCI_portName == "N/A") { //if data source == normal && if no serial port selected OR no SD setting selected
if ((eegDataSource == DATASOURCE_CYTON && cyton.getInterface() == INTERFACE_NONE) || (eegDataSource == DATASOURCE_GANGLION && ganglion.getInterface() == INTERFACE_NONE)) {
output("No Transfer Protocol selected. Please select your Transfer Protocol and retry system initiation.");
initSystemButton.wasPressed = false;
initSystemButton.setIsActive(false);
return;
} else if (eegDataSource == DATASOURCE_CYTON && cyton.getInterface() == INTERFACE_SERIAL && openBCI_portName == "N/A") { //if data source == normal && if no serial port selected OR no SD setting selected
output("No Serial/COM port selected. Please select your Serial/COM port and retry system initiation.");
initSystemButton.wasPressed = false;
initSystemButton.setIsActive(false);
Expand Down
21 changes: 20 additions & 1 deletion OpenBCI_GUI/DataLogging.pde
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,8 @@ public class OutputFile_BDF {
///////////////////////////////////////////////////////////////

class Table_CSV extends Table {
private int sampleRate;
public int getSampleRate() { return sampleRate; }
Table_CSV(String fname) throws IOException {
init();
readCSV(PApplet.createReader(createInput(fname)));
Expand All @@ -1336,7 +1338,24 @@ class Table_CSV extends Table {
while ( (line = reader.readLine ()) != null) {
//added by Chip, May 2, 2014 to ignore lines that are comments
if (line.charAt(0) == '%') {
//println("Table_CSV: readCSV: ignoring commented line...");
if (line.length() > 18) {
if (line.charAt(1) == 'S') {
// println(line.substring(15, 18));
sampleRate = Integer.parseInt(line.substring(15, 18));
if (sampleRate == 100 || sampleRate == 160) {
sampleRate = Integer.parseInt(line.substring(15, 19));
}
println("Sample rate set to " + sampleRate);
// String[] m = match(line, "\\d+");
// if (m != null) {
// println("Found '" + m[1] + "' inside the line");
// }
}
}
println(line);
// if (line.charAt(1) == 'S') {
// println("sampel rarteakjdsf;ldj");
// }
continue;
}

Expand Down
4 changes: 0 additions & 4 deletions OpenBCI_GUI/DataProcessing.pde
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@ class DataProcessing {
defineFilters(); //define the filters anyway just so that the code doesn't bomb
}

public float getSampleRateHz() {
return fs_Hz;
};

//define filters depending on the sampling rate
private void defineFilters() {
int n_filt;
Expand Down
54 changes: 34 additions & 20 deletions OpenBCI_GUI/OpenBCI_GUI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,24 @@ void initSystem() {

//prepare data variables
verbosePrint("OpenBCI_GUI: initSystem: Preparing data variables...");

if (eegDataSource == DATASOURCE_PLAYBACKFILE) {
//open and load the data file
println("OpenBCI_GUI: initSystem: loading playback data from " + playbackData_fname);
try {
playbackData_table = new Table_CSV(playbackData_fname);
playbackData_table.removeColumn(0);
} catch (Exception e) {
println("OpenBCI_GUI: initSystem: could not open file for playback: " + playbackData_fname);
println(" : quitting...");
abandonInit = true;
hub.killAndShowMsg("Could not open file for playback: " + playbackData_fname);
}
println("OpenBCI_GUI: initSystem: loading complete. " + playbackData_table.getRowCount() + " rows of data, which is " + round(float(playbackData_table.getRowCount())/getSampleRateSafe()) + " seconds of EEG data");
//removing first column of data from data file...the first column is a time index and not eeg data

}

fs_Hz = getSampleRateSafe();
Nfft = getNfftSafe();
nDataBackBuff = 3*(int)fs_Hz;
Expand Down Expand Up @@ -620,19 +638,6 @@ void initSystem() {
//do nothing
break;
case DATASOURCE_PLAYBACKFILE:
//open and load the data file
println("OpenBCI_GUI: initSystem: loading playback data from " + playbackData_fname);
try {
playbackData_table = new Table_CSV(playbackData_fname);
}
catch (Exception e) {
println("OpenBCI_GUI: initSystem: could not open file for playback: " + playbackData_fname);
println(" : quitting...");
exit();
}
println("OpenBCI_GUI: initSystem: loading complete. " + playbackData_table.getRowCount() + " rows of data, which is " + round(float(playbackData_table.getRowCount())/getSampleRateSafe()) + " seconds of EEG data");
//removing first column of data from data file...the first column is a time index and not eeg data
playbackData_table.removeColumn(0);
break;
case DATASOURCE_GANGLION:
if (ganglion.getInterface() == INTERFACE_HUB_BLE) {
Expand Down Expand Up @@ -703,22 +708,31 @@ void initSystem() {
float getSampleRateSafe() {
if (eegDataSource == DATASOURCE_GANGLION) {
return ganglion.getSampleRate();
} else {
// println("cyton sr: " + cyton.getSampleRate());
} else if (eegDataSource == DATASOURCE_CYTON){
return cyton.getSampleRate();
} else if (eegDataSource == DATASOURCE_PLAYBACKFILE) {
return playbackData_table.getSampleRate();
} else {
return 250;
}
}

/**
* @description Get the correct points of FFT based on sampling rate
* @returns `int` - Points of FFT. 125Hz, 200Hz, 250Hz -> 256points. 1000Hz -> 1024points. 1600Hz -> 2048 points.
*/

int getNfftSafe() {
if (eegDataSource == DATASOURCE_GANGLION) {
return ganglion.getNfft();
} else {
return cyton.getNfft();
int sampleRate = (int)getSampleRateSafe();
switch (sampleRate) {
case 1000:
return 1024;
case 1600:
return 2048;
case 125:
case 200:
case 250:
default:
return 256;
}
}

Expand Down

0 comments on commit 6ed0753

Please sign in to comment.