Skip to content

Commit

Permalink
🚀 3.10.0, #218
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail authored Sep 23, 2023
2 parents ad3a4f8 + 0db769d commit 7c7b8d5
Show file tree
Hide file tree
Showing 7 changed files with 385 additions and 248 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ Each relay has the following settings *(in order of appearance)*:
|-------------------------|------------------------------------------------------------------|
| Active | Activates the relay control and indication on the navigation bar |
| Label | The relay description to show on tooltip and in dialogs |
| This is printer relay | Closes the printer connection when turning this relay `OFF` |
| Icon `ON` / `OFF` | An image or emoji to indicate the relay state (supports HTML) |
| This is printer relay | Closes the printer connection when turning this relay `OFF` |
| AutoConnect delay | Printer relay feature adjustment when turning it `ON` |
| GPIO Number | The [GPIO pin on the Raspberry Pi](https://pinout.xyz/) |
| Inverted output | For normally closed relay: the relay is `ON` without power |
| Confirm turning `OFF` | Enables a confirmation dialog when turning the relay `OFF` |
Expand Down
Binary file modified img/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 5 additions & 7 deletions octoprint_octorelay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import octoprint.plugin
from octoprint.events import Events
from octoprint.util import RepeatedTimer
from octoprint.util import RepeatedTimer, ResettableTimer
from octoprint.access.permissions import Permissions

from .const import (
Expand Down Expand Up @@ -172,12 +172,10 @@ def on_event(self, event, payload):
elif hasattr(Events, "CONNECTIONS_AUTOREFRESHED"): # Requires OctoPrint 1.9+
if event == Events.CONNECTIONS_AUTOREFRESHED:
if payload is not None and "ports" in payload and len(payload["ports"]) > 0:
self._logger.debug("Connecting to the printer")
self._printer.connect()
#elif event == Events.PRINT_CANCELLING:
# self.print_stopped()
#elif event == Events.PRINT_CANCELLED:
# self.print_stopped()
delay = int(self._settings.get(["common", "delay"], merged=True) or 0) # expensive
self._logger.debug(f"AutoConnecting to the printer in {delay}s")
method = self._printer.connect
(method if delay == 0 else ResettableTimer(delay, method).start)()

def handle_plugin_event(self, event, scope = None):
if scope is None:
Expand Down
3 changes: 2 additions & 1 deletion octoprint_octorelay/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
def get_default_settings():
return {
"common": {
"printer": "r2"
"printer": "r2",
"auto_connect_delay": 0
},
"r1": {
"active": False,
Expand Down
36 changes: 25 additions & 11 deletions octoprint_octorelay/templates/octorelay_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@
</div>
</div>

{% for state in ["on", "off"] %}
<div class="control-group">
<label class="control-label">
{{ _('Icon') }}
<span class="label">{{ _(state.upper()) }}</span>
</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="fa fa-code fa-sm"></i></span>
<input
type="text"
class="input-xlarge code"
data-bind="value: icon_{{state}}"
>
</div>
</div>
</div>
{% endfor %}

<div class="control-group">
<label class="control-label">{{ _('This is printer relay') }}</label>
<div class="controls">
Expand Down Expand Up @@ -92,24 +111,19 @@
</div>
</div>

{% for state in ["on", "off"] %}
<div class="control-group">
<label class="control-label">
{{ _('Icon') }}
<span class="label">{{ _(state.upper()) }}</span>
</label>
<div class="control-group" data-bind="visible: $parent.common.printer() === 'r{{n}}'">
<label class="control-label">{{ _('AutoConnect delay') }}</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="fa fa-code fa-sm"></i></span>
<span class="add-on">{{ _('s') }}</span>
<input
type="text"
class="input-xlarge code"
data-bind="value: icon_{{state}}"
type="number" min="0" max="600" class="input-mini"
data-bind="value: $parent.common.delay"
>
</div>
<span class="help-inline">{{ _('Requires OctoPrint 1.9.0+') }}</a>
</div>
</div>
{% endfor %}

<div class="control-group">
<label class="control-label">{{ _('GPIO Number') }}</label>
Expand Down
Loading

0 comments on commit 7c7b8d5

Please sign in to comment.