From 73dfd1aaedece1690e3f6a22dd83755b47524c83 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Sun, 9 Jun 2013 19:18:15 -0400
Subject: [PATCH] Switch order of channels in RHD2000Thread so all neural data
 channels are grouped together

---
 Source/Processors/Channel.cpp                 |  5 ++
 Source/Processors/Channel.h                   |  3 +
 .../Processors/DataThreads/RHD2000Thread.cpp  | 87 +++++++++++--------
 3 files changed, 60 insertions(+), 35 deletions(-)

diff --git a/Source/Processors/Channel.cpp b/Source/Processors/Channel.cpp
index 19bf8e222..210ca9ac3 100644
--- a/Source/Processors/Channel.cpp
+++ b/Source/Processors/Channel.cpp
@@ -61,6 +61,11 @@ String Channel::getName()
 
 }
 
+void Channel::setName(String name_)
+{
+    name = name_;
+}
+
 void Channel::reset()
 {
     createDefaultName();
diff --git a/Source/Processors/Channel.h b/Source/Processors/Channel.h
index af30c38c8..a32c6cb93 100644
--- a/Source/Processors/Channel.h
+++ b/Source/Processors/Channel.h
@@ -61,6 +61,9 @@ public:
     /** Returns the name of a given channel. */
     String getName();
 
+    /** Sets the name of a given channel. */
+    void setName(String);
+
     /** Restores the default settings for a given channel. */
     void reset();
 
diff --git a/Source/Processors/DataThreads/RHD2000Thread.cpp b/Source/Processors/DataThreads/RHD2000Thread.cpp
index ee53e742b..3d4a19019 100644
--- a/Source/Processors/DataThreads/RHD2000Thread.cpp
+++ b/Source/Processors/DataThreads/RHD2000Thread.cpp
@@ -826,6 +826,7 @@ bool RHD2000Thread::updateBuffer()
                 int streamNumber = -1;
                 int channel = -1;
 
+                // do the neural data channels first
                 for (int dataStream = 0; dataStream < MAX_NUM_DATA_STREAMS; dataStream++)
                 {
                     if (numChannelsPerDataStream[dataStream] > 0)
@@ -842,48 +843,64 @@ bool RHD2000Thread::updateBuffer()
                             thisSample[channel] = float(value-32768)*0.195f;
                         }
 					
-						// TEMPORARILY DISABLED -- causing problems
-						if (samp % 4 == 1) { // every 4th sample should have auxiliary input data
-						
-							channel++;
-							thisSample[channel] = 0.0374 *
-							     float(dataBlock->auxiliaryData[dataStream][1][samp+0]);
-							auxBuffer[channel]=thisSample[channel];
+					}
 
-							channel++;
-							thisSample[channel] = 0.0374 *
-							     float(dataBlock->auxiliaryData[dataStream][1][samp+1]);
-							auxBuffer[channel]=thisSample[channel];
+				}
 
-						
-							channel++;
-							thisSample[channel] = 0.0374 *
-							     float(dataBlock->auxiliaryData[dataStream][1][samp+2]);
-							auxBuffer[channel]=thisSample[channel];
+                streamNumber = -1;
 
-						} else{ // repeat last values from buffer
-							channel++;
-							thisSample[channel] = auxBuffer[channel];
-							channel++;
-							thisSample[channel] = auxBuffer[channel];
-							channel++;
-							thisSample[channel] = auxBuffer[channel];
-						}
+                // then do the ADC channels
+                for (int dataStream = 0; dataStream < MAX_NUM_DATA_STREAMS; dataStream++)
+                {
+                    if (numChannelsPerDataStream[dataStream] > 0)
+                    {
+                        streamNumber++;
+
+                        if (samp % 4 == 1) { // every 4th sample should have auxiliary input data
+                        
+                            channel++;
+                            thisSample[channel] = 0.0374 *
+                                 float(dataBlock->auxiliaryData[dataStream][1][samp+0]);
+
+                            auxBuffer[channel]=thisSample[channel];
+
+                            channel++;
+                            thisSample[channel] = 0.0374 *
+                                 float(dataBlock->auxiliaryData[dataStream][1][samp+1]);
+
+                            auxBuffer[channel]=thisSample[channel];
+
+                        
+                            channel++;
+                            thisSample[channel] = 0.0374 *
+                                 float(dataBlock->auxiliaryData[dataStream][1][samp+2]);
+
+                            auxBuffer[channel]=thisSample[channel];
+
+                        } else{ // repeat last values from buffer
 
-                        if (acquireAdcChannels)
-                        {
-                            for (int adcChan = 0; adcChan < 8; ++adcChan) {
-                            
                             channel++;
-                            // ADC waveform units = volts
-                             thisSample[channel] = 
-                               0.000050354 * float(dataBlock->boardAdcData[adcChan][samp]);
-                            }
+                            thisSample[channel] = auxBuffer[channel];
+                            channel++;
+                            thisSample[channel] = auxBuffer[channel];
+                            channel++;
+                            thisSample[channel] = auxBuffer[channel];
                         }
-						
-					}
+                    }
 
-				}
+                }
+
+                // finally, loop through ADC channels if necessary
+                if (acquireAdcChannels)
+                {
+                    for (int adcChan = 0; adcChan < 8; ++adcChan) {
+                    
+                    channel++;
+                    // ADC waveform units = volts
+                     thisSample[channel] = 
+                       0.000050354 * float(dataBlock->boardAdcData[adcChan][samp]);
+                    }
+                }
 				// std::cout << channel << std::endl;
 
 				timestamp = dataBlock->timeStamp[samp];
-- 
GitLab