@@ -15,7 +15,8 @@ public class ConfigureUclaMiniscopeV4Camera : SingleDeviceFactory
1515 {
1616 readonly BehaviorSubject < double > ledBrightness = new ( 0 ) ;
1717 readonly BehaviorSubject < UclaMiniscopeV4SensorGain > sensorGain = new ( UclaMiniscopeV4SensorGain . Low ) ;
18- readonly BehaviorSubject < double > liquidLensVoltage = new ( 47 ) ; // NB: middle of range
18+ readonly BehaviorSubject < double > focus = new ( 0 ) ;
19+ UclaMiniscopeV4FramesPerSecond frameRate = UclaMiniscopeV4FramesPerSecond . Fps30 ;
1920
2021 /// <summary>
2122 /// Initialize a new instance of a <see cref="ConfigureUclaMiniscopeV4Camera"/> class.
@@ -41,7 +42,24 @@ public ConfigureUclaMiniscopeV4Camera()
4142 /// </summary>
4243 [ Category ( ConfigurationCategory ) ]
4344 [ Description ( "Camera video rate in frames per second." ) ]
44- public UclaMiniscopeV4FramesPerSecond FrameRate { get ; set ; } = UclaMiniscopeV4FramesPerSecond . Fps30Hz ;
45+ public UclaMiniscopeV4FramesPerSecond FrameRate
46+ {
47+ get => frameRate ;
48+ set
49+ {
50+ // NB: Required for backwards compatibility. The frameRate variable and get/set bodies can be
51+ // removed in v1.0.0 when the *Hz enums are removed.
52+ frameRate = value switch
53+ {
54+ UclaMiniscopeV4FramesPerSecond . Fps10 or UclaMiniscopeV4FramesPerSecond . Fps10Hz => UclaMiniscopeV4FramesPerSecond . Fps10 ,
55+ UclaMiniscopeV4FramesPerSecond . Fps15 or UclaMiniscopeV4FramesPerSecond . Fps15Hz => UclaMiniscopeV4FramesPerSecond . Fps15 ,
56+ UclaMiniscopeV4FramesPerSecond . Fps20 or UclaMiniscopeV4FramesPerSecond . Fps20Hz => UclaMiniscopeV4FramesPerSecond . Fps20 ,
57+ UclaMiniscopeV4FramesPerSecond . Fps25 or UclaMiniscopeV4FramesPerSecond . Fps25Hz => UclaMiniscopeV4FramesPerSecond . Fps25 ,
58+ UclaMiniscopeV4FramesPerSecond . Fps30 or UclaMiniscopeV4FramesPerSecond . Fps30Hz => UclaMiniscopeV4FramesPerSecond . Fps30 ,
59+ _ => UclaMiniscopeV4FramesPerSecond . Fps30
60+ } ;
61+ }
62+ }
4563
4664 /// <summary>
4765 /// Gets or sets the camera sensor's analog gain.
@@ -83,24 +101,25 @@ public double LedBrightness
83101 }
84102
85103 /// <summary>
86- /// Gets or sets the liquid lens driver voltage (Volts RMS) .
104+ /// Gets or sets the focal plane as a percentage up or down around its nominal depth .
87105 /// </summary>
88106 /// <remarks>
89- /// The imaging focal plane is controlled by using a MAX14574 high-voltage liquid lens driver. This
90- /// chip produces pulse-width modulated, 5 kHz alternative electric field that deforms the miniscope's
91- /// liquid lens in order to change the focal plane. The strength of this field determines the degree
92- /// of deformation and therefore the focal depth. The default setting of 47 Volts RMS corresponds to
93- /// approximately mid-range.
107+ /// The imaging focal plane is controlled by using a Max14574 high-voltage liquid lens driver. This
108+ /// chip produces pulse-width modulated, 5 kHz alternative electric field that deforms a liquid lens
109+ /// in order to change the Miniscope's focal plane. The strength of this field determines the degree
110+ /// of deformation and therefore the focal depth. The default setting of 0% corresponds to
111+ /// approximately mid-range with an excitation voltage of ~47 VRMS. -100% and 100% correspond to the
112+ /// minimum and maximum excitation voltage of ~24.4 and ~69.7 VRMS, respectively.
94113 /// </remarks>
95- [ Description ( "Liquid lens driver voltage (Volts RMS )." ) ]
114+ [ Description ( "Electro-wetting lens focal plane adjustment (percent of range around nominal depth )." ) ]
96115 [ Category ( AcquisitionCategory ) ]
97- [ Range ( 24.4 , 69.7 ) ]
98- [ Precision ( 1 , 1 ) ]
116+ [ Range ( - 100 , 100 ) ]
117+ [ Precision ( 1 , 0. 1) ]
99118 [ Editor ( DesignTypes . SliderEditor , typeof ( UITypeEditor ) ) ]
100- public double LiquidLensVoltage
119+ public double Focus
101120 {
102- get => liquidLensVoltage . Value ;
103- set => liquidLensVoltage . OnNext ( value ) ;
121+ get => focus . Value ;
122+ set => focus . OnNext ( value ) ;
104123 }
105124
106125 // This is a hack. The hardware is quite unreliable and requires special assistance in order to
@@ -121,7 +140,7 @@ public double LiquidLensVoltage
121140 /// configuration actions.</param>
122141 /// <returns>
123142 /// The original sequence but with each <see cref="ContextTask"/> instance now containing
124- /// configuration actions required to use the miniscope 's camera.
143+ /// configuration actions required to use the Miniscope 's camera.
125144 /// </returns>
126145 public override IObservable < ContextTask > Process ( IObservable < ContextTask > source )
127146 {
@@ -162,7 +181,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
162181 return new CompositeDisposable (
163182 ledBrightness . Subscribe ( value => SetLedBrightness ( device , value ) ) ,
164183 sensorGain . Subscribe ( value => SetSensorGain ( device , value ) ) ,
165- liquidLensVoltage . Subscribe ( value => SetLiquidLensVoltage ( device , value ) ) ,
184+ focus . Subscribe ( value => SetLiquidLensVoltage ( device , value ) ) ,
166185 DeviceManager . RegisterDevice ( deviceName , deviceInfo ) ,
167186 shutdown ) ;
168187 }
@@ -252,11 +271,11 @@ internal static void ConfigureCameraSystem(DeviceContext device, UclaMiniscopeV4
252271 // configuration properties
253272 uint shutterWidth = frameRate switch
254273 {
255- UclaMiniscopeV4FramesPerSecond . Fps10Hz => 10000 ,
256- UclaMiniscopeV4FramesPerSecond . Fps15Hz => 6667 ,
257- UclaMiniscopeV4FramesPerSecond . Fps20Hz => 5000 ,
258- UclaMiniscopeV4FramesPerSecond . Fps25Hz => 4000 ,
259- UclaMiniscopeV4FramesPerSecond . Fps30Hz => 3300 ,
274+ UclaMiniscopeV4FramesPerSecond . Fps10 => 10000 ,
275+ UclaMiniscopeV4FramesPerSecond . Fps15 => 6667 ,
276+ UclaMiniscopeV4FramesPerSecond . Fps20 => 5000 ,
277+ UclaMiniscopeV4FramesPerSecond . Fps25 => 4000 ,
278+ UclaMiniscopeV4FramesPerSecond . Fps30 => 3300 ,
260279 _ => 3300
261280 } ;
262281
@@ -302,10 +321,11 @@ internal static void SetSensorGain(DeviceContext device, UclaMiniscopeV4SensorGa
302321 Set200kHzI2C ( device ) ;
303322 }
304323
305- internal static void SetLiquidLensVoltage ( DeviceContext device , double voltage )
324+ internal static void SetLiquidLensVoltage ( DeviceContext device , double focus )
306325 {
307326 var max14574 = new I2CRegisterContext ( device , UclaMiniscopeV4 . Max14574Address ) ;
308- max14574 . WriteByte ( 0x08 , ( uint ) ( ( voltage - 24.4 ) / 0.0445 ) >> 2 ) ;
327+ var scaled = focus * 1.27 ;
328+ max14574 . WriteByte ( 0x08 , ( byte ) ( 127 + scaled ) ) ;
309329 max14574 . WriteByte ( 0x09 , 0x02 ) ;
310330 }
311331 }
@@ -357,26 +377,56 @@ public enum UclaMiniscopeV4FramesPerSecond
357377 /// <summary>
358378 /// Specifies 10 frames per second.
359379 /// </summary>
360- Fps10Hz ,
380+ Fps10 ,
361381
362382 /// <summary>
363383 /// Specifies 15 frames per second.
364384 /// </summary>
365- Fps15Hz ,
385+ Fps15 ,
366386
367387 /// <summary>
368388 /// Specifies 20 frames per second.
369389 /// </summary>
370- Fps20Hz ,
390+ Fps20 ,
371391
372392 /// <summary>
373393 /// Specifies 25 frames per second.
374394 /// </summary>
375- Fps25Hz ,
395+ Fps25 ,
376396
377397 /// <summary>
378398 /// Specifies 30 frames per second.
379399 /// </summary>
400+ Fps30 ,
401+
402+ /// <summary>
403+ /// This value is deprecated. Please use the corresponding version without the Hz suffix. This will be removed in v1.0.0.
404+ /// </summary>
405+ [ Browsable ( false ) ]
406+ Fps10Hz ,
407+
408+ /// <summary>
409+ /// This value is deprecated. Please use the corresponding version without the Hz suffix. This will be removed in v1.0.0.
410+ /// </summary>
411+ [ Browsable ( false ) ]
412+ Fps15Hz ,
413+
414+ /// <summary>
415+ /// This value is deprecated. Please use the corresponding version without the Hz suffix. This will be removed in v1.0.0.
416+ /// </summary>
417+ [ Browsable ( false ) ]
418+ Fps20Hz ,
419+
420+ /// <summary>
421+ /// This value is deprecated. Please use the corresponding version without the Hz suffix. This will be removed in v1.0.0.
422+ /// </summary>
423+ [ Browsable ( false ) ]
424+ Fps25Hz ,
425+
426+ /// <summary>
427+ /// This value is deprecated. Please use the corresponding version without the Hz suffix. This will be removed in v1.0.0.
428+ /// </summary>
429+ [ Browsable ( false ) ]
380430 Fps30Hz ,
381431 }
382432}
0 commit comments