@@ -30,7 +30,6 @@ public class ConfigureHeadstage64OpticalStimulator : SingleDeviceFactory
3030 readonly BehaviorSubject < uint > burstsPerTrain = new ( 1 ) ;
3131 readonly BehaviorSubject < double > delay = new ( 0 ) ;
3232
33-
3433 /// <summary>
3534 /// Initializes a new instance of the <see cref="ConfigureHeadstage64OpticalStimulator"/> class.
3635 /// </summary>
@@ -48,6 +47,7 @@ public ConfigureHeadstage64OpticalStimulator(ConfigureHeadstage64OpticalStimulat
4847 DeviceName = opticalStimulator . DeviceName ;
4948 DeviceAddress = opticalStimulator . DeviceAddress ;
5049 Enable = opticalStimulator . Enable ;
50+ StimEnable = opticalStimulator . StimEnable ;
5151 Delay = opticalStimulator . Delay ;
5252 MaxCurrent = opticalStimulator . MaxCurrent ;
5353 ChannelOneCurrent = opticalStimulator . ChannelOneCurrent ;
@@ -59,12 +59,6 @@ public ConfigureHeadstage64OpticalStimulator(ConfigureHeadstage64OpticalStimulat
5959 BurstsPerTrain = opticalStimulator . BurstsPerTrain ;
6060 }
6161
62- static double VerifyValueLimits ( double value , double min , double max ) =>
63- Math . Min ( Math . Max ( value , min ) , max ) ;
64-
65- static uint VerifyValueLimits ( uint value , uint min , uint max ) =>
66- Math . Min ( Math . Max ( value , min ) , max ) ;
67-
6862 /// <summary>
6963 /// Gets or sets the data enable state.
7064 /// </summary>
@@ -101,7 +95,7 @@ public bool StimEnable
10195 public double Delay
10296 {
10397 get => delay . Value ;
104- set => delay . OnNext ( VerifyValueLimits ( value , Headstage64OpticalStimulator . MinDelay , Headstage64OpticalStimulator . MaxDelay ) ) ;
98+ set => delay . OnNext ( Clamp ( value , Headstage64OpticalStimulator . MinDelay , Headstage64OpticalStimulator . MaxDelay ) ) ;
10599 }
106100
107101 /// <summary>
@@ -122,12 +116,12 @@ public double Delay
122116 public double MaxCurrent
123117 {
124118 get => maxCurrent . Value ;
125- set => maxCurrent . OnNext ( VerifyValueLimits ( value , Headstage64OpticalStimulator . MinCurrent , Headstage64OpticalStimulator . MaxCurrent ) ) ;
119+ set => maxCurrent . OnNext ( Clamp ( value , Headstage64OpticalStimulator . MinCurrent , Headstage64OpticalStimulator . MaxCurrent ) ) ;
126120 }
127121
128122 static double VerifyChannelPercentage ( double value , double min , double max , double step )
129123 {
130- value = VerifyValueLimits ( value , min , max ) ;
124+ value = Clamp ( value , min , max ) ;
131125
132126 return Math . Round ( value / step ) * step ;
133127 }
@@ -177,7 +171,7 @@ public double ChannelTwoCurrent
177171 public double PulseDuration
178172 {
179173 get => pulseDuration . Value ;
180- set => pulseDuration . OnNext ( VerifyValueLimits ( value , Headstage64OpticalStimulator . MinPulseDuration , Headstage64OpticalStimulator . MaxPulseDuration ) ) ;
174+ set => pulseDuration . OnNext ( Clamp ( value , Headstage64OpticalStimulator . MinPulseDuration , Headstage64OpticalStimulator . MaxPulseDuration ) ) ;
181175 }
182176
183177 /// <summary>
@@ -191,7 +185,7 @@ public double PulseDuration
191185 public double PulsesPerSecond
192186 {
193187 get => pulsesPerSecond . Value ;
194- set => pulsesPerSecond . OnNext ( VerifyValueLimits ( value , Headstage64OpticalStimulator . MinPulsePeriod , Headstage64OpticalStimulator . MaxPulsePeriod ) ) ;
188+ set => pulsesPerSecond . OnNext ( Clamp ( value , Headstage64OpticalStimulator . MinPulsePeriod , Headstage64OpticalStimulator . MaxPulsePeriod ) ) ;
195189 }
196190
197191 /// <summary>
@@ -205,7 +199,7 @@ public double PulsesPerSecond
205199 public uint PulsesPerBurst
206200 {
207201 get => pulsesPerBurst . Value ;
208- set => pulsesPerBurst . OnNext ( VerifyValueLimits ( value , 1 , int . MaxValue ) ) ;
202+ set => pulsesPerBurst . OnNext ( Clamp ( value , 1 , int . MaxValue ) ) ;
209203 }
210204
211205 /// <summary>
@@ -219,7 +213,7 @@ public uint PulsesPerBurst
219213 public double InterBurstInterval
220214 {
221215 get => interBurstInterval . Value ;
222- set => interBurstInterval . OnNext ( VerifyValueLimits ( value , Headstage64OpticalStimulator . MinInterBurstInterval , Headstage64OpticalStimulator . MaxInterBurstInterval ) ) ;
216+ set => interBurstInterval . OnNext ( Clamp ( value , Headstage64OpticalStimulator . MinInterBurstInterval , Headstage64OpticalStimulator . MaxInterBurstInterval ) ) ;
223217 }
224218
225219 /// <summary>
@@ -233,7 +227,7 @@ public double InterBurstInterval
233227 public uint BurstsPerTrain
234228 {
235229 get => burstsPerTrain . Value ;
236- set => burstsPerTrain . OnNext ( VerifyValueLimits ( value , 1 , int . MaxValue ) ) ;
230+ set => burstsPerTrain . OnNext ( Clamp ( value , 1 , int . MaxValue ) ) ;
237231 }
238232
239233 // TODO: Should this be checked before TRIGGER is written to below and an error thrown if
@@ -253,6 +247,12 @@ public double BurstCurrent
253247 }
254248 }
255249
250+ static double Clamp ( double value , double min , double max ) =>
251+ Math . Min ( Math . Max ( value , min ) , max ) ;
252+
253+ static uint Clamp ( uint value , uint min , uint max ) =>
254+ Math . Min ( Math . Max ( value , min ) , max ) ;
255+
256256 /// <summary>
257257 /// Configure a headstage-64 dual-channel optical stimulator.
258258 /// </summary>
@@ -269,13 +269,11 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
269269 var deviceName = DeviceName ;
270270 var deviceAddress = DeviceAddress ;
271271 var enable = Enable ;
272-
273272 return source . ConfigureDevice ( ( context , observer ) =>
274273 {
275274 var device = context . GetDeviceContext ( deviceAddress , DeviceType ) ;
276275
277276 device . WriteRegister ( Headstage64OpticalStimulator . ENABLE , enable ? 1u : 0u ) ;
278- device . WriteRegister ( Headstage64OpticalStimulator . STIMENABLE , 0u ) ;
279277
280278 uint currentSourceMask = 0 ;
281279 static uint percentToPulseMask ( int channel , double percent , uint oldMask )
0 commit comments