Commit 9267663e authored by Pietro Saccardi's avatar Pietro Saccardi

Reporting status on buffered recorder, still, telegram and pwmled.

parent 43cc5536
......@@ -12,6 +12,7 @@ from misc.settings import SETTINGS
from safe_picamera import PiVideoFrameType
from threading import Lock
import math
from specialized.plugin_status_led import Status
BUFFERED_RECORDER_PLUGIN_NAME = 'BufferedRecorder'
......@@ -33,6 +34,8 @@ class BufferedRecorderPlugin(PiCameraProcessBase):
self._buffer_max_age = None
self._sps_header_max_age = None
self._footage_max_age = None
self._record_status = None
self._record_status_lock = Lock()
def __enter__(self):
super(BufferedRecorderPlugin, self).__enter__()
......@@ -44,6 +47,14 @@ class BufferedRecorderPlugin(PiCameraProcessBase):
self._recorder.__exit__(exc_type, exc_val, exc_tb)
super(BufferedRecorderPlugin, self).__exit__(exc_type, exc_val, exc_tb)
def _set_recording_status(self, value):
with self._record_status_lock:
if value and self._record_status is None:
self._record_status = Status.pulse((0, 1, 0))
elif not value and self._record_status is not None:
self._record_status.cancel()
self._record_status = None
@pyro_expose
@property
def footage_age(self):
......@@ -141,6 +152,7 @@ class BufferedRecorderPlugin(PiCameraProcessBase):
self._footage_max_age = None
else:
self._footage_max_age = int(max(1., stop_after_seconds) * self._camera.framerate)
self._set_recording_status(True)
self._recorder.record()
@pyro_expose
......@@ -154,6 +166,7 @@ class BufferedRecorderPlugin(PiCameraProcessBase):
return self._recorder.is_recording and self._keep_media and not self._is_recording
def _stop_and(self, finalize, handle_split_point_if_flushed=True):
self._set_recording_status(False)
self._is_recording = False
self._keep_media = finalize
if handle_split_point_if_flushed:
......
......@@ -5,6 +5,7 @@ import logging
from misc.settings import SETTINGS
from gpiozero import PWMLED
from Pyro4 import expose as pyro_expose, oneway as pyro_oneway
from specialized.plugin_status_led import Status
PWMLED_PLUGIN_NAME = 'PWMLed'
......@@ -87,7 +88,10 @@ class PWMLedPlugin(PluginProcessBase):
if self._pwmled is not None:
_log.info('Setting PWM led on pin %d to value %s.', self.bcm_pin, str(v))
try:
self._pwmled.value = v
old_v = self._pwmled.value
with Status.custom((old_v, old_v, old_v), (v, v, v), fade_out_time=0.5, persist_on_time=0.25,
persist_off_time=0.25, n=1):
self._pwmled.value = v
except Exception as e: # pragma: no cover
_log.exception('Unable to set value to %s.', str(v))
raise e
......
......@@ -10,6 +10,7 @@ from misc.settings import SETTINGS
from tempfile import NamedTemporaryFile
import os
from specialized.support.thread_host import CallbackQueueThreadHost
from specialized.plugin_status_led import Status
STILL_PLUGIN_NAME = 'Still'
......@@ -54,7 +55,9 @@ class StillPlugin(PluginProcessBase):
temp_file:
media_path = temp_file.name
_log.info('Taking still picture with info %s to %s.', str(info), media_path)
camera.camera.capture(media_path, format='jpeg', use_video_port=True, quality=self._integral_jpg_quality)
with Status.set((0, 1, 0), persist_until_canceled=True):
camera.camera.capture(media_path, format='jpeg', use_video_port=True,
quality=self._integral_jpg_quality)
temp_file.flush()
temp_file.close()
media_mgr = find_plugin(MEDIA_MANAGER_PLUGIN_NAME, Process.CAMERA)
......
......@@ -13,6 +13,7 @@ from Pyro4 import expose as pyro_expose, oneway as pyro_oneway
from time import sleep
from specialized.support.txtutils import user_desc
import os
from specialized.plugin_status_led import Status
TELEGRAM_ROOT_PLUGIN_NAME = 'TelegramRoot'
......@@ -104,7 +105,8 @@ class TelegramRootPlugin(TelegramProcessBase):
_log.info('Sending media %s to %d.', str(media_obj), chat_id)
if file_id is None:
_log.info('Beginning upload of media %s...', str(media_obj))
msg = method(chat_id, media_obj, *args, **kwargs)
with Status.pulse((0, 0, 1)):
msg = method(chat_id, media_obj, *args, **kwargs)
if msg:
attachment = msg.effective_attachment
if isinstance(attachment, list) and len(attachment) > 0 and isinstance(attachment[0], PhotoSize):
......@@ -113,6 +115,7 @@ class TelegramRootPlugin(TelegramProcessBase):
file_id = attachment.file_id
_log.info('Media %s uploaded as file id %s...', str(media_obj), str(file_id))
else:
Status.blink((1, 0, 0), n=1)
_log.error('Unable to send media %s.', str(media_obj))
return
retval.append(msg)
......@@ -126,7 +129,8 @@ class TelegramRootPlugin(TelegramProcessBase):
try:
if i > 0:
_log.info('Retrying %d/%d...', i + 1, retries)
return method(chat_id, *args, **kwargs)
with Status.pulse((0, 0, 1)):
return method(chat_id, *args, **kwargs)
except terr.TimedOut as e:
_log.error('Telegram timed out when executing %s: %s.', str(method), e.message)
except terr.RetryAfter as e:
......@@ -155,6 +159,7 @@ class TelegramRootPlugin(TelegramProcessBase):
sleep(1)
except:
_log.exception('Error when performing %s.', str(method))
Status.blink((1, 0, 0), n=1)
return None
@property
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment