Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions OpenEphys.Onix1/NeuropixelsV2eBetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@ public unsafe override IObservable<NeuropixelsV2eBetaDataFrame> Generate()
return DeviceManager.GetDevice(DeviceName).SelectMany(deviceInfo =>
{
var info = (NeuropixelsV2eDeviceInfo)deviceInfo;
var metadata = ProbeIndex switch
var (metadata, gainCorrection) = ProbeIndex switch
{
NeuropixelsV2Probe.ProbeA => info.ProbeMetadataA,
NeuropixelsV2Probe.ProbeB => info.ProbeMetadataB,
NeuropixelsV2Probe.ProbeA => (info.ProbeMetadataA, info.GainCorrectionA),
NeuropixelsV2Probe.ProbeB => (info.ProbeMetadataB, info.GainCorrectionB),
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
};

if (metadata.ProbeSerialNumber == null)
{
throw new InvalidOperationException($"{ProbeIndex} is not detected. Ensure that the flex connection is properly seated.");
}
else if (gainCorrection == null)
{
throw new NullReferenceException($"Gain correction value is null for {ProbeIndex}.");
}

var device = info.GetDeviceContext(typeof(NeuropixelsV2eBeta));
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
Expand All @@ -70,13 +74,6 @@ public unsafe override IObservable<NeuropixelsV2eBetaDataFrame> Generate()
.Where(frame => NeuropixelsV2eBetaDataFrame.GetProbeIndex(frame) == (int)ProbeIndex);
var invertPolarity = info.InvertPolarity;

var gainCorrection = ProbeIndex switch
{
NeuropixelsV2Probe.ProbeA => (double)info.GainCorrectionA,
NeuropixelsV2Probe.ProbeB => (double)info.GainCorrectionB,
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
};

return Observable.Create<NeuropixelsV2eBetaDataFrame>(observer =>
{
var sampleIndex = 0;
Expand All @@ -89,7 +86,7 @@ public unsafe override IObservable<NeuropixelsV2eBetaDataFrame> Generate()
frame =>
{
var payload = (NeuropixelsV2BetaPayload*)frame.Data.ToPointer();
NeuropixelsV2eBetaDataFrame.CopyAmplifierBuffer(payload->SuperFrame, amplifierBuffer, frameCounter, sampleIndex, gainCorrection, invertPolarity);
NeuropixelsV2eBetaDataFrame.CopyAmplifierBuffer(payload->SuperFrame, amplifierBuffer, frameCounter, sampleIndex, gainCorrection.Value, invertPolarity);
hubClockBuffer[sampleIndex] = payload->HubClock;
clockBuffer[sampleIndex] = frame.Clock;
if (++sampleIndex >= bufferSize)
Expand Down
19 changes: 8 additions & 11 deletions OpenEphys.Onix1/NeuropixelsV2eData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ public unsafe override IObservable<NeuropixelsV2eDataFrame> Generate()
return DeviceManager.GetDevice(DeviceName).SelectMany(deviceInfo =>
{
var info = (NeuropixelsV2eDeviceInfo)deviceInfo;
var metadata = ProbeIndex switch
var (metadata, gainCorrection) = ProbeIndex switch
{
NeuropixelsV2Probe.ProbeA => info.ProbeMetadataA,
NeuropixelsV2Probe.ProbeB => info.ProbeMetadataB,
NeuropixelsV2Probe.ProbeA => (info.ProbeMetadataA, info.GainCorrectionA),
NeuropixelsV2Probe.ProbeB => (info.ProbeMetadataB, info.GainCorrectionB),
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
};

if (metadata.ProbeSerialNumber == null)
{
throw new InvalidOperationException($"{ProbeIndex} is not detected. Ensure that the flex connection is properly seated.");
}
else if (gainCorrection == null)
{
throw new NullReferenceException($"Gain correction value is null for {ProbeIndex}.");
}

var device = info.GetDeviceContext(typeof(NeuropixelsV2e));
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
Expand All @@ -74,13 +78,6 @@ public unsafe override IObservable<NeuropixelsV2eDataFrame> Generate()
.Where(frame => NeuropixelsV2eDataFrame.GetProbeIndex(frame) == (int)ProbeIndex);
var invertPolarity = info.InvertPolarity;

var gainCorrection = ProbeIndex switch
{
NeuropixelsV2Probe.ProbeA => (double)info.GainCorrectionA,
NeuropixelsV2Probe.ProbeB => (double)info.GainCorrectionB,
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
};

return Observable.Create<NeuropixelsV2eDataFrame>(observer =>
{
var sampleIndex = 0;
Expand All @@ -92,7 +89,7 @@ public unsafe override IObservable<NeuropixelsV2eDataFrame> Generate()
frame =>
{
var payload = (NeuropixelsV2Payload*)frame.Data.ToPointer();
NeuropixelsV2eDataFrame.CopyAmplifierBuffer(payload->AmplifierData, amplifierBuffer, sampleIndex, gainCorrection, invertPolarity);
NeuropixelsV2eDataFrame.CopyAmplifierBuffer(payload->AmplifierData, amplifierBuffer, sampleIndex, gainCorrection.Value, invertPolarity);
hubClockBuffer[sampleIndex] = payload->HubClock;
clockBuffer[sampleIndex] = frame.Clock;
if (++sampleIndex >= bufferSize)
Expand Down