Skip to content

Commit 924f27d

Browse files
committed
RhythmNode: add AUX chans toggle button
1 parent 89bf51a commit 924f27d

4 files changed

Lines changed: 127 additions & 92 deletions

File tree

Source/Plugins/RhythmNode/RHD2000Editor.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ void FPGAchannelList::update()
129129

130130
// find out which streams are active.
131131
bool hsActive[MAX_NUM_HEADSTAGES+1];
132-
//bool adcActive = false;
133132
int numActiveHeadstages = 0;
134133
int hsColumn[MAX_NUM_HEADSTAGES + 1];
135134
int numChannelsPerHeadstage[MAX_NUM_HEADSTAGES + 1];
@@ -193,11 +192,14 @@ void FPGAchannelList::update()
193192

194193
}
195194

196-
for (int k = 0; k < MAX_NUM_HEADSTAGES + 1; k++)
195+
for (int k = 0; k < MAX_NUM_HEADSTAGES + 1; k++) // +1 is for the ADC "headstage"
197196
{
198197
if (hsActive[k])
199198
{
200-
for (int ch = 0; ch < numChannelsPerHeadstage[k]+ (k < MAX_NUM_HEADSTAGES ? 3 : 0); ch++)
199+
int nchans = numChannelsPerHeadstage[k];
200+
if (k < MAX_NUM_HEADSTAGES && thread->isAuxEnabled())
201+
nchans += 3;
202+
for (int ch = 0; ch < nchans; ch++)
201203
{
202204
int channelGainIndex = 1;
203205
int realChan = thread->getChannelFromHeadstage(k, ch);
@@ -215,7 +217,7 @@ void FPGAchannelList::update()
215217
else
216218
type = DataChannel::ADC_CHANNEL;
217219

218-
FPGAchannelComponent* comp = new FPGAchannelComponent(this, realChan, channelGainIndex + 1, thread->getChannelName(realChan), gains,type);
220+
FPGAchannelComponent* comp = new FPGAchannelComponent(this, realChan, channelGainIndex + 1, thread->getChannelName(realChan), gains, type);
219221
comp->setBounds(10 + hsColumn[k], 70 + ch * 22, columnWidth, 22);
220222
comp->setUserDefinedData(k);
221223
addAndMakeVisible(comp);
@@ -586,6 +588,14 @@ RHD2000Editor::RHD2000Editor(GenericProcessor* parentNode,
586588
rescanButton->setTooltip("Check for connected headstages");
587589
addAndMakeVisible(rescanButton);
588590

591+
auxButton = new UtilityButton("AUX", Font("Small Text", 13, Font::plain));
592+
auxButton->setRadius(3.0f);
593+
auxButton->setBounds(80, 108, 32, 18);
594+
auxButton->addListener(this);
595+
auxButton->setClickingTogglesState(true);
596+
auxButton->setTooltip("Toggle AUX channels (3 per headstage)");
597+
addAndMakeVisible(auxButton);
598+
589599
for (int i = 0; i < 2; i++)
590600
{
591601
ElectrodeButton* button = new ElectrodeButton(-1);
@@ -825,13 +835,18 @@ void RHD2000Editor::buttonEvent(Button* button)
825835
{
826836
channelSelector->setRadioStatus(true);
827837
}
838+
else if (button == auxButton && !acquisitionIsActive)
839+
{
840+
board->enableAuxs(button->getToggleState());
841+
std::cout << "AUX Button toggled" << "\n";
842+
CoreServices::updateSignalChain(this);
843+
}
828844
else if (button == adcButton && !acquisitionIsActive)
829845
{
830846
board->enableAdcs(button->getToggleState());
831-
// board->updateChannelNames();
832847
std::cout << "ADC Button toggled" << "\n";
833-
std::cout << "Editor visible." << "\n";
834848
CoreServices::updateSignalChain(this);
849+
835850
}
836851
else if (button == dacTTLButton)
837852
{
@@ -877,10 +892,10 @@ void RHD2000Editor::startAcquisition()
877892
channelSelector->startAcquisition();
878893

879894
rescanButton->setEnabledState(false);
895+
auxButton->setEnabledState(false);
880896
adcButton->setEnabledState(false);
881897
dspoffsetButton-> setEnabledState(false);
882898
acquisitionIsActive = true;
883-
//canvas->channelList->setEnabled(false);
884899
if (canvas != nullptr)
885900
canvas->channelList->disableAll();
886901
}
@@ -891,11 +906,11 @@ void RHD2000Editor::stopAcquisition()
891906
channelSelector->stopAcquisition();
892907

893908
rescanButton->setEnabledState(true);
909+
auxButton->setEnabledState(true);
894910
adcButton->setEnabledState(true);
895911
dspoffsetButton-> setEnabledState(true);
896912

897913
acquisitionIsActive = false;
898-
// canvas->channelList->setEnabled(true);
899914
if (canvas != nullptr)
900915
canvas->channelList->enableAll();
901916
}
@@ -906,10 +921,7 @@ void RHD2000Editor::saveCustomParameters(XmlElement* xml)
906921
xml->setAttribute("SampleRateString", sampleRateInterface->getText());
907922
xml->setAttribute("LowCut", bandwidthInterface->getLowerBandwidth());
908923
xml->setAttribute("HighCut", bandwidthInterface->getUpperBandwidth());
909-
xml->setAttribute("ADCsOn", adcButton->getToggleState());
910-
xml->setAttribute("SampleRate", sampleRateInterface->getSelectedId());
911-
xml->setAttribute("LowCut", bandwidthInterface->getLowerBandwidth());
912-
xml->setAttribute("HighCut", bandwidthInterface->getUpperBandwidth());
924+
xml->setAttribute("AUXsOn", auxButton->getToggleState());
913925
xml->setAttribute("ADCsOn", adcButton->getToggleState());
914926
xml->setAttribute("AudioOutputL", electrodeButtons[0]->getChannelNum());
915927
xml->setAttribute("AudioOutputR", electrodeButtons[1]->getChannelNum());
@@ -937,6 +949,7 @@ void RHD2000Editor::loadCustomParameters(XmlElement* xml)
937949
sampleRateInterface->setSelectedId(xml->getIntAttribute("SampleRate"));
938950
bandwidthInterface->setLowerBandwidth(xml->getDoubleAttribute("LowCut"));
939951
bandwidthInterface->setUpperBandwidth(xml->getDoubleAttribute("HighCut"));
952+
auxButton->setToggleState(xml->getBoolAttribute("AUXsOn"), sendNotification);
940953
adcButton->setToggleState(xml->getBoolAttribute("ADCsOn"), sendNotification);
941954
//electrodeButtons[0]->setChannelNum(xml->getIntAttribute("AudioOutputL"));
942955
//board->assignAudioOut(0, xml->getIntAttribute("AudioOutputL"));

Source/Plugins/RhythmNode/RHD2000Editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class RHD2000Editor : public VisualizerEditor, public ComboBox::Listener, public
199199
ScopedPointer<ClockDivideInterface> clockInterface;
200200

201201
ScopedPointer<UtilityButton> rescanButton,dacTTLButton;
202+
ScopedPointer<UtilityButton> auxButton;
202203
ScopedPointer<UtilityButton> adcButton;
203204
ScopedPointer<UtilityButton> ledButton;
204205

Source/Plugins/RhythmNode/RHD2000Thread.cpp

Lines changed: 97 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void allocateDoubleArray3D(std::vector<std::vector<std::vector<double> > >& arra
6868

6969
DataThread* RHD2000Thread::createDataThread(SourceNode *sn)
7070
{
71-
return new RHD2000Thread(sn);
71+
return new RHD2000Thread(sn);
7272
}
7373

7474
RHD2000Thread::RHD2000Thread(SourceNode* sn) : DataThread(sn),
@@ -77,8 +77,8 @@ RHD2000Thread::RHD2000Thread(SourceNode* sn) : DataThread(sn),
7777
deviceFound(false),
7878
isTransmitting(false),
7979
dacOutputShouldChange(false),
80+
acquireAuxChannels(false),
8081
acquireAdcChannels(false),
81-
acquireAuxChannels(true),
8282
fastSettleEnabled(false),
8383
fastTTLSettleEnabled(false),
8484
fastSettleTTLChannel(-1),
@@ -818,6 +818,7 @@ void RHD2000Thread::setDefaultChannelNames()
818818
stream_prefix.add("D1");
819819
stream_prefix.add("D2");
820820

821+
// headstage channels
821822
for (int i = 0; i < MAX_NUM_HEADSTAGES; i++)
822823
{
823824
if (headstagesArray[i]->isPlugged())
@@ -839,32 +840,33 @@ void RHD2000Thread::setDefaultChannelNames()
839840
}
840841
}
841842
}
842-
//Aux channels
843-
for (int i = 0; i < MAX_NUM_HEADSTAGES; i++)
843+
// AUX channels
844+
if (acquireAuxChannels)
844845
{
845-
if (headstagesArray[i]->isPlugged())
846+
for (int i = 0; i < MAX_NUM_HEADSTAGES; i++)
846847
{
847-
for (int k = 0; k < 3; k++)
848+
if (headstagesArray[i]->isPlugged())
848849
{
849-
int chn = channelNumber - 1;
850-
851-
if (newScan || !channelInfo[chn].modified)
850+
for (int k = 0; k < 3; k++)
852851
{
853-
ChannelCustomInfo in;
854-
if (numberingScheme == 1)
855-
in.name = "AUX" + String(aux_counter);
856-
else
857-
in.name = "AUX_" + stream_prefix[i] + "_" + String(1 + k);
858-
in.gain = getBitVolts(sn->getDataChannel(chn));
859-
channelInfo.set(chn, in);
860-
852+
int chn = channelNumber - 1;
853+
if (newScan || !channelInfo[chn].modified)
854+
{
855+
ChannelCustomInfo in;
856+
if (numberingScheme == 1)
857+
in.name = "AUX" + String(aux_counter);
858+
else
859+
in.name = "AUX_" + stream_prefix[i] + "_" + String(1 + k);
860+
in.gain = getBitVolts(sn->getDataChannel(chn));
861+
channelInfo.set(chn, in);
862+
}
863+
channelNumber++;
864+
aux_counter++;
861865
}
862-
channelNumber++;
863-
aux_counter++;
864866
}
865867
}
866868
}
867-
//ADC channels
869+
// ADC channels
868870
if (acquireAdcChannels)
869871
{
870872
for (int k = 0; k < 8; k++)
@@ -1168,12 +1170,23 @@ int RHD2000Thread::getChannelsInHeadstage (int hsNum) const
11681170
11691171
}*/
11701172

1173+
void RHD2000Thread::enableAuxs(bool t)
1174+
{
1175+
acquireAuxChannels = t;
1176+
sourceBuffers[0]->resize(getNumChannels(), 10000);
1177+
updateRegisters();
1178+
}
1179+
11711180
void RHD2000Thread::enableAdcs(bool t)
11721181
{
11731182
acquireAdcChannels = t;
11741183
sourceBuffers[0]->resize(getNumChannels(), 10000);
11751184
}
11761185

1186+
bool RHD2000Thread::isAuxEnabled()
1187+
{
1188+
return acquireAuxChannels;
1189+
}
11771190

11781191
void RHD2000Thread::setSampleRate(int sampleRateIndex, bool isTemporary)
11791192
{
@@ -1344,10 +1357,10 @@ void RHD2000Thread::updateRegisters()
13441357
chipRegisters.enableDsp(dspEnabled);
13451358
//std::cout << "DSP Offset Status " << dspEnabled << std::endl;
13461359

1347-
// turn on aux inputs
1348-
chipRegisters.enableAux1(true);
1349-
chipRegisters.enableAux2(true);
1350-
chipRegisters.enableAux3(true);
1360+
// enable/disable aux inputs:
1361+
chipRegisters.enableAux1(acquireAuxChannels);
1362+
chipRegisters.enableAux2(acquireAuxChannels);
1363+
chipRegisters.enableAux3(acquireAuxChannels);
13511364

13521365
chipRegisters.createCommandListRegisterConfig(commandList, true);
13531366
// Upload version with ADC calibration to AuxCmd3 RAM Bank 0.
@@ -1513,11 +1526,13 @@ bool RHD2000Thread::updateBuffer()
15131526
bool return_code;
15141527

15151528
return_code = evalBoard->readRawDataBlock(&bufferPtr);
1529+
// see Rhd2000DataBlock::fillFromUsbBuffer() for an idea of data order in bufferPtr
15161530

15171531
int index = 0;
15181532
int auxIndex, chanIndex;
15191533
int numStreams = enabledStreams.size();
15201534
int nSamps = Rhd2000DataBlock::getSamplesPerDataBlock(evalBoard->isUSB3());
1535+
15211536
//evalBoard->printFIFOmetrics();
15221537
for (int samp = 0; samp < nSamps; samp++)
15231538
{
@@ -1529,71 +1544,74 @@ bool RHD2000Thread::updateBuffer()
15291544
break;
15301545
}
15311546

1532-
index += 8;
1533-
timestamps.set(0,Rhd2000DataBlock::convertUsbTimeStamp(bufferPtr,index));
1534-
index += 4;
1535-
auxIndex = index;
1536-
//skip the aux channels
1537-
index += numStreams * 6;
1538-
// do the neural data channels first
1539-
for (int dataStream = 0; dataStream < numStreams; dataStream++)
1540-
{
1541-
int nChans = numChannelsPerDataStream[dataStream];
1542-
chanIndex = index + 2*dataStream;
1543-
if ((chipId[dataStream] == CHIP_ID_RHD2132) && (nChans == 16)) //RHD2132 16ch. headstage
1544-
{
1545-
chanIndex += 2 * RHD2132_16CH_OFFSET*numStreams;
1546-
}
1547-
for (int chan = 0; chan < nChans; chan++)
1548-
{
1549-
channel++;
1550-
thisSample[channel] = float(*(uint16*)(bufferPtr + chanIndex) - 32768)*0.195f;
1551-
chanIndex += 2*numStreams;
1552-
}
1553-
}
1554-
index += 64 * numStreams;
1555-
//now we can do the aux channels
1556-
auxIndex += 2*numStreams;
1557-
for (int dataStream = 0; dataStream < numStreams; dataStream++)
1558-
{
1559-
if (chipId[dataStream] != CHIP_ID_RHD2164_B)
1560-
{
1561-
int auxNum = (samp+3) % 4;
1562-
if (auxNum < 3)
1563-
{
1564-
auxSamples[dataStream][auxNum] = float(*(uint16*)(bufferPtr + auxIndex) - 32768)*0.0000374;
1565-
}
1566-
for (int chan = 0; chan < 3; chan++)
1567-
{
1568-
channel++;
1569-
if (auxNum == 3)
1570-
{
1571-
auxBuffer[channel] = auxSamples[dataStream][chan];
1572-
}
1573-
thisSample[channel] = auxBuffer[channel];
1574-
}
1575-
}
1576-
auxIndex += 2;
1577-
1578-
}
1579-
index += 2 * numStreams;
1580-
if (acquireAdcChannels)
1581-
{
1582-
for (int adcChan = 0; adcChan < 8; ++adcChan)
1583-
{
1584-
1585-
index += 2;
1586-
index += 16;
1547+
index += 8; // magic number header width (bytes)
1548+
timestamps.set(0, Rhd2000DataBlock::convertUsbTimeStamp(bufferPtr, index));
1549+
index += 4; // timestamp width
1550+
auxIndex = index; // aux chans start at this offset
1551+
// skip aux channels for now
1552+
index += 6 * numStreams; // width of the 3 aux chans
1553+
// copy 64 neural data channels
1554+
for (int dataStream = 0; dataStream < numStreams; dataStream++)
1555+
{
1556+
int nChans = numChannelsPerDataStream[dataStream];
1557+
chanIndex = index + 2*dataStream;
1558+
if ((chipId[dataStream] == CHIP_ID_RHD2132) && (nChans == 16)) //RHD2132 16ch. headstage
1559+
{
1560+
chanIndex += 2 * RHD2132_16CH_OFFSET*numStreams;
1561+
}
1562+
for (int chan = 0; chan < nChans; chan++)
1563+
{
1564+
channel++;
1565+
thisSample[channel] = float(*(uint16*)(bufferPtr + chanIndex) - 32768)*0.195f;
1566+
chanIndex += 2*numStreams; // single chan width (2 bytes)
1567+
}
1568+
}
1569+
index += 64 * numStreams; // neural data width
1570+
auxIndex += 2 * numStreams; // mspacek: not clear why this is here
1571+
// copy the 3 aux channels
1572+
if (acquireAuxChannels)
1573+
{
1574+
for (int dataStream = 0; dataStream < numStreams; dataStream++)
1575+
{
1576+
if (chipId[dataStream] != CHIP_ID_RHD2164_B)
1577+
{
1578+
int auxNum = (samp+3) % 4;
1579+
if (auxNum < 3)
1580+
{
1581+
auxSamples[dataStream][auxNum] = float(*(uint16*)(bufferPtr + auxIndex) - 32768)*0.0000374;
1582+
}
1583+
for (int chan = 0; chan < 3; chan++)
1584+
{
1585+
channel++;
1586+
if (auxNum == 3)
1587+
{
1588+
auxBuffer[channel] = auxSamples[dataStream][chan];
1589+
}
1590+
thisSample[channel] = auxBuffer[channel];
1591+
}
1592+
}
1593+
auxIndex += 2; // single chan width (2 bytes)
1594+
}
1595+
}
1596+
index += 2 * numStreams; // skip over filler word at the end of each data stream
1597+
// copy the 8 ADC channels
1598+
if (acquireAdcChannels)
1599+
{
1600+
for (int adcChan = 0; adcChan < 8; ++adcChan)
1601+
{
1602+
15871603
channel++;
15881604
// ADC waveform units = volts
15891605
thisSample[channel] = adcRangeSettings[adcChan] == 0 ?
15901606
//0.000050354 * float(dataBlock->boardAdcData[adcChan][samp]);
15911607
0.00015258789 * float(*(uint16*)(bufferPtr + index)) - 5 - 0.4096 : // account for +/-5V input range and DC offset
15921608
0.00030517578 * float(*(uint16*)(bufferPtr + index));
1609+
index += 2; // single chan width (2 bytes)
15931610
}
15941611
}
15951612
else
15961613
{
1614+
index += 16; // skip ADC chans (8 * 2 bytes)
15971615
}
15981616
ttlEventWords.set(0, *(uint16*)(bufferPtr + index));
15991617
index += 4;

0 commit comments

Comments
 (0)