diff --git a/OpenEphys.Onix1/NeuropixelsV2eBetaData.cs b/OpenEphys.Onix1/NeuropixelsV2eBetaData.cs index 846e1a5d..b347ceb4 100644 --- a/OpenEphys.Onix1/NeuropixelsV2eBetaData.cs +++ b/OpenEphys.Onix1/NeuropixelsV2eBetaData.cs @@ -51,10 +51,10 @@ public unsafe override IObservable 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}") }; @@ -62,6 +62,10 @@ public unsafe override IObservable Generate() { 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)); @@ -70,13 +74,6 @@ public unsafe override IObservable 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(observer => { var sampleIndex = 0; @@ -89,7 +86,7 @@ public unsafe override IObservable 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) diff --git a/OpenEphys.Onix1/NeuropixelsV2eData.cs b/OpenEphys.Onix1/NeuropixelsV2eData.cs index c01a0d15..12625c9d 100644 --- a/OpenEphys.Onix1/NeuropixelsV2eData.cs +++ b/OpenEphys.Onix1/NeuropixelsV2eData.cs @@ -55,10 +55,10 @@ public unsafe override IObservable 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}") }; @@ -66,6 +66,10 @@ public unsafe override IObservable Generate() { 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)); @@ -74,13 +78,6 @@ public unsafe override IObservable 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(observer => { var sampleIndex = 0; @@ -92,7 +89,7 @@ public unsafe override IObservable 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)