Commit 23242719 authored by Pietro Saccardi's avatar Pietro Saccardi

Added controller part of PWM LED for Ratcam plugin.

parent 02e898c2
......@@ -7,6 +7,7 @@ from specialized.plugin_picamera import PiCameraRootPlugin
from specialized.plugin_buffered_recorder import BufferedRecorderPlugin
from specialized.plugin_motion_detector import MotionDetectorResponder, MotionDetectorCameraPlugin
from specialized.plugin_telegram import TelegramProcessBase, handle_command, TelegramRootPlugin
from specialized.plugin_pwmled import PWMLedPlugin
import os
import logging
from misc.logging import camel_to_snake
......@@ -45,7 +46,8 @@ class KnownPluginsCache:
MotionDetectorCameraPlugin: find_plugin(MotionDetectorCameraPlugin, Process.CAMERA),
PiCameraRootPlugin: find_plugin(PiCameraRootPlugin, Process.CAMERA),
StillPlugin: find_plugin(StillPlugin, Process.CAMERA),
TelegramRootPlugin: find_plugin(TelegramRootPlugin, Process.TELEGRAM)
TelegramRootPlugin: find_plugin(TelegramRootPlugin, Process.TELEGRAM),
PWMLedPlugin: find_plugin(PWMLedPlugin, Process.MAIN)
def _clear_plugins_cache(self):
......@@ -66,6 +68,11 @@ class KnownPluginsCache:
return self._plugins_cache[MotionDetectorCameraPlugin]
def pwm_led_plugin(self):
return self._plugins_cache[PWMLedPlugin]
def still_plugin(self):
......@@ -152,6 +159,43 @@ class RatcamTelegramPlugin(TelegramProcessBase, MediaReceiver, MotionDetectorRes
except ValueError:
self.root_telegram_plugin.reply_message(upd, 'Please specify \'on\' or \'off\' or nothing.')
@handle_command('light', pass_args=True)
def cmd_detect(self, upd, args):
if len(args) not in (0, 1):
return # More than one argument is not something we handle
if self.pwm_led_plugin is None:
self.root_telegram_plugin.reply_message(upd, 'Cannot offer LED light, the %s is not loaded.' %
if len(args) == 0:
light_value = self.pwm_led_plugin.value
if light_value is None:
self.root_telegram_plugin.reply_message(upd, 'Cannot offer LED light, pin number not set.')
self.root_telegram_plugin.reply_message(upd, 'Light is %s (set at %d%%).' %
(bool_desc(light_value > 0), int(100. * light_value)))
# Try a float first
light_value = None
light_value = float(args[0])
except ValueError:
# Try a bool then
if fuzzy_bool(args[0]):
light_value = 1.
light_value = 0.
except ValueError:
self.root_telegram_plugin.reply_message(upd, 'Please specify \'on\' or \'off\' or a valid number.')
if light_value == self.pwm_led_plugin.value:
self.root_telegram_plugin.reply_message(upd, 'Light is already set to %d%%.' % int(100. * light_value))
self.pwm_led_plugin.value = light_value'[%s] set the light to %d%%.', user_desc(upd), int(100. * light_value))
self.root_telegram_plugin.reply_message(upd, 'Setting light to %d%%.' % int(100. * light_value))
def cmd_photo(self, upd):
if self.still_plugin is None:
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