Skip to content

Commit 49ba97e

Browse files
committed
Add ADC range selector to Rhythm node
1 parent fee60f9 commit 49ba97e

4 files changed

Lines changed: 59 additions & 34 deletions

File tree

Source/Plugins/RhythmNode/RHD2000Editor.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -349,40 +349,30 @@ type(type_), gains(gains_), channelList(cl), channel(ch), name(N), gainIndex(gai
349349
editName->setColour(Label::backgroundColourId,juce::Colours::lightgrey);
350350
editName->addListener(this);
351351
addAndMakeVisible(editName);
352-
/* if (gainIndex > 0)
353-
{
354352

355-
gainComboBox = new ComboBox("Gains");
356-
for (int k=0; k<gains.size(); k++)
357-
{
358-
if (gains[k] < 1)
359-
{
360-
gainComboBox->addItem("x"+String(gains[k],2),k+1);
361-
}
362-
else
363-
{
364-
gainComboBox->addItem("x"+String((int)gains[k]),k+1);
365-
}
366-
}
367-
gainComboBox->setSelectedId(gainIndex, sendNotificationSync);
368-
gainComboBox->addListener(this);
369-
addAndMakeVisible(gainComboBox);
370-
}
371-
else
372-
{*/
373-
gainComboBox = nullptr;
374-
//}
375-
376-
if (type == DataChannel::HEADSTAGE_CHANNEL)
353+
if (type == DataChannel::HEADSTAGE_CHANNEL)
377354
{
378355
impedance = new Label("Impedance","? Ohm");
379356
impedance->setFont(Font("Default", 13, Font::plain));
380357
impedance->setEditable(false);
381358
addAndMakeVisible(impedance);
382359
}
360+
else if (type == DataChannel::ADC_CHANNEL)
361+
{
362+
impedance = nullptr;
363+
rangeComboBox = new ComboBox("ADC Ranges");
364+
rangeComboBox->addItem("-5V - +5V",1);
365+
rangeComboBox->addItem("0V - +5V",2);
366+
SourceNode* proc = channelList->proc;
367+
RHD2000Thread* thread = static_cast<RHD2000Thread*>(proc->getThread());
368+
rangeComboBox->setSelectedId(thread->getAdcRange(proc->getDataChannel(channel)->getSourceTypeIndex()) + 1, dontSendNotification);
369+
rangeComboBox->addListener(this);
370+
addAndMakeVisible(rangeComboBox);
371+
}
383372
else
384373
{
385374
impedance = nullptr;
375+
rangeComboBox = nullptr;
386376
}
387377
}
388378
FPGAchannelComponent::~FPGAchannelComponent()
@@ -409,12 +399,11 @@ void FPGAchannelComponent::setImpedanceValues(float mag, float phase)
409399

410400
void FPGAchannelComponent::comboBoxChanged(ComboBox* comboBox)
411401
{
412-
if (comboBox == gainComboBox)
402+
if (comboBox == rangeComboBox)
413403
{
414-
int newGainIndex = gainComboBox->getSelectedId();
415-
float mult = gains[newGainIndex-1];
416-
float bitvolts = channelList->proc->getBitVolts(channelList->proc->getDataChannel(channel));
417-
channelList->setNewGain(channel, mult*bitvolts);
404+
SourceNode* proc = channelList->proc;
405+
RHD2000Thread* thread = static_cast<RHD2000Thread*>(proc->getThread());
406+
thread->setAdcRange(proc->getDataChannel(channel)->getSourceTypeIndex(), comboBox->getSelectedId() - 1);
418407
}
419408
}
420409
void FPGAchannelComponent::labelTextChanged(Label* lbl)
@@ -450,9 +439,9 @@ int FPGAchannelComponent::getUserDefinedData()
450439
void FPGAchannelComponent::resized()
451440
{
452441
editName->setBounds(0,0,90,20);
453-
if (gainComboBox != nullptr)
442+
if (rangeComboBox != nullptr)
454443
{
455-
gainComboBox->setBounds(100,0,70,20);
444+
rangeComboBox->setBounds(100,0,80,20);
456445
}
457446
if (impedance != nullptr)
458447
{
@@ -934,6 +923,12 @@ void RHD2000Editor::saveCustomParameters(XmlElement* xml)
934923
xml->setAttribute("auto_measure_impedances",measureWhenRecording);
935924
xml->setAttribute("LEDs", ledButton->getToggleState());
936925
xml->setAttribute("ClockDivideRatio", clockInterface->getClockDivideRatio());
926+
for (int i = 0; i < 8; i++)
927+
{
928+
XmlElement* adc = xml->createNewChildElement("ADCRANGE");
929+
adc->setAttribute("Channel", i);
930+
adc->setAttribute("Range", board->getAdcRange(i));
931+
}
937932
}
938933

939934
void RHD2000Editor::loadCustomParameters(XmlElement* xml)
@@ -957,6 +952,13 @@ void RHD2000Editor::loadCustomParameters(XmlElement* xml)
957952
measureWhenRecording = xml->getBoolAttribute("auto_measure_impedances");
958953
ledButton->setToggleState(xml->getBoolAttribute("LEDs", true),sendNotification);
959954
clockInterface->setClockDivideRatio(xml->getIntAttribute("ClockDivideRatio"));
955+
forEachXmlChildElementWithTagName(*xml, adc, "ADCRANGE")
956+
{
957+
int channel = adc->getIntAttribute("Channel", -1);
958+
int range = adc->getIntAttribute("Range", -1);
959+
if (channel >= 0 && range >= 0)
960+
board->setAdcRange(channel, range);
961+
}
960962
}
961963

