Skip to content
Snippets Groups Projects
Commit aad38deb authored by jsiegle's avatar jsiegle
Browse files

Multiple headstage inputs are working on RHD2000Thread

parent 4c509f0a
No related branches found
No related tags found
No related merge requests found
......@@ -48,23 +48,36 @@ RHD2000Thread::RHD2000Thread(SourceNode* sn) : DataThread(sn)
// Initialize board.
evalBoard->initialize();
evalBoard->setContinuousRunMode(false);
// set defaults
// 4 data sources : 0 -> PortA1
// 1 -> PortB1
// 2 -> PortC1
// 3 -> PortD1
//
// source 0 is enabled with 32 channels; the rest are disabled
//
// sample rate is 10 kHz
evalBoard->setDataSource(0, Rhd2000EvalBoard::PortA1);
evalBoard->setDataSource(1, Rhd2000EvalBoard::PortB1);
evalBoard->setContinuousRunMode(false);
evalBoard->setDataSource(2, Rhd2000EvalBoard::PortC1);
evalBoard->setDataSource(3, Rhd2000EvalBoard::PortD1);
numChannelsPerDataStream.add(32);
numChannelsPerDataStream.add(32);
for (int i = 0; i < 4; i++)
{
numChannelsPerDataStream.add(0);
}
numChannels = 64;
enableHeadstage(0, true);
enableHeadstage(1, true);
enableHeadstage(2, false);
enableHeadstage(3, false);
// Select per-channel amplifier sampling rate.
evalBoard->setSampleRate(Rhd2000EvalBoard::SampleRate10000Hz);
// Now that we have set our sampling rate, we can set the MISO sampling delay
// which is dependent on the sample rate. We assume a 3-foot cable.
evalBoard->setCableLengthFeet(Rhd2000EvalBoard::PortA, 3.0);
evalBoard->setCableLengthFeet(Rhd2000EvalBoard::PortB, 3.0);
// Let's turn one LED on to indicate that the program is running.
int ledArray[8] = {1, 0, 0, 0, 0, 0, 0, 0};
evalBoard->setLedDisplay(ledArray);
......@@ -84,8 +97,7 @@ RHD2000Thread::RHD2000Thread(SourceNode* sn) : DataThread(sn)
dataBlock = new Rhd2000DataBlock(evalBoard->getNumEnabledDataStreams());
dataBuffer = new DataBuffer(numChannels, 10000);
dataBuffer = new DataBuffer(getNumChannels(), 10000);
}
......@@ -107,6 +119,14 @@ RHD2000Thread::~RHD2000Thread()
int RHD2000Thread::getNumChannels()
{
numChannels = 0;
for (int i = 0; i < numChannelsPerDataStream.size(); i++)
{
numChannels += numChannelsPerDataStream[i];
}
return numChannels;
}
......@@ -132,6 +152,55 @@ bool RHD2000Thread::foundInputSource()
}
void RHD2000Thread::enableHeadstage(int hsNum, bool enabled)
{
evalBoard->enableDataStream(hsNum, enabled);
if (enabled)
{
numChannelsPerDataStream.set(hsNum, 32);
} else {
numChannelsPerDataStream.set(hsNum, 0);
}
std::cout << "Enabled channels: " << numChannelsPerDataStream[0] <<
" " << numChannelsPerDataStream[1] <<
" " << numChannelsPerDataStream[2] <<
" " << numChannelsPerDataStream[3] << std::endl;
std::cout << "Enabled data streams: " << evalBoard->getNumEnabledDataStreams() << std::endl;
delete(dataBlock);
dataBlock = new Rhd2000DataBlock(evalBoard->getNumEnabledDataStreams());
}
void RHD2000Thread::setCableLength(int hsNum, float length)
{
// Set the MISO sampling delay, which is dependent on the sample rate.
switch (hsNum)
{
case 0:
evalBoard->setCableLengthFeet(Rhd2000EvalBoard::PortA, length);
break;
case 1:
evalBoard->setCableLengthFeet(Rhd2000EvalBoard::PortB, length);
break;
case 2:
evalBoard->setCableLengthFeet(Rhd2000EvalBoard::PortC, length);
break;
case 3:
evalBoard->setCableLengthFeet(Rhd2000EvalBoard::PortD, length);
break;
default:
break;
}
}
bool RHD2000Thread::startAcquisition()
{
......@@ -210,15 +279,26 @@ bool RHD2000Thread::updateBuffer()
for (int samp = 0; samp < dataBlock->getSamplesPerDataBlock(); samp++)
{
for (int dataStream = 0; dataStream < 1; dataStream++)
int ds = -1;
int channel = -1;
for (int dataStream = 0; dataStream < 2; dataStream++) //numChannelsPerDataStream.size(); dataStream++)
{
for (int chan = 0; chan < numChannelsPerDataStream[dataStream]; chan++)
if (numChannelsPerDataStream[dataStream] > 0)
{
int value = dataBlock->amplifierData[dataStream][chan][samp];
ds++;
for (int chan = 0; chan < numChannelsPerDataStream[dataStream]; chan++)
{
channel++;
int value = dataBlock->amplifierData[ds][chan][samp];
thisSample[chan] = float(value-32768)*0.195f;
thisSample[channel] = float(value-32768)*0.195f;
}
}
}
......
......@@ -61,6 +61,10 @@ public:
float getSampleRate();
float getBitVolts();
void enableHeadstage(int hsNum, bool enabled);
void setCableLength(int hsNum, float length);
void setNumChannels(int hsNum, int nChannels);
int getNumEventChannels();
private:
......
......@@ -20,7 +20,7 @@
#ifndef RHD2000DATABLOCK_H
#define RHD2000DATABLOCK_H
#define SAMPLES_PER_DATA_BLOCK 200
#define SAMPLES_PER_DATA_BLOCK 300
#define RHD2000_HEADER_MAGIC_NUMBER 0xc691199927021942
using namespace std;
......
......@@ -72,6 +72,8 @@ void GenericEditor::constructorInitialize(GenericProcessor* owner, bool useDefau
if (!owner->isMerger() && !owner->isSplitter())
{
std::cout << "Adding drawer button." << std::endl;
drawerButton = new DrawerButton("name");
drawerButton->addListener(this);
addAndMakeVisible(drawerButton);
......
......@@ -23,17 +23,26 @@
#include "RHD2000Editor.h"
RHD2000Editor::RHD2000Editor(GenericProcessor* parentNode, bool useDefaultParameterEditors=true)
: GenericEditor(parentNode, useDefaultParameterEditors)
#include "../DataThreads/RHD2000Thread.h"
RHD2000Editor::RHD2000Editor(GenericProcessor* parentNode,
RHD2000Thread* board_,
bool useDefaultParameterEditors=true
)
: GenericEditor(parentNode, useDefaultParameterEditors), board(board_)
{
desiredWidth = 400;
int width = desiredWidth/4 - 10;
for (int i = 0; i < 4; i++)
{
HeadstageOptionsInterface* hsOptions = new HeadstageOptionsInterface(i);
headstageOptionsInterfaces.add(hsOptions);
addAndMakeVisible(hsOptions);
hsOptions->setBounds(8+i*width,30, width, 85);
}
}
......@@ -43,16 +52,6 @@ RHD2000Editor::~RHD2000Editor()
}
void RHD2000Editor::resized()
{
int width = getWidth()/4 - 20;
for (int i = 0; i < headstageOptionsInterfaces.size(); i++)
{
headstageOptionsInterfaces[i]->setBounds(10+i*width,30, width,getHeight()-50);
}
}
// --------------------------------------------------------------------
......@@ -91,4 +90,10 @@ void HeadstageOptionsInterface::paint(Graphics& g)
g.fillRoundedRectangle(5,0,getWidth()-10,getHeight(),4.0f);
g.setColour(Colours::grey);
g.setFont(Font("Small Text",10,Font::plain));
g.drawText("Headstage " + name, 8, 5, 200, 15, Justification::left, false);
}
\ No newline at end of file
......@@ -36,21 +36,22 @@
*/
class HeadstageOptionsInterface;
class RHD2000Thread;
class RHD2000Editor : public GenericEditor
{
public:
RHD2000Editor(GenericProcessor* parentNode, bool useDefaultParameterEditors);
RHD2000Editor(GenericProcessor* parentNode, RHD2000Thread*, bool useDefaultParameterEditors);
~RHD2000Editor();
void resized();
private:
OwnedArray<HeadstageOptionsInterface> headstageOptionsInterfaces;
RHD2000Thread* board;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(RHD2000Editor);
};
......@@ -69,6 +70,7 @@ private:
int hsNumber;
String name;
};
......
......@@ -90,6 +90,14 @@ SourceNode::SourceNode(const String& name_)
SourceNode::~SourceNode()
{
if (dataThread->isThreadRunning())
{
std::cout << "Forcing thread to stop." << std::endl;
dataThread->stopThread(500);
}
if (eventChannelState)
delete[] eventChannelState;
}
......@@ -198,7 +206,7 @@ AudioProcessorEditor* SourceNode::createEditor()
if (getName().equalsIgnoreCase("RHD2000 USB Board"))
{
editor = new RHD2000Editor(this, true);
editor = new RHD2000Editor(this, (RHD2000Thread*) dataThread.get(), true);
}
else
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment