1818
1919"""Adds support for Aurox devices
2020
21- Requires package hidapi."""
21+ Requires package hidapi.
2222
23+ Config sample:
24+
25+ device(microscope.filterwheels.aurox.Clarity,
26+ {'camera': 'microscope.Cameras.cameramodule.SomeCamera',
27+ 'camera.someSetting': value})
28+ """
29+ import functools
2330import hid
31+ import logging
2432import microscope .devices
33+ import typing
2534from enum import Enum
2635
36+ _logger = logging .getLogger (__name__ )
37+
2738## Clarity constants. These may differ across products, so mangle names.
2839# USB IDs
2940_Clarity__VENDORID = 0x1F0A
7283_Clarity__SETSVCMODE1 = 0xe0 #1 byte for service mode. SLEEP activates service mode. RUN returns to normal mode.
7384
7485
75- class Clarity (microscope .devices .FilterWheelBase ):
86+ class Clarity (microscope .devices .ControllerDevice , microscope . devices . FilterWheelBase ):
7687 _slide_to_sectioning = {__SLDPOS0 : 'bypass' ,
7788 __SLDPOS1 : 'low' ,
7889 __SLDPOS2 : 'mid' ,
@@ -86,16 +97,44 @@ class Clarity(microscope.devices.FilterWheelBase):
8697 __GETSERIAL : 4 ,
8798 __FULLSTAT : 10 }
8899
89- def __init__ (self , ** kwargs ):
100+ def __init__ (self , camera = None , ** kwargs ) -> None :
101+ # Extract kwargs for camera device.
102+ cam_kw_keys = [k for k in kwargs if k .startswith ("camera." )]
103+ cam_kwargs = {}
104+ for key in cam_kw_keys :
105+ cam_kwargs [key .replace ("camera." , "" )] = kwargs [key ]
106+ del kwargs [key ]
90107 super ().__init__ (** kwargs )
91108 from threading import Lock
92109 self ._lock = Lock ()
93110 self ._hid = None
111+ self ._devices = {}
112+ if camera is None :
113+ self ._cam = None
114+ _logger .warn ("No camera specified." )
115+ else :
116+ self ._cam = camera (** cam_kwargs )
117+ self ._cam .pipeline .append (self ._c_process_data )
118+ self ._devices ['camera' ] = self ._cam
119+ try :
120+ from clarity_process import ClarityProcessor
121+ except :
122+ _logger .warn ("Could not import clarity_process module: no processing available." )
123+ self ._processor = None
94124 self .add_setting ("sectioning" , "enum" ,
95125 self .get_slide_position ,
96126 lambda val : self .set_slide_position (val ),
97127 self ._slide_to_sectioning )
98128
129+ def _c_process_data (self , data ):
130+ # TODO
131+ _logger .info ("Clarity processed data." )
132+ return data
133+
134+ @property
135+ def devices (self ) -> typing .Mapping [str , microscope .devices .Device ]:
136+ return self ._devices
137+
99138 def _send_command (self , command , param = 0 , max_length = 16 , timeout_ms = 100 ):
100139 """Send a command to the Clarity and return its response"""
101140 if not self ._hid :
@@ -263,8 +302,5 @@ def set_position(self, pos, blocking=True):
263302 pass
264303 return result
265304
266- def _on_shutdown (self ):
267- pass
268-
269305 def initialize (self ):
270306 pass
0 commit comments