diff --git a/octoprint_CalibrationTools/__init__.py b/octoprint_CalibrationTools/__init__.py index 9114d38..80d5afc 100644 --- a/octoprint_CalibrationTools/__init__.py +++ b/octoprint_CalibrationTools/__init__.py @@ -20,7 +20,6 @@ class CalibrationtoolsPlugin( def initialize(self): self.collectCommand = False - # self._api = api.API(self) def on_after_startup(self): self._logger.debug("----------------[ CalibrationTools ]----------------") @@ -36,8 +35,6 @@ class CalibrationtoolsPlugin( "js": ["js/CalibrationTools.js"], "css": ["css/style.css"] } - def startExtrusion(self, temps): - self._logger.debug("Temperature achieved, extrusion started %s", temps) def get_update_information(self): # Define the configuration for your plugin to use with the Software Update diff --git a/octoprint_CalibrationTools/api.py b/octoprint_CalibrationTools/api.py index f0950cb..b778c6f 100644 --- a/octoprint_CalibrationTools/api.py +++ b/octoprint_CalibrationTools/api.py @@ -5,9 +5,11 @@ import octoprint.plugin import flask -CMD_LOAD_STEPS = "loadSteps" CMD_TEST = "TEST" +CMD_LOAD_STEPS = "loadSteps" CMD_START_EXTRUSION = "startExtrusion" +CMD_SAVE_E_STEPS = "saveESteps" + def someTestFunc(self, temps): self._logger.debug("a ajuns %s", temps) @@ -19,6 +21,7 @@ class API(octoprint.plugin.SimpleApiPlugin): return { CMD_LOAD_STEPS: [], CMD_START_EXTRUSION: [], + CMD_SAVE_E_STEPS: [], CMD_TEST: [] } @@ -33,16 +36,45 @@ class API(octoprint.plugin.SimpleApiPlugin): def on_api_command(self, command, data): self._logger.debug("api command [%s] received", command) if command == CMD_LOAD_STEPS: + if not self._printer.is_ready(): + self._logger.warning("Printer not ready, operation canceled") + return flask.abort(503, { + "msg": "Printer not ready, operation canceled" + }) + self._printer.commands("M92") + return flask.jsonify({ "data": self.data["steps"] }) + if command == CMD_START_EXTRUSION: self._logger.debug("Heating the tools") - self._printer.commands("M104 S180") + if not self._printer.is_ready(): + self._logger.warning("Printer not ready, operation canceled") + return flask.abort(503, { + "msg": "Printer not ready, operation canceled" + }) + + # Register event to be trigger when temp is achieved self.registerEventTemp("T0", 180, self.startExtrusion) + # Heating the tool + self._printer.commands("M104 S180") return + + if command == CMD_SAVE_E_STEPS: + return + if command == CMD_TEST: - self.registerEventTemp("T0", 100, someTestFunc) - return + # self.registerEventTemp("T0", 100, someTestFunc) + return flask.abort(503, { + "msg": "Printer not ready, operation canceled" + }) + + @staticmethod + def startExtrusion(self, temps, *args): + self._logger.debug("Temperature achieved, extrusion started %s, %s", temps, args) + + # Extrude + self._printer.extrude(amount=120, speed=50) diff --git a/octoprint_CalibrationTools/hooks.py b/octoprint_CalibrationTools/hooks.py index f42a6d4..0713afe 100644 --- a/octoprint_CalibrationTools/hooks.py +++ b/octoprint_CalibrationTools/hooks.py @@ -72,6 +72,7 @@ class Hooks(): if event["tool"] == tool and curTemp >= event["targetTemp"]: arg = (temps, *event["args"]) if isinstance(event["func"], types.FunctionType): + self._logger.debug("addSelf") arg = (self, *arg) threading.Thread(target=event["func"], args=arg).start() self.events.remove(event) @@ -88,5 +89,5 @@ class Hooks(): "func": func, "args": arguments } - self._logger.debug("Registering event [%s]", event) + self._logger.debug("Registering event [%s, isFunction: %s]", event, isinstance(func, types.FunctionType)) self.events.append(event) diff --git a/octoprint_CalibrationTools/static/js/CalibrationTools.js b/octoprint_CalibrationTools/static/js/CalibrationTools.js index e653258..dd62392 100644 --- a/octoprint_CalibrationTools/static/js/CalibrationTools.js +++ b/octoprint_CalibrationTools/static/js/CalibrationTools.js @@ -15,10 +15,16 @@ $(function () { self.steps["E"] = ko.observable(); self.results = {}; + self.testParam = {}; + self.testParam["extrudeTemp"] = ko.observable(210); + self.testParam["extrudeLength"] = ko.observable(100); + self.testParam["extrudeSpeed"] = ko.observable(50); + self.testParam["markLength"] = ko.observable(120); + self.results["remainedLength"] = ko.observable(20); - self.results["markLength"] = ko.observable(120); + self.results["actualExtrusion"] = ko.computed(function () { - return (self.results.markLength() - self.results.remainedLength()).toFixed(3); + return (self.testParam.markLength() - self.results.remainedLength()).toFixed(3); }); self.results["newSteps"] = ko.computed(function () { @@ -47,14 +53,15 @@ $(function () { OctoPrint.simpleApiCommand("CalibrationTools","loadSteps").done(function (response) { self.from_json(response); }) - // OctoPrint.simpleApiGet("CalibrationTools").done(function (response) { - // console.log("CalibrationTools"); - // self.from_json(response); - // }); } self.startExtrusion = function () { - OctoPrint.simpleApiCommand("CalibrationTools","startExtrusion").done(function (response) { + OctoPrint.simpleApiCommand("CalibrationTools", "startExtrusion").done(function (response) { + new PNotify({ + title: "Test request", + text: "Heating nuzzle has started!!!
When extrusion stops you have to fulfil Length after extrusion and save the new value ", + type: "info" + }); console.log(response); }) } @@ -62,8 +69,8 @@ $(function () { self.tempRestart = function () { OctoPrint.system.executeCommand("core", "restart"); } - self.runCommand = function () { - OctoPrint.control.sendGcodeWithParameters("G90"); + self.saveESteps = function () { + OctoPrint.system.executeCommand("core", "restart"); } self.onAllBound = self.onEventConnected = function () { @@ -74,8 +81,14 @@ $(function () { } self.test = function () { - OctoPrint.simpleApiCommand("CalibrationTools","TEST").done(function (response) { + OctoPrint.simpleApiCommand("CalibrationTools", "TEST").done(function (response) { console.log(response) + }).fail(function (response) { + new PNotify({ + title: "Test request", + text: response.responseJSON.error.msg, + type: "error" + }); }) } diff --git a/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 b/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 index 5f060c5..63a22b2 100644 --- a/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 +++ b/octoprint_CalibrationTools/templates/CalibrationTools_tab.jinja2 @@ -4,12 +4,12 @@

Calibration

-
+ + +
+
+
+ M104    S + +
-{{ snipped.subSection("Compute", true) }} +
+
+ +
+
+
+ G1   E + +    F + +
+
+
+ +{{ snipped.field("Extrusion marking length", "The length marked on filament before extrusion. ", "number", "$root.testParam.markLength", "true", "mm") }}
@@ -27,27 +49,46 @@
+{{ snipped.subSection("Test results", true) }} + +
+
+ +
+
+
+ + steps/mm + +
+
+
+ +{{ snipped.field("Length after extrusion", "The remained length between filament mark and extruder entry", "number", "$root.results.remainedLength", "true", "mm") }} {{ snipped.field("Actual extrusion", "How much filament has been extruded", "number", "$root.results.actualExtrusion", "false", "mm") }} {{ snipped.field("New steps/mm", "The new number of steps/mm which should be set on EEPROM", "number", "$root.results.newSteps", "false", "steps/mm") }} -{{ snipped.field("Extrusion marking length", "The length marked on filament before extrusion", "number", "$root.results.markLength", "true", "mm") }} -{{ snipped.field("Measured value", "The length between filament mark and extruder entry after extrusion", "number", "$root.results.remainedLength", "true", "mm") }} -
+
+ {{ snipped.subSection("Process description", true) }} {{ snipped.quote(" First Read this

This calibration is best done with the extruder detached from the hot end, so no restriction is present on the movement. If it is convenient, you can partially disassemble the printer so the output of the extruder is open and the filament exits in free air. If this is inconvenient, the process below aims to minimize restrictions by extruding very slowly and with a slightly higher temperature. The results from this should still be reliable. -", "text-warning" ) }} - - +", "text-warning" ) }} \ No newline at end of file