Skip to content

Commit c14ee3a

Browse files
committed
Refactor Neuropixels metadata
- Introduced NeuropixelsProbeMetadata class to encapsulate probe metadata retrieval and management. - Updated Neuropixels1e, Neuropixels1f, and Neuropixels2e classes to utilize the new metadata class for serial number, part number, and flex version retrieval. - Enhanced UI components to display probe part number and flex information. - Improved error handling and logging for metadata reading processes.
1 parent 358eb72 commit c14ee3a

13 files changed

+478
-149
lines changed

Source/Devices/Neuropixels1.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,37 @@ void Neuropixels1::defineMetadata (ProbeSettings<numberOfChannels, numberOfElect
302302

303303
uint64_t Neuropixels1::getProbeSerialNumber (int index)
304304
{
305-
return probeNumber;
305+
return probeMetadata.getProbeSerialNumber();
306+
}
307+
308+
std::string Neuropixels1::getProbePartNumber (int index)
309+
{
310+
return probeMetadata.getProbePartNumber();
311+
}
312+
313+
std::string Neuropixels1::getFlexPartNumber (int index)
314+
{
315+
return probeMetadata.getFlexPartNumber();
316+
}
317+
318+
std::string Neuropixels1::getFlexVersion (int index)
319+
{
320+
return probeMetadata.getFlexVersion();
306321
}
307322

308323
bool Neuropixels1::parseGainCalibrationFile()
309324
{
310325
if (gainCalibrationFilePath == "None" || gainCalibrationFilePath == "")
311326
{
312-
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing gain calibration file for probe " + std::to_string (probeNumber));
327+
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing gain calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
313328
return false;
314329
}
315330

316331
File gainFile = File (gainCalibrationFilePath);
317332

318333
if (! gainFile.existsAsFile())
319334
{
320-
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid gain calibration file for probe " + std::to_string (probeNumber));
335+
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid gain calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
321336
return false;
322337
}
323338

@@ -328,9 +343,9 @@ bool Neuropixels1::parseGainCalibrationFile()
328343

329344
LOGD ("Gain calibration file SN = ", gainSN);
330345

331-
if (gainSN != probeNumber)
346+
if (gainSN != probeMetadata.getProbeSerialNumber())
332347
{
333-
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "Gain calibration file serial number (" + std::to_string (gainSN) + ") does not match probe serial number (" + std::to_string (probeNumber) + ").");
348+
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "Gain calibration file serial number (" + std::to_string (gainSN) + ") does not match probe serial number (" + std::to_string (probeMetadata.getProbeSerialNumber()) + ").");
334349
return false;
335350
}
336351

@@ -366,15 +381,15 @@ bool Neuropixels1::parseAdcCalibrationFile()
366381
{
367382
if (adcCalibrationFilePath == "None" || adcCalibrationFilePath == "")
368383
{
369-
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing ADC calibration file for probe " + std::to_string (probeNumber));
384+
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing ADC calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
370385
return false;
371386
}
372387

373388
File adcFile = File (adcCalibrationFilePath);
374389

375390
if (! adcFile.existsAsFile())
376391
{
377-
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid ADC calibration file for probe " + std::to_string (probeNumber));
392+
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid ADC calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
378393
return false;
379394
}
380395

@@ -385,9 +400,9 @@ bool Neuropixels1::parseAdcCalibrationFile()
385400

386401
LOGD ("ADC calibration file SN = ", adcSN);
387402

388-
if (adcSN != probeNumber)
403+
if (adcSN != probeMetadata.getProbeSerialNumber())
389404
{
390-
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "ADC calibration serial number (" + std::to_string (adcSN) + ") does not match probe serial number (" + std::to_string (probeNumber) + ").");
405+
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "ADC calibration serial number (" + std::to_string (adcSN) + ") does not match probe serial number (" + std::to_string (probeMetadata.getProbeSerialNumber()) + ").");
391406
return false;
392407
}
393408

Source/Devices/Neuropixels1.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "../I2CRegisterContext.h"
2626
#include "../NeuropixelsComponents.h"
27-
#include "../OnixDevice.h"
27+
#include "NeuropixelsProbeMetadata.h"
2828

2929
namespace OnixSourcePlugin
3030
{
@@ -52,10 +52,13 @@ class Neuropixels1 : public INeuropixel<NeuropixelsV1Values::numberOfChannels, N
5252
/** Select a preset electrode configuration, based on the index of the given enum */
5353
std::vector<int> selectElectrodeConfiguration (int electrodeConfigurationIndex) override;
5454

55-
uint64_t getProbeSerialNumber (int index = 0) override;
56-
5755
void setSettings (ProbeSettings<numberOfChannels, numberOfElectrodes>* settings_, int index = 0) override;
5856

57+
uint64_t getProbeSerialNumber (int index = 0) override;
58+
std::string getProbePartNumber (int index = 0) override;
59+
std::string getFlexPartNumber (int index = 0) override;
60+
std::string getFlexVersion (int index = 0) override;
61+
5962
bool parseGainCalibrationFile();
6063
bool parseAdcCalibrationFile();
6164

@@ -73,7 +76,7 @@ class Neuropixels1 : public INeuropixel<NeuropixelsV1Values::numberOfChannels, N
7376

7477
const uint32_t ENABLE = 0x8000;
7578

76-
static constexpr int ProbeI2CAddress = 0x70;
79+
NeuropixelsProbeMetadata probeMetadata;
7780

7881
static constexpr int superFramesPerUltraFrame = 12;
7982
static constexpr int framesPerSuperFrame = 13;
@@ -84,6 +87,9 @@ class Neuropixels1 : public INeuropixel<NeuropixelsV1Values::numberOfChannels, N
8487
static constexpr uint16_t NumberOfAdcBins = 1024;
8588
static constexpr float DataMidpoint = NumberOfAdcBins / 2;
8689

90+
static constexpr int ProbeI2CAddress = 0x70;
91+
static constexpr int FlexEepromI2CAddress = 0x50;
92+
8793
static constexpr int secondsToSettle = 5;
8894
static constexpr int samplesToAverage = 100;
8995

Source/Devices/Neuropixels1e.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ Neuropixels1e::Neuropixels1e (std::string name, std::string hubName, const oni_d
117117
apEventCodes[i] = 0;
118118
lfpEventCodes[i] = 0;
119119
}
120-
121-
probeNumber = 0;
122120
}
123121