962964

Source/Plugins/RhythmNode/RHD2000Editor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class FPGAchannelComponent : public Component, Button::Listener, public ComboBox
118118
Array<float> gains;
119119
FPGAchannelList* channelList;
120120
ScopedPointer<Label> staticLabel, editName, impedance;
121-
ScopedPointer<ComboBox> gainComboBox;
121+
ScopedPointer<ComboBox> rangeComboBox;
122122
int channel;
123123
String name;
124124
int gainIndex;

Source/Plugins/RhythmNode/RHD2000Thread.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ RHD2000Thread::RHD2000Thread(SourceNode* sn) : DataThread(sn),
9797
memset(auxBuffer, 0, sizeof(auxBuffer));
9898
memset(auxSamples, 0, sizeof(auxSamples));
9999

100+
for (int i = 0; i < 8; i++)
101+
adcRangeSettings[i] = 0;
102+
100103
for (int i=0; i < MAX_NUM_HEADSTAGES; i++)
101104
headstagesArray.add(new RHDHeadstage(static_cast<Rhd2000EvalBoard::BoardDataSource>(i)));
102105

@@ -1578,9 +1581,10 @@ bool RHD2000Thread::updateBuffer()
15781581

15791582
channel++;
15801583
// ADC waveform units = volts
1581-
thisSample[channel] =
1584+
thisSample[channel] = adcRangeSettings[adcChan] == 0 ?
15821585
//0.000050354 * float(dataBlock->boardAdcData[adcChan][samp]);
1583-
0.00015258789 * float(*(uint16*)(bufferPtr + index)) - 5 - 0.4096; // account for +/-5V input range and DC offset
1586+
0.00015258789 * float(*(uint16*)(bufferPtr + index)) - 5 - 0.4096 : // account for +/-5V input range and DC offset
1587+
0.00030517578 * float(*(uint16*)(bufferPtr + index));
15841588
index += 2;
15851589
}
15861590
}
@@ -1764,6 +1768,16 @@ int RHD2000Thread::setClockDivider(int divide_ratio)
17641768
return divide_ratio;
17651769
}
17661770

1771+
void RHD2000Thread::setAdcRange(int channel, short range)
1772+
{
1773+
adcRangeSettings[channel] = range;
1774+
}
1775+
1776+
short RHD2000Thread::getAdcRange(int channel) const
1777+
{
1778+
return adcRangeSettings[channel];
1779+
}
1780+
17671781
void RHD2000Thread::runImpedanceTest(ImpedanceData* data)
17681782
{
17691783
impedanceThread->stopThreadSafely();

Source/Plugins/RhythmNode/RHD2000Thread.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include <stdio.h>
3030
#include <string.h>
31+
#include <array>
32+
#include <atomic>
3133

3234
#include "rhythm-api/rhd2000evalboard.h"
3335
#include "rhythm-api/rhd2000registers.h"
@@ -136,6 +138,10 @@ class RHD2000Thread : public DataThread
136138
void runImpedanceTest (ImpedanceData* data);
137139
void enableBoardLeds( bool enable);
138140
int setClockDivider (int divide_ratio);
141+
142+
void setAdcRange(int adcChannel, short rangeType);
143+
short getAdcRange(int adcChannel) const;
144+
139145
GenericEditor* createEditor (SourceNode* sn);
140146

141147
static DataThread* createDataThread (SourceNode* sn);
@@ -221,6 +227,9 @@ class RHD2000Thread : public DataThread
221227
// Sync ouput divide factor
222228
uint16 clockDivideFactor;
223229

230+
//ADC ranges
231+
std::array<atomic_short, 8> adcRangeSettings;
232+
224233
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(RHD2000Thread);
225234
};
226235

0 commit comments

Comments
 (0)