2018-06-23 01:00:43 +02:00
|
|
|
"""
|
|
|
|
.. moduleauthor:: Fabio Manganiello <blacklight86@gmail.com>
|
|
|
|
"""
|
|
|
|
|
2018-06-14 00:34:30 +02:00
|
|
|
from platypush.context import get_backend
|
2018-07-06 02:08:38 +02:00
|
|
|
from platypush.plugins import Plugin, action
|
2018-06-14 00:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CameraPiPlugin(Plugin):
|
2018-06-23 01:00:43 +02:00
|
|
|
"""
|
|
|
|
Plugin to control a Pi camera.
|
2018-06-26 00:36:01 +02:00
|
|
|
It acts as a wrapper around the :mod:`platypush.backend.camera.pi` backend
|
2018-06-23 01:00:43 +02:00
|
|
|
to programmatically control the status.
|
|
|
|
"""
|
|
|
|
|
2018-07-06 02:08:38 +02:00
|
|
|
def __init__(*args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
@action
|
2018-06-14 00:34:30 +02:00
|
|
|
def start_recording(self):
|
2018-06-23 01:00:43 +02:00
|
|
|
"""
|
|
|
|
Start recording
|
|
|
|
"""
|
2018-06-14 00:34:30 +02:00
|
|
|
camera = get_backend('camera.pi')
|
2018-06-14 12:37:09 +02:00
|
|
|
camera.send_camera_action(camera.CameraAction.START_RECORDING)
|
2018-06-14 00:34:30 +02:00
|
|
|
|
2018-07-06 02:08:38 +02:00
|
|
|
@action
|
2018-06-14 00:34:30 +02:00
|
|
|
def stop_recording(self):
|
2018-06-23 01:00:43 +02:00
|
|
|
"""
|
|
|
|
Stop recording
|
|
|
|
"""
|
2018-06-14 00:34:30 +02:00
|
|
|
camera = get_backend('camera.pi')
|
2018-06-14 12:37:09 +02:00
|
|
|
camera.send_camera_action(camera.CameraAction.STOP_RECORDING)
|
2018-06-14 00:34:30 +02:00
|
|
|
|
2018-07-06 02:08:38 +02:00
|
|
|
@action
|
2018-06-14 00:34:30 +02:00
|
|
|
def take_picture(self, image_file):
|
2018-06-23 01:00:43 +02:00
|
|
|
"""
|
|
|
|
Take a picture.
|
|
|
|
|
|
|
|
:param image_file: Path where the output image will be stored.
|
|
|
|
:type image_file: str
|
|
|
|
"""
|
2018-06-14 00:34:30 +02:00
|
|
|
camera = get_backend('camera.pi')
|
2018-06-14 12:37:09 +02:00
|
|
|
camera.send_camera_action(camera.CameraAction.TAKE_PICTURE, image_file=image_file)
|
2018-07-06 02:08:38 +02:00
|
|
|
return {'image_file': image_file}
|
2018-06-14 00:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|
|
|
|
|