From 0cfab099eca1983b51db9a68baf8cb2212bba81b Mon Sep 17 00:00:00 2001 From: jonnew Date: Tue, 29 Oct 2024 18:27:13 -0400 Subject: [PATCH] Hardcode ConfigureHeartbeat to enabled in ConfigureBreakoutBoard - Additionally, hardcode its BeatsPerSecond to 100 --- OpenEphys.Onix1/ConfigureBreakoutBoard.cs | 7 +++++-- OpenEphys.Onix1/ConfigureHeartbeat.cs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/OpenEphys.Onix1/ConfigureBreakoutBoard.cs b/OpenEphys.Onix1/ConfigureBreakoutBoard.cs index 881163c..2dbae8a 100644 --- a/OpenEphys.Onix1/ConfigureBreakoutBoard.cs +++ b/OpenEphys.Onix1/ConfigureBreakoutBoard.cs @@ -25,10 +25,13 @@ public class ConfigureBreakoutBoard : MultiDeviceFactory /// /// Gets or sets the heartbeat configuration. /// - [TypeConverter(typeof(SingleDeviceFactoryConverter))] + /// + /// This heartbeat is always enabled and beats at 100 Hz. + /// + [TypeConverter(typeof(HeartbeatSingleDeviceFactoryConverter))] [Description("Specifies the configuration for the heartbeat device in the ONIX breakout board.")] [Category(DevicesCategory)] - public ConfigureHeartbeat Heartbeat { get; set; } = new(); + public ConfigureHeartbeat Heartbeat { get; set; } = new ConfigureHeartbeat { Enable = true, BeatsPerSecond = 100 }; /// /// Gets or sets the breakout board's analog IO configuration. diff --git a/OpenEphys.Onix1/ConfigureHeartbeat.cs b/OpenEphys.Onix1/ConfigureHeartbeat.cs index b612a8f..15ee297 100644 --- a/OpenEphys.Onix1/ConfigureHeartbeat.cs +++ b/OpenEphys.Onix1/ConfigureHeartbeat.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Linq; using System.Reactive.Disposables; using System.Reactive.Subjects; using Bonsai; @@ -101,4 +102,21 @@ public NameConverter() } } } + + // NB: Can be used to remove Enable and BeatsPerSecond properties from MultiDeviceFactories that + // include a Heartbeat when having those options would cause confusion + internal class HeartbeatSingleDeviceFactoryConverter : SingleDeviceFactoryConverter + { + public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) + { + var properties = (from property in base.GetProperties(context, value, attributes).Cast() + where !property.IsReadOnly && + !(property.DisplayName == "Enable") && + !(property.DisplayName == "BeatsPerSecond") && + property.ComponentType != typeof(SingleDeviceFactory) + select property) + .ToArray(); + return new PropertyDescriptorCollection(properties).Sort(properties.Select(p => p.Name).ToArray()); + } + } }