Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ConfigureNeuropixelV1/2eBno055.Enable #220

Merged
merged 1 commit into from
Aug 20, 2024
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
13 changes: 12 additions & 1 deletion OpenEphys.Onix1/ConfigureNeuropixelsV1eBno055.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var device = context.GetPassthroughDeviceContext(deviceAddress, typeof(DS90UB9x));
ConfigureDeserializer(device);
ConfigureBno055(device);
var deviceInfo = new DeviceInfo(context, DeviceType, deviceAddress);
var deviceInfo = new NeuropixelsV1eBno055DeviceInfo(context, DeviceType, deviceAddress, enable);
return DeviceManager.RegisterDevice(deviceName, deviceInfo);
});
}
Expand Down Expand Up @@ -91,4 +91,15 @@ public NameConverter()
}
}
}

class NeuropixelsV1eBno055DeviceInfo : DeviceInfo
{
public NeuropixelsV1eBno055DeviceInfo(ContextTask context, Type deviceType, uint deviceAddress, bool enable)
: base(context, deviceType, deviceAddress)
{
Enable = enable;
}

public bool Enable { get; }
}
}
13 changes: 12 additions & 1 deletion OpenEphys.Onix1/ConfigureNeuropixelsV2eBno055.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var device = context.GetPassthroughDeviceContext(deviceAddress, typeof(DS90UB9x));
ConfigureDeserializer(device);
ConfigureBno055(device);
var deviceInfo = new DeviceInfo(context, DeviceType, deviceAddress);
var deviceInfo = new NeuropixelsV2eBno055DeviceInfo(context, DeviceType, deviceAddress, enable);
return DeviceManager.RegisterDevice(deviceName, deviceInfo);
});
}
Expand Down Expand Up @@ -91,4 +91,15 @@ public NameConverter()
}
}
}

class NeuropixelsV2eBno055DeviceInfo : DeviceInfo
{
public NeuropixelsV2eBno055DeviceInfo(ContextTask context, Type deviceType, uint deviceAddress, bool enable)
: base(context, deviceType, deviceAddress)
{
Enable = enable;
}

public bool Enable { get; }
}
}
43 changes: 24 additions & 19 deletions OpenEphys.Onix1/NeuropixelsV1eBno055Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,37 @@ public override IObservable<Bno055DataFrame> Generate()
public unsafe IObservable<Bno055DataFrame> Generate<TSource>(IObservable<TSource> source)
{
return DeviceManager.GetDevice(DeviceName).SelectMany(
deviceInfo => Observable.Create<Bno055DataFrame>(observer =>
deviceInfo =>
{
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV1eBno055));
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV1eBno055.BNO055Address);

return source.SubscribeSafe(observer, _ =>
return !((NeuropixelsV1eBno055DeviceInfo)deviceInfo).Enable
? Observable.Empty<Bno055DataFrame>()
: Observable.Create<Bno055DataFrame>(observer =>
{
Bno055DataFrame frame = default;
device.Context.EnsureContext(() =>
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV1eBno055));
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV1eBno055.BNO055Address);

return source.SubscribeSafe(observer, _ =>
{
var data = i2c.ReadBytes(NeuropixelsV1eBno055.DataAddress, sizeof(Bno055DataPayload));
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
fixed (byte* dataPtr = data)
Bno055DataFrame frame = default;
device.Context.EnsureContext(() =>
{
var data = i2c.ReadBytes(NeuropixelsV1eBno055.DataAddress, sizeof(Bno055DataPayload));
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
fixed (byte* dataPtr = data)
{
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
}
});

if (frame != null)
{
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
observer.OnNext(frame);
}
});

if (frame != null)
{
observer.OnNext(frame);
}
});
}));
});
}
}
}
49 changes: 27 additions & 22 deletions OpenEphys.Onix1/NeuropixelsV2eBno055Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,37 @@ public override IObservable<Bno055DataFrame> Generate()
public unsafe IObservable<Bno055DataFrame> Generate<TSource>(IObservable<TSource> source)
{
return DeviceManager.GetDevice(DeviceName).SelectMany(
deviceInfo => Observable.Create<Bno055DataFrame>(observer =>
deviceInfo =>
{
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV2eBno055));
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV2eBno055.BNO055Address);

return source.SubscribeSafe(observer, _ =>
{
Bno055DataFrame frame = default;
device.Context.EnsureContext(() =>
return !((NeuropixelsV2eBno055DeviceInfo)deviceInfo).Enable
? Observable.Empty<Bno055DataFrame>()
: Observable.Create<Bno055DataFrame>(observer =>
{
var data = i2c.ReadBytes(NeuropixelsV2eBno055.DataAddress, sizeof(Bno055DataPayload));
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
fixed (byte* dataPtr = data)
var device = deviceInfo.GetDeviceContext(typeof(NeuropixelsV2eBno055));
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
var i2c = new I2CRegisterContext(passthrough, NeuropixelsV2eBno055.BNO055Address);

return source.SubscribeSafe(observer, _ =>
{
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
}
});
Bno055DataFrame frame = default;
device.Context.EnsureContext(() =>
{
var data = i2c.ReadBytes(NeuropixelsV2eBno055.DataAddress, sizeof(Bno055DataPayload));
ulong clock = passthrough.ReadRegister(DS90UB9x.LASTI2CL);
clock += (ulong)passthrough.ReadRegister(DS90UB9x.LASTI2CH) << 32;
fixed (byte* dataPtr = data)
{
frame = new Bno055DataFrame(clock, (Bno055DataPayload*)dataPtr);
}
});

if (frame != null)
{
observer.OnNext(frame);
}
});
}));
if (frame != null)
{
observer.OnNext(frame);
}
});
});
});
}
}
}