30import RPi.GPIO
as GPIO
33from microscope
import ROI, Binning, TriggerMode, TriggerType
40_logger = logging.getLogger(__name__)
46 SOFTWARE = TriggerType.SOFTWARE
47 EDGE_RISING = TriggerType.RISING_EDGE
52 super(PiCamera, self).
__init__(**kwargs)
63 self.
roi =
ROI(
None,
None,
None,
None)
70 GPIO.setmode(GPIO.BCM)
72 GPIO.setup(GPIO_Trigger, GPIO.IN)
74 GPIO.setup(GPIO_CAMLED, GPIO.OUT)
76 trg_source_names = [x.name
for x
in TrgSourceMap]
78 self.
_queue = queue.Queue()
80 self.
_iso_modes = [0, 100, 200, 320, 400, 500, 640, 800]
82 def _trigger_source_setter(index: int) ->
None:
83 trigger_type = TrgSourceMap[trg_source_names[index]].value
90 _trigger_source_setter,
119 def get_awb_mode(self):
120 return self.
camera.awb_mode
122 def set_awb_mode(self, val):
125 self.
camera.awb_mode = key
127 def set_iso_mode(self, val):
131 """Function called by GPIO interupt, needs to trigger image capture"""
132 with picamera.array.PiYUVArray(self.
camera)
as output:
133 self.
camera.capture(output, format=
"yuv", use_video_port=
False)
134 self.
_queue.put(output.array[:, :, 0])
136 def _fetch_data(self):
137 if self.
_queue.qsize()
is not 0:
139 _logger.info(
"Sending image")
144 def initialize(self):
145 """Initialise the Pi Camera camera.
146 Open the connection, connect properties and populate settings dict.
151 self.
camera = picamera.PiCamera(sensor_mode=2)
153 raise Exception(
"Problem opening camera.")
154 _logger.info(
"Initializing camera.")
156 _logger.info(
"cam version " + self.
camversion)
168 def _do_disable(self):
171 def _do_shutdown(self):
175 def _do_enable(self):
176 _logger.info(
"Preparing for acquisition.")
183 _logger.info(
"Acquisition enabled.")
187 _logger.info(
"Disabling acquisition.")
192 self, ttype: TriggerType, tmode: TriggerMode
196 elif ttype == TriggerType.SOFTWARE:
197 GPIO.remove_event_detect(GPIO_Trigger)
199 elif ttype == TriggerType.RISING_EDGE:
200 GPIO.add_event_detect(
209 def trigger_mode(self) -> TriggerMode:
211 return TriggerMode.ONCE
217 def trigger_type(self) -> TriggerType:
221 """Return the current ROI (left, top, width, height)."""
224 def _set_binning(self, h_bin, v_bin):
227 def _get_binning(self):
231 def _set_roi(self, left, top, width, height):
232 """Set the ROI to (left, tip, width, height)."""
233 self.
roi =
ROI(left, top, width, height)
236 def setLED(self, state=False):
237 GPIO.output(GPIO_CAMLED, state)
241 self.
camera.shutter_speed = int(value * 1.0e6)
245 return self.
camera.exposure_speed * 1.0e-6
250 return self.
camera.exposure_speed * 1.0e-6 + 0.1
252 def _get_sensor_shape(self):
254 self.
camera.resolution = (2592, 1944)
256 res = self.
camera.resolution
260 def _do_trigger(self):
263 def soft_trigger(self):
268 with picamera.array.PiYUVArray(self.
camera)
as output:
269 self.
camera.capture(output, format=
"yuv", use_video_port=
False)
270 self.
_queue.put(output.array[:, :, 0])
def _set_roi(self, microscope.ROI roi)
typing.Tuple[int, int] _get_sensor_shape(self)
None add_setting(self, name, dtype, get_func, set_func, values, typing.Optional[typing.Callable[[], bool]] readonly=None)
None set_trigger(self, microscope.TriggerType ttype, microscope.TriggerMode tmode)
microscope.TriggerMode trigger_mode(self)
def HW_trigger(self, channel)
def set_awb_mode(self, val)
def set_iso_mode(self, val)
TriggerMode trigger_mode(self)
def __init__(self, *args, **kwargs)
def _get_sensor_shape(self)
def set_exposure_time(self, value)
None set_trigger(self, TriggerType ttype, TriggerMode tmode)
def _set_roi(self, left, top, width, height)
def get_exposure_time(self)
def setLED(self, state=False)