Skip to content

Commit

Permalink
ProbeSettings follow probe serial number when moved
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Aug 23, 2024
1 parent 8c615aa commit b4dcd6b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 52 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"files.associations": {
"list": "cpp",
"vector": "cpp"
"vector": "cpp",
"xhash": "cpp",
"xstring": "cpp",
"xutility": "cpp"
}
}
78 changes: 29 additions & 49 deletions Source/NeuropixEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,65 +317,49 @@ void BackgroundLoader::run()

if (isRefreshing)
{
std::map<std::tuple<int, int, int>, std::pair<int, ProbeSettings>> updatedMap;

ProbeSettings temp;
LOGC("Scanning for hardware changes...");
//Assume basestation counts/slots do not change
for (int i = 0; i < thread->getBasestations().size(); i++) {
Basestation* bs = thread->getBasestations()[i];
if (bs != nullptr) {
/*
for (auto probe : bs->getProbes()) {
if (probe != nullptr) {
Neuropixels::NP_ErrorCode err = Neuropixels::closePort (bs->slot, probe->headstage->port);
LOGD("### Closing port ", probe->headstage->port, " on slot ", bs->slot, " returned ", err);
if (err == 8) {
LOGD("### Probe was most likely disconnected...");
}
}
}
*/
bs->close();
bs->open();
//bs->probes.clear();
//bs->headstages.clear();
//bs->searchForProbes(); //populates headstages and probes
for (auto hs : bs->getHeadstages()) {
if (hs != nullptr) {
for (auto probe : hs->getProbes()) {
if (probe != nullptr) {
LOGC("### Found probe on slot ", bs->slot, " port ", hs->port, " dock ", probe->dock, " with serial number ", probe->info.serial_number);
//check if probe key exists
std::tuple<int, int, int> current_location = std::make_tuple(bs->slot, hs->port, probe->dock);
if (thread->probeMap.find(current_location) != thread->probeMap.end()) {
//There was a probe there before refresh, make sure it's still the same probe by checking serial number
// There is a probe in the map at this location
if (std::get<0>(thread->probeMap[current_location]) == probe->info.serial_number) {
//It's the same probe as before, apply the saved settings for this probe
LOGC("### Found same probe on slot ", bs->slot, " port ", hs->port, " dock ", probe->dock, " with serial number ", probe->info.serial_number);
//thread->updateProbeSettingsQueue(ProbeSettings(probeMap[key].second));
LOGC ("### Found same probe in same location!");
//Serial number matches the previous one, just copy entry to updated map
temp = ProbeSettings(thread->probeMap[current_location].second);
temp.probe = probe;
updatedMap[current_location] = std::make_pair(probe->info.serial_number, temp);
}
//else check if serial number of current probe is from somewhere else in the map
else {
bool found = false;
std::tuple<int, int, int> old_location;
for (auto it = thread->probeMap.begin(); it != thread->probeMap.end(); it++) {
if (it->second.first == probe->info.serial_number) {
found = true;
old_location = it->first;
break;
}
}
if (!found) {
LOGC("###Found new probe on slot ", bs->slot, " port ", hs->port, " dock ", probe->dock, " with serial number ", probe->info.serial_number);
}
else
{
LOGC("###Found probe was moved from: slot ", std::get<0>(old_location), " port ", std::get<1>(old_location), " dock ", std::get<2>(old_location), " to slot ", bs->slot, " port ", hs->port, " dock ", probe->dock);
}
}


}
else
{
//Check if probe serial number is in the map
bool found = false;
std::tuple<int, int, int> old_location;
for (auto it = thread->probeMap.begin(); it != thread->probeMap.end(); it++) {
uint64 old_serial = it->second.first;
if (old_serial == probe->info.serial_number) {
found = true;
old_location = it->first;
temp = ProbeSettings(it->second.second);
temp.probe = probe;
updatedMap[current_location] = std::make_pair(probe->info.serial_number, temp);
//delete old-location entry
thread->probeMap.erase(it);
break;
}
}
LOGC("###Found new probe on slot ", bs->slot, " port ", hs->port, " dock ", probe->dock, " with serial number ", probe->info.serial_number);
}
}
Expand All @@ -387,20 +371,16 @@ void BackgroundLoader::run()
thread->initializeProbes();
thread->updateStreamInfo();

for (auto probe : thread->getProbes())
{
//Apply saved settings here
thread->updateProbeSettingsQueue (ProbeSettings (probe->settings));
}

MessageManagerLock mml;
editor->drawBasestations(thread->getBasestations());
editor->resetCanvas();

//TODO: This needs to be generalized to match probes to the correct interfaces
editor->canvas->settingsInterfaces[0]->applyProbeSettings(temp, true);

isRefreshing = false;
thread->isRefreshing = false;

editor->resetCanvas();

CoreServices::updateSignalChain (editor);
}

Expand Down
3 changes: 2 additions & 1 deletion Source/NeuropixEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ class NeuropixEditor : public VisualizerEditor,

std::unique_ptr<BackgroundLoader> uiLoader;

NeuropixCanvas* canvas;

private:
OwnedArray<UtilityButton> directoryButtons;
OwnedArray<FifoMonitor> fifoMonitors;
Expand All @@ -286,7 +288,6 @@ class NeuropixEditor : public VisualizerEditor,
std::unique_ptr<UtilityButton> refreshButton;

Viewport* viewport;
NeuropixCanvas* canvas;
NeuropixThread* thread;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NeuropixEditor);
Expand Down
2 changes: 1 addition & 1 deletion Source/NeuropixThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class NeuropixThread : public DataThread, public Timer

DeviceType type;

// Map from <slot,port,dock> to <probe_serial, probe_settings>
/** Map from <slot,port,dock> to <probe_serial, probe_settings> */
std::map<std::tuple<int,int,int>, std::pair<uint64, ProbeSettings>> probeMap;

bool isRefreshing = false;
Expand Down

0 comments on commit b4dcd6b

Please sign in to comment.