From: Benjamin Braatz Date: Thu, 12 Aug 2021 08:00:48 +0000 (+0200) Subject: Finisch configuration details. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=425e51f2447efa387e6b1ad28051301cdbbba8f1;p=graphit%2Fcontrolpi-camera.git Finisch configuration details. --- diff --git a/controlpi_plugins/camera.py b/controlpi_plugins/camera.py index 58752d8..167d38a 100644 --- a/controlpi_plugins/camera.py +++ b/controlpi_plugins/camera.py @@ -19,35 +19,44 @@ class Camera(BasePlugin): {'pause': {'type': 'number'}, 'keep': {'type': 'integer'}, 'path': {'type': 'string'}, - 'iso': {'enum': [0, 100, 200, 320, 400, 500, 640, 800]}, - 'shutter speed': {'type': 'integer', + 'iso': {'enum': [0, 100, 200, 320, 400, 500, 640, 800], + 'default': 0}, + 'shutter_speed': {'type': 'integer', 'minimum': 0, - 'maximum': 11111}, - 'exposure mode': {'enum': ['off', 'auto', 'night', + 'maximum': 11111, + 'default': 0}, + 'exposure_mode': {'enum': ['off', 'auto', 'night', 'nightpreview', 'backlight', 'spotlight', 'sports', 'snow', 'beach', 'verylong', 'fixedfps', 'antishake', - 'fireworks']}, - 'exposure compensation': {'type': 'integer', + 'fireworks'], + 'default': 'auto'}, + 'exposure_compensation': {'type': 'integer', 'minimum': -25, - 'maximum': 25}, + 'maximum': 25, + 'default': 0}, 'brightness': {'type': 'integer', 'minimum': 0, - 'maximum': 100}, + 'maximum': 100, + 'default': 50}, 'sharpness': {'type': 'integer', 'minimum': -100, - 'maximum': 100}, + 'maximum': 100, + 'default': 0}, 'contrast': {'type': 'integer', 'minimum': -100, - 'maximum': 100}, + 'maximum': 100, + 'default': 0}, 'saturation': {'type': 'integer', 'minimum': -100, - 'maximum': 100}, - 'awb mode': {'enum': ['off', 'auto', 'sunlight', 'cloudy', + 'maximum': 100, + 'default': 0}, + 'awb_mode': {'enum': ['off', 'auto', 'sunlight', 'cloudy', 'shade', 'tungsten', 'fluorescent', 'incandescent', 'flash', - 'horizon']}}, + 'horizon'], + 'default': 'auto'}}, 'required': ['pause', 'keep', 'path']} async def _receive(self, message: Message) -> None: @@ -60,6 +69,22 @@ class Camera(BasePlugin): self._capture = True elif message['command'] == 'stop capture': self._capture = False + else: + for prop in self.CONF_SCHEMA['properties']: + if message['command'] == f"get {prop}": + await self.bus.send(Message(self.name, + {prop: self.conf[prop]})) + elif message['command'] == f"set {prop}": + setattr(self._camera, prop, message[f"new {prop}"]) + new_value = getattr(self._camera, prop) + if new_value != self.conf[prop]: + self.conf[prop] = new_value + await self.bus.send(Message(self.name, + {'event': f"new {prop}", + prop: self.conf[prop]})) + else: + await self.bus.send(Message(self.name, + {prop: self.conf[prop]})) def process_conf(self) -> None: """Register plugin as bus client.""" @@ -68,65 +93,36 @@ class Camera(BasePlugin): self._camera = picamera.PiCamera(sensor_mode=7, resolution=(640, 480), framerate=90) - if 'iso' not in self.conf: - self.conf['iso'] = 0 - if 'shutter speed' not in self.conf: - self.conf['shutter speed'] = 0 - if 'exposure mode' not in self.conf: - self.conf['exposure mode'] = 'auto' - if 'exposure compensation' not in self.conf: - self.conf['exposure compensation'] = 0 - if 'brightness' not in self.conf: - self.conf['brightness'] = 50 - if 'sharpness' not in self.conf: - self.conf['sharpness'] = 0 - if 'contrast' not in self.conf: - self.conf['contrast'] = 0 - if 'saturation' not in self.conf: - self.conf['saturation'] = 0 - if 'awb mode' not in self.conf: - self.conf['awb mode'] = 'auto' sends = [MessageTemplate({'event': {'const': 'new image'}, 'image': {'type': 'string'}, 'date': {'type': 'string'}}), MessageTemplate({'image': {'type': 'string'}, - 'date': {'type': 'string'}}), - MessageTemplate({'event': {'const': 'new iso'}, - 'iso': {'type': 'integer'}}), - MessageTemplate({'iso': {'type': 'integer'}}), - MessageTemplate({'event': {'const': 'new shutter speed'}, - 'shutter speed': {'type': 'integer'}}), - MessageTemplate({'shutter speed': {'type': 'integer'}}), - MessageTemplate({'event': {'const': 'new exposure mode'}, - 'exposure mode': {'type': 'string'}}), - MessageTemplate({'exposure mode': {'type': 'string'}}), - MessageTemplate({'event': {'const': - 'new exposure compensation'}, - 'exposure compensation': - {'type': 'integer'}}), - MessageTemplate({'exposure compensation': - {'type': 'integer'}}), - MessageTemplate({'event': {'const': 'new brightness'}, - 'brightness': {'type': 'integer'}}), - MessageTemplate({'brightness': {'type': 'integer'}}), - MessageTemplate({'event': {'const': 'new sharpness'}, - 'sharpness': {'type': 'integer'}}), - MessageTemplate({'sharpness': {'type': 'integer'}}), - MessageTemplate({'event': {'const': 'new contrast'}, - 'contrast': {'type': 'integer'}}), - MessageTemplate({'contrast': {'type': 'integer'}}), - MessageTemplate({'event': {'const': 'new saturation'}, - 'saturation': {'type': 'integer'}}), - MessageTemplate({'saturation': {'type': 'integer'}}), - MessageTemplate({'event': {'const': 'new awb mode'}, - 'awb mode': {'type': 'string'}}), - MessageTemplate({'awb mode': {'type': 'string'}})] + 'date': {'type': 'string'}})] receives = [MessageTemplate({'target': {'const': self.name}, 'command': {'const': 'get image'}}), MessageTemplate({'target': {'const': self.name}, 'command': {'const': 'start capture'}}), MessageTemplate({'target': {'const': self.name}, 'command': {'const': 'stop capture'}})] + for prop in self.CONF_SCHEMA['properties']: + schema = self.CONF_SCHEMA['properties'][prop] + if 'default' in schema: + if prop not in self.conf: + self.conf[prop] = schema['default'] + sends.append(MessageTemplate({'event': + {'const': f"new {prop}"}, + prop: schema})) + sends.append(MessageTemplate({prop: schema})) + receives.append(MessageTemplate({'target': + {'const': self.name}, + 'command': + {'const': f"get {prop}"}})) + receives.append(MessageTemplate({'target': + {'const': self.name}, + 'command': + {'const': f"set {prop}"}, + f"new {prop}": + schema})) self.bus.register(self.name, 'Camera', sends, receives, self._receive) async def run(self) -> None: