From 99364df94e94ed9f666dc94caef9b4d601f33a17 Mon Sep 17 00:00:00 2001 From: ntoff Date: Mon, 6 Nov 2017 17:23:25 +1000 Subject: [PATCH 01/20] wrap it in a try catch Hopefully when something in my plugin breaks (that's when, not if) it won't take down all of octoprint's UI. --- .../static/js/fanslider.js | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index e4f610c..5ca6260 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -21,36 +21,41 @@ $(function() { //send gcode to set fan speed sendFanSpeed = function () { self.control.sendCustomCommand({ command: "M106 S" + self.fanPWM() }); - }; - //extra classes - $("#control > div.jog-panel").eq(0).addClass("controls"); - $("#control > div.jog-panel").eq(1).addClass("tools"); - $("#control > div.jog-panel").eq(2).addClass("general"); - //If !TouchUI then remove standard buttons + add slider + new buttons - if ($("#touch body").length ==0 ) { - //add ID to buttons - $("#control > div.general").find("button").eq(0).attr("id", "motors-off"); - $("#control > div.general").find("button").eq(1).attr("id", "fan-on"); - $("#control > div.general").find("button").eq(2).attr("id", "fan-off"); - //remove original fan on/off buttons - $("#fan-on").remove(); - $("#fan-off").remove(); - //add new fan controls - $("#control > div.jog-panel.general").find("button").eq(0).before("\ - \ - \ - \ - "); - } else { //if TouchUI is active we only add the speed input + fan on button in a new section. - console.log("Fan Speed Slider: NOTICE! TouchUI is active, adding simplified control."); - $("#control > div.jog-panel.general").after("\ -
\ -
\ - \ - \ + }; + try { + //extra classes + $("#control > div.jog-panel").eq(0).addClass("controls"); + $("#control > div.jog-panel").eq(1).addClass("tools"); + $("#control > div.jog-panel").eq(2).addClass("general"); + //If !TouchUI then remove standard buttons + add slider + new buttons + if ($("#touch body").length ==0 ) { + //add ID to buttons + $("#control > div.general").find("button").eq(0).attr("id", "motors-off"); + $("#control > div.general").find("button").eq(1).attr("id", "fan-on"); + $("#control > div.general").find("button").eq(2).attr("id", "fan-off"); + //remove original fan on/off buttons + $("#fan-on").remove(); + $("#fan-off").remove(); + //add new fan controls + $("#control > div.jog-panel.general").find("button").eq(0).before("\ + \ + \ + \ + "); + } else { //if TouchUI is active we only add the speed input + fan on button in a new section. + console.log("Fan Speed Slider: NOTICE! TouchUI is active, adding simplified control."); + $("#control > div.jog-panel.general").after("\ +
\ +
\ + \ + \ +
\
\ -
\ - "); + "); + } + } + catch(error) { + console.log(error); } //retrieve settings self.onBeforeBinding = function() { From 0e71971e668c13520c5bfc5552921445877488b4 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 11 Nov 2017 21:31:05 +1000 Subject: [PATCH 02/20] add percentage to logger message add a more "human readable" percentage value to the logged fan speed (if modified) --- octoprint_fanspeedslider/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_fanspeedslider/__init__.py b/octoprint_fanspeedslider/__init__.py index 09d104b..2ea42de 100644 --- a/octoprint_fanspeedslider/__init__.py +++ b/octoprint_fanspeedslider/__init__.py @@ -50,11 +50,11 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin, if fanPwm and fanPwm.group(1): fanPwm = fanPwm.group(1) if Decimal(fanPwm) < self.minPWM and Decimal(fanPwm) != 0: - self._logger.info("fan pwm value " + str(fanPwm) + " is below threshold, increasing to " + str(self.minPWM)) + self._logger.info("fan pwm value " + str(fanPwm) + " is below threshold, increasing to " + str(self.minPWM) + " (" + str(self.minSpeed) + "%)") cmd = "M106 S" + str(self.minPWM) return cmd, elif Decimal(fanPwm) > self.maxPWM: - self._logger.info("fan pwm value " + str(fanPwm) + " is above threshold, decreasing to " + str(self.maxPWM)) + self._logger.info("fan pwm value " + str(fanPwm) + " is above threshold, decreasing to " + str(self.maxPWM) + " (" + str(self.maxSpeed) + "%)") cmd = "M106 S" + str(self.maxPWM) return cmd, From 7bdd260617b70fcde63aa834e3daa71b56ea9821 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 11 Nov 2017 21:41:07 +1000 Subject: [PATCH 03/20] use other view model push method http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels says the other way is depreciated --- octoprint_fanspeedslider/static/js/fanslider.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index 5ca6260..1ace80d 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -62,8 +62,12 @@ $(function() { fanSpeed(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed()); } } - OCTOPRINT_VIEWMODELS.push([ - FanSliderPluginViewModel, - ["settingsViewModel", "controlViewModel", "loginStateViewModel"] - ]); -}); + + OCTOPRINT_VIEWMODELS.push({ + construct: FanSliderPluginViewModel, + additionalNames: [], + dependencies: ["settingsViewModel", "controlViewModel", "loginStateViewModel"], + optional: [], + elements: [] + }); +}); \ No newline at end of file From f4bb25718ac44744e9b4a2241cb231faab4213f9 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 01:02:29 +1000 Subject: [PATCH 04/20] add some notifications about fan speed being altered Added a popup notification (can be disabled) and some console log text if the fan speed is altered. Also made the slider snap to the min/max value if it is out of range to give visual feedback that the plugin is doing something to the fan speed. --- octoprint_fanspeedslider/__init__.py | 3 +- .../static/js/fanslider.js | 68 +++++++++++++++---- .../templates/fanspeedslider_settings.jinja2 | 14 +++- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/octoprint_fanspeedslider/__init__.py b/octoprint_fanspeedslider/__init__.py index 2ea42de..1a2e2b9 100644 --- a/octoprint_fanspeedslider/__init__.py +++ b/octoprint_fanspeedslider/__init__.py @@ -17,7 +17,8 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin, return dict( defaultFanSpeed=100, minSpeed=0, - maxSpeed=100 + maxSpeed=100, + notifyDelay=3000 ) def on_settings_save(self, data): diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index 1ace80d..ada8aef 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -5,29 +5,60 @@ $(function() { function FanSliderPluginViewModel(parameters) { + //'use strict'; var self = this; self.settings = parameters[0]; self.control = parameters[1]; self.loginState = parameters[2]; - fanSpeed = ko.observable(undefined); + //fanSpeed = ko.observable("0"); + self.control.fanSpeed = new ko.observable("100"); + self.control.minFanSpeed = new ko.observable("000"); + self.control.maxFanSpeed = new ko.observable("100"); + self.control.notifyDelay = new ko.observable("3000"); //time in milliseconds - //convert percentage into PWM - self.fanPWM = ko.pureComputed(function () { - self.speed = fanSpeed() * 255 / 100 //don't forget to limit this to 2 decimal places at some point. - return self.speed; + self.showNotify = function(self,options) { + options.hide = true; + options.title = "Fan Speed Control"; + options.delay = self.control.notifyDelay(); + options.type = "info"; + if (options.delay != "0") { + new PNotify(options); + } + + }; + + //send gcode to set fan speed TODO: not be a global function + sendFanSpeed = ko.pureComputed(function () { + self.speed = self.control.fanSpeed() * 255 / 100 //don't forget to limit this to 2 decimal places at some point. + if (self.control.fanSpeed() < self.control.minFanSpeed() && self.control.fanSpeed() != "0") { + self.control.fanSpeed(self.control.minFanSpeed()); + var options = { + text: 'Fan speed increased to meet minimum requirement.', + } + self.showNotify(self,options); + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed set in the fan control settings, increasing to " + self.control.minFanSpeed() + "%"); + } + else { + if (self.control.fanSpeed() > self.control.maxFanSpeed()) { + self.control.fanSpeed(self.control.maxFanSpeed()); + var options = { + text: 'Fan speed decreased to meet minimum requirement.', + } + self.showNotify(self,options); + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed set in the fan control settings, decreasing to " + self.control.maxFanSpeed() + "%"); + } + } + self.control.sendCustomCommand({ command: "M106 S" + self.speed }); }); - //send gcode to set fan speed - sendFanSpeed = function () { - self.control.sendCustomCommand({ command: "M106 S" + self.fanPWM() }); - }; + //ph34r try { - //extra classes + //extra classes, I hate using this but it makes finding the buttons easier $("#control > div.jog-panel").eq(0).addClass("controls"); $("#control > div.jog-panel").eq(1).addClass("tools"); $("#control > div.jog-panel").eq(2).addClass("general"); - //If !TouchUI then remove standard buttons + add slider + new buttons + //If not TouchUI then remove standard buttons + add slider + new buttons if ($("#touch body").length ==0 ) { //add ID to buttons $("#control > div.general").find("button").eq(0).attr("id", "motors-off"); @@ -39,7 +70,7 @@ $(function() { //add new fan controls $("#control > div.jog-panel.general").find("button").eq(0).before("\ \ - \ + \ \ "); } else { //if TouchUI is active we only add the speed input + fan on button in a new section. @@ -59,7 +90,16 @@ $(function() { } //retrieve settings self.onBeforeBinding = function() { - fanSpeed(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed()); + self.control.fanSpeed(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed()); + self.control.minFanSpeed(self.settings.settings.plugins.fanspeedslider.minSpeed()); + self.control.maxFanSpeed(self.settings.settings.plugins.fanspeedslider.maxSpeed()); + self.control.notifyDelay(self.settings.settings.plugins.fanspeedslider.notifyDelay()); + } + //update settings in case user changes them, otherwise a refresh of the UI is required + self.onSettingsHidden = function() { + self.control.minFanSpeed(self.settings.settings.plugins.fanspeedslider.minSpeed()); + self.control.maxFanSpeed(self.settings.settings.plugins.fanspeedslider.maxSpeed()); + self.control.notifyDelay(self.settings.settings.plugins.fanspeedslider.notifyDelay()); } } @@ -69,5 +109,5 @@ $(function() { dependencies: ["settingsViewModel", "controlViewModel", "loginStateViewModel"], optional: [], elements: [] - }); + }); }); \ No newline at end of file diff --git a/octoprint_fanspeedslider/templates/fanspeedslider_settings.jinja2 b/octoprint_fanspeedslider/templates/fanspeedslider_settings.jinja2 index c05a308..00a318e 100644 --- a/octoprint_fanspeedslider/templates/fanspeedslider_settings.jinja2 +++ b/octoprint_fanspeedslider/templates/fanspeedslider_settings.jinja2 @@ -1,12 +1,11 @@

