Skip to content

Commit 3563597

Browse files
authored
Merge pull request #220 from open-ephys/issue-191
Implement ConfigureNeuropixelV1/2eBno055.Enable
2 parents 048e90e + 499b815 commit 3563597

File tree

4 files changed

+75
-43
lines changed

4 files changed

+75
-43
lines changed

OpenEphys.Onix1/ConfigureNeuropixelsV1eBno055.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
5151
var device = context.GetPassthroughDeviceContext(deviceAddress, typeof(DS90UB9x));
5252
ConfigureDeserializer(device);
5353
ConfigureBno055(device);
54-
var deviceInfo = new DeviceInfo(context, DeviceType, deviceAddress);
54+
var deviceInfo = new NeuropixelsV1eBno055DeviceInfo(context, DeviceType, deviceAddress, enable);
5555
return DeviceManager.RegisterDevice(deviceName, deviceInfo);
5656
});
5757
}
@@ -91,4 +91,15 @@ public NameConverter()
9191
}
9292
}
9393
}
94+
95+
class NeuropixelsV1eBno055DeviceInfo : DeviceInfo
96+
{
97+
public NeuropixelsV1eBno055DeviceInfo(ContextTask context, Type deviceType, uint deviceAddress, bool enable)
98+
: base(context, deviceType, deviceAddress)
99+
{
100+
Enable = enable;
101+
}
102+
103+
public bool Enable { get; }
104+
}
94105
}

OpenEphys.Onix1/ConfigureNeuropixelsV2eBno055.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
5151
var device = context.GetPassthroughDeviceContext(deviceAddress, typeof(DS90UB9x));
5252
ConfigureDeserializer(device);
5353
ConfigureBno055(device);
54-
var deviceInfo = new DeviceInfo(context, DeviceType, deviceAddress);
54+
var deviceInfo = new NeuropixelsV2eBno055DeviceInfo(context, DeviceType, deviceAddress, enable);
5555
return DeviceManager.RegisterDevice(deviceName, deviceInfo);
5656
});
5757
}
@@ -91,4 +91,15 @@ public NameConverter()
9191
}
9292
}
9393
}
94+
95+
class NeuropixelsV2eBno055DeviceInfo : DeviceInfo
96+
{
97+
public NeuropixelsV2eBno055DeviceInfo(ContextTask context, Type deviceType, uint deviceAddress, bool enable)
98+
: base(context, deviceType, deviceAddress)
99+
{
100+
Enable = enable;
101+
}
102+
103+
public bool Enable { get; }
104+
}
94105
}

OpenEphys.Onix1/NeuropixelsV1eBno055Data.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,37 @@ public override IObservable<Bno055DataFrame> Generate()
3939
public unsafe IObservable<Bno055DataFrame> Generate<TSource>(IObservable<TSource> source)
4040
{
4141
return DeviceManager.GetDevice(DeviceName).SelectMany(
42-
deviceInfo => Observable.Create<Bno055DataFrame>(observer =>
42+
deviceInfo =>
4343
{
44-
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV1eBno055));
45-
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
46-
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV1eBno055.BNO055Address);
47-
48-
return source.SubscribeSafe(observer, _ =>
44+
return !((NeuropixelsV1eBno055DeviceInfo)deviceInfo).Enable
45+
? Observable.Empty<Bno055DataFrame>()
46+
: Observable.Create<Bno055DataFrame>(observer =>
4947
{
50-
Bno055DataFrame frame = default;
51-
device.Context.EnsureContext(() =>
48+
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV1eBno055));
49+
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
50+
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV1eBno055.BNO055Address);
51+
52+
return source.SubscribeSafe(observer, _ =>
5253
{
53-
var data = i2c.ReadBytes(NeuropixelsV1eBno055.DataAddress, sizeof(Bno055DataPayload));
54-
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
55-
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
56-
fixed (byte* dataPtr = data)
54+
Bno055DataFrame frame = default;
55+
device.Context.EnsureContext(() =>
56+
{
57+
var data = i2c.ReadBytes(NeuropixelsV1eBno055.DataAddress, sizeof(Bno055DataPayload));
58+
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
59+
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
60+
fixed (byte* dataPtr = data)
61+
{
62+
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
63+
}
64+
});
65+
66+
if (frame != null)
5767
{
58-
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
68+
observer.OnNext(frame);
5969
}
6070
});
61-
62-
if (frame != null)
63-
{
64-
observer.OnNext(frame);
65-
}
6671
});
67-
}));
72+
});
6873
}
6974
}
7075
}

OpenEphys.Onix1/NeuropixelsV2eBno055Data.cs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,37 @@ public override IObservable<Bno055DataFrame> Generate()
3939
public unsafe IObservable<Bno055DataFrame> Generate<TSource>(IObservable<TSource> source)
4040
{
4141
return DeviceManager.GetDevice(DeviceName).SelectMany(
42-
deviceInfo => Observable.Create<Bno055DataFrame>(observer =>
42+
deviceInfo =>
4343
{
44-
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV2eBno055));
45-
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
46-
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV2eBno055.BNO055Address);
47-
48-
return source.SubscribeSafe(observer, _ =>
49-
{
50-
Bno055DataFrame frame = default;
51-
device.Context.EnsureContext(() =>
44+
return !((NeuropixelsV2eBno055DeviceInfo)deviceInfo).Enable
45+
? Observable.Empty<Bno055DataFrame>()
46+
: Observable.Create<Bno055DataFrame>(observer =>
5247
{
53-
var data = i2c.ReadBytes(NeuropixelsV2eBno055.DataAddress, sizeof(Bno055DataPayload));
54-
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
55-
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
56-
fixed (byte* dataPtr = data)
48+
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV2eBno055));
49+
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
50+
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV2eBno055.BNO055Address);
51+
52+
return source.SubscribeSafe(observer, _ =>
5753
{
58-
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
59-
}
60-
});
54+
Bno055DataFrame frame = default;
55+
device.Context.EnsureContext(() =>
56+
{
57+
var data = i2c.ReadBytes(NeuropixelsV2eBno055.DataAddress, sizeof(Bno055DataPayload));
58+
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
59+
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
60+
fixed (byte* dataPtr = data)
61+
{
62+
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
63+
}
64+
});
6165

62-
if (frame != null)
63-
{
64-
observer.OnNext(frame);
65-
}
66-
});
67-
}));
66+
if (frame != null)
67+
{
68+
observer.OnNext(frame);
69+
}
70+
});
71+
});
72+
});
6873
}
6974
}
7075
}

0 commit comments

Comments
 (0)