def __init__(self): Controller.__init__(self, "controller.test", "test") self.type = "test" #define an input and link it to the dashboard panel self.test_number = self.inputs.add("test_number", "Number", NumberValue) self.test_number.unit = "%" self.test_number.link_to_dashboard("dashboard", "number", label="xy") self.test_number.link_to_dashboard("dashboard", "number", label="#", label_icon="highlight") self.test_number.link_to_dashboard("dashboard", "number_inline", inline=True, label="#", label_icon="mdi:bluetooth") self.test_number.link_to_dashboard("dashboard", "number_gauge", type="radial_gauge") self.test_number.add_error_range((0, 10), "l error message", channels=["user_log", "email"]) self.test_number.add_warning_range((10, 20), "l warning message") self.test_number.add_warning_range((80, 90), "h warning message") self.test_number.add_normal_range((20, 80), "normal") self.test_number.add_error_range((90, 100), "h error message", channels=["user_log", "email"])
def __init__(self): Controller.__init__(self, "controller.test", "test") self.type = "test" #define an input and link it to the dashboard panel self.color = self.inputs.add("color", "Boolean", ColorValue) self.color.value = "#000f00" self.color.persist_value = True self.color.link_to_dashboard("dashboard", "boolean") self.color.link_to_dashboard("dashboard", "boolean", label="#", label_icon="lightbulb-o") self.color.link_to_dashboard( "dashboard", "boolean", label="#", ) self.inputs["color"].link_to_dashboard( "dashboard", "color", label="#", ) self.inputs["color"].link_to_dashboard("color", "color_inline", label="#inline", inline=True) self.color_out = self.outputs.add("color_out", "Color out", ColorValue) self.color_out.link_to_dashboard()
def link_to_dashboard(self, dashboard_id=None, panel_id=None, **kwargs): r""" Links this camera to a dashboard section or to the background of a dashboard. :param dashboard_id: id of the dashboard to link to. :type section_id: str :param section_id: id of the section. :type section_id: str :param \**kwargs: Use the kwargs below to override default values set in ui_parameters :Keyword Arguments: * *ui_size* (``int``) -- Size of the component in dashboard unit size. In order to make the sections and components align correct a dashboard unit is defined. Default the dashboard unit is a square that is 150 x 150 pixels. The width of the camera picture is ui_size * dashboard unit size. * *show_buttons* (``bool``) -- Add this component to header of section. * *show_pan_tilt* (``bool``) -- Add this component to header of section. """ if panel_id is None: panel_id = "background" Controller.link_to_dashboard(self, dashboard_id, panel_id, **kwargs)
def __init__(self): Controller.__init__(self, "fan_controller", "Fan") self.type = "fan" self.temp = self.inputs.add_number("temp", min=0, max=150, unit="c") # self.temp = self.inputs.add("temp", "Temperature", NumberValue) # self.temp.min = 0 # self.temp.max = 150 # self.temp.unit = "c" self.trigger_temp = self.inputs.add("trigger_temp", "Trigger temperature y", NumberValue) self.trigger_temp.min = 0 self.trigger_temp.max = 100 self.trigger_temp.unit = "c" #remember the value when app restarts self.trigger_temp.persist_value = True self.max_temp = self.inputs.add("max_temp", "Max speed temperature", NumberValue) self.max_temp.min = 0 self.max_temp.max = 100 self.max_temp.unit = "c" #remember the value when app restarts self.max_temp.persist_value = True self.active = self.inputs.add("active", "Active", BooleanValue) self.active.value = False self.active.persist_value = True self.fan_speed = self.outputs.add("fan_speed", "Fanspeed", NumberValue) self.fan_on = self.outputs.add("fan_on", "Fan on", BooleanValue)
def __init__(self): Controller.__init__(self, "systemController", "System") self.type = "system_power" self.power_button = self.inputs.add("power", "Power", BooleanValue) self.power_button.link_to_dashboard( "system", "power", #inline=True, button_text=None, button_icon="power-off", type="switch") self.reboot_button = self.inputs.add("reboot", "Reboot", BooleanValue) self.reboot_button.link_to_dashboard( "system", "power", #inline=True, button_text=None, button_icon="repeat", type="button") self.reboot_button.link_to_dashboard( "*", "header_right", #inline=True, label=None, button_text="Reboot", button_icon="repeat", type="button")
def __init__(self): Controller.__init__(self, "controller.test", "test") self.type = "test" self.test_string = self.inputs.add("test_string", "String", StringValue) self.test_string.persist_value = True self.test_string.link_to_dashboard() self.test_string.link_to_dashboard(label="#", label_icon="lightbulb-o") self.test_string.link_to_dashboard(label="#", label_icon="lightbulb-o", inline=True) self.test_string.link_to_dashboard(label=None, input_size="30px") self.test_string.link_to_dashboard(label="30px", input_size="30px") self.test_string.link_to_dashboard(label="30%", input_size="30%") self.test_string.link_to_dashboard(label="5rem", input_size="5rem") self.test_string.link_to_dashboard(label="5rem", input_size="5rem", inline=True) self.test_string.link_to_dashboard(label=None, inline=True) self.test_string_out = self.outputs.add("test_string_out", "String out", StringValue) self.test_string_out.link_to_dashboard() self.test_string_out.link_to_dashboard(inline=True) self.test_string_out.value = "a test"
def __init__(self, log_queue): Controller.__init__(self, "storage_manager", "Storage manager") self._spine = Spine() self._spine.register_event_handler("valueChanged", self._store_value) self._spine.register_query_handler("getValueData", self._get_value_data) self._spine.register_command_handler("storeSetting", self._store_setting) self._spine.register_query_handler("retrieveSetting", self._retrieve_setting) self._spine.register_query_handler("getMessageItems", self._get_messages) self._spine.register_event_handler("newMessage", self._store_message) #SPINE.register_command_handler("createCronJob", create_cron_job) #SPINE.register_command_handler("deleteCronJob", delete_cron_job) #SPINE.register_query_handler("queryCronJob", query_cron_job) self._plugin_manager = None self._plugin_manager = PluginManager(Configuration, "storage", [StoragePlugin], log_queue=log_queue) self._plugin_manager.load_managed_plugins()
def __init__(self): Controller.__init__(self, "fan_controller", "Fan") self.type = "fan" self.temp = self.inputs.add("temp", "Temperature", NumberValue) self.temp.min = 0 self.temp.max = 150 self.trigger_temp = self.inputs.add("trigger_temp", "Trigger temperature", NumberValue) self.trigger_temp.min = 0 self.trigger_temp.max = 100 #remember the value when app restarts self.trigger_temp.persist_value = True self.max_temp = self.inputs.add("max_temp", "Max speed temperature", NumberValue) self.max_temp.min = 0 self.max_temp.max = 100 #remember the value when app restarts self.max_temp.persist_value = True #The only output from this controller is the speed of the fan self.fan_speed = self.outputs.add("fan_speed", "Fanspeed", NumberValue) #private flag that indicate the controller is active and monitors temp and set speed. self._active = True
def __init__(self): Controller.__init__(self, "fan_controller", "Fan") self.type = "fan" self.temp = self.inputs.add("temp", "Temperature", NumberValue) self.temp.min = 0 self.temp.max = 150 self.trigger_temp = self.inputs.add("trigger_temp", "Trigger temperature", NumberValue) self.trigger_temp.min = 0 self.trigger_temp.max = 100 #remember the value when app restarts self.trigger_temp.persist_value = True self.max_temp = self.inputs.add("max_temp", "Max speed temperature", NumberValue) self.max_temp.min = 0 self.max_temp.max = 100 #remember the value when app restarts self.max_temp.persist_value = True self.fan_speed = self.outputs.add("fan_speed", "Fanspeed", NumberValue) self._active = True
def __init__(self, stream_id, stream_event, observer_id, handler=None, name="stream", observer_type="stream_observer"): Controller.__init__(self, observer_id, name) self.type = observer_type self.observer_id = observer_id self.stream_id = stream_id self.stream_event = stream_event self._epc_start_time = time.time() self._epc_counter = 0 self._handler = handler self._last_event_frame = None self._lock = Lock() self._ui_parameters["source_stream"] = stream_id self._ui_parameters["stream"] = stream_id + "." + self.observer_id self.streamed_eps = self.outputs.add("source_eps", "Events per second", NumberValue) self.spine.register_stream_handler(stream_id, self._on_event, stream_event)
def __init__(self): Controller.__init__(self, "systemController", "System") self.type = "system_power" self.power_button = self.inputs.add("power", "Power", BooleanValue) self.power_button.link_to_dashboard( "system", "power", #inline=True, on_text="Til", on_icon="cloud", off_text="fra", off_icon="check", type="switch") self.reboot_button = self.inputs.add("reboot", "Reboot", BooleanValue) self.reboot_button.link_to_dashboard( "system", "power", #inline=True, button_text="knap", button_icon="cloud", type="button", #button_width="5rem", #button_height="6rem" )
def __init__(self, controller_id, device_name, num_motors): Controller.__init__(self, controller_id, device_name + "-DC motors") self._num_motors = num_motors self._device_name = device_name for motor in range(0, num_motors): self.inputs.add("motor_" + str(motor), "Motor " + str(motor), NumberValue)
def __init__(self, input_id="user_input", name="User input", device=None, **kwargs): Controller.__init__(self, input_id, name) listen_to_keyboard = kwargs.pop("listen_to_keyboard", False) listen_to_mouse = kwargs.pop("listen_to_mouse", False) listen_to_gamepad = kwargs.pop("listen_to_gamepad", True) self._devices = hal.get_user_inputs() self._keyboard_thread = None self._mouse_thread = None self._gamepad_thread = None if listen_to_keyboard: if len(self._devices.keyboards): self._keyboard_thread = _InputThread(self, self._devices.keyboards[0]) else: self.spine.log.warning("no keyboards found") if listen_to_mouse: if len(self._devices.mice): self._mouse_thread = _InputThread(self, self._devices.mice[0]) else: self.spine.log.warning("no mouse found") if listen_to_gamepad: if len(self._devices.gamepads): self._gamepad_thread = _InputThread(self, self._devices.gamepads[0]) else: self.spine.log.warning("no gamepads found") self.key = self.outputs.add("key", "Key", StringValue) self.mouse_x = self.outputs.add("mouse_x", "Mouse x", NumberValue) self.mouse_y = self.outputs.add("mouse_y", "Mouse y", NumberValue) self.mouse_wheel = self.outputs.add("mouse_wheel", "Mouse wheel", NumberValue) self._key_map = {} self._ctrl_keys = ["KEY_LEFTCTRL", "KEY_LEFTMETA", "KEY_LEFTSHIFT", "KEY_RIGHTCTRL", "KEY_RIGNTMETA", "KEY_RIGHTSHIFT"]
def __init__(self, page_id, name=None): Controller.__init__(self, page_id, name) self.spine.register_event_handler("valueChanged", self._link_changed_event) self._template = "" self._links = {} self._displays = [] self._text = None self._lines = 1
def __init__(self, log_queue): Controller.__init__(self, "message_manager", "Message handler") self.spine.register_command_handler("messageManagerSend", self.send_message) self._channels = {} self._authorization = Authorization() self._plugin_manager = PluginManager(Configuration, "messaging", [MessagePlugin], log_queue=log_queue) self._plugin_manager.load_managed_plugins() self._users = self._authorization.get_users() self.load()
def __init__(self): Controller.__init__(self, "fan_controller", "Fan") #define an input that is a number self.temp = self.inputs.add("temp", "Temperature", NumberValue) self.temp.min = 0 self.temp.max = 150 #define an output that is a number self.fan_speed = self.outputs.add("fan_speed", "Fan speed", NumberValue)
def __init__(self): Controller.__init__(self, "fan_controller", "Fan") self.temp = self.inputs.add("temp", "Temperature", NumberValue) self.temp.min = 0 self.temp.max = 150 self.fan_speed = self.outputs.add("fan_speed", "Fanspeed", NumberValue) self._active = False
def __init__(self): Controller.__init__(self, "controller.test", "test") self.type = "test" self.lcd = CharLCDDeviceDriver() self.lcd.enable_display(True) self.lcd.message("test") self.lcd.set_backlight(True) self.inputs.add("text", "LCD text", StringValue) self.inputs["text"].link_to_dashboard("dashboard.ctrl", "input")
def __init__(self): Controller.__init__(self, "controller.test", "test") self.type = "test" #define an input and link it to the dashboard panel select = self.inputs.add("select1", "enum ", EnumValue) select.add_option("1", "option 1", selected=True) select.add_option("2", "option 2") select.add_option("3", "option 3") select.persist_value = True select.link_to_dashboard() select.link_to_dashboard(type="buttons")
def __init__(self, **kwargs): Controller.__init__(self, "test_controller", "Test controller", **kwargs) self.input_1 = self.inputs.add("controller_input_1", "input 1", NumberValue) self.input_2 = self.inputs.add("controller_input_2", "input 2", NumberValue) self.output = self.outputs.add("controller_output", "output", NumberValue) self.last_input = None self.start_event = False self.exit_event = False
def __init__(self, display_id, name, device_driver): Controller.__init__(self, display_id, name) self._device = device_driver self.text = self.inputs.add("text", "Text", StringValue) self._bitmap = None self._display_active = False self._line_height = 0 self._font = None self._background_color = (0) self._text_color = (255) self._pages = {} self._active_page = None self._page_change_speed = 5 self._page_timer = None self._bitmap_lock = threading.Lock()
def __init__(self, sensor_id, name, device=None, **kwargs): Controller.__init__(self, sensor_id, name, **kwargs) self._device = device self._sub_sensors = [] self._dimensions = 1 self._index = kwargs.pop("index", -1) self._enabled = None if device.value_type == "color": self._sensor_value = self.outputs.add("value", name, ColorValue) elif device.value_type == "number": self._sensor_value = self.outputs.add(sensor_id, name, NumberValue) else: raise ValueError("Can not handle device value type: " + device.value_type) if self._device: self.value_type = self._device.type self.value_unit = self._device.unit self._sensor_value.type = self._device.type self._sensor_value.unit = self._device.unit self._sensor_value.min = self._device.min self._sensor_value.max = self._device.max if self._index == -1: self._dimensions = self._device.dimensions self._dimension_labels = self._device.dimension_labels if self._dimensions > 1: count = 0 for label in self._dimension_labels: sub_sensor = Sensor( self.component_id + "." + label, label, self._device, use_thread=False, #parent=self, index=count, **kwargs) sub_sensor.value_unit = self.value_unit self._sub_sensors += [sub_sensor] count += 1 if kwargs.get("use_thread", True): self._sensor_thread = _SensorThread( self, kwargs.get("polling_interval", 1)) else: self._sensor_thread = None
def __init__(self): Controller.__init__(self, "controller.test", "test") self.type = "test" #define an input and link it to the dashboard panel button = UIButtonControllerInput("switchbtn", "Switch", self) button.link_to_dashboard("dahsboard.ctrl", "button") button1 = UIButtonControllerInput("switchbtn1", "Switch 1", self) button1.link_to_dashboard("dahsboard.ctrl", "button", button_icon="lightbulb-o", button_text="btn text") button2 = UIButtonControllerInput("switchbtn2", "button 1", self) button2.link_to_dashboard("dahsboard.ctrl", "button", button_icon="lightbulb-o", label="label", label_icon="lightbulb-o") button2.link_to_dashboard("dahsboard.ctrl", "button_inline", button_icon="lightbulb-o", label="label", label_icon="lightbulb-o") #inline button5 = UIButtonControllerInput("switchbtn5", "Switch", self) button5.link_to_dashboard("dahsboard.ctrl", "button_inline", inline=True, button_icon="lightbulb-o") button6 = UIButtonControllerInput("switchbtn6", "Switch", self) button6.link_to_dashboard("dahsboard.ctrl", "button_inline", inline=True, label=False, label_icon="lightbulb-o") button7 = UIButtonControllerInput("switchbtn7", "Switch", self) button7.link_to_dashboard("dahsboard.ctrl", "button_inline", inline=True, label=False)
def __init__(self): Controller.__init__(self, "authentication", "Authentication") #self._config = Configuration.authentication self._sessions = {} self._plugin_manager = PluginManager(Configuration, "authentication", [AuthenticationPlugin]) self.spine.register_query_handler("authorizationActive", self._is_active) self.spine.register_query_handler("authorizationValidSessionHeader", self._is_session_valid) self.spine.register_query_handler("authorizationAllowAnonymousUser", self.allow_anonymous) self.spine.register_query_handler("authorizationGetUsers", self.get_users) self.spine.register_query_handler("authorizationAuthorizeUser", self.authorize) self.spine.register_command_handler("authorizationRemoveSession", self.remove_session)
def __init__(self, camera_id, name, **kwargs): Controller.__init__(self, camera_id, name) self.type = "camera" #self.media_config = Configuration.media self.inputs.add("pan", "Pan", NumberValue) self.inputs.add("tilt", "Tilt", NumberValue) self.fpc_start_time = time.time() self.fpc_counter = 0 self.pan = self.outputs.add("pan", "Pan", NumberValue) self.tilt = self.outputs.add("tilt", "Tilt", NumberValue) self.streamed_fps = self.outputs.add("stream_fps", "Streamed frames pr second", NumberValue) self.flip_vertical = kwargs.get("flip_vertical", False) self.flip_horizontal = kwargs.get("flip_horizontal", False) self.inputs.add("fps", "FPS", EnumValue) self.inputs["fps"].set_ui_parameter("inline", True) self.actions["take_picture"].set_ui_parameter("button_icon", "camera") self.actions["take_picture"].set_ui_parameter("inline", True) self.actions["take_picture"].set_ui_parameter("display_type", "button") self.actions["take_picture"].set_ui_parameter("label", None) self.actions["take_picture"].set_ui_parameter("button_text", None) self.actions["take_picture"].stop_message_enabled = False self.actions["record"].set_ui_parameter("button_icon", "video") self.actions["record"].set_ui_parameter("inline", True) self.actions["record"].set_ui_parameter("display_type", "switch") self.actions["record"].set_ui_parameter("label", None) self.actions["record"].set_ui_parameter("button_text", None) self._ui_parameters["height"] = kwargs.get("height", 480) self._ui_parameters["width"] = kwargs.get("width", 640) self._ui_parameters["type"] = kwargs.get("type", "") self._ui_parameters["fps"] = kwargs.get("fps", 20) self._ui_parameters["source"] = kwargs.get("source", "") self._ui_parameters["show_pan_tilt"] = kwargs.get( "show_pan_tilt", False) self._ui_parameters["show_buttons"] = kwargs.get("show_buttons", True)
def __init__(self, controller_id="steering", name="Steering"): Controller.__init__(self, controller_id, name) self.type = "steering" self.left_speed = self.outputs.add("left_speed", "Left speed", NumberValue) self.right_speed = self.outputs.add("right_speed", "Right speed", NumberValue) self.inputs.add("left_encoder", "Left encoder", NumberValue) self.inputs.add("right_encoder", "Right encoder", NumberValue) self._adjust = 0 self.speed = self.inputs.add("speed", "Speed", NumberValue) self.adaptive_speed = self.inputs.add("adaptive_speed", "Adaptive speed", NumberValue) self.direction = self.inputs.add("direction", "Direction", NumberValue) self.adaptive_direction = self.inputs.add("Adaptive direction", "Adaptive direction", NumberValue)
def __init__(self, stream_id, region_group, observer_id, handler=None, name="stream", observer_type="stream_observer"): Controller.__init__(self, observer_id, name) self.type = observer_type self.observer_id = observer_id self.stream_id = stream_id self.region_group = region_group self._epc_start_time = time.time() self._epc_counter = 0 self._handler = handler self.streamed_eps = self.outputs.add("source_eps", "Events per second", NumberValue) self.spine.register_event_handler("visionRegionChange", self._on_event, stream_id)
def __init__(self, camera_id, name, **kwargs): Controller.__init__(self, camera_id, name) self.type = "camera" self.media_config = Configuration.media self.inputs.add("pan", "Pan", NumberValue) self.inputs.add("tilt", "Tilt", NumberValue) self.pan = self.outputs.add("pan", "Pan", NumberValue) self.tilt = self.outputs.add("tilt", "Tilt", NumberValue) self.flip_vertical = kwargs.get("flip_vertical", False) self.flip_horizontal = kwargs.get("flip_horizontal", False) self.inputs.add("fps", "FPS", EnumValue) self.inputs["fps"].set_ui_parameter("inline", True) self.actions["take_picture"].set_ui_parameter("button_icon", "camera") self.actions["take_picture"].set_ui_parameter("inline", True) self.actions["take_picture"].set_ui_parameter("type", "button") self.actions["take_picture"].set_ui_parameter("label", None) self.actions["take_picture"].set_ui_parameter("button_text", None) self.actions["record"].set_ui_parameter("button_icon", "video") self.actions["record"].set_ui_parameter("inline", True) self.actions["record"].set_ui_parameter("type", "button") self.actions["record"].set_ui_parameter("label", None) self.actions["record"].set_ui_parameter("button_text", None) self._ui_parameters["height"] = kwargs.get("height", 480) self._ui_parameters["width"] = kwargs.get("width", 640) self._ui_parameters["type"] = kwargs.get("type", "") self._ui_parameters["fps"] = kwargs.get("fps", 10) self._ui_parameters["source"] = kwargs.get("source", "") self._ui_parameters["show_pan_tilt"] = kwargs.get( "show_pan_tilt", False) self._ui_parameters["show_buttons"] = kwargs.get("show_buttons", True) self.spine.register_query_handler(camera_id + ".getMedia", self._get_media)
def __init__(self): Controller.__init__(self, "controller.test", "test") self.type = "test" #define an input and link it to the dashboard panel self.input1 = self.inputs.add("d1", "DateTime 1", DateTimeValue) self.input1.persist_value = True self.input1.link_to_dashboard("dahsboard.ctrl", "textinput") self.input2 = self.inputs.add("d2", "DateTime 2", DateTimeValue) self.input2.link_to_dashboard("dahsboard.ctrl", "textinput", type="date", input_size=None) self.input3 = self.inputs.add("d3", "DateTime 3", DateTimeValue) self.input3.link_to_dashboard("dahsboard.ctrl", "textinput", type="time", input_size=75) self.input1.link_to_dashboard("dahsboard.ctrl", "text_inline")
def __init__(self, controller_id , device_name, num_motors): Controller.__init__(self, controller_id, device_name + "-DC motors") self._num_motors = num_motors self._device_name = device_name