From 0ecf00cd375bb328bcc3456b76df7e333aa153d4 Mon Sep 17 00:00:00 2001 From: Josh Siegle Date: Fri, 5 Jul 2024 10:43:36 -0700 Subject: [PATCH] Allow block-based updating of activity view --- Source/Basestations/SimulatedBasestation.cpp | 2 +- Source/NeuropixEditor.cpp | 6 +- Source/Probes/Neuropixels_QuadBase.cpp | 22 ++++++- Source/UI/ActivityView.h | 62 ++++++++++++++------ Source/UI/NeuropixInterface.cpp | 4 +- Source/UI/WavePlayer.cpp | 8 +-- 6 files changed, 72 insertions(+), 32 deletions(-) diff --git a/Source/Basestations/SimulatedBasestation.cpp b/Source/Basestations/SimulatedBasestation.cpp index 97a8317..dde3de5 100644 --- a/Source/Basestations/SimulatedBasestation.cpp +++ b/Source/Basestations/SimulatedBasestation.cpp @@ -51,7 +51,7 @@ SimulatedBasestationConfigWindow::SimulatedBasestationConfigWindow (SimulatedBas comboBox->setBounds (65, 50 + 35 * i, 200, 20); } - acceptButton = std::make_unique ("LAUNCH", Font ("Small Text", 13, Font::plain)); + acceptButton = std::make_unique ("LAUNCH", FontOptions ("Small Text", 13, Font::plain)); acceptButton->setBounds (120, 200, 80, 20); acceptButton->addListener (this); addAndMakeVisible (acceptButton.get()); diff --git a/Source/NeuropixEditor.cpp b/Source/NeuropixEditor.cpp index 01a1aa2..d5aa2e9 100644 --- a/Source/NeuropixEditor.cpp +++ b/Source/NeuropixEditor.cpp @@ -101,8 +101,6 @@ void EditorBackground::paint (Graphics& g) g.setFont (10); g.drawText ("SLOT", 90 * i + 72, 15, 50, 12, Justification::centredLeft); - //g.setFont(26); - //g.drawText(String(basestations[i]->slot), 90 * i + 72, 28, 25, 26, Justification::centredLeft); g.setFont (8); g.drawText (String ("0"), 90 * i + 87, 100, 50, 10, Justification::centredLeft); g.drawText (String ("100"), 90 * i + 87, 60, 50, 10, Justification::centredLeft); @@ -444,7 +442,7 @@ NeuropixEditor::NeuropixEditor (GenericProcessor* parentNode, NeuropixThread* t) int x_pos = i * 90 + 70; int y_pos = 50; - UtilityButton* b = new UtilityButton ("", Font ("Small Text", 13, Font::plain)); + UtilityButton* b = new UtilityButton ("", FontOptions ("Small Text", 13, Font::plain)); b->setBounds (x_pos, y_pos, 30, 20); b->addListener (this); //addAndMakeVisible(b); @@ -501,7 +499,7 @@ NeuropixEditor::NeuropixEditor (GenericProcessor* parentNode, NeuropixThread* t) background->toBack(); background->repaint(); - addSyncChannelButton = std::make_unique ("+", Font ("Small Text", 13, Font::plain)); + addSyncChannelButton = std::make_unique ("+", FontOptions ("Small Text", 13, Font::plain)); addSyncChannelButton->setBounds (90 * basestations.size() + 78, 40, 20, 20); addSyncChannelButton->addListener (this); addSyncChannelButton->setTooltip ("Add sync channel to the continuous data stream."); diff --git a/Source/Probes/Neuropixels_QuadBase.cpp b/Source/Probes/Neuropixels_QuadBase.cpp index 0a5f53c..f1dfa26 100644 --- a/Source/Probes/Neuropixels_QuadBase.cpp +++ b/Source/Probes/Neuropixels_QuadBase.cpp @@ -111,7 +111,20 @@ bool Neuropixels_QuadBase::open() lfp_timestamp = 0; eventCode = 0; - apView = new ActivityView (384 * 4, 3000); + Array> blocks; + + for (int shank = 0; shank < 4; shank++) + { + + blocks.add (Array()); + + for (int i = 0; i < 384; i++) + { + blocks.getReference(shank).add (i + 384 * shank); + } + } + + apView = new ActivityView (384 * 4, 3000, blocks); return errorCode == Neuropixels::SUCCESS; } @@ -325,12 +338,15 @@ void Neuropixels_QuadBase::writeConfiguration() void Neuropixels_QuadBase::startAcquisition() { - apView->reset(); + if (acquisitionThreads.size() == 0) { for (int shank = 0; shank < 4; shank++) { + + apView->reset(shank); + quadBaseBuffers[shank]->clear(); acquisitionThreads.add ( @@ -454,7 +470,7 @@ void AcquisitionThread::run() apSamples[packetNum + count * j] = float (data[packetNum * shank_channel_count + j]) / 4096.0f / 100.0f * 1000000.0f; // convert to microvolts - apView->addSample (apSamples[packetNum + count * j], j + shank * 384); + apView->addSample (apSamples[packetNum + count * j], j + shank * 384, shank); } if (sendSync) diff --git a/Source/UI/ActivityView.h b/Source/UI/ActivityView.h index 0a03e78..ddc62b3 100644 --- a/Source/UI/ActivityView.h +++ b/Source/UI/ActivityView.h @@ -41,14 +41,37 @@ Helper class for viewing real-time activity across the probe. class ActivityView { public: - ActivityView (int numChannels, int updateInterval_) + ActivityView (int numChannels, int updateInterval_, Array> blocks_ = Array>()) { - for (int i = 0; i < numChannels; i++) - peakToPeakValues.add (0); + if (blocks_.size() == 0) + { + Array block; + + for (int i = 0; i < numChannels; i++) + { + block.add (i); + } + blocks.add (block); + } + else + { + blocks = blocks_; + } + updateInterval = updateInterval_; - reset(); + for (int i = 0; i < numChannels; i++) + { + minChannelValues.add (999999.9f); + maxChannelValues.add (-999999.9f); + peakToPeakValues.add (0); + } + + for (int i = 0; i < blocks.size(); i++) + { + counters.add (0); + } } const float* getPeakToPeakValues() @@ -56,17 +79,17 @@ class ActivityView return peakToPeakValues.getRawDataPointer(); } - void addSample (float sample, int channel) + void addSample (float sample, int channel, int block=0) { - if (channel == 0) + if (channel == blocks[block][0]) { - if (counter == updateInterval) - reset(); + if (counters[block] == updateInterval) + reset(block); - counter++; + counters.set (block, counters[block] + 1); } - if (counter % 10 == 0) + if (counters[block] % 10 == 0) { if (sample < minChannelValues[channel]) { @@ -81,17 +104,19 @@ class ActivityView } } - void reset() + void reset(int blockIndex = 0) { - for (int i = 0; i < peakToPeakValues.size(); i++) - { - peakToPeakValues.set (i, maxChannelValues[i] - minChannelValues[i]); - minChannelValues.set (i, 999999.9f); - maxChannelValues.set (i, -999999.9f); + for (auto ch : blocks[blockIndex]) + { + peakToPeakValues.set (ch, maxChannelValues[ch] - minChannelValues[ch]); + minChannelValues.set (ch, 999999.9f); + maxChannelValues.set (ch, -999999.9f); } - counter = 0; + counters.set (blockIndex, 0); + + } private: @@ -99,7 +124,8 @@ class ActivityView Array maxChannelValues; Array peakToPeakValues; - int counter; + Array> blocks; + Array counters; int updateInterval; }; diff --git a/Source/UI/NeuropixInterface.cpp b/Source/UI/NeuropixInterface.cpp index 682c7e3..e5e1f72 100644 --- a/Source/UI/NeuropixInterface.cpp +++ b/Source/UI/NeuropixInterface.cpp @@ -1477,7 +1477,7 @@ bool NeuropixInterface::applyProbeSettings (ProbeSettings p, bool shouldUpdatePr probe->settings.clearElectrodeSelection(); - for (auto electrode : electrodeMetadata) + for (auto const electrode : electrodeMetadata) { if (electrode.status == ElectrodeStatus::CONNECTED) { @@ -1563,7 +1563,7 @@ ProbeSettings NeuropixInterface::getProbeSettings() if (p.probeType != ProbeType::UHD2) { - for (auto electrode : electrodeMetadata) + for (auto const electrode : electrodeMetadata) { if (electrode.status == ElectrodeStatus::CONNECTED) { diff --git a/Source/UI/WavePlayer.cpp b/Source/UI/WavePlayer.cpp index 4ba2a8e..f2547d8 100644 --- a/Source/UI/WavePlayer.cpp +++ b/Source/UI/WavePlayer.cpp @@ -97,25 +97,25 @@ WavePlayer::WavePlayer (OneBoxDAC* dac_) patternSelector->setEditableText (true); addAndMakeVisible (patternSelector); - startStopButton = new UtilityButton ("RUN", Font ("Small Text", 15, Font::plain)); + startStopButton = new UtilityButton ("RUN", FontOptions ("Small Text", 15, Font::plain)); startStopButton->setBounds (30, 85, 55, 30); startStopButton->addListener (this); addAndMakeVisible (startStopButton); - pulsePatternButton = new UtilityButton ("Pulse", Font ("Small Text", 10, Font::plain)); + pulsePatternButton = new UtilityButton ("Pulse", FontOptions ("Small Text", 10, Font::plain)); pulsePatternButton->setCorners (true, false, true, false); pulsePatternButton->setBounds (140, 40, 50, 20); pulsePatternButton->addListener (this); pulsePatternButton->setToggleState (true, false); addAndMakeVisible (pulsePatternButton); - sinePatternButton = new UtilityButton ("Sine", Font ("Small Text", 10, Font::plain)); + sinePatternButton = new UtilityButton ("Sine", FontOptions ("Small Text", 10, Font::plain)); sinePatternButton->setCorners (false, false, false, false); sinePatternButton->setBounds (190, 40, 50, 20); sinePatternButton->addListener (this); addAndMakeVisible (sinePatternButton); - customPatternButton = new UtilityButton ("Custom", Font ("Small Text", 10, Font::plain)); + customPatternButton = new UtilityButton ("Custom", FontOptions ("Small Text", 10, Font::plain)); customPatternButton->setCorners (false, true, false, true); customPatternButton->setBounds (240, 40, 60, 20); customPatternButton->addListener (this);