From f4b23a9d106952e3d479db6d93978d428de16c5a Mon Sep 17 00:00:00 2001 From: Maksim Pushkarev Date: Tue, 14 Apr 2020 03:40:44 +0400 Subject: [PATCH 01/10] Add after PowerON commands (#144) --- octoprint_psucontrol/__init__.py | 15 +++++++++++++++ .../templates/psucontrol_settings.jinja2 | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index b01f4ea..ace9188 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -100,6 +100,8 @@ def __init__(self): self.autoOn = False self.autoOnTriggerGCodeCommands = '' self._autoOnTriggerGCodeCommandsArray = [] + self.afterOnGCodeCommands = '' + self._afterOnGCodeCommandsArray = [] self.enablePowerOffWarningDialog = True self.powerOffWhenIdle = False self.idleTimeout = 0 @@ -192,6 +194,10 @@ def on_settings_initialized(self): self._autoOnTriggerGCodeCommandsArray = self.autoOnTriggerGCodeCommands.split(',') self._logger.debug("autoOnTriggerGCodeCommands: %s" % self.autoOnTriggerGCodeCommands) + self.afterOnGCodeCommands = self._settings.get(["afterOnGCodeCommands"]) + self._afterOnGCodeCommandsArray = self.afterOnGCodeCommands.split(',') + self._logger.debug("afterOnGCodeCommands: %s" % self.afterOnGCodeCommands) + self.enablePowerOffWarningDialog = self._settings.get_boolean(["enablePowerOffWarningDialog"]) self._logger.debug("enablePowerOffWarningDialog: %s" % self.enablePowerOffWarningDialog) @@ -539,6 +545,12 @@ def turn_psu_on(self): if self.sensingMethod not in ('GPIO','SYSTEM'): self._noSensing_isPSUOn = True + time.sleep(0.1) + + if self.afterOnGCodeCommands: + for command in self._afterOnGCodeCommandsArray: + self._printer.commands(command) + time.sleep(0.1 + self.postOnDelay) self.check_psu_state() @@ -632,6 +644,7 @@ def get_settings_defaults(self): senseSystemCommand = '', autoOn = False, autoOnTriggerGCodeCommands = "G0,G1,G2,G3,G10,G11,G28,G29,G32,M104,M106,M109,M140,M190", + afterOnGCodeCommands = '', enablePowerOffWarningDialog = True, powerOffWhenIdle = False, idleTimeout = 30, @@ -672,6 +685,8 @@ def on_settings_save(self, data): self.autoOn = self._settings.get_boolean(["autoOn"]) self.autoOnTriggerGCodeCommands = self._settings.get(["autoOnTriggerGCodeCommands"]) self._autoOnTriggerGCodeCommandsArray = self.autoOnTriggerGCodeCommands.split(',') + self.afterOnGCodeCommands = self._settings.get(["afterOnGCodeCommands"]) + self._afterOnGCodeCommandsArray = self.afterOnGCodeCommands.split(',') self.powerOffWhenIdle = self._settings.get_boolean(["powerOffWhenIdle"]) self.idleTimeout = self._settings.get_int(["idleTimeout"]) self.idleIgnoreCommands = self._settings.get(["idleIgnoreCommands"]) diff --git a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 index cfcb06d..a90464d 100644 --- a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 +++ b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 @@ -157,6 +157,12 @@ +
+ +
+ +
+
From 55d6b1c4bbc9debab66c93048dc77e1918a2d6af Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Mon, 13 Apr 2020 19:44:53 -0400 Subject: [PATCH 02/10] Remove 0.1s delay and move afterOnGCodeCommands command execution to after postOnDelay --- octoprint_psucontrol/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index ace9188..45e4066 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -545,13 +545,12 @@ def turn_psu_on(self): if self.sensingMethod not in ('GPIO','SYSTEM'): self._noSensing_isPSUOn = True - time.sleep(0.1) + time.sleep(0.1 + self.postOnDelay) if self.afterOnGCodeCommands: for command in self._afterOnGCodeCommandsArray: self._printer.commands(command) - - time.sleep(0.1 + self.postOnDelay) + self.check_psu_state() def turn_psu_off(self): From 3dd1bb0d93902629a81b88e86c694cd12a99130d Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Mon, 13 Apr 2020 20:24:49 -0400 Subject: [PATCH 03/10] GitHub issue template changes Updated readme with support URL and feature requests. --- .github/ISSUE_TEMPLATE.md | 20 ++++++++++++++------ README.md | 8 ++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 5c8e3ea..bbbdf75 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,23 +1,31 @@ diff --git a/README.md b/README.md index 54485b2..9f955a9 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,8 @@ Supports Commands (G-Code or System) or GPIO to switch power supply on/off. ## Setup - Install the plugin using Plugin Manager from Settings - ## Settings See the [Wiki](https://github.com/kantlivelong/OctoPrint-PSUControl/wiki/Settings) @@ -21,3 +19,9 @@ See the [Wiki](https://github.com/kantlivelong/OctoPrint-PSUControl/wiki/Trouble ## API See the [Wiki](https://github.com/kantlivelong/OctoPrint-PSUControl/wiki/API) + +## Support +Help can be found at the [OctoPrint Community Forums](https://community.octoprint.org) + +## Feature Requests +[![Feature Requests](https://feathub.com/kantlivelong/OctoPrint-PSUControl?format=svg)](https://feathub.com/kantlivelong/OctoPrint-PSUControl) From b8cc5cbc5eda4a06c40d1284bd9c88fa08a91d19 Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Wed, 2 Dec 2020 19:58:00 -0500 Subject: [PATCH 04/10] Fix an issue where switching/sensing methods would not reflect the correct value if using GPIO --- octoprint_psucontrol/__init__.py | 17 ++++++++++++----- octoprint_psucontrol/static/js/psucontrol.js | 11 ++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index 45e4066..5c2a773 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -7,6 +7,7 @@ import octoprint.plugin from octoprint.server import user_permission +from octoprint.events import Events import time import subprocess import threading @@ -68,10 +69,11 @@ def reset(self, interval=None): class PSUControl(octoprint.plugin.StartupPlugin, - octoprint.plugin.TemplatePlugin, - octoprint.plugin.AssetPlugin, - octoprint.plugin.SettingsPlugin, - octoprint.plugin.SimpleApiPlugin): + octoprint.plugin.TemplatePlugin, + octoprint.plugin.AssetPlugin, + octoprint.plugin.SettingsPlugin, + octoprint.plugin.SimpleApiPlugin, + octoprint.plugin.EventHandlerPlugin): def __init__(self): try: @@ -381,7 +383,7 @@ def _check_psu_state(self): elif (old_isPSUOn != self.isPSUOn) and not self.isPSUOn: self._stop_idle_timer() - self._plugin_manager.send_plugin_message(self._identifier, dict(hasGPIO=self._hasGPIO, isPSUOn=self.isPSUOn)) + self._plugin_manager.send_plugin_message(self._identifier, dict(isPSUOn=self.isPSUOn)) self._check_psu_state_event.wait(self.sensePollingInterval) self._check_psu_state_event.clear() @@ -593,6 +595,11 @@ def turn_psu_off(self): time.sleep(0.1) self.check_psu_state() + def on_event(self, event, payload): + if event == Events.CLIENT_OPENED: + self._plugin_manager.send_plugin_message(self._identifier, dict(hasGPIO=self._hasGPIO, isPSUOn=self.isPSUOn)) + return + def get_api_commands(self): return dict( turnPSUOn=[], diff --git a/octoprint_psucontrol/static/js/psucontrol.js b/octoprint_psucontrol/static/js/psucontrol.js index ac28ee9..e2a15e3 100644 --- a/octoprint_psucontrol/static/js/psucontrol.js +++ b/octoprint_psucontrol/static/js/psucontrol.js @@ -5,7 +5,7 @@ $(function() { self.settingsViewModel = parameters[0] self.loginState = parameters[1]; self.settings = undefined; - self.hasGPIO = ko.observable(undefined); + self.hasGPIO = ko.observable(true); self.isPSUOn = ko.observable(undefined); self.psu_indicator = $("#psucontrol_indicator"); @@ -40,8 +40,13 @@ $(function() { return; } - self.hasGPIO(data.hasGPIO); - self.isPSUOn(data.isPSUOn); + if (data.hasGPIO !== undefined) { + self.hasGPIO(data.hasGPIO); + } + + if (data.isPSUOn !== undefined) { + self.isPSUOn(data.isPSUOn); + } }; self.togglePSU = function() { From 1753ff86700f9ce137b6f7bbe044ad10c809ab6b Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Wed, 2 Dec 2020 21:29:09 -0500 Subject: [PATCH 05/10] Swap out afterOnGCodeCommands in favor of an actual gcode script. --- octoprint_psucontrol/__init__.py | 23 ++++++++----------- octoprint_psucontrol/static/js/psucontrol.js | 16 +++++++++++++ .../templates/psucontrol_settings.jinja2 | 12 +++++----- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index 45e4066..04796a5 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -100,8 +100,6 @@ def __init__(self): self.autoOn = False self.autoOnTriggerGCodeCommands = '' self._autoOnTriggerGCodeCommandsArray = [] - self.afterOnGCodeCommands = '' - self._afterOnGCodeCommandsArray = [] self.enablePowerOffWarningDialog = True self.powerOffWhenIdle = False self.idleTimeout = 0 @@ -194,10 +192,6 @@ def on_settings_initialized(self): self._autoOnTriggerGCodeCommandsArray = self.autoOnTriggerGCodeCommands.split(',') self._logger.debug("autoOnTriggerGCodeCommands: %s" % self.autoOnTriggerGCodeCommands) - self.afterOnGCodeCommands = self._settings.get(["afterOnGCodeCommands"]) - self._afterOnGCodeCommandsArray = self.afterOnGCodeCommands.split(',') - self._logger.debug("afterOnGCodeCommands: %s" % self.afterOnGCodeCommands) - self.enablePowerOffWarningDialog = self._settings.get_boolean(["enablePowerOffWarningDialog"]) self._logger.debug("enablePowerOffWarningDialog: %s" % self.enablePowerOffWarningDialog) @@ -214,6 +208,10 @@ def on_settings_initialized(self): self.idleTimeoutWaitTemp = self._settings.get_int(["idleTimeoutWaitTemp"]) self._logger.debug("idleTimeoutWaitTemp: %s" % self.idleTimeoutWaitTemp) + scripts = self._settings.listScripts("gcode") + if not "psucontrol_post_on" in scripts: + self._settings.saveScript("gcode", "psucontrol_post_on", u'') + if self.switchingMethod == 'GCODE': self._logger.info("Using G-Code Commands for On/Off") elif self.switchingMethod == 'GPIO': @@ -547,11 +545,9 @@ def turn_psu_on(self): time.sleep(0.1 + self.postOnDelay) - if self.afterOnGCodeCommands: - for command in self._afterOnGCodeCommandsArray: - self._printer.commands(command) - self.check_psu_state() + + self._printer.script("psucontrol_post_on", must_be_set=False) def turn_psu_off(self): if self.switchingMethod == 'GCODE' or self.switchingMethod == 'GPIO' or self.switchingMethod == 'SYSTEM': @@ -643,7 +639,6 @@ def get_settings_defaults(self): senseSystemCommand = '', autoOn = False, autoOnTriggerGCodeCommands = "G0,G1,G2,G3,G10,G11,G28,G29,G32,M104,M106,M109,M140,M190", - afterOnGCodeCommands = '', enablePowerOffWarningDialog = True, powerOffWhenIdle = False, idleTimeout = 30, @@ -684,8 +679,6 @@ def on_settings_save(self, data): self.autoOn = self._settings.get_boolean(["autoOn"]) self.autoOnTriggerGCodeCommands = self._settings.get(["autoOnTriggerGCodeCommands"]) self._autoOnTriggerGCodeCommandsArray = self.autoOnTriggerGCodeCommands.split(',') - self.afterOnGCodeCommands = self._settings.get(["afterOnGCodeCommands"]) - self._afterOnGCodeCommandsArray = self.afterOnGCodeCommands.split(',') self.powerOffWhenIdle = self._settings.get_boolean(["powerOffWhenIdle"]) self.idleTimeout = self._settings.get_int(["idleTimeout"]) self.idleIgnoreCommands = self._settings.get(["idleIgnoreCommands"]) @@ -693,6 +686,10 @@ def on_settings_save(self, data): self._idleIgnoreCommandsArray = self.idleIgnoreCommands.split(',') self.idleTimeoutWaitTemp = self._settings.get_int(["idleTimeoutWaitTemp"]) + if 'scripts_gcode_psucontrol_post_on' in data: + script = data["scripts_gcode_psucontrol_post_on"] + self._settings.saveScript("gcode", "psucontrol_post_on", u'' + script.replace("\r\n", "\n").replace("\r", "\n")) + #GCode switching and PseudoOnOff are not compatible. if self.switchingMethod == 'GCODE' and self.enablePseudoOnOff: self.enablePseudoOnOff = False diff --git a/octoprint_psucontrol/static/js/psucontrol.js b/octoprint_psucontrol/static/js/psucontrol.js index ac28ee9..25a92b5 100644 --- a/octoprint_psucontrol/static/js/psucontrol.js +++ b/octoprint_psucontrol/static/js/psucontrol.js @@ -5,6 +5,7 @@ $(function() { self.settingsViewModel = parameters[0] self.loginState = parameters[1]; self.settings = undefined; + self.scripts_gcode_psucontrol_post_on = ko.observable(undefined); self.hasGPIO = ko.observable(undefined); self.isPSUOn = ko.observable(undefined); self.psu_indicator = $("#psucontrol_indicator"); @@ -13,6 +14,21 @@ $(function() { self.settings = self.settingsViewModel.settings; }; + self.onSettingsShown = function () { + self.scripts_gcode_psucontrol_post_on(self.settings.scripts.gcode["psucontrol_post_on"]()); + }; + + self.onSettingsHidden = function () { + self.settings.plugins.psucontrol.scripts_gcode_psucontrol_post_on = null; + }; + + self.onSettingsBeforeSave = function () { + if (self.scripts_gcode_psucontrol_post_on() != self.settings.scripts.gcode["psucontrol_post_on"]()) { + self.settings.plugins.psucontrol.scripts_gcode_psucontrol_post_on = self.scripts_gcode_psucontrol_post_on; + self.settings.scripts.gcode["psucontrol_post_on"](self.scripts_gcode_psucontrol_post_on()); + } + }; + self.onStartup = function () { self.isPSUOn.subscribe(function() { if (self.isPSUOn()) { diff --git a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 index a90464d..ffdd8c2 100644 --- a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 +++ b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 @@ -157,12 +157,6 @@
-
- -
- -
-
@@ -172,6 +166,12 @@
+
+ +
+ +
+

Power Off Options

From b9a98dc0d2e6efa1d7f137c8a4bd9c4457d2b8f4 Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Wed, 2 Dec 2020 21:45:18 -0500 Subject: [PATCH 06/10] Add Pre Off GCode script --- octoprint_psucontrol/__init__.py | 10 ++++++++++ octoprint_psucontrol/static/js/psucontrol.js | 8 ++++++++ .../templates/psucontrol_settings.jinja2 | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index 04796a5..16772de 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -212,6 +212,10 @@ def on_settings_initialized(self): if not "psucontrol_post_on" in scripts: self._settings.saveScript("gcode", "psucontrol_post_on", u'') + scripts = self._settings.listScripts("gcode") + if not "psucontrol_pre_off" in scripts: + self._settings.saveScript("gcode", "psucontrol_pre_off", u'') + if self.switchingMethod == 'GCODE': self._logger.info("Using G-Code Commands for On/Off") elif self.switchingMethod == 'GPIO': @@ -551,6 +555,8 @@ def turn_psu_on(self): def turn_psu_off(self): if self.switchingMethod == 'GCODE' or self.switchingMethod == 'GPIO' or self.switchingMethod == 'SYSTEM': + self._printer.script("psucontrol_pre_off", must_be_set=False) + self._logger.info("Switching PSU Off") if self.switchingMethod == 'GCODE': self._logger.debug("Switching PSU Off Using GCODE: %s" % self.offGCodeCommand) @@ -690,6 +696,10 @@ def on_settings_save(self, data): script = data["scripts_gcode_psucontrol_post_on"] self._settings.saveScript("gcode", "psucontrol_post_on", u'' + script.replace("\r\n", "\n").replace("\r", "\n")) + if 'scripts_gcode_psucontrol_pre_off' in data: + script = data["scripts_gcode_psucontrol_pre_off"] + self._settings.saveScript("gcode", "psucontrol_pre_off", u'' + script.replace("\r\n", "\n").replace("\r", "\n")) + #GCode switching and PseudoOnOff are not compatible. if self.switchingMethod == 'GCODE' and self.enablePseudoOnOff: self.enablePseudoOnOff = False diff --git a/octoprint_psucontrol/static/js/psucontrol.js b/octoprint_psucontrol/static/js/psucontrol.js index 25a92b5..6fb4efb 100644 --- a/octoprint_psucontrol/static/js/psucontrol.js +++ b/octoprint_psucontrol/static/js/psucontrol.js @@ -6,6 +6,7 @@ $(function() { self.loginState = parameters[1]; self.settings = undefined; self.scripts_gcode_psucontrol_post_on = ko.observable(undefined); + self.scripts_gcode_psucontrol_pre_off = ko.observable(undefined); self.hasGPIO = ko.observable(undefined); self.isPSUOn = ko.observable(undefined); self.psu_indicator = $("#psucontrol_indicator"); @@ -16,10 +17,12 @@ $(function() { self.onSettingsShown = function () { self.scripts_gcode_psucontrol_post_on(self.settings.scripts.gcode["psucontrol_post_on"]()); + self.scripts_gcode_psucontrol_pre_off(self.settings.scripts.gcode["psucontrol_pre_off"]()); }; self.onSettingsHidden = function () { self.settings.plugins.psucontrol.scripts_gcode_psucontrol_post_on = null; + self.settings.plugins.psucontrol.scripts_gcode_psucontrol_pre_off = null; }; self.onSettingsBeforeSave = function () { @@ -27,6 +30,11 @@ $(function() { self.settings.plugins.psucontrol.scripts_gcode_psucontrol_post_on = self.scripts_gcode_psucontrol_post_on; self.settings.scripts.gcode["psucontrol_post_on"](self.scripts_gcode_psucontrol_post_on()); } + + if (self.scripts_gcode_psucontrol_pre_off() != self.settings.scripts.gcode["psucontrol_pre_off"]()) { + self.settings.plugins.psucontrol.scripts_gcode_psucontrol_pre_off = self.scripts_gcode_psucontrol_pre_off; + self.settings.scripts.gcode["psucontrol_pre_off"](self.scripts_gcode_psucontrol_pre_off()); + } }; self.onStartup = function () { diff --git a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 index ffdd8c2..2d9878e 100644 --- a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 +++ b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 @@ -207,6 +207,12 @@ +
+ +
+ +
+
From 4c15b3033e5537a24bdef13985e980f0585308fb Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Sun, 13 Dec 2020 10:42:29 -0500 Subject: [PATCH 07/10] Add experimental warning --- octoprint_psucontrol/templates/psucontrol_settings.jinja2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 index 2d9878e..259ba13 100644 --- a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 +++ b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 @@ -167,7 +167,7 @@
- +
@@ -208,7 +208,7 @@
- +
From 6cf34b081d2b03940cf3c7a2de8b06c69ee3cf5a Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Sun, 13 Dec 2020 11:10:23 -0500 Subject: [PATCH 08/10] Add connect on power on --- octoprint_psucontrol/__init__.py | 8 ++++++++ octoprint_psucontrol/templates/psucontrol_settings.jinja2 | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index b09ec7a..ea94a20 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -166,6 +166,9 @@ def on_settings_initialized(self): self.postOnDelay = self._settings.get_float(["postOnDelay"]) self._logger.debug("postOnDelay: %s" % self.postOnDelay) + self.connectOnPowerOn = self._settings.get_boolean(["connectOnPowerOn"]) + self._logger.debug("connectOnPowerOn: %s" % self.connectOnPowerOn) + self.disconnectOnPowerOff = self._settings.get_boolean(["disconnectOnPowerOff"]) self._logger.debug("disconnectOnPowerOff: %s" % self.disconnectOnPowerOff) @@ -553,6 +556,9 @@ def turn_psu_on(self): self.check_psu_state() + if self.connectOnPowerOn and self._printer.is_closed_or_error(): + self._printer.connect() + self._printer.script("psucontrol_post_on", must_be_set=False) def turn_psu_off(self): @@ -643,6 +649,7 @@ def get_settings_defaults(self): pseudoOnGCodeCommand = 'M80', pseudoOffGCodeCommand = 'M81', postOnDelay = 0.0, + connectOnPowerOn = False, disconnectOnPowerOff = False, sensingMethod = 'INTERNAL', senseGPIOPin = 0, @@ -682,6 +689,7 @@ def on_settings_save(self, data): self.pseudoOnGCodeCommand = self._settings.get(["pseudoOnGCodeCommand"]) self.pseudoOffGCodeCommand = self._settings.get(["pseudoOffGCodeCommand"]) self.postOnDelay = self._settings.get_float(["postOnDelay"]) + self.connectOnPowerOn = self._settings.get_boolean(["connectOnPowerOn"]) self.disconnectOnPowerOff = self._settings.get_boolean(["disconnectOnPowerOff"]) self.sensingMethod = self._settings.get(["sensingMethod"]) self.senseGPIOPin = self._settings.get_int(["senseGPIOPin"]) diff --git a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 index 259ba13..0c06c18 100644 --- a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 +++ b/octoprint_psucontrol/templates/psucontrol_settings.jinja2 @@ -166,6 +166,13 @@
+
+
+ +
+
From 00b3f9dfe2ed9d466153e8cb09bca00f557a79a5 Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Sun, 13 Dec 2020 11:12:24 -0500 Subject: [PATCH 09/10] Ensure we're connected before sending script --- octoprint_psucontrol/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index ea94a20..c41a5e5 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -559,11 +559,13 @@ def turn_psu_on(self): if self.connectOnPowerOn and self._printer.is_closed_or_error(): self._printer.connect() - self._printer.script("psucontrol_post_on", must_be_set=False) + if not self._printer.is_closed_or_error(): + self._printer.script("psucontrol_post_on", must_be_set=False) def turn_psu_off(self): if self.switchingMethod == 'GCODE' or self.switchingMethod == 'GPIO' or self.switchingMethod == 'SYSTEM': - self._printer.script("psucontrol_pre_off", must_be_set=False) + if not self._printer.is_closed_or_error(): + self._printer.script("psucontrol_pre_off", must_be_set=False) self._logger.info("Switching PSU Off") if self.switchingMethod == 'GCODE': From 66d736ed675488a405641da2207da6b118d58d4e Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Sun, 13 Dec 2020 11:19:33 -0500 Subject: [PATCH 10/10] Add slight delay after connect so that gcode script can run if defined. Likely a better way --- octoprint_psucontrol/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py index c41a5e5..887648c 100644 --- a/octoprint_psucontrol/__init__.py +++ b/octoprint_psucontrol/__init__.py @@ -558,6 +558,7 @@ def turn_psu_on(self): if self.connectOnPowerOn and self._printer.is_closed_or_error(): self._printer.connect() + time.sleep(0.1) if not self._printer.is_closed_or_error(): self._printer.script("psucontrol_post_on", must_be_set=False)