diff --git a/octoprint_psucontrol/__init__.py b/octoprint_psucontrol/__init__.py
index 887648c..5082c5c 100644
--- a/octoprint_psucontrol/__init__.py
+++ b/octoprint_psucontrol/__init__.py
@@ -8,6 +8,7 @@
import octoprint.plugin
from octoprint.server import user_permission
from octoprint.events import Events
+from octoprint.util import RepeatedTimer
import time
import subprocess
import threading
@@ -103,6 +104,7 @@ def __init__(self):
self.autoOnTriggerGCodeCommands = ''
self._autoOnTriggerGCodeCommandsArray = []
self.enablePowerOffWarningDialog = True
+ self.enableIdleCountdownTimer = True
self.powerOffWhenIdle = False
self.idleTimeout = 0
self.idleIgnoreCommands = ''
@@ -120,6 +122,9 @@ def __init__(self):
self._check_psu_state_thread = None
self._check_psu_state_event= threading.Event()
self._idleTimer = None
+ self._idleCountdown = None
+ self._idleStartTime = 0
+ self._idleTimeLeft = None
self._waitForHeaters = False
self._skipIdleTimer = False
self._configuredGPIOPins = []
@@ -200,6 +205,9 @@ def on_settings_initialized(self):
self.enablePowerOffWarningDialog = self._settings.get_boolean(["enablePowerOffWarningDialog"])
self._logger.debug("enablePowerOffWarningDialog: %s" % self.enablePowerOffWarningDialog)
+ self.enableIdleCountdownTimer = self._settings.get_boolean(["enableIdleCountdownTimer"])
+ self._logger.debug("enableIdleCountdownTimer: %s" % self.enableIdleCountdownTimer)
+
self.powerOffWhenIdle = self._settings.get_boolean(["powerOffWhenIdle"])
self._logger.debug("powerOffWhenIdle: %s" % self.powerOffWhenIdle)
@@ -393,22 +401,40 @@ def _check_psu_state(self):
self._check_psu_state_event.wait(self.sensePollingInterval)
self._check_psu_state_event.clear()
+ def _set_start_time(self):
+ self._idleStartTime = time.time()
+
+ def _refresh_countdown(self):
+ if self._idleStartTime == 0 or not self.powerOffWhenIdle or not self.enableIdleCountdownTimer or self._printer.is_printing() or self._printer.is_paused():
+ self.idleTimeLeft = None
+ else:
+ self.idleTimeLeft = time.strftime("%-M:%S", time.gmtime((self.idleTimeout * 60) - (time.time() - self._idleStartTime)))
+ self._plugin_manager.send_plugin_message(self._identifier, dict(idleTimeLeft=self.idleTimeLeft))
+
def _start_idle_timer(self):
self._stop_idle_timer()
if self.powerOffWhenIdle and self.isPSUOn:
self._idleTimer = ResettableTimer(self.idleTimeout * 60, self._idle_poweroff)
+ self._idleCountdown = RepeatedTimer(1.0, self._refresh_countdown)
self._idleTimer.start()
+ self._set_start_time()
+ self._idleCountdown.start()
def _stop_idle_timer(self):
if self._idleTimer:
self._idleTimer.cancel()
self._idleTimer = None
+ self._idleStartTime = 0
+ self._idleCountdown.cancel()
+ self._idleCountdown = None
+ self._refresh_countdown()
def _reset_idle_timer(self):
try:
if self._idleTimer.is_alive():
self._idleTimer.reset()
+ self._set_start_time()
else:
raise Exception()
except:
@@ -663,6 +689,7 @@ def get_settings_defaults(self):
autoOn = False,
autoOnTriggerGCodeCommands = "G0,G1,G2,G3,G10,G11,G28,G29,G32,M104,M106,M109,M140,M190",
enablePowerOffWarningDialog = True,
+ enableIdleCountdownTimer = True,
powerOffWhenIdle = False,
idleTimeout = 30,
idleIgnoreCommands = 'M105',
@@ -707,6 +734,7 @@ def on_settings_save(self, data):
self.idleTimeout = self._settings.get_int(["idleTimeout"])
self.idleIgnoreCommands = self._settings.get(["idleIgnoreCommands"])
self.enablePowerOffWarningDialog = self._settings.get_boolean(["enablePowerOffWarningDialog"])
+ self.enableIdleCountdownTimer = self._settings.get_boolean(["enableIdleCountdownTimer"])
self._idleIgnoreCommandsArray = self.idleIgnoreCommands.split(',')
self.idleTimeoutWaitTemp = self._settings.get_int(["idleTimeoutWaitTemp"])
diff --git a/octoprint_psucontrol/static/js/psucontrol.js b/octoprint_psucontrol/static/js/psucontrol.js
index e98bb85..2a65c05 100644
--- a/octoprint_psucontrol/static/js/psucontrol.js
+++ b/octoprint_psucontrol/static/js/psucontrol.js
@@ -4,13 +4,14 @@ $(function() {
self.settingsViewModel = parameters[0]
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(true);
self.isPSUOn = ko.observable(undefined);
+ self.idleTimeLeft = ko.observable(undefined);
self.psu_indicator = $("#psucontrol_indicator");
@@ -78,6 +79,10 @@ $(function() {
if (data.isPSUOn !== undefined) {
self.isPSUOn(data.isPSUOn);
}
+
+ if (data.idleTimeLeft !== undefined) {
+ self.idleTimeLeft(data.idleTimeLeft);
+ }
};
self.togglePSU = function() {
diff --git a/octoprint_psucontrol/templates/psucontrol_navbar.jinja2 b/octoprint_psucontrol/templates/psucontrol_navbar.jinja2
index f4b574a..374ef47 100644
--- a/octoprint_psucontrol/templates/psucontrol_navbar.jinja2
+++ b/octoprint_psucontrol/templates/psucontrol_navbar.jinja2
@@ -1,3 +1,4 @@
+
diff --git a/octoprint_psucontrol/templates/psucontrol_settings.jinja2 b/octoprint_psucontrol/templates/psucontrol_settings.jinja2
index 0c06c18..8718e88 100644
--- a/octoprint_psucontrol/templates/psucontrol_settings.jinja2
+++ b/octoprint_psucontrol/templates/psucontrol_settings.jinja2
@@ -5,6 +5,9 @@
+