From 182af94b0374f3bfecb38ff594159b349c6b8fe6 Mon Sep 17 00:00:00 2001 From: AJ Keller Date: Mon, 4 Sep 2017 13:57:59 -0400 Subject: [PATCH] FIX: #233 #228 --- OpenBCI_GUI/ControlPanel.pde | 7 ++++- OpenBCI_GUI/DataLogging.pde | 21 ++++++++++++- OpenBCI_GUI/DataProcessing.pde | 4 --- OpenBCI_GUI/OpenBCI_GUI.pde | 54 +++++++++++++++++++++------------- 4 files changed, 60 insertions(+), 26 deletions(-) diff --git a/OpenBCI_GUI/ControlPanel.pde b/OpenBCI_GUI/ControlPanel.pde index d8885faa3..199fa7d8c 100644 --- a/OpenBCI_GUI/ControlPanel.pde +++ b/OpenBCI_GUI/ControlPanel.pde @@ -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); diff --git a/OpenBCI_GUI/DataLogging.pde b/OpenBCI_GUI/DataLogging.pde index 44d30764e..e7a495438 100644 --- a/OpenBCI_GUI/DataLogging.pde +++ b/OpenBCI_GUI/DataLogging.pde @@ -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))); @@ -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; } diff --git a/OpenBCI_GUI/DataProcessing.pde b/OpenBCI_GUI/DataProcessing.pde index 78c876880..3c2547776 100644 --- a/OpenBCI_GUI/DataProcessing.pde +++ b/OpenBCI_GUI/DataProcessing.pde @@ -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; diff --git a/OpenBCI_GUI/OpenBCI_GUI.pde b/OpenBCI_GUI/OpenBCI_GUI.pde index ef9191066..4ca0c1932 100644 --- a/OpenBCI_GUI/OpenBCI_GUI.pde +++ b/OpenBCI_GUI/OpenBCI_GUI.pde @@ -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; @@ -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) { @@ -703,9 +708,12 @@ 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; } } @@ -713,12 +721,18 @@ float getSampleRateSafe() { * @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; } }