{{ _('Fan Speed Control') }}

-

{{ _('Set the default value for the speed slider.') }}

- + %
{{ _('The default value the slider will be set to when opening OctoPrint\'s UI') }} @@ -34,5 +33,16 @@

{{ _('NOTE: The min/max setting has no effect when you are printing from an SD card that is attached directly to the printer as the gcode does not pass through OctoPrint.') }}

+

{{ _('Notification Auto Hide Delay') }}

+
+ +
+
+ + ms +
+ {{ _('Delay (in milliseconds) before notifications are auto-hidden. Set to 0 to disable notifications.') }} +
+
From 175722a0159c9642dc5158c91654a6c40681eb52 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 01:08:27 +1000 Subject: [PATCH 05/20] fix javascript console logging of fan speed notification log was being output after the slider was set causing it to display the wrong value --- octoprint_fanspeedslider/static/js/fanslider.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index ada8aef..81dd1d4 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -33,21 +33,23 @@ $(function() { sendFanSpeed = ko.pureComputed(function () { self.speed = self.control.fanSpeed() * 255 / 100 //don't forget to limit this to 2 decimal places at some point. if (self.control.fanSpeed() < self.control.minFanSpeed() && self.control.fanSpeed() != "0") { + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed set in the fan control settings, increasing to " + self.control.minFanSpeed() + "%"); self.control.fanSpeed(self.control.minFanSpeed()); var options = { text: 'Fan speed increased to meet minimum requirement.', } self.showNotify(self,options); - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed set in the fan control settings, increasing to " + self.control.minFanSpeed() + "%"); + } else { if (self.control.fanSpeed() > self.control.maxFanSpeed()) { + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed set in the fan control settings, decreasing to " + self.control.maxFanSpeed() + "%"); self.control.fanSpeed(self.control.maxFanSpeed()); var options = { text: 'Fan speed decreased to meet minimum requirement.', } self.showNotify(self,options); - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed set in the fan control settings, decreasing to " + self.control.maxFanSpeed() + "%"); + } } self.control.sendCustomCommand({ command: "M106 S" + self.speed }); From deb15025d830b8e9f2cf006829d16f997ac38444 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 01:11:36 +1000 Subject: [PATCH 06/20] min/max requirement notification text fix speed decrease notification used "meet minimum requirement" which might be misleading, changed to "meet maximum requirement" --- octoprint_fanspeedslider/static/js/fanslider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index 81dd1d4..bc2d168 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -46,7 +46,7 @@ $(function() { console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed set in the fan control settings, decreasing to " + self.control.maxFanSpeed() + "%"); self.control.fanSpeed(self.control.maxFanSpeed()); var options = { - text: 'Fan speed decreased to meet minimum requirement.', + text: 'Fan speed decreased to meet maximum requirement.', } self.showNotify(self,options); From 2d7f2f443a7878cb0574fc5b8eafd9061158a28e Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 01:20:17 +1000 Subject: [PATCH 07/20] update readme with new autohide setting --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d76ee2c..d9a1c09 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,15 @@ Add a slider to control the speed of a parts cooling fan. Slide the slider, click the button. There really isn't much else to do :) -The default value of the slider is user configurable, this is the value that the slider will be set to upon loading OctoPrint's UI, and any time you refresh the page. +## Settings -The minimum fan speed setting will limit how slow the fan runs, this is useful since some fans don't work below a certain speed. +* The default value of the slider is user configurable, this is the value that the slider will be set to upon loading OctoPrint's UI, and any time you refresh the page. -The maximum fan speed setting will limit how fast the fan runs, this is useful if your fan is too strong, or you wish to limit the speed post-slice without having to re-slice your file. +* The minimum fan speed setting will limit how slow the fan runs, this is useful since some fans don't work below a certain speed. + +* The maximum fan speed setting will limit how fast the fan runs, this is useful if your fan is too strong, or you wish to limit the speed post-slice without having to re-slice your file. + +* Notification autohide delay controls how long any notifications will remain on the screen for. If the user manually sets a speed outside of the set range, a notification will be displayed informing the user the fan speed has been modified. Print jobs shouldn't trigger these notifications, and so popup spam shouldn't occur, however if a user wishes not to receive notifications when setting fan speeds outside of the set range, this value can be set to 0 (zero) to disable notifications. (this setting won't / shouldn't affect OctoPrint's global notifications, it only applies to info popups generated by this plugin). *Note: Slider does __not__ follow the speed of the fan. If the fan speed is set via gcode or an LCD panel on the printer, the slider will not respond to the change. It is a __setting__, not an indicator, and functions the same way the feedrate and flowrate sliders do.* From f7faf42a87c185b19bd14ca85783bac4524cd4d6 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 02:20:17 +1000 Subject: [PATCH 08/20] remove unnecessary added classes get rid of the extra classes added to make finding the buttons easier, turns out they aren't needed --- .../static/js/fanslider.js | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index bc2d168..970f58d 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -18,7 +18,7 @@ $(function() { self.control.maxFanSpeed = new ko.observable("100"); self.control.notifyDelay = new ko.observable("3000"); //time in milliseconds - self.showNotify = function(self,options) { + self.showNotify = function(self,options) { options.hide = true; options.title = "Fan Speed Control"; options.delay = self.control.notifyDelay(); @@ -26,8 +26,7 @@ $(function() { if (options.delay != "0") { new PNotify(options); } - - }; + }; //send gcode to set fan speed TODO: not be a global function sendFanSpeed = ko.pureComputed(function () { @@ -39,7 +38,6 @@ $(function() { text: 'Fan speed increased to meet minimum requirement.', } self.showNotify(self,options); - } else { if (self.control.fanSpeed() > self.control.maxFanSpeed()) { @@ -49,35 +47,32 @@ $(function() { text: 'Fan speed decreased to meet maximum requirement.', } self.showNotify(self,options); - } } self.control.sendCustomCommand({ command: "M106 S" + self.speed }); }); //ph34r try { - //extra classes, I hate using this but it makes finding the buttons easier - $("#control > div.jog-panel").eq(0).addClass("controls"); - $("#control > div.jog-panel").eq(1).addClass("tools"); - $("#control > div.jog-panel").eq(2).addClass("general"); //If not TouchUI then remove standard buttons + add slider + new buttons if ($("#touch body").length ==0 ) { - //add ID to buttons - $("#control > div.general").find("button").eq(0).attr("id", "motors-off"); - $("#control > div.general").find("button").eq(1).attr("id", "fan-on"); - $("#control > div.general").find("button").eq(2).attr("id", "fan-off"); + $("#control-jog-general").find("button").eq(0).attr("id", "motors-off"); + $("#control-jog-general").find("button").eq(1).attr("id", "fan-on"); + $("#control-jog-general").find("button").eq(2).attr("id", "fan-off"); //remove original fan on/off buttons $("#fan-on").remove(); $("#fan-off").remove(); //add new fan controls - $("#control > div.jog-panel.general").find("button").eq(0).before("\ + $("#control-jog-general").find("button").eq(0).before("\ \ - \ - \ + \ + \ "); - } else { //if TouchUI is active we only add the speed input + fan on button in a new section. + } else { + /* if TouchUI is active we only add the speed input + fan on button in a new section. + * perhaps some day I'll see about messing directly with touchui's fan on button + */ console.log("Fan Speed Slider: NOTICE! TouchUI is active, adding simplified control."); - $("#control > div.jog-panel.general").after("\ + $("#control-jog-extrusion").after("\
\
\ \ @@ -106,10 +101,10 @@ $(function() { } OCTOPRINT_VIEWMODELS.push({ - construct: FanSliderPluginViewModel, - additionalNames: [], - dependencies: ["settingsViewModel", "controlViewModel", "loginStateViewModel"], - optional: [], - elements: [] + construct: FanSliderPluginViewModel, + additionalNames: [], + dependencies: ["settingsViewModel", "controlViewModel", "loginStateViewModel"], + optional: [], + elements: [] }); }); \ No newline at end of file From a47ead4db34c8f8def4cad87b94630905e758924 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 03:38:25 +1000 Subject: [PATCH 09/20] tweak settings loader parseint to make sure we're loading numbers and tweak the slider to adapt to the min/max value on UI load if the default value is outside the allowed range --- .../static/js/fanslider.js | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index 970f58d..cf100d0 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -13,10 +13,11 @@ $(function() { self.loginState = parameters[2]; //fanSpeed = ko.observable("0"); - self.control.fanSpeed = new ko.observable("100"); - self.control.minFanSpeed = new ko.observable("000"); - self.control.maxFanSpeed = new ko.observable("100"); - self.control.notifyDelay = new ko.observable("3000"); //time in milliseconds + self.control.defaultFanSpeed = new ko.observable(100); + self.control.fanSpeed = new ko.observable(100); + self.control.minFanSpeed = new ko.observable(0); + self.control.maxFanSpeed = new ko.observable(100); + self.control.notifyDelay = new ko.observable(3000); //time in milliseconds self.showNotify = function(self,options) { options.hide = true; @@ -27,37 +28,37 @@ $(function() { new PNotify(options); } }; - + //send gcode to set fan speed TODO: not be a global function sendFanSpeed = ko.pureComputed(function () { self.speed = self.control.fanSpeed() * 255 / 100 //don't forget to limit this to 2 decimal places at some point. if (self.control.fanSpeed() < self.control.minFanSpeed() && self.control.fanSpeed() != "0") { - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed set in the fan control settings, increasing to " + self.control.minFanSpeed() + "%"); + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed ("+self.control.minFanSpeed()+"%), increasing."); self.control.fanSpeed(self.control.minFanSpeed()); var options = { text: 'Fan speed increased to meet minimum requirement.', } self.showNotify(self,options); } - else { - if (self.control.fanSpeed() > self.control.maxFanSpeed()) { - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed set in the fan control settings, decreasing to " + self.control.maxFanSpeed() + "%"); + else if (self.control.fanSpeed() > self.control.maxFanSpeed()) { + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed ("+self.control.maxFanSpeed()+"%), decreasing."); self.control.fanSpeed(self.control.maxFanSpeed()); var options = { text: 'Fan speed decreased to meet maximum requirement.', } self.showNotify(self,options); - } } self.control.sendCustomCommand({ command: "M106 S" + self.speed }); }); + //ph34r try { + //for some reason touchui uses "jog general" for the fan controls? Oh well, makes my job easier + $("#control-jog-general").find("button").eq(0).attr("id", "motors-off"); + $("#control-jog-general").find("button").eq(1).attr("id", "fan-on"); + $("#control-jog-general").find("button").eq(2).attr("id", "fan-off"); //If not TouchUI then remove standard buttons + add slider + new buttons if ($("#touch body").length ==0 ) { - $("#control-jog-general").find("button").eq(0).attr("id", "motors-off"); - $("#control-jog-general").find("button").eq(1).attr("id", "fan-on"); - $("#control-jog-general").find("button").eq(2).attr("id", "fan-off"); //remove original fan on/off buttons $("#fan-on").remove(); $("#fan-off").remove(); @@ -68,10 +69,12 @@ $(function() { \ "); } else { - /* if TouchUI is active we only add the speed input + fan on button in a new section. - * perhaps some day I'll see about messing directly with touchui's fan on button - */ - console.log("Fan Speed Slider: NOTICE! TouchUI is active, adding simplified control."); + //replace touch UI's fan on button with one that sends whatever speed is set in this plugin + $("#fan-on").remove(); + $("#control-jog-general").find("button").eq(0).after("\ + \ + "); + //also add spin box + button below in its own section, button is redundant but convenient $("#control-jog-extrusion").after("\
\
\ @@ -85,18 +88,33 @@ $(function() { catch(error) { console.log(error); } - //retrieve settings - self.onBeforeBinding = function() { - self.control.fanSpeed(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed()); - self.control.minFanSpeed(self.settings.settings.plugins.fanspeedslider.minSpeed()); - self.control.maxFanSpeed(self.settings.settings.plugins.fanspeedslider.maxSpeed()); - self.control.notifyDelay(self.settings.settings.plugins.fanspeedslider.notifyDelay()); + + self.updateSettings = function() { + try { + self.control.minFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.minSpeed())); + self.control.maxFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.maxSpeed())); + self.control.notifyDelay(parseInt(self.settings.settings.plugins.fanspeedslider.notifyDelay())); + } + catch(error) { + console.log(error); + } } + + self.onBeforeBinding = function() { + self.control.defaultFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed())); + self.updateSettings(); + //if the default fan speed is above or below max/min then set to either max or min + if (self.control.defaultFanSpeed() < self.control.minFanSpeed()) { + self.control.fanSpeed(self.control.minFanSpeed()); + } + else if (self.control.defaultFanSpeed() > self.control.maxFanSpeed()) { + self.control.fanSpeed(self.control.maxFanSpeed()); + } + } + //update settings in case user changes them, otherwise a refresh of the UI is required self.onSettingsHidden = function() { - self.control.minFanSpeed(self.settings.settings.plugins.fanspeedslider.minSpeed()); - self.control.maxFanSpeed(self.settings.settings.plugins.fanspeedslider.maxSpeed()); - self.control.notifyDelay(self.settings.settings.plugins.fanspeedslider.notifyDelay()); + self.updateSettings(); } } From 21e4627da29af5210a32c5eea6050d874d05315f Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 04:46:00 +1000 Subject: [PATCH 10/20] missing span on touchui button + less global hopefully nothing global "use strict" seems to not complain :D --- octoprint_fanspeedslider/static/js/fanslider.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index cf100d0..9d6940c 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -5,7 +5,7 @@ $(function() { function FanSliderPluginViewModel(parameters) { - //'use strict'; + 'use strict'; var self = this; self.settings = parameters[0]; @@ -29,8 +29,8 @@ $(function() { } }; - //send gcode to set fan speed TODO: not be a global function - sendFanSpeed = ko.pureComputed(function () { + //send gcode to set fan speed + self.control.sendFanSpeed = ko.pureComputed(function () { self.speed = self.control.fanSpeed() * 255 / 100 //don't forget to limit this to 2 decimal places at some point. if (self.control.fanSpeed() < self.control.minFanSpeed() && self.control.fanSpeed() != "0") { console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed ("+self.control.minFanSpeed()+"%), increasing."); @@ -65,21 +65,21 @@ $(function() { //add new fan controls $("#control-jog-general").find("button").eq(0).before("\ \ - \ + \ \ "); } else { //replace touch UI's fan on button with one that sends whatever speed is set in this plugin $("#fan-on").remove(); $("#control-jog-general").find("button").eq(0).after("\ - \ + \ "); //also add spin box + button below in its own section, button is redundant but convenient $("#control-jog-extrusion").after("\
\
\ \ - \ + \
\
\ "); From 3049d0fedf1426a5b9d145483ae40bde2add49be Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 05:19:12 +1000 Subject: [PATCH 11/20] fix default fan speed slider position oops, forgot the last bit of the if else statement --- octoprint_fanspeedslider/static/js/fanslider.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index 9d6940c..2e6b755 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -110,6 +110,9 @@ $(function() { else if (self.control.defaultFanSpeed() > self.control.maxFanSpeed()) { self.control.fanSpeed(self.control.maxFanSpeed()); } + else { + self.control.fanSpeed(self.control.defaultFanSpeed()); + } } //update settings in case user changes them, otherwise a refresh of the UI is required From 9ff32751f85a76f8c270f01b8db4120cc95a7a1b Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 05:53:52 +1000 Subject: [PATCH 12/20] dev version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 247880d..1414379 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_package = "octoprint_fanspeedslider" plugin_name = "OctoPrint-FanSpeedSlider" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.1.5" +plugin_version = "0.1.6.dev1" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From 70d3e0803b8fb86a1775e2f74e275c010b1d728d Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 06:33:51 +1000 Subject: [PATCH 13/20] separate stuff into their own functions move percent to pwm function and checking the slider value is within range into their own functions --- .../static/js/fanslider.js | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index 2e6b755..d6e0eff 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -2,7 +2,7 @@ * Author: ntoff * License: AGPLv3 */ -$(function() { +$(function () { function FanSliderPluginViewModel(parameters) { 'use strict'; @@ -19,38 +19,46 @@ $(function() { self.control.maxFanSpeed = new ko.observable(100); self.control.notifyDelay = new ko.observable(3000); //time in milliseconds - self.showNotify = function(self,options) { + self.showNotify = function (self, options) { options.hide = true; options.title = "Fan Speed Control"; - options.delay = self.control.notifyDelay(); + options.delay = self.control.notifyDelay(); options.type = "info"; if (options.delay != "0") { new PNotify(options); } }; - //send gcode to set fan speed - self.control.sendFanSpeed = ko.pureComputed(function () { + self.control.fanSpeedToPwm = ko.pureComputed(function () { self.speed = self.control.fanSpeed() * 255 / 100 //don't forget to limit this to 2 decimal places at some point. + return self.speed; + }); + + self.control.checkSliderValue = ko.pureComputed(function () { if (self.control.fanSpeed() < self.control.minFanSpeed() && self.control.fanSpeed() != "0") { - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed ("+self.control.minFanSpeed()+"%), increasing."); + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed (" + self.control.minFanSpeed() + "%), increasing."); self.control.fanSpeed(self.control.minFanSpeed()); var options = { text: 'Fan speed increased to meet minimum requirement.', } - self.showNotify(self,options); + self.showNotify(self, options); } else if (self.control.fanSpeed() > self.control.maxFanSpeed()) { - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed ("+self.control.maxFanSpeed()+"%), decreasing."); - self.control.fanSpeed(self.control.maxFanSpeed()); - var options = { - text: 'Fan speed decreased to meet maximum requirement.', - } - self.showNotify(self,options); + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed (" + self.control.maxFanSpeed() + "%), decreasing."); + self.control.fanSpeed(self.control.maxFanSpeed()); + var options = { + text: 'Fan speed decreased to meet maximum requirement.', + } + self.showNotify(self, options); } - self.control.sendCustomCommand({ command: "M106 S" + self.speed }); }); + //send gcode to set fan speed + self.control.sendFanSpeed = function () { + self.control.checkSliderValue(); + self.control.sendCustomCommand({ command: "M106 S" + self.control.fanSpeedToPwm() }); + }; + //ph34r try { //for some reason touchui uses "jog general" for the fan controls? Oh well, makes my job easier @@ -58,7 +66,7 @@ $(function() { $("#control-jog-general").find("button").eq(1).attr("id", "fan-on"); $("#control-jog-general").find("button").eq(2).attr("id", "fan-off"); //If not TouchUI then remove standard buttons + add slider + new buttons - if ($("#touch body").length ==0 ) { + if ($("#touch body").length == 0) { //remove original fan on/off buttons $("#fan-on").remove(); $("#fan-off").remove(); @@ -68,7 +76,7 @@ $(function() { \ \ "); - } else { + } else { //replace touch UI's fan on button with one that sends whatever speed is set in this plugin $("#fan-on").remove(); $("#control-jog-general").find("button").eq(0).after("\ @@ -85,22 +93,22 @@ $(function() { "); } } - catch(error) { + catch (error) { console.log(error); } - self.updateSettings = function() { + self.updateSettings = function () { try { - self.control.minFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.minSpeed())); - self.control.maxFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.maxSpeed())); - self.control.notifyDelay(parseInt(self.settings.settings.plugins.fanspeedslider.notifyDelay())); + self.control.minFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.minSpeed())); + self.control.maxFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.maxSpeed())); + self.control.notifyDelay(parseInt(self.settings.settings.plugins.fanspeedslider.notifyDelay())); } - catch(error) { + catch (error) { console.log(error); } } - self.onBeforeBinding = function() { + self.onBeforeBinding = function () { self.control.defaultFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed())); self.updateSettings(); //if the default fan speed is above or below max/min then set to either max or min @@ -116,10 +124,10 @@ $(function() { } //update settings in case user changes them, otherwise a refresh of the UI is required - self.onSettingsHidden = function() { + self.onSettingsHidden = function () { self.updateSettings(); } - } + } OCTOPRINT_VIEWMODELS.push({ construct: FanSliderPluginViewModel, From addd0ffa4bdc63cb03f3a498e5486b124731f020 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sun, 12 Nov 2017 16:26:38 +1000 Subject: [PATCH 14/20] check for notifications and don't display if one is active check for high / low speed out of range popups and only display one, block popping up of multiple notifications for the same event --- octoprint_fanspeedslider/static/js/fanslider.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index d6e0eff..6d0ebe1 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -40,16 +40,22 @@ $(function () { self.control.fanSpeed(self.control.minFanSpeed()); var options = { text: 'Fan speed increased to meet minimum requirement.', + addclass: 'fan_speed_notice_low', + } + if ($(".fan_speed_notice_low").length <1) { + self.showNotify(self, options); } - self.showNotify(self, options); } else if (self.control.fanSpeed() > self.control.maxFanSpeed()) { console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed (" + self.control.maxFanSpeed() + "%), decreasing."); self.control.fanSpeed(self.control.maxFanSpeed()); var options = { text: 'Fan speed decreased to meet maximum requirement.', + addclass: 'fan_speed_notice_high', + } + if ($(".fan_speed_notice_high").length <1) { + self.showNotify(self, options); } - self.showNotify(self, options); } }); From b359461d80fd12281e67feb535a8960048aba29e Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 18 Nov 2017 04:18:37 +1000 Subject: [PATCH 15/20] fix issue with touch ui max slider value being wrong and fix padding if touchui was active the max value was 255, also added a bit of extra width so the button doesn't resize (at least when the button text is in english) --- octoprint_fanspeedslider/static/js/fanslider.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index 6d0ebe1..c984a6b 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -78,7 +78,7 @@ $(function () { $("#fan-off").remove(); //add new fan controls $("#control-jog-general").find("button").eq(0).before("\ - \ + \ \ \ "); @@ -92,7 +92,7 @@ $(function () { $("#control-jog-extrusion").after("\
\
\ - \ + \ \
\
\ @@ -126,7 +126,7 @@ $(function () { } else { self.control.fanSpeed(self.control.defaultFanSpeed()); - } + } } //update settings in case user changes them, otherwise a refresh of the UI is required From 943fca8581a53164e714be433073a8431aa1833b Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 18 Nov 2017 04:36:40 +1000 Subject: [PATCH 16/20] control -> settings + tweak info timeout for some reason I was saving settings in the control viewmodel, changed to the settings viewmodel and increased the default time the notices are visible by 1 second --- octoprint_fanspeedslider/__init__.py | 2 +- .../static/js/fanslider.js | 44 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/octoprint_fanspeedslider/__init__.py b/octoprint_fanspeedslider/__init__.py index 1a2e2b9..de05370 100644 --- a/octoprint_fanspeedslider/__init__.py +++ b/octoprint_fanspeedslider/__init__.py @@ -18,7 +18,7 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin, defaultFanSpeed=100, minSpeed=0, maxSpeed=100, - notifyDelay=3000 + notifyDelay=4000 ) def on_settings_save(self, data): diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index c984a6b..cb8eeb4 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -13,16 +13,16 @@ $(function () { self.loginState = parameters[2]; //fanSpeed = ko.observable("0"); - self.control.defaultFanSpeed = new ko.observable(100); + self.settings.defaultFanSpeed = new ko.observable(100); self.control.fanSpeed = new ko.observable(100); - self.control.minFanSpeed = new ko.observable(0); - self.control.maxFanSpeed = new ko.observable(100); - self.control.notifyDelay = new ko.observable(3000); //time in milliseconds + self.settings.minFanSpeed = new ko.observable(0); + self.settings.maxFanSpeed = new ko.observable(100); + self.settings.notifyDelay = new ko.observable(4000); //time in milliseconds self.showNotify = function (self, options) { options.hide = true; options.title = "Fan Speed Control"; - options.delay = self.control.notifyDelay(); + options.delay = self.settings.notifyDelay(); options.type = "info"; if (options.delay != "0") { new PNotify(options); @@ -35,22 +35,22 @@ $(function () { }); self.control.checkSliderValue = ko.pureComputed(function () { - if (self.control.fanSpeed() < self.control.minFanSpeed() && self.control.fanSpeed() != "0") { - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed (" + self.control.minFanSpeed() + "%), increasing."); - self.control.fanSpeed(self.control.minFanSpeed()); + if (self.control.fanSpeed() < self.settings.minFanSpeed() && self.control.fanSpeed() != "0") { + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed (" + self.settings.minFanSpeed() + "%), increasing."); + self.control.fanSpeed(self.settings.minFanSpeed()); var options = { - text: 'Fan speed increased to meet minimum requirement.', + text: gettext('Fan speed increased to meet minimum speed requirement.'), addclass: 'fan_speed_notice_low', } if ($(".fan_speed_notice_low").length <1) { self.showNotify(self, options); } } - else if (self.control.fanSpeed() > self.control.maxFanSpeed()) { - console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed (" + self.control.maxFanSpeed() + "%), decreasing."); - self.control.fanSpeed(self.control.maxFanSpeed()); + else if (self.control.fanSpeed() > self.settings.maxFanSpeed()) { + console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed (" + self.settings.maxFanSpeed() + "%), decreasing."); + self.control.fanSpeed(self.settings.maxFanSpeed()); var options = { - text: 'Fan speed decreased to meet maximum requirement.', + text: gettext('Fan speed decreased to meet maximum speed requirement.'), addclass: 'fan_speed_notice_high', } if ($(".fan_speed_notice_high").length <1) { @@ -105,9 +105,9 @@ $(function () { self.updateSettings = function () { try { - self.control.minFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.minSpeed())); - self.control.maxFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.maxSpeed())); - self.control.notifyDelay(parseInt(self.settings.settings.plugins.fanspeedslider.notifyDelay())); + self.settings.minFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.minSpeed())); + self.settings.maxFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.maxSpeed())); + self.settings.notifyDelay(parseInt(self.settings.settings.plugins.fanspeedslider.notifyDelay())); } catch (error) { console.log(error); @@ -115,17 +115,17 @@ $(function () { } self.onBeforeBinding = function () { - self.control.defaultFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed())); + self.settings.defaultFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed())); self.updateSettings(); //if the default fan speed is above or below max/min then set to either max or min - if (self.control.defaultFanSpeed() < self.control.minFanSpeed()) { - self.control.fanSpeed(self.control.minFanSpeed()); + if (self.settings.defaultFanSpeed() < self.settings.minFanSpeed()) { + self.control.fanSpeed(self.settings.minFanSpeed()); } - else if (self.control.defaultFanSpeed() > self.control.maxFanSpeed()) { - self.control.fanSpeed(self.control.maxFanSpeed()); + else if (self.settings.defaultFanSpeed() > self.settings.maxFanSpeed()) { + self.control.fanSpeed(self.settings.maxFanSpeed()); } else { - self.control.fanSpeed(self.control.defaultFanSpeed()); + self.control.fanSpeed(self.settings.defaultFanSpeed()); } } From c7c2f521492f9075c99030a332ec69c1b18fc688 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 18 Nov 2017 05:01:52 +1000 Subject: [PATCH 17/20] add some comments clarify fan speeds are 0-100% not 0-255 pwm values --- octoprint_fanspeedslider/static/js/fanslider.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index cb8eeb4..b6df059 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -12,12 +12,11 @@ $(function () { self.control = parameters[1]; self.loginState = parameters[2]; - //fanSpeed = ko.observable("0"); - self.settings.defaultFanSpeed = new ko.observable(100); - self.control.fanSpeed = new ko.observable(100); - self.settings.minFanSpeed = new ko.observable(0); - self.settings.maxFanSpeed = new ko.observable(100); - self.settings.notifyDelay = new ko.observable(4000); //time in milliseconds + self.settings.defaultFanSpeed = new ko.observable(100); //this, + self.control.fanSpeed = new ko.observable(100); //this, + self.settings.minFanSpeed = new ko.observable(0); //this, + self.settings.maxFanSpeed = new ko.observable(100); //and this are percents 0 - 100% + self.settings.notifyDelay = new ko.observable(4000); //time in milliseconds self.showNotify = function (self, options) { options.hide = true; From 59ef6652eb4b551559550d67f3ef35c0ce9be6b7 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 18 Nov 2017 05:02:44 +1000 Subject: [PATCH 18/20] remove use strict testing's over, remove "use strict" --- octoprint_fanspeedslider/static/js/fanslider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_fanspeedslider/static/js/fanslider.js b/octoprint_fanspeedslider/static/js/fanslider.js index b6df059..878cf68 100644 --- a/octoprint_fanspeedslider/static/js/fanslider.js +++ b/octoprint_fanspeedslider/static/js/fanslider.js @@ -5,7 +5,7 @@ $(function () { function FanSliderPluginViewModel(parameters) { - 'use strict'; + //'use strict'; var self = this; self.settings = parameters[0]; From f13fda67e28c7337c0cdd7f0512f6860c89ed215 Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 18 Nov 2017 05:59:54 +1000 Subject: [PATCH 19/20] modify settings saving to save integers --- octoprint_fanspeedslider/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/octoprint_fanspeedslider/__init__.py b/octoprint_fanspeedslider/__init__.py index de05370..277fb15 100644 --- a/octoprint_fanspeedslider/__init__.py +++ b/octoprint_fanspeedslider/__init__.py @@ -22,7 +22,15 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin, ) def on_settings_save(self, data): - octoprint.plugin.SettingsPlugin.on_settings_save(self, data) + s = self._settings + if "defaultFanSpeed" in data.keys(): + s.setInt(["defaultFanSpeed"], data["defaultFanSpeed"]) + if "minSpeed" in data.keys(): + s.setInt(["minSpeed"], data["minSpeed"]) + if "maxSpeed" in data.keys(): + s.setInt(["maxSpeed"], data["maxSpeed"]) + if "notifyDelay" in data.keys(): + s.setInt(["notifyDelay"], data["notifyDelay"]) self.get_settings_updates() def get_assets(self): @@ -37,9 +45,9 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin, ] def get_settings_updates(self): - self.defaultFanSpeed = self._settings.get(["defaultFanSpeed"]) - self.minSpeed = self._settings.get(["minSpeed"]) - self.maxSpeed = self._settings.get(["maxSpeed"]) + self.defaultFanSpeed = self._settings.getInt(["defaultFanSpeed"]) + self.minSpeed = self._settings.getInt(["minSpeed"]) + self.maxSpeed = self._settings.getInt(["maxSpeed"]) getcontext().prec=5 #sets precision for "Decimal" not sure if this'll cause conflicts, ideas? self.minPWM = round( Decimal(self.minSpeed) * Decimal(2.55), 2 ) From d2f1ed57ad7a95e5526f6674b722817b5a9de26c Mon Sep 17 00:00:00 2001 From: ntoff Date: Sat, 18 Nov 2017 06:31:22 +1000 Subject: [PATCH 20/20] add settings cleanup function Clean up and remove empty config if everything is set to default values --- octoprint_fanspeedslider/__init__.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/octoprint_fanspeedslider/__init__.py b/octoprint_fanspeedslider/__init__.py index 277fb15..9e7c3f9 100644 --- a/octoprint_fanspeedslider/__init__.py +++ b/octoprint_fanspeedslider/__init__.py @@ -32,6 +32,34 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin, if "notifyDelay" in data.keys(): s.setInt(["notifyDelay"], data["notifyDelay"]) self.get_settings_updates() + #clean up settings if everything's default + self.on_settings_cleanup() + s.save() + + #function stolen...err borrowed :D from types.py @ 1663 + def on_settings_cleanup(self): + import octoprint.util + from octoprint.settings import NoSuchSettingsPath + + try: + config = self._settings.get_all_data(merged=False, incl_defaults=False, error_on_path=True) + except NoSuchSettingsPath: + return + + if config is None: + self._settings.clean_all_data() + return + + if self.config_version_key in config and config[self.config_version_key] is None: + del config[self.config_version_key] + + defaults = self.get_settings_defaults() + diff = octoprint.util.dict_minimal_mergediff(defaults, config) + + if not diff: + self._settings.clean_all_data() + else: + self._settings.set([], diff) def get_assets(self): return dict(