diff --git a/README.md b/README.md index b090bfe..c6c0e02 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ Before start using this plugin I strongly recommend reading some documentation a ## Screens -![E-Steps](assets/eSteps.png) -![X-Y-Z Steps](assets/XYZSteps.png) -![PID Autotune](assets/PID-autotune.png) +![E-Steps](extras/assets/img/plugins/CalibrationTools/eSteps.png) +![X-Y-Z Steps](extras/assets/img/plugins/CalibrationTools/featuredimage.png) +![PID Autotune](extras/assets/img/plugins/CalibrationTools/PID-autotune.png) ## Setup diff --git a/extras/CalibrationTools.md b/extras/CalibrationTools.md deleted file mode 100644 index 2924283..0000000 --- a/extras/CalibrationTools.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -layout: plugin - -id: CalibrationTools -title: OctoPrint-CalibrationTools -description: Calibration tools -authors: -- Sergiu Toporjinschi -license: GNUv3 - -# TODO -date: today's date in format YYYY-MM-DD, e.g. 2015-04-21 - -homepage: https://github.com/SergiuToporjinschi/OctoPrint-CalibrationTools -source: https://github.com/SergiuToporjinschi/OctoPrint-CalibrationTools -archive: https://github.com/SergiuToporjinschi/OctoPrint-CalibrationTools/archive/master.zip - -# TODO -# Set this to true if your plugin uses the dependency_links setup parameter to include -# library versions not yet published on PyPi. SHOULD ONLY BE USED IF THERE IS NO OTHER OPTION! -#follow_dependency_links: false - -# TODO -tags: -- a list -- of tags -- that apply -- to your plugin -- (take a look at the existing plugins for what makes sense here) - -# TODO -screenshots: -- url: url of a screenshot, /assets/img/... - alt: alt-text of a screenshot - caption: caption of a screenshot -- url: url of another screenshot, /assets/img/... - alt: alt-text of another screenshot - caption: caption of another screenshot -- ... - -# TODO -featuredimage: url of a featured image for your plugin, /assets/img/... - -# TODO -# You only need the following if your plugin requires specific OctoPrint versions or -# specific operating systems to function - you can safely remove the whole -# "compatibility" block if this is not the case. - -compatibility: - - # List of compatible versions - # - # A single version number will be interpretated as a minimum version requirement, - # e.g. "1.3.1" will show the plugin as compatible to OctoPrint versions 1.3.1 and up. - # More sophisticated version requirements can be modelled too by using PEP440 - # compatible version specifiers. - # - # You can also remove the whole "octoprint" block. Removing it will default to all - # OctoPrint versions being supported. - - octoprint: - - 1.2.0 - - # List of compatible operating systems - # - # Valid values: - # - # - windows - # - linux - # - macos - # - freebsd - # - # There are also two OS groups defined that get expanded on usage: - # - # - posix: linux, macos and freebsd - # - nix: linux and freebsd - # - # You can also remove the whole "os" block. Removing it will default to all - # operating systems being supported. - - os: - - linux - - windows - - macos - - freebsd - - # Compatible Python version - # - # Plugins should aim for compatibility for Python 2 and 3 for now, in which case the value should be ">=2.7,<4". - # - # Plugins that only wish to support Python 3 should set it to ">=3,<4". - # - # If your plugin only supports Python 2 (worst case, not recommended for newly developed plugins since Python 2 - # is EOL), leave at ">=2.7,<3" - be aware that your plugin will not be allowed to register on the - # plugin repository if it only support Python 2. - - python: ">=2.7,<3" - ---- - -**TODO**: Longer description of your plugin, configuration examples etc. This part will be visible on the page at -http://plugins.octoprint.org/plugin/CalibrationTools/ diff --git a/extras/README.txt b/extras/README.txt deleted file mode 100644 index f3eb322..0000000 --- a/extras/README.txt +++ /dev/null @@ -1,8 +0,0 @@ -Currently Cookiecutter generates the following helpful extras to this folder: - -CalibrationTools.md - Data file for plugins.octoprint.org. Fill in the missing TODOs once your - plugin is ready for release and file a PR as described at - http://plugins.octoprint.org/help/registering/ to get it published. - -This folder may be safely removed if you don't need it. diff --git a/assets/PID-autotune.png b/extras/assets/img/plugins/CalibrationTools/PID-autotune.png similarity index 100% rename from assets/PID-autotune.png rename to extras/assets/img/plugins/CalibrationTools/PID-autotune.png diff --git a/assets/eSteps.png b/extras/assets/img/plugins/CalibrationTools/eSteps.png similarity index 100% rename from assets/eSteps.png rename to extras/assets/img/plugins/CalibrationTools/eSteps.png diff --git a/assets/XYZSteps.png b/extras/assets/img/plugins/CalibrationTools/featuredimage.png similarity index 100% rename from assets/XYZSteps.png rename to extras/assets/img/plugins/CalibrationTools/featuredimage.png diff --git a/octoprint_CalibrationTools/EStepsApi.py b/octoprint_CalibrationTools/EStepsApi.py index e0488f8..31d1bc3 100644 --- a/octoprint_CalibrationTools/EStepsApi.py +++ b/octoprint_CalibrationTools/EStepsApi.py @@ -26,9 +26,7 @@ class API(octoprint.plugin.SimpleApiPlugin): self._logger.debug("Load steps from EEPROM") if not self._printer.is_ready(): self._logger.warning("Printer not ready, operation canceled") - return flask.abort(503, { - "msg": "Printer not ready, operation canceled" - }) + return flask.abort(503, 'Printer not ready, operation canceled') # Register listener waiting response for M92 command m92Event = Event() @@ -46,9 +44,7 @@ class API(octoprint.plugin.SimpleApiPlugin): self._logger.debug("Heating the extruder [%s]", data) if not self._printer.is_ready(): self._logger.warning("Printer not ready, operation canceled") - return flask.abort(503, { - "msg": "Printer not ready, operation canceled" - }) + return flask.abort(503,"Printer not ready, operation canceled") # Register event to be trigger when temp is achieved self.registerEventTemp("T0", int(data["extrudeTemp"]), self.startExtrusion, data["extrudeLength"], data["extrudeSpeed"]) @@ -56,11 +52,12 @@ class API(octoprint.plugin.SimpleApiPlugin): self._printer.commands("M104 S%(extrudeTemp)s" % data) if command == CMD_ESTEPS_SAVE: - if "newESteps" not in data and ("newXSteps" not in data and "newYSteps" not in data and "newZSteps" not in data): - return flask.abort(400, { - "msg": "Invalid arguments. No value provided for X,Y, Z or E steps" - }) - + if (("newESteps" not in data or data["newESteps"] <= 0) + and + (("newXSteps" not in data or data["newXSteps"] <= 0) or + ("newYSteps" not in data or data["newYSteps"] <= 0) or + ("newZSteps" not in data or data["newZSteps"] <= 0))): + return flask.abort(400, "Invalid arguments. No value provided for X,Y, Z or E steps") stopHeater = [] if "newESteps" in data: eStepsSettings = self._settings.get(['eSteps']) @@ -90,7 +87,7 @@ class API(octoprint.plugin.SimpleApiPlugin): @staticmethod def m92GCodeResponse(self, line, regex, event): - reg = re.compile("echo:\s*(?P(?PM\d{1,3}) X(?P\d{1,3}.\d{1,3}) Y(?P\d{1,3}.\d{1,3}) Z(?P\d{1,3}.\d{1,3}) E(?P\d{1,3}.\d{1,3}))") + reg = re.compile("(echo:?)\s*(?P(?PM\d{1,3}) X(?P\d{1,3}.\d{1,3}) Y(?P\d{1,3}.\d{1,3}) Z(?P\d{1,3}.\d{1,3}) E(?P\d{1,3}.\d{1,3}))") isM92command = reg.match(line) if isM92command: command = isM92command.group("command") diff --git a/octoprint_CalibrationTools/api.py b/octoprint_CalibrationTools/api.py index 50a4807..c07fcef 100644 --- a/octoprint_CalibrationTools/api.py +++ b/octoprint_CalibrationTools/api.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera import traceback import flask +from werkzeug.exceptions import HTTPException from octoprint_CalibrationTools import EStepsApi, PIDAutoTune @@ -35,9 +36,7 @@ class API(EStepsApi.API, PIDAutoTune.API): ) except Exception as e: self._logger.error(traceback.format_exc()) - return flask.abort(500, { - "msg": "An error curred" - }) + return flask.abort(500, "An error curred") def on_api_command(self, command, data): try: @@ -47,6 +46,9 @@ class API(EStepsApi.API, PIDAutoTune.API): return api["cls"].apiGateWay(self, command, data) except Exception as e: self._logger.error(traceback.format_exc()) - return flask.abort(500, { - "msg": "An error curred" - }) + exCode = 500 + exMessage = "An error curred" + if isinstance(e, HTTPException): + exCode = e.code + exMessage = e.description + return flask.abort(exCode, exMessage) diff --git a/octoprint_CalibrationTools/static/js/EStepsViewModel.js b/octoprint_CalibrationTools/static/js/EStepsViewModel.js index 0531c6f..dc3a993 100644 --- a/octoprint_CalibrationTools/static/js/EStepsViewModel.js +++ b/octoprint_CalibrationTools/static/js/EStepsViewModel.js @@ -30,14 +30,14 @@ $(function () { self.results = {}; self.results["remainedLength"] = ko.observable(20); self.results["actualExtrusion"] = ko.computed(function () { - return (self.testParam.markLength() - self.results.remainedLength()).toFixed(3); + return self.generalVM.round(self.testParam.markLength() - self.results.remainedLength()); }); self.results["newSteps"] = ko.computed(function () { - return (self.steps.E() / self.results.actualExtrusion() * 100).toFixed(3); - }); - self.results["newStepsDisplay"] = ko.computed(function () { - return "M92 E" + self.results.newSteps(); + return self.generalVM.round(self.steps.E() / self.results.actualExtrusion() * 100); }); + // self.results["newStepsDisplay"] = ko.computed(function () { + // return "M92 E" + self.results.newSteps(); + // }); self.onBeforeBinding = self.onUserLoggedIn = self.onUserLoggedOut = function () { self.testParam.extrudeTemp(self.settingsViewModel.settings.plugins.CalibrationTools.eSteps.extrudeTemp()); @@ -70,18 +70,9 @@ $(function () { "extrudeLength": self.testParam.extrudeLength(), "extrudeSpeed": self.testParam.extrudeSpeed() }).done(function (response) { - new PNotify({ - title: "E axe calibration started", - text: "Heating nuzzle has started!!!
When extrusion stops you have to fulfil Length after extrusion and save the new value ", - type: "warning" - }); + self.generalVM.notifyWarning("E axe calibration started", "Heating nuzzle has started!!!
When extrusion stops you have to fulfil Length after extrusion and save the new value ") }).fail(function (response) { - new PNotify({ - title: "Error on starting extrusion ", - text: response.responseJSON.error, - type: "error", - hide: false - }); + self.generalVM.notifyError("Error on starting extrusion ", response.responseJSON.error); }).always(function (response) { self.startExtrusionActive(false); }); @@ -91,12 +82,8 @@ $(function () { OctoPrint.simpleApiCommand("CalibrationTools", "eSteps_save", { "newESteps": self.results.newSteps() }).done(function () { - new PNotify({ - title: "Saved", - text: self.results.newSteps() + " steps/mm had been set for E axe", - type: "info" - }); - }); + self.generalVM.notifyInfo("Saved", self.results.newSteps() + " steps/mm had been set for E axe"); + }).fail(self.generalVM.failedFunction); } self.onAllBound = self.onEventConnected = function () { diff --git a/octoprint_CalibrationTools/static/js/GeneralViewModel.js b/octoprint_CalibrationTools/static/js/GeneralViewModel.js index b4d398c..a19e6d4 100644 --- a/octoprint_CalibrationTools/static/js/GeneralViewModel.js +++ b/octoprint_CalibrationTools/static/js/GeneralViewModel.js @@ -1,7 +1,8 @@ $(function () { function CalibrationToolsGeneralViewModel(parameters) { this.loginState = parameters[0]; - this.decimal3 = function (defaultVal) { + var self = this; + self.decimal3 = function (defaultVal) { return { numeric: { decimals: 3, @@ -9,7 +10,7 @@ $(function () { } } } - this.isSmall = ko.observable($("#tab_plugin_CalibrationTools").width() < 800); + self.isSmall = ko.observable($("#tab_plugin_CalibrationTools").width() < 800); ko.extenders.numeric = function (target, options) { var returnObs = ko.pureComputed({ read: target, @@ -24,9 +25,33 @@ $(function () { return returnObs; }; - this.onStartupComplete = function () { + self.onStartupComplete = function () { this.isSmall($("#tabs_content").width() < 800); } + self.notify = function (title, message, type, hide) { + new PNotify({ + title: title, + text: message, + type: type, + hide: hide + }); + } + self.notifyError = function (title, message) { + self.notify(title, message, 'error', false); + } + self.notifyInfo = function (title, message) { + self.notify(title, message, 'info', true); + } + self.notifyWarning = function (title, message) { + self.notify(title, message, 'warning', false); + } + self.failedFunction = function (response) { + self.notifyError("Error", response.responseJSON.error); + } + self.round = function (number, decimals) { + decimals = decimals ? decimals : 3; + return +(Math.round(number + ("e+" + decimals)) + ("e-" + decimals)); + } } OCTOPRINT_VIEWMODELS.push({ // This is the constructor to call for instantiating the plugin diff --git a/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js b/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js index bb3c7d2..f92a50e 100644 --- a/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js +++ b/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js @@ -51,14 +51,7 @@ $(function () { self.pidCurrentValues.bed.P(response.data.bed.P); self.pidCurrentValues.bed.I(response.data.bed.I); self.pidCurrentValues.bed.D(response.data.bed.D); - }).fail(function (response) { - new PNotify({ - title: "Error on getting current PID values ", - text: response.responseJSON.error, - type: "error", - hide: false - }); - }); + }).fail(self.generalVM.failFunction); }; self.onBeforeBinding = self.onUserLoggedIn = self.onUserLoggedOut = function () { @@ -79,19 +72,8 @@ $(function () { "hotEndIndex": Number(self.pid.hotEnd.hotEndIndex()), "targetTemp": Number(self.pid.hotEnd.targetTemp()) }).done(function (response) { - new PNotify({ - title: "PID HotEnd tuning has started", - text: "In progress", - type: "info" - }); - }).fail(function (response) { - new PNotify({ - title: "Error on starting PID autotune ", - text: response.responseJSON.error, - type: "error", - hide: false - }); - }); + self.generalVM.notifyWarning("PID HotEnd tuning has started", "In progress"); + }).fail(self.generalVM.failFunction); } self.startPidBed = function () { OctoPrint.simpleApiCommand("CalibrationTools", "pid_start", { @@ -101,19 +83,8 @@ $(function () { "hotEndIndex": -1, "targetTemp": self.pid.bed.targetTemp() }).done(function (response) { - new PNotify({ - title: "PID HotEnd tuning has started", - text: "In progress", - type: "info" - }); - }).fail(function (response) { - new PNotify({ - title: "Error on starting PID autotune ", - text: response.responseJSON.error, - type: "error", - hide: false - }); - }); + self.generalVM.notifyWarning("PID Heated bed tuning has started", "In progress"); + }).fail(self.generalVM.failFunction); } } OCTOPRINT_VIEWMODELS.push({ diff --git a/octoprint_CalibrationTools/static/js/XYZStepsViewModel.js b/octoprint_CalibrationTools/static/js/XYZStepsViewModel.js index dee0e96..22adf01 100644 --- a/octoprint_CalibrationTools/static/js/XYZStepsViewModel.js +++ b/octoprint_CalibrationTools/static/js/XYZStepsViewModel.js @@ -33,15 +33,15 @@ $(function () { Z: ko.observable().extend(self.generalVM.decimal3(0.000)) } }; - + // self.generalVM.decimal3(10.000) self.eStepsXYZ.newSteps.X = ko.computed(function () { - return parseFloat(self.eStepsXYZ.currentSteps.X() * self.eStepsXYZ.gCodeCubeSize.X() / self.eStepsXYZ.printedCubeSize.X()).toFixed(3); + return self.generalVM.round(self.eStepsXYZ.currentSteps.X() * self.eStepsXYZ.gCodeCubeSize.X() / self.eStepsXYZ.printedCubeSize.X()); }, self); self.eStepsXYZ.newSteps.Y = ko.computed(function () { - return parseFloat(self.eStepsXYZ.currentSteps.Y() * self.eStepsXYZ.gCodeCubeSize.Y() / self.eStepsXYZ.printedCubeSize.Y()).toFixed(3); + return self.generalVM.round(self.eStepsXYZ.currentSteps.Y() * self.eStepsXYZ.gCodeCubeSize.Y() / self.eStepsXYZ.printedCubeSize.Y()); }, self); self.eStepsXYZ.newSteps.Z = ko.computed(function () { - return parseFloat(self.eStepsXYZ.currentSteps.Z() * self.eStepsXYZ.gCodeCubeSize.Z() / self.eStepsXYZ.printedCubeSize.Z()).toFixed(3); + return self.generalVM.round(self.eStepsXYZ.currentSteps.Z() * self.eStepsXYZ.gCodeCubeSize.Z() / self.eStepsXYZ.printedCubeSize.Z()); }, self); self.loadEStepsActive = ko.observable(true); @@ -58,20 +58,17 @@ $(function () { self.saveEStepsXYZActive = ko.observable(true) self.saveEStepsXYZ = function () { + console.log(self.eStepsXYZ.newSteps.X()); self.saveEStepsXYZActive(false); OctoPrint.simpleApiCommand("CalibrationTools", "eSteps_save", { "newXSteps": self.eStepsXYZ.newSteps.X(), "newYSteps": self.eStepsXYZ.newSteps.Y(), "newZSteps": self.eStepsXYZ.newSteps.Z() }).done(function (response) { - new PNotify({ - title: "Saved", - text: "X: " + self.eStepsXYZ.newSteps.X() + "steps/mm
Y: " + self.eStepsXYZ.newSteps.Y() + "steps/mm
Z: " + self.eStepsXYZ.newSteps.Z() + " steps/mm
had been set for X/Y/Z axes", - type: "info" - }); + self.generalVM.notifyInfo("Saved", "X: " + self.eStepsXYZ.newSteps.X() + "steps/mm
Y: " + self.eStepsXYZ.newSteps.Y() + "steps/mm
Z: " + self.eStepsXYZ.newSteps.Z() + " steps/mm
had been set for X/Y/Z axes"); }).always(function (response) { self.saveEStepsXYZActive(true); - }) + }).fail(self.generalVM.failedFunction) }; // self.labelColumnCss = viewModel.profitStatus = ko.pureComputed(function () { @@ -88,7 +85,6 @@ $(function () { self.eStepsXYZ.printedCubeSize.X(self.settingsViewModel.settings.plugins.CalibrationTools.XYZSteps.gCodeCubeSize.X()); self.eStepsXYZ.printedCubeSize.Y(self.settingsViewModel.settings.plugins.CalibrationTools.XYZSteps.gCodeCubeSize.Y()); self.eStepsXYZ.printedCubeSize.Z(self.settingsViewModel.settings.plugins.CalibrationTools.XYZSteps.gCodeCubeSize.Z()); - } } OCTOPRINT_VIEWMODELS.push({ diff --git a/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 b/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 index 7e82281..8cbe1c2 100644 --- a/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 +++ b/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 @@ -55,18 +55,8 @@ self.restart = function () { OctoPrint.system.executeCommand('core', 'restart') }; self.test = function () { OctoPrint.simpleApiCommand("CalibrationTools", "pid_save").done(function (response) { - new PNotify({ - title: "Saved", - text: "PID values successfully saved", - type: "info" - }); - }).fail(function (response) { - new PNotify({ - title: "Test request", - text: response.responseJSON.error.msg, - type: "error" - }); - }); + self.generalVM.notifyInfo("Saved", "PID values successfully saved"); + }).fail(self.generalVM.failFunction);; }; self.onSettingsClick = function () { diff --git a/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 b/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 index 9139223..661fcfb 100644 --- a/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 +++ b/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 @@ -106,7 +106,8 @@ reliable.
{{ snipped.linkToMarlin("M092", "Marlin website") }} - + M92 E + {{ snipped.m500Icon() }}
diff --git a/octoprint_CalibrationTools/templates/tabs/tab-xyz.jinja2 b/octoprint_CalibrationTools/templates/tabs/tab-xyz.jinja2 index e5e88c3..afc05a1 100644 --- a/octoprint_CalibrationTools/templates/tabs/tab-xyz.jinja2 +++ b/octoprint_CalibrationTools/templates/tabs/tab-xyz.jinja2 @@ -80,7 +80,7 @@ sized."," {{ snipped.linkToMarlin("M092", "Marlin website") }} M92   X - +    Y    Z diff --git a/setup.py b/setup.py index 8827360..13a8b2b 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_package = "octoprint_CalibrationTools" plugin_name = "OctoPrint-CalibrationTools" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.1" +plugin_version = "1.0.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module