124122
int Neuropixels1e::configureDevice()
@@ -132,25 +130,10 @@ int Neuropixels1e::configureDevice()
132130
if (rc != ONI_ESUCCESS)
133131
throw error_str ("Unable to set I2C rate for " + getName());
134132

135-
// Get Probe SN
136-
137-
int errorCode = 0;
138-
139-
for (int i = 0; i < 8; i++)
140-
{
141-
oni_reg_val_t reg_val;
142-
rc = flex->ReadByte (OFFSET_ID + i, &reg_val);
143-
144-
if (rc != ONI_ESUCCESS)
145-
throw error_str ("Unable to read the probe serial number for device at address " + getDeviceIdx());
146-
147-
if (reg_val <= 0xFF)
148-
{
149-
probeNumber |= (((uint64_t) reg_val) << (i * 8));
150-
}
151-
}
133+
// Get Probe Metadata
134+
probeMetadata = NeuropixelsProbeMetadata (flex.get(), OnixDeviceType::NEUROPIXELSV1E);
152135

153-
LOGD ("Probe SN: ", probeNumber);
136+
LOGD ("Probe SN: ", probeMetadata.getProbeSerialNumber());
154137

155138
return ONI_ESUCCESS;
156139
}

Source/Devices/Neuropixels1e.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,15 @@ class Neuropixels1e : public Neuropixels1
5353

5454
static constexpr int FlexEepromI2CAddress = 0x50;
5555

56-
static constexpr uint32_t OFFSET_ID = 0;
57-
static constexpr uint32_t OFFSET_VERSION = 10;
58-
static constexpr uint32_t OFFSET_REVISION = 11;
59-
static constexpr uint32_t OFFSET_FLEXPN = 20;
60-
static constexpr uint32_t OFFSET_PROBEPN = 40;
56+
std::unique_ptr<I2CRegisterContext> deserializer;
57+
std::unique_ptr<I2CRegisterContext> serializer;
58+
std::unique_ptr<I2CRegisterContext> flex;
6159

6260
static constexpr uint8_t DefaultGPO10Config = 0b00010001; // GPIO0 Low, NP in MUX reset
6361
static constexpr uint8_t DefaultGPO32Config = 0b10010001; // LED off, GPIO1 Low
6462
static constexpr uint32_t Gpo10ResetMask = 1 << 3; // Used to issue mux reset command to probe
6563
static constexpr uint32_t Gpo32LedMask = 1 << 7; // Used to turn on and off LED
6664

67-
std::unique_ptr<I2CRegisterContext> deserializer;
68-
std::unique_ptr<I2CRegisterContext> serializer;
69-
std::unique_ptr<I2CRegisterContext> flex;
70-
7165
void resetProbe();
7266
void writeShiftRegisters();
7367

Source/Devices/Neuropixels1f.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ Neuropixels1f::Neuropixels1f (std::string name, std::string hubName, const oni_d
105105
apEventCodes[i] = 0;
106106
lfpEventCodes[i] = 0;
107107
}
108-
109-
probeNumber = 0;
110108
}
111109

112110
int Neuropixels1f::configureDevice()
@@ -123,32 +121,11 @@ int Neuropixels1f::configureDevice()
123121
return ONI_ESUCCESS;
124122
}
125123

126-
// Get Probe SN
127-
uint32_t eepromOffset = 0;
128-
uint32_t i2cAddr = 0x50;
129-
int errorCode = 0;
130-
131-
for (int i = 0; i < 8; i++)
132-
{
133-
oni_reg_addr_t reg_addr = ((eepromOffset + i) << 7) | i2cAddr;
134-
135-
oni_reg_val_t reg_val;
136-
rc = deviceContext->readRegister (deviceIdx, reg_addr, &reg_val);
137-
138-
if (rc != ONI_ESUCCESS)
139-
{
140-
LOGE (oni_error_str (rc));
141-
throw error_str ("Could not communicate with " + getName() + " on " + getHubName()
142-
+ ". Ensure that the flex connection is properly seated, or disable the device if it is not connected.");
143-
}
144-
145-
if (reg_val <= 0xFF)
146-
{
147-
probeNumber |= (((uint64_t) reg_val) << (i * 8));
148-
}
149-
}
124+
// Get Probe Metadata
125+
auto flex = std::make_unique<I2CRegisterContext> (FlexEepromI2CAddress, deviceIdx, deviceContext);
126+
probeMetadata = NeuropixelsProbeMetadata (flex.get(), OnixDeviceType::NEUROPIXELSV1F);
150127

151-
LOGD ("Probe SN: ", probeNumber);
128+
LOGD ("Probe SN: ", probeMetadata.getProbeSerialNumber());
152129

153130
// Enable device streaming
154131
rc = deviceContext->writeRegister (deviceIdx, 0x8000, 1);

0 commit comments

Comments
 (0)